Cherry React Library

Cherry Design System is a versatile foundation for projects. It offers a white label base, ready-to-use Figma designs, open-source React components, built-in support for theming and dark mode. Explore the docs to create delightful user interfaces.
Installation
Install the package along with its peer dependencies:
npm install cherry-styled-components react react-dom styled-components lucide-react
Quick Start
Wrap your app in CherryThemeProvider and start using components. The provider injects the global styles and, when you pass themeDark, handles dark mode automatically: it follows the OS until the visitor picks a mode, and switches through CSS variables without re-rendering your components:
import {
Button,
CherryThemeProvider,
theme,
themeDark,
} from "cherry-styled-components";
export default function App() {
return (
<CherryThemeProvider theme={theme} themeDark={themeDark}>
<Button $variant="primary">Hello Cherry</Button>
</CherryThemeProvider>
);
}
The built-in theme and themeDark objects are a starting point; both are plain objects you can extend or replace to white-label the system. Styled props use a $ prefix ($variant, $size, $fullWidth) so they never leak into the DOM.
The library ships form components (Button, Input, Select, Textarea, Toggle, Range, Password, Checkbox, Radio, Dropzone, AvatarDropzone), layout primitives (Container, Grid, Col, Flex, Box, MaxWidth, Space), interactive components (Accordion, Modal, Toast, ThemeToggle, Icon, IconButton), content components (Prose, Callout, Avatar), and a chat kit (see below). See the component docs for the full API.
Icons come from lucide, a peer dependency. Pass an imported component, <Icon icon={ArrowRight} />, which ships only that glyph and renders on the server. Component icon props such as Avatar's $icon take the same component, or a rendered element. For an icon chosen at runtime, import DynamicIcon from cherry-styled-components/dynamic: it resolves a name on demand, and only apps that import that subpath carry lucide's dynamic import map.
Chat kit
Cherry ships everything needed to build an AI-assistant chat UI, split into a headless provider and presentational components. The provider owns panel state, focus management, the transcript, and streaming bookkeeping; the app owns the transport — Cherry never fetches, parses SSE, or assumes an endpoint.
import {
ChatInput,
ChatLauncher,
ChatMessage,
ChatMessageList,
ChatPanel,
ChatProvider,
Prose,
useChat,
} from "cherry-styled-components";
<ChatProvider
onSend={async (question, { signal, history, setAssistant }) => {
const res = await fetch("/api/chat", {
method: "POST",
body: JSON.stringify({ question, history }),
signal,
});
for await (const text of readMyStream(res)) {
setAssistant(text); // patches the same assistant bubble on each call
}
setAssistant(<Prose $compact>{renderMarkdown(text)}</Prose>, {
text, // plain-text mirror used for the next request's history
sources: [{ id: "1", label: "Docs", href: "/docs" }],
});
}}
>
<ChatLauncher $glow />
<ChatPanel>
<MyTranscript /> {/* map useChat().messages into ChatMessageList */}
<ChatInput $glow />
</ChatPanel>
</ChatProvider>;
ChatProvider — headless state: useChat() returns { isOpen, open, close, toggle, messages, input, setInput, loading, error, send, ask, reset, inputRef }. Props: onSend, greeting, historyLimit, shortcut (Cmd/Ctrl+I by default, null to disable), and $showcase.
$showcase — demo mode. Chat input matching a showcase command is answered locally with a live rendering of that element; everything else still goes to onSend (which becomes optional). help lists the commands: list (the component catalog), callout, avatar, prose, sources, and typing. Off by default — without $showcase every message goes to the transport.
ChatPanel — the shell. $variant="drawer" (fixed side panel, full-screen modal below lg), "inline" (flows with the page), or "fullscreen". Handles dialog semantics, focus trapping, inert siblings, and body scroll locking while modal.
ChatMessageList — scroll container with stick-to-bottom behavior that releases when the reader scrolls up.
ChatMessage — $role="user" (filled bubble) or "assistant" (full-width, pair with Prose for markdown), plus an $avatar slot.
ChatInput — auto-growing composer; Enter submits, Shift+Enter breaks the line. $glow opts into the animated rainbow border and sparkles.
ChatLauncher, ChatTyping, ChatSources/ChatSource — the "Ask AI" pill, the typing indicator, and the source-chip row.
Theming
Cherry ships two theme providers. Both take a light theme and an optional themeDark (plain objects with real color values) and share one implementation:
ClientThemeProvider - the full provider. Props: theme, themeDark, $initial, $mode, $themeColor (keeps <meta name="theme-color"> on a theme color, "light" by default, false to disable) and $globalStyles (pass false to skip Cherry's global styles).
CherryThemeProvider - the same provider without the theme-color meta sync, kept as the name client-only apps have used. Props: theme, themeDark, $mode.
Light and dark mode switch through CSS variables. The provider runs createThemeVariables(theme, themeDark), which turns the two objects into one theme for both modes: every color and shadow your styled components read is a CSS variable (theme.colors.primary is var(--cherry-color-primary), theme.shadows.md is var(--cherry-shadow-md)). The light values are declared on :root and the dark ones on :root.dark, in a plain <style data-cherry-theme> element the provider renders. The mode is the dark class on <html>: a switch flips the class and the browser repaints, without rendering any styled component again. Transitions are turned off for the frame that paints the switch (.theme-switching on <html>), so the page changes at once. Without themeDark the page stays light.
The visitor's preference is "light", "dark" or "system":
- An explicit choice (a
ThemeToggle click, setPreference) is stored in localStorage as themePreference. A theme entry in localStorage, written by Cherry before 0.3, also counts as an explicit choice.
- Without one, the page follows the OS preference, live.
- The mode in force is mirrored to the
theme cookie, for server code that wants it. The cookie only decides the mode when storage is blocked.
$mode="light" or $mode="dark" pins the mode: the page shows it whatever the visitor's preference, nothing is stored, and toggling does nothing.
ThemeContext provides { toggleTheme, setPreference }, and the ThemeToggle component works under either provider. setPreference("light" | "dark" | "system") picks a mode, or hands it back to the OS. Its value never changes, so reading it does not re-render a component when the mode switches.
Most code never needs the mode in JS: a color that differs by mode is a theme token, a :root.dark & rule, or modes() (see Migrating to 0.3). For the rest there are two hooks, and only components that call them render again on a switch:
useColorMode() returns { mode, preference, setPreference, toggleTheme }.
useResolvedTheme() returns the theme with real color values for the mode in force, plus isDark, for code that hands a theme color to something CSS does not style (a canvas, a JS color library, an editor theme).
import { useEffect, useRef } from "react";
import {
Select,
useColorMode,
useResolvedTheme,
type ColorModePreference,
} from "cherry-styled-components";
function ModePicker() {
const { preference, setPreference } = useColorMode();
return (
<Select
value={preference}
onChange={(e) => setPreference(e.target.value as ColorModePreference)}
>
<option value="system">System</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</Select>
);
}
function Swatch() {
const ref = useRef<HTMLCanvasElement>(null);
const theme = useResolvedTheme(); // real values: theme.colors.primary is a hex
useEffect(() => {
const context = ref.current?.getContext("2d");
if (!context) return;
context.fillStyle = theme.colors.primary;
context.fillRect(0, 0, 40, 40);
}, [theme]);
return <canvas ref={ref} width={40} height={40} />;
}
Server-rendered apps
A Next.js App Router setup looks like this:
// app/layout.tsx (server component)
import { cookies } from "next/headers";
// StyledComponentsRegistry is the one export that depends on Next, so it ships
// from the `/next` subpath instead of the package root.
import { StyledComponentsRegistry } from "cherry-styled-components/next";
import { ClientThemeProvider, themeInitScript } from "cherry-styled-components";
import { theme, themeDark } from "./theme";
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const cookieTheme = (await cookies()).get("theme")?.value;
return (
// The init script sets the `dark` class before React hydrates.
<html lang="en" suppressHydrationWarning>
<head>
{/* Puts the page in the visitor's mode before the first paint. */}
<script dangerouslySetInnerHTML={{ __html: themeInitScript }} />
</head>
<body>
<StyledComponentsRegistry>
<ClientThemeProvider
theme={theme}
themeDark={themeDark}
$initial={cookieTheme === "dark" ? "dark" : "light"}
>
{children}
</ClientThemeProvider>
</StyledComponentsRegistry>
</body>
</html>
);
}
themeInitScript is a blocking script for the document <head>. On every load it makes the same decision as the provider (stored preference, else the OS) and sets the dark class on <html> before the first paint, so the server render arrives in the right mode with nothing hidden. It also keeps the theme cookie and the theme-color meta in step. createThemeInitScript(options) builds a custom one: themeColor: { light, dark } sets the meta values for each mode (use the values of the token $themeColor tracks; the default is Cherry's light token, white and black), and themeColor: false leaves the meta alone.
const initScript = createThemeInitScript({
themeColor: { light: "#ffffff", dark: "#0b0b0b" },
});
The colors never depend on the server render, so $initial only sets the mode useColorMode() reports during it. Pass the theme cookie's value when you read it, as above, so components that read the mode render the right thing on the server. To have that value on a first visit in Chrome, opt into color-scheme client hints in your middleware:
// middleware.ts
res.headers.set("Accept-CH", "Sec-CH-Prefers-Color-Scheme");
res.headers.set("Vary", "Sec-CH-Prefers-Color-Scheme");
res.headers.set("Critical-CH", "Sec-CH-Prefers-Color-Scheme");
const hint = req.headers.get("Sec-CH-Prefers-Color-Scheme");
if (!req.cookies.get("theme")?.value && hint) {
res.cookies.set("theme", hint === "dark" ? "dark" : "light", {
path: "/",
maxAge: 60 * 60 * 24 * 365,
sameSite: "lax",
});
}
resolveTheme(cookieValue, theme, themeDark) is exported for other server code that needs the active theme object, e.g. generateViewport for the initial theme-color. createThemeVariables, modeValue, createThemeInitScript, themeInitScript and resolveTheme are server-safe. Cherry's default theme and themeDark exports come from a "use client" module, so server code that reads theme values (for createThemeVariables, resolveTheme or a viewport color) must pass its own theme objects.
In a client-only app, run themeInitScript before the first render so the first paint is already in the right mode, as this repo's demo does in src/main.tsx:
import { themeInitScript } from "cherry-styled-components";
const init = document.createElement("script");
init.textContent = themeInitScript;
document.head.appendChild(init); // an inline script runs as soon as it is inserted
Migrating to 0.3
0.3 replaces the theme object swap with CSS variables. Your providers keep their theme and themeDark props; what changes is code that reads the mode or computes with theme colors.
-
theme.isDark is gone. Components receive one theme for both modes, so a style cannot branch on the mode in JS, and TypeScript flags every read. Replace each one with:
- a mode token, when Cherry has one:
colors.accent, link, onFilled, primaryTintHover / primaryTintDrop / primaryTintActive, shadows.toast. The providers fill every one you leave out, per mode;
- a
:root.dark & rule, for a block that only applies in dark mode;
modes(), which wraps an interpolation written against theme.isDark and emits CSS that follows the mode. Most branches migrate by wrapping them. modeValue(light, dark) is the plain-CSS form.
import styled from "styled-components";
import { modes, type Theme } from "cherry-styled-components";
// Before: border-color: ${({ theme }) => (theme.isDark ? gray : grayLight)}
const Card = styled.div<{ theme: Theme }>`
border-color: ${modes(({ theme }) =>
theme.isDark ? theme.colors.gray : theme.colors.grayLight,
)};
:root.dark & {
outline: 1px solid ${({ theme }) => theme.colors.grayDark};
}
`;
-
Remove isDark from your own theme objects. The Theme type no longer has it.
-
No JS color math on theme values. Inside styled components the colors are var(--cherry-color-...) strings, so darken(), rgba(), readableColor() and the like from polished (or any JS color library) break. Use Cherry's alpha, shade and tint, which emit native color-mix(), or read real values from useResolvedTheme().
-
setTheme is gone. ThemeContext provides { toggleTheme, setPreference }: call setPreference("light" | "dark" | "system") instead of setTheme(themeObject).
-
createThemeInitScript takes options. createThemeInitScript(darkBackground, darkThemeColor) becomes createThemeInitScript({ themeColor: { light, dark } }), or { themeColor: false }. The script no longer hides the page, so it needs no background color. Keep rendering it in the <head> of a server-rendered app.
-
darkFilledTextRule and darkPrimaryTintRule are removed. The mode tokens they patched follow the mode now: drop the calls and keep filledTextColor / primaryTintColor.
-
$initial only affects useColorMode() during the server render. Use $mode to pin a mode.
AI assistant skill
Cherry ships a guide that teaches Claude and other LLMs to build with the library correctly: use Cherry components for every button and form control, read design values from the theme instead of hardcoding them, and wire up the provider. It lives in skills/cherry-design-system and is documentation only (it is not part of the published npm package).
Install it with the skills CLI, a cross-agent installer that supports Claude Code, Cursor, Codex, and many others and detects your agent automatically:
# add to the current project
npx -y skills add cherry-design-system/styled-components
# preview what would be installed
npx -y skills add cherry-design-system/styled-components --list
# install globally for Claude Code, no prompts
npx -y skills add cherry-design-system/styled-components --skill cherry-design-system -g -a claude-code -y