Theming
A Theme sets the values that apply to your whole app, such as its appearance, accent colour, radius and fonts.Theme sets how your app looks with seven options: light or dark, the accent colour, the gray colour, the corner radius, the control size, and the font families for text and headings.
It began as the Theme component from Radix Themes. Its options have changed since, so use the table on this page and not the Radix reference.
Installation
npm install @kushagradhawan/kookie-uiUsage
Wrap your application with the Theme component at the root level:
import { Theme } from '@kushagradhawan/kookie-ui';
export default function App() {
return (
<Theme accentColor="blue" grayColor="gray">
{/* Your app */}
</Theme>
);
}Next.js App Router
Theme is already a Client Component. Render it directly in your root layout, which can stay a Server Component:
// app/layout.tsx
import '@kushagradhawan/kookie-ui/styles.css';
import { Theme } from '@kushagradhawan/kookie-ui';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<Theme accentColor="blue" grayColor="slate">
{children}
</Theme>
</body>
</html>
);
}Props
| Prop | Type | Description |
|---|---|---|
appearance | 'light' | 'dark' | 'inherit' | Color scheme. inherit takes it from a light or dark class on an element above, such as <html>. Default: 'inherit' |
accentColor | AccentColor | Primary accent used for interactive components. Default: 'gray' |
grayColor | GrayColor | Neutral gray scale for backgrounds and text. Default: 'gray' |
radius | 'none' | 'small' | 'medium' | 'large' | 'full' | Global corner radius scale. Default: 'full' |
size | '1' | '2' | '3' | '4' | Size for controls that set none of their own. Default: '2' |
fontFamily | 'sans' | 'mono' | 'serif' | Font family for body text. Default: 'sans' |
headingFontFamily | 'sans' | 'mono' | 'serif' | Font family for Heading, set independently of body text. Follows fontFamily when unset |
hasBackground | boolean | Whether to apply background color to the Theme element. Default: true for root Theme |
asChild | boolean | Merges Theme props with child element using Radix Slot pattern |
Appearance
Set appearance to force light or dark, or leave it at inherit and let the page decide.
Light
Force light mode regardless of system preference.
<Theme appearance="light"><YourApp /></Theme>Dark
Force dark mode regardless of system preference.
<Theme appearance="dark"><YourApp /></Theme>Inherit
The default. The Theme writes no mode of its own and takes light or dark from a light or dark class on an element above it, usually <html>. With no class it is light.
<Theme appearance="inherit"><YourApp /></Theme>Following the system setting
To follow the visitor's system setting, and remember a choice they make, put appearanceScript in <head>. It runs before the first paint, reads the stored choice or the system setting, and writes the class on <html>:
// app/layout.tsx
import { Theme } from '@kushagradhawan/kookie-ui';
import { appearanceScript } from '@kushagradhawan/kookie-ui/appearance-script';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
<script dangerouslySetInnerHTML={{ __html: appearanceScript }} />
</head>
<body>
<Theme>{children}</Theme>
</body>
</html>
);
}useAppearance reads and changes the mode from a component. choice is what the person picked ('system' until they pick), and appearance is what is showing:
import { Button, useAppearance } from '@kushagradhawan/kookie-ui';
function ModeToggle() {
const { appearance, setAppearance } = useAppearance();
return (
<Button variant="soft" color="gray" onClick={() => setAppearance(appearance === 'dark' ? 'light' : 'dark')}>
Use {appearance === 'dark' ? 'light' : 'dark'} mode
</Button>
);
}Accent Color
Use accentColor to set the primary color for interactive elements like buttons, links, and focus indicators.
Available colors: gray, gold, bronze, brown, yellow, amber, orange, tomato, red, ruby, crimson, pink, plum, purple, violet, iris, indigo, blue, cyan, teal, jade, green, grass, lime, mint, sky.
<Theme accentColor="blue"><YourApp /></Theme><Theme accentColor="crimson"><YourApp /></Theme>Gray Color
Use grayColor to set the neutral gray scale for backgrounds and text. The gray color affects the overall tone and contrast of your interface.
Available grays: auto, gray, mauve, slate, sage, olive, sand.
When set to auto, the gray color automatically matches your accent color for a cohesive look.
<Theme grayColor="slate"><YourApp /></Theme><Theme grayColor="auto" accentColor="blue"><YourApp /></Theme>Radius
Set radius to control the global corner radius scale for all components. This affects buttons, cards, inputs, and other rounded elements.
Available values: none, small, medium, large, full (default).
<Theme radius="medium"><YourApp /></Theme><Theme radius="large"><YourApp /></Theme>Size
Set size to size every control inside the Theme at once. Heights are 28, 32, 40 and 48px for sizes 1 to 4. A control's own size still wins, and a control with fewer sizes takes its nearest one.
<Theme size="3"><YourApp /></Theme>Chip does not follow it.
Font Family
Set fontFamily to choose the typeface for body text. Available values: sans (default), mono, serif.
<Theme fontFamily="sans"><YourApp /></Theme><Theme fontFamily="mono"><YourApp /></Theme>Heading Font
headingFontFamily sets the typeface for Heading on its own, so headings and body text can differ:
<Theme fontFamily="sans" headingFontFamily="serif">
<Heading>Set in the serif stack</Heading>
<Text>Set in the sans stack</Text>
</Theme>Leave it unset and headings follow fontFamily. The typefaces behind sans, mono and serif come from the --font-sans, --font-mono and --font-serif tokens — see Typography for how to point those at your own fonts.
Nested Themes
You can nest Theme components to override specific settings in parts of your application:
<Theme accentColor="blue" grayColor="slate">
<MainContent />
<Theme accentColor="crimson" radius="large">
<SpecialSection />
</Theme>
</Theme>Tokens
Use CSS custom properties to access theme values in your styles:
/* Color tokens */
var(--accent-9) /* Primary accent color */
var(--neutral-11) /* High contrast text */
var(--neutral-1) /* Subtle background *//* Layout tokens */
var(--space-5) /* Standard spacing */
var(--radius-3) /* Component border radius */
var(--font-size-3) /* Base font size */