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.
function AppearanceProvider(props: AppearanceProviderProps): ElementParameters
| Name | Type | Description |
|---|---|---|
| props | AppearanceProviderProps |
Returns
ElementProps
| Name | Type | Description |
|---|---|---|
| children | ReactNode | The app. |
| extensions? | ExtensionsHost | The extensions host: its |
| folder? | string | null | The folder whose extra themes are offered ( |
| host | AppearanceHost | Where the preferences live, the extra themes, the snapshot and the window effects. |
| legacyThemeId? | string | A theme id from elsewhere (zidane's shared |
| motion? | boolean | Puts the tree under the motion preferences ( |
| root? | HTMLElement | Where the theme vars go. Default: |
| themesKey? | string | Changes when the folder's themes may have changed (its enabled extensions): they are read again. |
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.
function applyPalette(options: ApplyPaletteOptions): voidParameters
| Name | Type | Description |
|---|---|---|
| options | ApplyPaletteOptions | The palette, contrast, extra vars, root and snapshot sink. |
codeThemesOfFunction#
The bundled code themes of one appearance, sorted by display name.
function codeThemesOf(type: Appearance): { id: CodeThemeId; name: string }[]Parameters
| Name | Type | Description |
|---|---|---|
| type | Appearance |
|
Returns
{ id: CodeThemeId; name: string }[]codeThemeTypeOfFunction#
The appearance a bundled code theme is made for.
function codeThemeTypeOf(id: string): Appearance | undefinedParameters
| Name | Type | Description |
|---|---|---|
| id | string | A code theme id, such as |
Returns
Appearance | undefined'light' or 'dark', or undefined when id is not a bundled theme.
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.
function resolveCodeTheme(
choice: CodeThemeChoice,
themeId: string,
appearance: Appearance,
): CodeThemeIdParameters
| Name | Type | Description |
|---|---|---|
| choice | CodeThemeChoice | The code theme per appearance. |
| themeId | string | The active app theme. |
| appearance | Appearance | The active appearance. |
Returns
CodeThemeIduseAppearanceFunction#
The appearance state and its setters. Outside an AppearanceProvider the setters do nothing.
function useAppearance(): AppearanceApiReturns
useAppearanceHostFunction#
The host from the nearest AppearanceProvider, or null outside one.
function useAppearanceHost(): AppearanceHost | nullReturns
AppearanceHost | nulluseAppearanceMotionFunction#
The motion level the preferences resolve to (system follows the OS).
function useAppearanceMotion(): 'off' | 'reduced' | 'full'Returns
'off' | 'reduced' | 'full'useAppearanceReducedMotionFunction#
True for off and reduced: skip decorative JS-driven animation.
function useAppearanceReducedMotion(): booleanReturns
booleanuseAppearanceStateFunction#
The stored preferences (DEFAULT_APPEARANCE outside an AppearanceProvider).
function useAppearanceState(): AppearanceStateReturns
useColorsFunction#
The active theme's colors.
function useColors(): ThemeColorsReturns
useOsReducedMotionFunction#
Whether the OS asks for reduced motion, followed live. False on the server.
function useOsReducedMotion(): booleanReturns
booleanusePaletteFunction#
The active derived palette.
function usePalette(): ResolvedPaletteReturns
useShikiThemeFunction#
The theme for code right now: the code theme pick for the current appearance, else the app theme's.
function useShikiTheme(): CodeThemeIdReturns
CodeThemeIduseThemeFunction#
The active theme (the default theme outside an AppearanceProvider).
Interfaces#
AppearanceApiInterface#
The appearance state and its setters, for a settings panel.
interface AppearanceApiProperties
| Name | Type | Description |
|---|---|---|
| activeThemeId | string | The active theme's id. |
| appearance | Appearance | The active appearance. |
| availableThemes | readonly 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. |
| state | AppearanceState | The stored preferences. |
AppearanceProviderPropsInterface#
Props for AppearanceProvider.
interface AppearanceProviderPropsProperties
| Name | Type | Description |
|---|---|---|
| children | ReactNode | The app. |
| extensions? | ExtensionsHost | The extensions host: its |
| folder? | string | null | The folder whose extra themes are offered ( |
| host | AppearanceHost | Where the preferences live, the extra themes, the snapshot and the window effects. |
| legacyThemeId? | string | A theme id from elsewhere (zidane's shared |
| motion? | boolean | Puts the tree under the motion preferences ( |
| root? | HTMLElement | Where the theme vars go. Default: |
| themesKey? | string | Changes when the folder's themes may have changed (its enabled extensions): they are read again. |
ApplyPaletteOptionsInterface#
Options of applyPalette.
interface ApplyPaletteOptionsProperties
| Name | Type | Description |
|---|---|---|
| boot? | (snapshot: BootSnapshot) => void | Stores the pre-paint snapshot after a write ( |
| contrast? | number | 50..200, default 100. |
| extraVars? | Record<string, string> | Extra vars applied in the same frame (fonts) and included in the snapshot. |
| palette | ResolvedPalette | The derived palette. |
| root? | HTMLElement | Where the vars go. Default: |
Types#
CodeThemeType#
A bundled code theme id, what the highlighters take.
type CodeTheme = ReturnType<typeof shikiThemeFor>