Skip to content
satin

Astro

Satin components as React islands, with the styles and the theme in a layout.

Install

Satin is React, so Astro needs its React integration (React 19). This site is built the same way.

Terminal
npx astro add react
npm i @uisatin/ui @fontsource-variable/geist @fontsource-variable/geist-mono

Layout

Import the stylesheet in the layout every page uses; Astro bundles it into the page's CSS. themeCss runs in the frontmatter, at build time or on the server, and set:html writes its output into a <style>; is:inline tells Astro to leave that tag as it is. The inline script sets the theme before the first paint.

src/layouts/Layout.astro
---
// src/layouts/Layout.astro
import '@uisatin/ui/styles.css'
import '../styles/app.css'
import { themeCss } from '@uisatin/ui/theme'

const theme = themeCss({ brand: '#E5533D', radius: 1 })
---

<html lang="en" data-theme="system">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script is:inline>
      // Runs before the first paint: the saved choice, or follow the system.
      try {
        document.documentElement.dataset.theme = localStorage.getItem('theme') || 'system'
      } catch {}
    </script>
    <style is:inline set:html={theme}></style>
  </head>
  <body>
    <slot />
  </body>
</html>
src/styles/app.css
/* src/styles/app.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);
}

Components as islands

A Satin component without a directive is rendered to static HTML: it looks right and costs no JavaScript, but it doesn't respond. Anything that opens, switches or validates needs client:load, or client:visible to wait until it scrolls into view. Props from .astro files must be serializable, so handlers like onClick live inside a React component of your own.

src/pages/index.astro
---
// src/pages/index.astro
import Layout from '../layouts/Layout.astro'
import { Badge } from '@uisatin/ui/badge'
import { Button } from '@uisatin/ui/button'
import { Tabs } from '@uisatin/ui/tabs'
import { SignUpForm } from '../components/SignUpForm'
---

<Layout>
  <!-- No directive: rendered to HTML at build time, no JavaScript sent. -->
  <Badge>Beta</Badge>
  <Button asChild><a href="/docs">Read the docs</a></Button>

  <!-- Interactive: hydrated on load, or once scrolled into view. -->
  <Tabs client:load aria-label="Plan" items={['Monthly', 'Yearly']} />
  <SignUpForm client:visible />
</Layout>

Each island is a separate React root, and React context doesn't cross between them. A provider and the components that read it go in the same island: Toaster with the buttons that call toast(), SatinLabels or Radix's DirectionProvider with what they wrap.

src/components/Notifications.tsx
// src/components/Notifications.tsx: one island, so the provider and its users share a React root
import { Toaster, toast } from '@uisatin/ui/toast'
import { Button } from '@uisatin/ui/button'

export function Notifications() {
  return (
    <>
      <Button onClick={() => toast('Saved')}>Save</Button>
      <Toaster />
    </>
  )
}

Dark mode with view transitions

The toggle is in the Dark mode guide. If you use Astro's <ClientRouter />, the new page's <html> replaces the old one's attributes on every navigation, so set the theme again after each swap.

src/layouts/Layout.astro
<script is:inline>
  // With <ClientRouter />, each navigation swaps in a new <html>: put the theme back on it.
  document.addEventListener('astro:after-swap', () => {
    try {
      document.documentElement.dataset.theme = localStorage.getItem('theme') || 'system'
    } catch {}
  })
</script>