summaryrefslogtreecommitdiff
path: root/frontend/src/lib
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-18 12:03:27 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-18 12:03:27 +0800
commit1f16a357213611a6d7f84e506064fc0d9c6317c6 (patch)
tree780f53b2068c1c47e2cee9f08075a31514c66d2c /frontend/src/lib
parenta9e5053e51501346bd956609157aa2d1df75f566 (diff)
downloadstrategy-lab-1f16a357213611a6d7f84e506064fc0d9c6317c6.tar.gz
[变更性质] feat(frontend)
[新增功能] round3 主题基建:shadcn preset CLI init(mira)+ app.css 重写 + theme.ts 双主题 [实现方案] 无 legacy 组件选择器的全新 app.css(mint/amber 双 token 组、--radius 0.75rem、保留布局原语);theme.ts 持久化 .theme-amber;utils.ts 本地 cn 实现 [影响范围] frontend/src/app.css、src/lib/theme.ts、utils.ts、package.json
Diffstat (limited to 'frontend/src/lib')
-rw-r--r--frontend/src/lib/theme.ts28
-rw-r--r--frontend/src/lib/utils.ts6
2 files changed, 31 insertions, 3 deletions
diff --git a/frontend/src/lib/theme.ts b/frontend/src/lib/theme.ts
new file mode 100644
index 0000000..ad949a4
--- /dev/null
+++ b/frontend/src/lib/theme.ts
@@ -0,0 +1,28 @@
+// 主题切换(round3):默认 mint;.theme-amber 类挂 <html> 切到 amber 变量组。
+// 两套 token 都是 app.css 里的 CSS 变量组,本模块只负责持久化与挂类。
+
+export type BrandTheme = 'mint' | 'amber';
+const KEY = 'sl-brand-theme';
+
+export function currentTheme(): BrandTheme {
+ if (typeof document === 'undefined' || typeof localStorage === 'undefined') return 'mint';
+ const stored = localStorage.getItem(KEY);
+ return stored === 'amber' ? 'amber' : 'mint';
+}
+
+export function applyTheme(t: BrandTheme): void {
+ if (typeof document === 'undefined') return;
+ if (t === 'amber') document.documentElement.classList.add('theme-amber');
+ else document.documentElement.classList.remove('theme-amber');
+ if (typeof localStorage !== 'undefined') localStorage.setItem(KEY, t);
+}
+
+export function toggleTheme(): BrandTheme {
+ const next: BrandTheme = currentTheme() === 'mint' ? 'amber' : 'mint';
+ applyTheme(next);
+ return next;
+}
+
+if (typeof document !== 'undefined') {
+ applyTheme(currentTheme());
+}
diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts
index 55b3a91..8048253 100644
--- a/frontend/src/lib/utils.ts
+++ b/frontend/src/lib/utils.ts
@@ -1,7 +1,7 @@
-import { clsx, type ClassValue } from "clsx";
-import { twMerge } from "tailwind-merge";
+import { clsx, type ClassValue } from 'clsx';
+import { twMerge } from 'tailwind-merge';
-export function cn(...inputs: ClassValue[]) {
+export function cn(...inputs: ClassValue[]): string {
return twMerge(clsx(inputs));
}