Skip to content

zidane-ui/appearance

import { … } from 'zidane-ui/appearance'ui/src/appearance/index.ts

Components#

AppearanceProviderComponent#

Applies the host's appearance to the document and provides it to the hooks below: the active theme and palette, contrast, accent, fonts, the code theme and the motion policy.

TypeScript
function AppearanceProvider(props: AppearanceProviderProps): Element
Parameters
NameTypeDescription
propsAppearanceProviderProps

See AppearanceProviderProps.

Element
AppearanceProvider props
NameTypeDescription
childrenReactNode

The app.

extensions?ExtensionsHost

The extensions host: its Theme items are offered too, after the host's own extra themes. One theme id shows once (the appearance host's copy wins: zidane's registry serves extension themes through host.themes as well). AppHostProvider passes AppHost.extensions.

folder?string | null

The folder whose extra themes are offered (host.themes). Without one, the last folder's stay.

hostAppearanceHost

Where the preferences live, the extra themes, the snapshot and the window effects.

legacyThemeId?string

A theme id from elsewhere (zidane's shared Settings.theme), read once on the first run to seed the pairing.

motion?boolean

Puts the tree under the motion preferences (MotionProvider, which writes html[data-motion]). Default: true.

root?HTMLElement

Where the theme vars go. Default: <html>. Elsewhere, no snapshot is written and the window is left alone.

themesKey?string

Changes when the folder's themes may have changed (its enabled extensions): they are read again.

ui/src/appearance/AppearanceProvider.tsx:117

Functions#

applyPaletteFunction#

Applies palette and contrast to the document. Toggles .light / .dark on the root (UnoCSS dark: and color-scheme key off them); a root other than <html> also gets .zg-theme-scope, so the derived tokens (--zg-text, --zg-tray…) resolve against its own vars instead of the page's. Suppresses transitions for one frame, so a theme swap snaps instead of cross-fading every surface at a different speed. Values equal to the last ones written are a no-op.

TypeScript
function applyPalette(options: ApplyPaletteOptions): void
Parameters
NameTypeDescription
optionsApplyPaletteOptions

The palette, contrast, extra vars, root and snapshot sink.

ui/src/appearance/apply.ts:35

codeThemesOfFunction#

The bundled code themes of one appearance, sorted by display name.

TypeScript
function codeThemesOf(type: Appearance): { id: CodeThemeId; name: string }[]
Parameters
NameTypeDescription
typeAppearance

'light' or 'dark'.

{ id: CodeThemeId; name: string }[]

ui/src/code/code-themes.ts:183

codeThemeTypeOfFunction#

The appearance a bundled code theme is made for.

TypeScript
function codeThemeTypeOf(id: string): Appearance | undefined
Parameters
NameTypeDescription
idstring

A code theme id, such as nord.

Appearance | undefined

'light' or 'dark', or undefined when id is not a bundled theme.

ui/src/code/code-themes.ts:174

resolveCodeThemeFunction#

The code theme code renders with: the pick for the current appearance, else ('auto', or a pick that is not a bundled theme of that appearance) the app theme's mapping.

TypeScript
function resolveCodeTheme(
  choice: CodeThemeChoice,
  themeId: string,
  appearance: Appearance,
): CodeThemeId
Parameters
NameTypeDescription
choiceCodeThemeChoice

The code theme per appearance.

themeIdstring

The active app theme.

appearanceAppearance

The active appearance.

CodeThemeId

ui/src/appearance/AppearanceProvider.tsx:52

useAppearanceFunction#

The appearance state and its setters. Outside an AppearanceProvider the setters do nothing.

TypeScript
function useAppearance(): AppearanceApi

ui/src/appearance/AppearanceProvider.tsx:258

useAppearanceHostFunction#

The host from the nearest AppearanceProvider, or null outside one.

TypeScript
function useAppearanceHost(): AppearanceHost | null

ui/src/appearance/AppearanceProvider.tsx:218

useAppearanceMotionFunction#

The motion level the preferences resolve to (system follows the OS).

TypeScript
function useAppearanceMotion(): 'off' | 'reduced' | 'full'
'off' | 'reduced' | 'full'

ui/src/appearance/AppearanceProvider.tsx:228

useAppearanceReducedMotionFunction#

True for off and reduced: skip decorative JS-driven animation.

TypeScript
function useAppearanceReducedMotion(): boolean
boolean

ui/src/appearance/AppearanceProvider.tsx:233

useAppearanceStateFunction#

The stored preferences (DEFAULT_APPEARANCE outside an AppearanceProvider).

TypeScript
function useAppearanceState(): AppearanceState

ui/src/appearance/AppearanceProvider.tsx:223

useColorsFunction#

The active theme's colors.

TypeScript
function useColors(): ThemeColors

ui/src/appearance/AppearanceProvider.tsx:203

useOsReducedMotionFunction#

Whether the OS asks for reduced motion, followed live. False on the server.

TypeScript
function useOsReducedMotion(): boolean
boolean

ui/src/appearance/AppearanceProvider.tsx:299

usePaletteFunction#

The active derived palette.

TypeScript
function usePalette(): ResolvedPalette

ui/src/appearance/AppearanceProvider.tsx:208

useShikiThemeFunction#

The theme for code right now: the code theme pick for the current appearance, else the app theme's.

TypeScript
function useShikiTheme(): CodeThemeId
CodeThemeId

ui/src/appearance/AppearanceProvider.tsx:213

useThemeFunction#

The active theme (the default theme outside an AppearanceProvider).

TypeScript
function useTheme(): Theme

ui/src/appearance/AppearanceProvider.tsx:198

Interfaces#

AppearanceApiInterface#

The appearance state and its setters, for a settings panel.

TypeScript
interface AppearanceApi
AppearanceApi properties
NameTypeDescription
activeThemeIdstring

The active theme's id.

appearanceAppearance

The active appearance.

availableThemesreadonly Theme[]

Every theme selectable right now (built-in and the host's extra ones).

pickTheme(theme: Theme) => void

Assigns a theme to the slot its own appearance implies (light theme → light slot).

reset() => void

Back to the defaults.

set(update: Partial<AppearanceState>) => void

Merges a change into the preferences.

setMode(mode: AppearanceMode) => void

Sets the mode.

stateAppearanceState

The stored preferences.

ui/src/appearance/AppearanceProvider.tsx:238

AppearanceProviderPropsInterface#

Props for AppearanceProvider.

TypeScript
interface AppearanceProviderProps
AppearanceProviderProps properties
NameTypeDescription
childrenReactNode

The app.

extensions?ExtensionsHost

The extensions host: its Theme items are offered too, after the host's own extra themes. One theme id shows once (the appearance host's copy wins: zidane's registry serves extension themes through host.themes as well). AppHostProvider passes AppHost.extensions.

folder?string | null

The folder whose extra themes are offered (host.themes). Without one, the last folder's stay.

hostAppearanceHost

Where the preferences live, the extra themes, the snapshot and the window effects.

legacyThemeId?string

A theme id from elsewhere (zidane's shared Settings.theme), read once on the first run to seed the pairing.

motion?boolean

Puts the tree under the motion preferences (MotionProvider, which writes html[data-motion]). Default: true.

root?HTMLElement

Where the theme vars go. Default: <html>. Elsewhere, no snapshot is written and the window is left alone.

themesKey?string

Changes when the folder's themes may have changed (its enabled extensions): they are read again.

ui/src/appearance/AppearanceProvider.tsx:88

ApplyPaletteOptionsInterface#

Options of applyPalette.

TypeScript
interface ApplyPaletteOptions
ApplyPaletteOptions properties
NameTypeDescription
boot?(snapshot: BootSnapshot) => void

Stores the pre-paint snapshot after a write (AppearanceHost.boot.write).

contrast?number

50..200, default 100.

extraVars?Record<string, string>

Extra vars applied in the same frame (fonts) and included in the snapshot.

paletteResolvedPalette

The derived palette.

root?HTMLElement

Where the vars go. Default: <html>.

ui/src/appearance/apply.ts:11

Types#

CodeThemeType#

A bundled code theme id, what the highlighters take.

TypeScript
type CodeTheme = ReturnType<typeof shikiThemeFor>

ui/src/appearance/AppearanceProvider.tsx:42