Colors

Base's color tokens, read from its theme.css, in light and dark mode. Components use them through Tailwind, like bg-primary or text-muted-foreground.

Palette

Preview
colors.tsx
import { useSyncExternalStore } from "react"

import { Inline } from "~/components/ui/inline"
import { Stack } from "~/components/ui/stack"
import { Text } from "~/components/ui/text"

// Each surface with the text color meant for it.
const pairs = [
  {
    name: "background",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-background text-foreground",
  },
  {
    name: "surface",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-surface text-surface-foreground",
  },
  {
    name: "card",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-card text-card-foreground",
  },
  {
    name: "overlay",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-overlay text-overlay-foreground",
  },
  {
    name: "primary",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-primary text-primary-foreground",
  },
  {
    name: "secondary",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-secondary text-secondary-foreground",
  },
  {
    name: "muted",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-muted text-muted-foreground",
  },
  {
    name: "accent",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-accent text-accent-foreground",
  },
  {
    name: "destructive",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-destructive text-destructive-foreground",
  },
  {
    name: "warning",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-warning text-warning-foreground",
  },
  {
    name: "success",
    className:
      "flex h-20 flex-col justify-between rounded-lg p-md ring-1 ring-border bg-success text-success-foreground",
  },
]

// Colors for lines and states, with no text on them.
const lines = [
  { name: "border", className: "size-4 rounded-sm ring-1 ring-border bg-border" },
  { name: "input", className: "size-4 rounded-sm ring-1 ring-border bg-input" },
  { name: "ring", className: "size-4 rounded-sm ring-1 ring-border bg-ring" },
  { name: "backdrop", className: "size-4 rounded-sm ring-1 ring-border bg-backdrop" },
]

const names = [...pairs, ...lines].map((color) => color.name)

/** The colors this system's theme sets, space-separated: a system may not have every one. */
function definedNames(): string {
  const style = getComputedStyle(document.documentElement)
  return names.filter((name) => style.getPropertyValue(`--${name}`).trim() !== "").join(" ")
}

// The theme doesn't change while the page is open, so there's nothing to subscribe to.
const subscribe = () => () => {}

export default function Example() {
  const defined = new Set(
    useSyncExternalStore(subscribe, definedNames, () => names.join(" ")).split(" "),
  )
  return (
    <Stack gap="xl" className="w-full">
      <div className="grid grid-cols-2 gap-sm sm:grid-cols-3 lg:grid-cols-4">
        {pairs
          .filter((color) => defined.has(color.name))
          .map((color) => (
            <div key={color.name} className={color.className}>
              <Text size="lg" weight="semibold" family="heading">
                Aa
              </Text>
              <Text size="xs" family="mono">
                {color.name}
              </Text>
            </div>
          ))}
      </div>
      <Inline gap="lg">
        {lines
          .filter((color) => defined.has(color.name))
          .map((color) => (
            <Inline key={color.name} gap="xs">
              <span className={color.className} />
              <Text render={<span />} size="xs" family="mono" tone="muted">
                {color.name}
              </Text>
            </Inline>
          ))}
      </Inline>
    </Stack>
  )
}

Tokens

Each color's light and dark value. Tokens without a dark value stay the same in dark mode.

TokenLightDark
--backgroundoklch(1 0 0)oklch(0.145 0 0)
--foregroundoklch(0.145 0 0)oklch(0.985 0 0)
--surfaceoklch(0.985 0 0)oklch(0.205 0 0)
--surface-foregroundoklch(0.145 0 0)oklch(0.985 0 0)
--cardoklch(1 0 0)oklch(0.205 0 0)
--card-foregroundoklch(0.145 0 0)oklch(0.985 0 0)
--overlayoklch(1 0 0)oklch(0.205 0 0)
--overlay-foregroundoklch(0.145 0 0)oklch(0.985 0 0)
--primaryoklch(0.205 0 0)oklch(0.922 0 0)
--primary-foregroundoklch(0.985 0 0)oklch(0.205 0 0)
--secondaryoklch(0.97 0 0)oklch(0.269 0 0)
--secondary-foregroundoklch(0.205 0 0)oklch(0.985 0 0)
--mutedoklch(0.97 0 0)oklch(0.269 0 0)
--muted-foregroundoklch(0.556 0 0)oklch(0.708 0 0)
--accentoklch(0.97 0 0)oklch(0.269 0 0)
--accent-foregroundoklch(0.205 0 0)oklch(0.985 0 0)
--destructiveoklch(0.577 0.245 27.325)oklch(0.704 0.191 22.216)
--destructive-foregroundoklch(0.985 0 0)oklch(0.145 0 0)
--warningoklch(0.666 0.179 58.318)oklch(0.769 0.188 70.08)
--warning-foregroundoklch(0.985 0 0)oklch(0.145 0 0)
--successoklch(0.6 0.14 150)oklch(0.72 0.15 150)
--success-foregroundoklch(0.985 0 0)oklch(0.145 0 0)
--borderoklch(0.922 0 0)oklch(1 0 0 / 0.1)
--inputoklch(0.922 0 0)oklch(1 0 0 / 0.15)
--ringoklch(0.708 0 0)oklch(0.556 0 0)
--backdropoklch(0 0 0 / 0.3)oklch(0 0 0 / 0.3)