Installation
Usage
Out of the box the ThemeProvider tries to match the theme based on the users system preferences.
Passing in any value to the `theme` prop wil result in a class name added to the html tag of your application to manage your theme. Handles any theme name or value and as many theme options you may want to provide.
Import the `ThemeProvider` component as a parent to the application you want to wrap:
Storing a Theme
By default the Theme Provider will set a cookie for you out of the box. All that is required is that the application provides the correct theme value to load to support SSR. The application will have to manage the cookie and provide it.
Next.js example below:
Optional Theme Toggle
You can create a theme toggle to allow the user to toggle between theme settings.
Prop options
Out of the box Theme Handler defaults to the users preference. Internally it is referenced as `system`.
<ThemeProvider /> component props:
- children-ReactNode-RequiredThe child nodes that are wrapped by the ThemeProvider.
- theme-string-OptionalDefault is `system` if you want user preferences to decide between a class named `light` or `dark` provide `system`.
- setStoredTheme-(storageKey: string, theme: string) => void-OptionalThe callback function that set updates the theme value if changed on the client.
- storedKey-string-OptionalThe key name of the stored theme value. Defaults to `theme`.
Future Support
- Multiple themes on a page
- Data attribute option instead of class name