Dark mode
How to use dark mode in your application
Casper UI supports dark mode, as it extends the built in support from Chakra UI. By default the theme is set to light mode, and needs to be manually toggled.
The default Casper UI color theme includes dark mode colors. But when using custom theme colors
(type of the colors-prop provided to <ThemeProvider>) they must include a dark mode version per color to work as expected.
Read and Toggle dark and light mode using the useColorMode-hook
Section titled “Read and Toggle dark and light mode using the useColorMode-hook”Import the useColorMode-hook from the theme to control the color mode in your application.
- To toggle between dark and light mode, call the
toggleColorMode-function returned from the hook. - To get the current color mode, use the
colorMode-property returned from the hook.
Example usage:
import { useColorMode, FormControl, FormLabel, Switch } from "@caspeco/casper-ui-library";
function ToggleDarkModeSwitch() { const { colorMode, setColorMode } = useColorMode(); return ( <FormControl display="flex"> <FormLabel>Use Dark Mode</FormLabel> <Switch isChecked={colorMode === "dark"} onCheckedChange={({ checked }) => setColorMode(checked ? "dark" : "light")} /> </FormControl> );}