Next.js
Satin in the App Router: styles and theme in the root layout, dark mode set on the server.
Install
Satin needs React 19, which the App Router ships with since Next.js 15. No Tailwind or PostCSS config: the package brings one compiled stylesheet.
npm i @uisatin/uiRoot layout
Import @uisatin/ui/styles.css once, in app/layout.tsx. The layout is a Server Component, and it can call themeCss: @uisatin/ui/theme is plain functions, not marked 'use client', so the theme is rendered into the HTML and there's no unstyled first frame.
The layout also sets data-theme on <html> from a cookie. The page then arrives in the reader's theme and never flashes light before turning dark. Reading a cookie renders each request on the server; for statically rendered pages, use the head script from the Dark mode guide instead.
// app/layout.tsx
import '@uisatin/ui/styles.css'
import './globals.css'
import { cookies } from 'next/headers'
import { themeCss } from '@uisatin/ui/theme'
export default async function RootLayout({ children }: { children: React.ReactNode }) {
// light, dark or system, saved by the theme toggle. system follows the OS in CSS, no script.
const theme = (await cookies()).get('theme')?.value ?? 'system'
return (
<html lang="en" data-theme={theme}>
<head>
<style>{themeCss({ brand: '#E5533D', radius: 1 })}</style>
</head>
<body>{children}</body>
</html>
)
}Server Components
Every component entry is marked 'use client', so a Server Component can import and render them directly. What can't cross from the server is a function: an onClick or onValueChange belongs in a file of your own marked 'use client'.
// app/page.tsx: a Server Component, no 'use client' here
import { Button } from '@uisatin/ui/button'
import { Badge } from '@uisatin/ui/badge'
import { SaveButton } from './save-button'
export default function Page() {
return (
<main>
<Badge>Beta</Badge>
<Button variant="secondary" asChild>
<a href="/docs">Read the docs</a>
</Button>
<SaveButton />
</main>
)
}// app/save-button.tsx
'use client'
import { Button } from '@uisatin/ui/button'
export function SaveButton() {
return <Button onClick={() => fetch('/api/save', { method: 'POST' })}>Save</Button>
}Theme toggle
The toggle changes the attribute at once and saves the choice in the cookie the layout reads. Render it from the layout or a page with <ThemeToggle initial={theme} />, passing the value the layout read.
// app/theme-toggle.tsx
'use client'
import * as React from 'react'
import { SegmentedControl } from '@uisatin/ui/segmented-control'
export function ThemeToggle({ initial }: { initial: string }) {
const [theme, setTheme] = React.useState(initial)
return (
<SegmentedControl
aria-label="Theme"
size="xs"
value={theme}
onValueChange={(next) => {
setTheme(next)
document.documentElement.dataset.theme = next
// The layout reads this on the next request, so the page arrives in the right theme.
document.cookie = `theme=${next}; path=/; max-age=31536000; samesite=lax`
}}
items={[
{ value: 'light', label: 'Light' },
{ value: 'dark', label: 'Dark' },
{ value: 'system', label: 'System' },
]}
/>
)
}Fonts
Satin's tokens ask for Geist and Geist Mono by name, or as the variable packages call them. Import the Fontsource packages in your global CSS; next/font gives each font a generated family name the tokens can't see. Without them the system font is used.
npm i @fontsource-variable/geist @fontsource-variable/geist-mono/* app/globals.css */
/* Geist and Geist Mono, the families Satin's tokens ask for. */
@import '@fontsource-variable/geist';
@import '@fontsource-variable/geist-mono';
/* Satin styles its own elements, not the page: paint the page from its tokens so dark mode reaches it. */
body {
margin: 0;
background: var(--sa-bg-canvas);
color: var(--sa-text-default);
}Something wrong or missing on this page?
Report a problemSuggest an improvement