feat(web): design tokens, Tailwind config, base components (TEC-3057)

- Add chart palette, motion, and z-index CSS vars to globals.css
- Replace custom theme-provider with next-themes (dark default)
- Extend tailwind.config.ts with heading fonts, spacing (row-compact,
  row-roomy, sidebar), chart colors, elevation shadows, glow shadows,
  transition timing, pill border-radius, z-index scale
- Update tick-flash animations to match design token spec (480ms)
- Add prefers-reduced-motion support for all animations
- Create base design-system components:
  Surface, SurfaceElevated, Divider, DensityProvider/useDensity,
  Numeric (VND/percent/compact formatting), Signal (up/down/neutral pill)
- Add dev-only /dev/tokens showcase route (404 in production)
- Update theme-provider tests to match next-themes integration

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-21 03:19:40 +07:00
parent e1beda2573
commit 7d6fcb4d8d
13 changed files with 665 additions and 138 deletions

View File

@@ -1,51 +1,31 @@
'use client';
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
type Theme = 'light' | 'dark';
interface ThemeContextValue {
theme: Theme;
toggleTheme: () => void;
}
const ThemeContext = createContext<ThemeContextValue>({
theme: 'light',
toggleTheme: () => {},
});
export function useTheme() {
return useContext(ThemeContext);
}
const STORAGE_KEY = 'goodgo-theme';
import { ThemeProvider as NextThemesProvider, useTheme as useNextTheme } from 'next-themes';
export function ThemeProvider({ children }: { children: React.ReactNode }) {
const [theme, setTheme] = useState<Theme>('light');
useEffect(() => {
const stored = localStorage.getItem(STORAGE_KEY) as Theme | null;
if (stored === 'dark' || stored === 'light') {
setTheme(stored);
document.documentElement.classList.toggle('dark', stored === 'dark');
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
setTheme('dark');
document.documentElement.classList.add('dark');
}
}, []);
const toggleTheme = useCallback(() => {
setTheme((prev) => {
const next = prev === 'light' ? 'dark' : 'light';
localStorage.setItem(STORAGE_KEY, next);
document.documentElement.classList.toggle('dark', next === 'dark');
return next;
});
}, []);
return (
<ThemeContext.Provider value={{ theme, toggleTheme }}>
<NextThemesProvider
attribute="class"
defaultTheme="dark"
storageKey="goodgo-theme"
enableSystem={false}
>
{children}
</ThemeContext.Provider>
</NextThemesProvider>
);
}
/**
* Backward-compatible useTheme hook.
* Returns `theme` ('light' | 'dark') and `toggleTheme`.
*/
export function useTheme() {
const { theme, setTheme, resolvedTheme } = useNextTheme();
const current = (resolvedTheme ?? theme ?? 'dark') as 'light' | 'dark';
const toggleTheme = () => {
setTheme(current === 'dark' ? 'light' : 'dark');
};
return { theme: current, toggleTheme };
}