Files
backnotprop__plannotator/packages/ui/components/themeModes.tsx
Vladyslav Hrabovyi 92c311ab1d fix(review): show System theme coherently across UI (#1015)
Use one shared Light/Dark/System registry across review, plan, annotate, Settings, and published UI consumers. Preserve the public Mode contract, scope wider menu geometry to theme pickers, and keep constrained palettes coherent in rendering and previews.

Co-authored-by: Vladyslav Hrabovyi <vladyslav.hrabovyii@gmail.com>
Co-authored-by: sasha <kredich05@gmail.com>
2026-07-15 22:39:52 -07:00

29 lines
1.0 KiB
TypeScript

import type { FC } from 'react';
import { MoonIcon, SunIcon, SystemIcon, type IconProps } from './icons/themeIcons';
interface ThemeMode {
readonly id: string;
readonly label: string;
readonly Icon: FC<IconProps>;
}
/** The shared catalog rendered by every Light/Dark/System picker. */
export const THEME_MODES = [
{ id: 'light', label: 'Light', Icon: SunIcon },
{ id: 'dark', label: 'Dark', Icon: MoonIcon },
{ id: 'system', label: 'System', Icon: SystemIcon },
] as const satisfies readonly ThemeMode[];
/** A persisted theme-mode preference. */
export type Mode = (typeof THEME_MODES)[number]['id'];
/** Return whether an unknown persisted value is a supported theme mode. */
export function isThemeMode(value: unknown): value is Mode {
return typeof value === 'string' && THEME_MODES.some(({ id }) => id === value);
}
/** Parse an unknown persisted value, falling back to a caller-provided mode. */
export function parseThemeMode(value: unknown, fallback: Mode): Mode {
return isThemeMode(value) ? value : fallback;
}