ThemeProvider
A React Native provider that supplies one colour palette to the tree through a useTheme hook, with per-colour overrides.
Supplies one palette to everything below it. Components call useTheme() and read colours by role, so switching between light and dark restyles the whole tree at once with no per-component logic. Override individual colours with colors; anything you leave out keeps its default. Works in React and in React Native with no extra packages.
Installation
CLI
npx @modus-ui/cli add theme-providerManual
- Copy the code from the code tab, using the React or React Native switch for your project.
- Create a file at
components/ui/theme-provider.tsx. - Paste the code.
The CLI installs the React Native version in an Expo or React Native app and the React version everywhere else. In a project that targets both, keep the React file theme-provider.tsx and the React Native file theme-provider.native.tsx side by side and import ./theme-provider; Metro picks the .native file on its own.
Usage
Props
| Prop | Type | Default | Description |
|---|---|---|---|
scheme | "light" | "dark" | - | Which palette to use. Leave it out to follow the system. |
colors | Partial<ThemeColors> | - | Overrides for single colours in either palette, as { light: {...}, dark: {...} }. |
useTheme() returns the active scheme and its colors, and throws outside a ThemeProvider.
Comments