🎨 feat(web/default): add Anthropic theme preset and configurable serif typography
Introduce a switchable Anthropic-inspired color preset and a new Font customization axis so users can adopt the editorial serif look across the entire UI, including sidebar navigation, tabs, form controls, buttons, and table headers. Theme preset Add anthropic to the theme preset registry with warm cream canvas, slate foreground, and clay/coral accent tokens for light and dark modes Define explicit surface colors for the Anthropic preset instead of relying on the semantic surface bridge Exclude anthropic from the primary-color surface bridge so bespoke warm neutrals are not overridden by accent-tinted mixes Typography system Add @fontsource-variable/lora and a global --font-serif token with CJK serif fallbacks (Noto Serif SC, Source Han Serif, Songti SC, etc.) Introduce a --font-body token and drive <body> font-family from it Add a Font axis (default | sans | serif) parallel to radius/scale Resolve font: 'default' against preset defaults (anthropic → serif) Persist font preference via cookie and apply data-theme-font on <body> Apply serif OpenType features (kern, liga, calt, tnum) and heading display tuning when serif is active Remove per-component sans opt-outs so serif inherits through sidebar, tabs, inputs, buttons, badges, and table headers via natural CSS cascade Keep monospace contexts unchanged via Tailwind preflight and .font-mono UI and i18n Add Font selector to the theme config drawer (Auto / Sans / Serif) Add "Font" and "Select body font" translations for en, zh, fr, ja, ru, vi Misc Tighten group and status badge sizing for better balance with serif text
This commit is contained in:
+37
-2
@@ -29,11 +29,14 @@ import {
|
||||
CONTENT_LAYOUT_VALUES,
|
||||
type ContentLayout,
|
||||
DEFAULT_THEME_CUSTOMIZATION,
|
||||
resolveThemeFont,
|
||||
THEME_COOKIE_KEYS,
|
||||
THEME_FONT_VALUES,
|
||||
THEME_PRESET_VALUES,
|
||||
THEME_RADIUS_VALUES,
|
||||
THEME_SCALE_VALUES,
|
||||
type ThemeCustomization,
|
||||
type ThemeFont,
|
||||
type ThemePreset,
|
||||
type ThemeRadius,
|
||||
type ThemeScale,
|
||||
@@ -65,6 +68,7 @@ type ThemeCustomizationContextType = {
|
||||
defaults: ThemeCustomization
|
||||
customization: ThemeCustomization
|
||||
setPreset: (preset: ThemePreset) => void
|
||||
setFont: (font: ThemeFont) => void
|
||||
setRadius: (radius: ThemeRadius) => void
|
||||
setScale: (scale: ThemeScale) => void
|
||||
setContentLayout: (contentLayout: ContentLayout) => void
|
||||
@@ -79,6 +83,7 @@ const FALLBACK_CONTEXT: ThemeCustomizationContextType = {
|
||||
defaults: DEFAULT_THEME_CUSTOMIZATION,
|
||||
customization: DEFAULT_THEME_CUSTOMIZATION,
|
||||
setPreset: () => {},
|
||||
setFont: () => {},
|
||||
setRadius: () => {},
|
||||
setScale: () => {},
|
||||
setContentLayout: () => {},
|
||||
@@ -98,6 +103,13 @@ export function ThemeCustomizationProvider(props: {
|
||||
DEFAULT_THEME_CUSTOMIZATION.preset
|
||||
)
|
||||
)
|
||||
const [font, _setFont] = useState<ThemeFont>(() =>
|
||||
readCookie<ThemeFont>(
|
||||
THEME_COOKIE_KEYS.font,
|
||||
THEME_FONT_VALUES,
|
||||
DEFAULT_THEME_CUSTOMIZATION.font
|
||||
)
|
||||
)
|
||||
const [radius, _setRadius] = useState<ThemeRadius>(() =>
|
||||
readCookie<ThemeRadius>(
|
||||
THEME_COOKIE_KEYS.radius,
|
||||
@@ -129,6 +141,16 @@ export function ThemeCustomizationProvider(props: {
|
||||
)
|
||||
}, [preset])
|
||||
|
||||
// Font is the one axis where we resolve before writing the attribute:
|
||||
// the persisted preference may be `default`, but CSS works in terms of
|
||||
// the concrete `sans`/`serif` choice that should drive the cascade.
|
||||
// Resolving here (instead of in CSS via `:not()` selectors) keeps the
|
||||
// stylesheet to one simple `[data-theme-font='serif']` selector and lets
|
||||
// future presets opt into typography via `PRESET_DEFAULT_FONT` alone.
|
||||
useEffect(() => {
|
||||
applyAttribute('data-theme-font', resolveThemeFont(font, preset))
|
||||
}, [font, preset])
|
||||
|
||||
useEffect(() => {
|
||||
applyAttribute(
|
||||
'data-theme-radius',
|
||||
@@ -156,6 +178,15 @@ export function ThemeCustomizationProvider(props: {
|
||||
}
|
||||
}, [])
|
||||
|
||||
const setFont = useCallback((value: ThemeFont) => {
|
||||
_setFont(value)
|
||||
if (value === DEFAULT_THEME_CUSTOMIZATION.font) {
|
||||
removeCookie(THEME_COOKIE_KEYS.font)
|
||||
} else {
|
||||
setCookie(THEME_COOKIE_KEYS.font, value, COOKIE_MAX_AGE)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const setRadius = useCallback((value: ThemeRadius) => {
|
||||
_setRadius(value)
|
||||
if (value === DEFAULT_THEME_CUSTOMIZATION.radius) {
|
||||
@@ -185,16 +216,18 @@ export function ThemeCustomizationProvider(props: {
|
||||
|
||||
const resetCustomization = useCallback(() => {
|
||||
setPreset(DEFAULT_THEME_CUSTOMIZATION.preset)
|
||||
setFont(DEFAULT_THEME_CUSTOMIZATION.font)
|
||||
setRadius(DEFAULT_THEME_CUSTOMIZATION.radius)
|
||||
setScale(DEFAULT_THEME_CUSTOMIZATION.scale)
|
||||
setContentLayout(DEFAULT_THEME_CUSTOMIZATION.contentLayout)
|
||||
}, [setPreset, setRadius, setScale, setContentLayout])
|
||||
}, [setPreset, setFont, setRadius, setScale, setContentLayout])
|
||||
|
||||
const value = useMemo<ThemeCustomizationContextType>(
|
||||
() => ({
|
||||
defaults: DEFAULT_THEME_CUSTOMIZATION,
|
||||
customization: { preset, radius, scale, contentLayout },
|
||||
customization: { preset, font, radius, scale, contentLayout },
|
||||
setPreset,
|
||||
setFont,
|
||||
setRadius,
|
||||
setScale,
|
||||
setContentLayout,
|
||||
@@ -202,10 +235,12 @@ export function ThemeCustomizationProvider(props: {
|
||||
}),
|
||||
[
|
||||
preset,
|
||||
font,
|
||||
radius,
|
||||
scale,
|
||||
contentLayout,
|
||||
setPreset,
|
||||
setFont,
|
||||
setRadius,
|
||||
setScale,
|
||||
setContentLayout,
|
||||
|
||||
Reference in New Issue
Block a user