ThemeSwitch
Used to toggle the theme of the application.
Mode: light
Mode: light
Example
Section titled “Example”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} />);<script setup lang="ts">import { ThemeSwitch, type ThemeSwitchMode,} from '@fintech-sandpit/ui/vue';import { ref } from 'vue';
const mode = ref<ThemeSwitchMode>(() => { return document.documentElement.dataset.theme === 'dark' ? 'dark' : 'light';});
const handleToggle = (mode: ThemeSwitchMode) => { document.documentElement.dataset.theme = mode; localStorage.theme = mode; mode.value = mode;};</script>
<template> <ThemeSwitch :mode="mode" size="md" @toggle="handleToggle" /></template>| Name | Type | Default | Description |
|---|---|---|---|
mode | ThemeSwitchMode | light | The mode of the theme switch |
size | ThemeSwitchSize | md | The size of the theme switch |
Events
Section titled “Events”| Name | Type | Description |
|---|---|---|
onToggle | (mode: ThemeSwitchMode) => void | Callback fired when the mode changes |
| Name | Argument | Description |
|---|---|---|
toggle | ThemeSwitchMode | Event emitted when the mode changes |
export type ThemeSwitchMode = 'light' | 'dark'export type ThemeSwitchSize = 'sm' | 'md' | 'lg'