React Native / Theme
ThemeProvider
Gives every Stylhero component the theme: colors for light or dark mode, type, spacing, radii and shadows from tokens.json. Wrap the app in it once. Read the theme in your own components with useTheme().
import { ThemeProvider } from "@stylhero/native";
Example
import { Text, ThemeProvider } from "@stylhero/native";
function ThemeProviderExample() {
return (
<ThemeProvider colorScheme="system">
<Text variant="h3">Follows the device's light or dark setting</Text>
</ThemeProvider>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children required |
ReactNode |
- | |
colorScheme |
ColorScheme | "system" |
"system" |
"system" (default) follows the device setting and updates live. |
fonts |
FontResolver |
- | Maps a token font family and weight to a loaded font name; the system font without it. |
Types
type ColorScheme = (typeof colorSchemes)[number];
type FontResolver = (family: FontFamilyToken, weight: FontWeight) => string | undefined;
type FontFamilyToken = (typeof typography)[TypographyToken]["family"];
type TypographyToken = keyof typeof typography;
type FontWeight = "400" | "500" | "600" | "700" | "800";
Accessibility
- Colors come from tokens whose text and control pairs are checked against WCAG AA in light and dark mode when the tokens are built.
Generated from src/theme/ThemeProvider.tsx. Something wrong or missing? Open an issue.