Skip to content

ThemeSwitch

Used to toggle the theme of the application.

Mode: light
import {
ThemeSwitch,
type ThemeSwitchMode,
} from '@fintech-sandpit/ui/react';
import { useState } from 'react';
const [mode, setMode] = useState<ThemeSwitchMode>(() => {
return document.documentElement.dataset.theme === 'dark' ? 'dark' : 'light';
});
const handleToggle = (mode: ThemeSwitchMode) => {
document.documentElement.dataset.theme = mode;
localStorage.theme = mode;
setMode(mode);
};
return (
<ThemeSwitch
mode={mode}
size="md"
onToggle={handleToggle}
/>
);
NameTypeDefaultDescription
modeThemeSwitchModelightThe mode of the theme switch
sizeThemeSwitchSizemdThe size of the theme switch
NameTypeDescription
onToggle(mode: ThemeSwitchMode) => voidCallback fired when the mode changes
export type ThemeSwitchMode = 'light' | 'dark'
export type ThemeSwitchSize = 'sm' | 'md' | 'lg'