Skip to content
satin

Vite

Satin in a Vite React app, with dark mode applied before the first paint.

Install

Start from npm create vite@latest with the React template, on React 19. The fonts are optional; without them Satin falls back to the system font.

Terminal
npm i @uisatin/ui @fontsource-variable/geist @fontsource-variable/geist-mono

Styles

Import @uisatin/ui/styles.css once, at the entry point, before your own CSS so your rules come later in the cascade. Then import each component from its own entry, @uisatin/ui/button.

src/main.tsx
// src/main.tsx
import '@uisatin/ui/styles.css'
import './app.css'
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { App } from './App'

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>,
)

Your own stylesheet loads the fonts and paints the page. Vite resolves the package paths inside url(), so the font files are bundled like any other asset.

src/app.css
/* src/app.css */

/* Geist under the names Satin's tokens ask for. @fontsource-variable/geist registers it as
   "Geist Variable", so its own stylesheet alone leaves Satin on the system font. */
@font-face {
  font-family: 'Geist';
  src: url('@fontsource-variable/geist/files/geist-latin-wght-normal.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('@fontsource-variable/geist-mono/files/geist-mono-latin-wght-normal.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-display: swap;
}

/* 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);
}

Dark mode without a flash

A Vite app renders in the browser, so the theme has to be on <html> before React starts. A small script in index.html runs before the first paint and sets data-theme from the saved choice; with nothing saved, system follows the operating system without any script. The toggle that saves the choice is in the Dark mode guide.

index.html
<!doctype html>
<html lang="en" data-theme="system">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>My app</title>
    <script>
      // Runs before the first paint: the saved choice, or follow the system.
      try {
        document.documentElement.dataset.theme = localStorage.getItem('theme') || 'system'
      } catch {}
    </script>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>

Theme

Load your brand and corners after Satin's styles: the file the customizer exports, or the same stylesheet built with themeCss.

src/main.tsx
// src/main.tsx, after the styles
import './satin-theme.css' // from the customizer on /theming: Export → Download

// Or build it in code from the same two values:
import { themeCss } from '@uisatin/ui/theme'

const style = document.createElement('style')
style.textContent = themeCss({ brand: '#E5533D', radius: 1 })
document.head.append(style)