🎨 fix(web): align UI and charts with theme tokens and presets

Improve theme switching fidelity (including system preference), extend design tokens so color presets tint real surfaces—not only primary/chrome—and refactor shared badges, tables, and dashboard visuals to semantic colors. Wire VChart series colors to `--chart-*` with safe fallbacks.

**Changes**

- **Theme runtime** (`theme-provider.tsx`): Validate stored theme cookie; keep `resolvedTheme` in sync with DOM + `(prefers-color-scheme)`; `resetTheme` respects `defaultTheme`; memoized context value.
- **Tokens** (`theme.css`): Add `--success|warning|info|neutral` (+ foregrounds) and map them under `@theme inline` for Tailwind utilities.
- **Presets** (`theme-presets.css`): For non-`default` presets, derive `card`, `popover`, `muted`, `accent`, `border`, `input`, and sidebar tokens from `--primary`/`--background`; map semantic status colors to preset chart variables.
- **Components**: `status-badge`, `colors` (avatars, announcements), `copy-button`, `group-badge`, `data-table` row styles, `sidebar` outline shadow (fix `var(--sidebar-border)` usage), ai-elements tool/web-preview status colors.
- **Dashboard**: Latency/API helpers and overview fragments use semantic tokens; `charts.ts` reads `--chart-1`…`--chart-5` from computed styles with fallbacks; `processChartData` / `processUserChartData` accept optional `themeKey` for preset churn; chart components pass `customization.preset` and bump `VChart` keys.

**Verification**

- `bun run typecheck`
This commit is contained in:
t0ng7u
2026-05-07 11:20:43 +08:00
parent 415d21d071
commit a7475a1e67
19 changed files with 315 additions and 172 deletions
+5 -5
View File
@@ -57,11 +57,11 @@ const getStatusBadge = (status: ExtendedToolState) => {
const icons: Record<ExtendedToolState, ReactNode> = {
'input-streaming': <CircleIcon className='size-4' />,
'input-available': <ClockIcon className='size-4 animate-pulse' />,
'approval-requested': <ClockIcon className='size-4 text-yellow-600' />,
'approval-responded': <CheckCircleIcon className='size-4 text-blue-600' />,
'output-available': <CheckCircleIcon className='size-4 text-green-600' />,
'output-error': <XCircleIcon className='size-4 text-red-600' />,
'output-denied': <XCircleIcon className='size-4 text-orange-600' />,
'approval-requested': <ClockIcon className='text-warning size-4' />,
'approval-responded': <CheckCircleIcon className='text-info size-4' />,
'output-available': <CheckCircleIcon className='text-success size-4' />,
'output-error': <XCircleIcon className='text-destructive size-4' />,
'output-denied': <XCircleIcon className='text-warning size-4' />,
}
return (
+1 -1
View File
@@ -258,7 +258,7 @@ export const WebPreviewConsole = ({
className={cn(
'text-xs',
log.level === 'error' && 'text-destructive',
log.level === 'warn' && 'text-yellow-600',
log.level === 'warn' && 'text-warning',
log.level === 'log' && 'text-foreground'
)}
key={`${log.timestamp.getTime()}-${index}`}
+1 -1
View File
@@ -50,7 +50,7 @@ export function CopyButton({
aria-label={isCopied ? copiedAriaLabel : resolvedAriaLabel}
>
{isCopied ? (
<Check className={cn('text-green-600', iconClassName)} />
<Check className={cn('text-success', iconClassName)} />
) : (
<Copy className={cn(iconClassName)} />
)}
+2 -2
View File
@@ -10,7 +10,7 @@ export { MobileCardList } from './mobile-card-list'
export { DataTablePage, type DataTablePageProps } from './data-table-page'
export const DISABLED_ROW_DESKTOP =
'bg-muted/85 hover:bg-muted [&>td:first-child]:border-l-muted-foreground/35 dark:bg-zinc-700/55 dark:hover:bg-zinc-700/70 [&>td:first-child]:border-l-4 [&>td:first-child]:pl-1 dark:[&>td:first-child]:border-l-zinc-300/70'
'bg-muted/85 hover:bg-muted [&>td:first-child]:border-l-muted-foreground/35 [&>td:first-child]:border-l-4 [&>td:first-child]:pl-1'
export const DISABLED_ROW_MOBILE =
'border-l-4 border-l-muted-foreground/35 bg-muted/85 dark:border-l-zinc-300/70 dark:bg-zinc-700/55'
'border-l-4 border-l-muted-foreground/35 bg-muted/85'
+2 -2
View File
@@ -13,10 +13,10 @@ type GroupBadgeProps = Omit<
function getGroupRatioClassName(ratio: number): string {
if (ratio > 1) {
return 'border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/40 dark:text-amber-300'
return 'border-warning/25 bg-warning/10 text-warning'
}
if (ratio < 1) {
return 'border-sky-200 bg-sky-50 text-sky-700 dark:border-sky-900/60 dark:bg-sky-950/40 dark:text-sky-300'
return 'border-info/25 bg-info/10 text-info'
}
return 'border-border bg-muted text-muted-foreground'
}
+40 -40
View File
@@ -6,51 +6,51 @@ import { cn } from '@/lib/utils'
import { useCopyToClipboard } from '@/hooks/use-copy-to-clipboard'
export const dotColorMap = {
success: 'bg-emerald-500',
warning: 'bg-amber-500',
danger: 'bg-rose-500',
info: 'bg-sky-500',
neutral: 'bg-slate-400',
purple: 'bg-purple-500',
amber: 'bg-amber-500',
blue: 'bg-blue-500',
cyan: 'bg-cyan-500',
green: 'bg-green-500',
grey: 'bg-gray-500',
indigo: 'bg-indigo-500',
'light-blue': 'bg-sky-500',
'light-green': 'bg-green-500',
lime: 'bg-lime-500',
orange: 'bg-orange-500',
pink: 'bg-pink-500',
red: 'bg-red-500',
teal: 'bg-teal-500',
violet: 'bg-violet-500',
yellow: 'bg-yellow-500',
success: 'bg-success',
warning: 'bg-warning',
danger: 'bg-destructive',
info: 'bg-info',
neutral: 'bg-neutral',
purple: 'bg-chart-4',
amber: 'bg-warning',
blue: 'bg-chart-1',
cyan: 'bg-chart-2',
green: 'bg-success',
grey: 'bg-neutral',
indigo: 'bg-chart-1',
'light-blue': 'bg-info',
'light-green': 'bg-success',
lime: 'bg-chart-3',
orange: 'bg-warning',
pink: 'bg-chart-5',
red: 'bg-destructive',
teal: 'bg-chart-2',
violet: 'bg-chart-4',
yellow: 'bg-warning',
} as const
export const textColorMap = {
success: 'text-emerald-700 dark:text-emerald-400',
warning: 'text-amber-700 dark:text-amber-400',
danger: 'text-rose-700 dark:text-rose-400',
info: 'text-sky-700 dark:text-sky-400',
success: 'text-success',
warning: 'text-warning',
danger: 'text-destructive',
info: 'text-info',
neutral: 'text-muted-foreground',
purple: 'text-purple-700 dark:text-purple-400',
amber: 'text-amber-700 dark:text-amber-400',
blue: 'text-blue-700 dark:text-blue-400',
cyan: 'text-cyan-700 dark:text-cyan-400',
green: 'text-green-700 dark:text-green-400',
purple: 'text-chart-4',
amber: 'text-warning',
blue: 'text-chart-1',
cyan: 'text-chart-2',
green: 'text-success',
grey: 'text-muted-foreground',
indigo: 'text-indigo-700 dark:text-indigo-400',
'light-blue': 'text-sky-700 dark:text-sky-400',
'light-green': 'text-green-600 dark:text-green-400',
lime: 'text-lime-700 dark:text-lime-400',
orange: 'text-orange-700 dark:text-orange-400',
pink: 'text-pink-700 dark:text-pink-400',
red: 'text-red-700 dark:text-red-400',
teal: 'text-teal-700 dark:text-teal-400',
violet: 'text-violet-700 dark:text-violet-400',
yellow: 'text-yellow-700 dark:text-yellow-400',
indigo: 'text-chart-1',
'light-blue': 'text-info',
'light-green': 'text-success',
lime: 'text-chart-3',
orange: 'text-warning',
pink: 'text-chart-5',
red: 'text-destructive',
teal: 'text-chart-2',
violet: 'text-chart-4',
yellow: 'text-warning',
} as const
export type StatusVariant = keyof typeof dotColorMap
+1 -1
View File
@@ -481,7 +481,7 @@ const sidebarMenuButtonVariants = cva(
variant: {
default: 'hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
outline:
'bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]',
'bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]',
},
size: {
default: 'h-8 text-sm',