Skip to content
throw-if-nullPublic

About

Design system: tokens, themes and React components

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

66 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@throw-if-null/ui

Design tokens, themes and React components for throw-if-null projects. Components are built on Base UI, which provides behavior and accessibility. This package provides the look.

The first theme is retro: windows with colored title bars, outlines, hard offset shadows and accent colors. It uses Space Mono for titles, labels and buttons, and IBM Plex Sans for body text. It has five color palettes, each in a light and a dark mode.

The published Storybook at https://ui.appsandtools.work shows every component in every theme, palette and mode.

Install

The package is private and published to GitHub Packages.

  1. Add an .npmrc to the consuming project:

    @throw-if-null:registry=https://npm.pkg.github.com
    //npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}
  2. Set NODE_AUTH_TOKEN to a token with the read:packages scope:

    • Locally, with the GitHub CLI: export NODE_AUTH_TOKEN=$(gh auth token). If the token lacks the scope, run gh auth refresh -s read:packages first.
    • In a CI or build service: a classic personal access token with only read:packages. GitHub Packages does not accept fine-grained tokens for npm.
  3. Install the package. It needs react and react-dom 19 as peer dependencies.

    npm install @throw-if-null/ui

Use

Import the stylesheet once, and set the theme on <html>:

import '@throw-if-null/ui/styles.css'
import { Button } from '@throw-if-null/ui'
<html data-theme="retro">
  • The theme goes on <html> because dialogs, menus, sheets and tooltips render in a portal under <body>. On an inner element, those overlays would not get the theme.

  • Without data-theme, the default theme applies. data-theme="default" restores the default theme inside a subtree.

  • The retro theme reads two more attributes. Put them on the same element as data-theme:

    Attribute Values Default
    data-palette teal, blue, lavender, orange, brown teal
    data-mode light, dark light
    <html data-theme="retro" data-palette="blue" data-mode="dark">

    retroPalettes exports the palette values. To follow the operating system's dark setting, set data-mode from matchMedia('(prefers-color-scheme: dark)').

  • Importing the JS loads no CSS. Only the explicit styles.css import does.

Cascade layers and Tailwind

All package CSS is in the cascade layer ui. Unlayered CSS in the consuming project overrides it. A project that also uses layers must declare ui before the layer that should win. With Tailwind v4, put this first in the main stylesheet so that utility classes override component styles:

@layer theme, base, ui, components, utilities;
@import "tailwindcss";
@import "@throw-if-null/ui/styles.css";

Tokens and themes

Tokens are CSS custom properties with the --ui- prefix, in two layers:

  • Palette (--ui-palette-*): raw values. Each theme defines its own palette.
  • Semantic (--ui-color-*, --ui-border-width, --ui-radius*, --ui-shadow*, --ui-font-*, --ui-space-*, --ui-control-height*, --ui-icon-size, --ui-duration, --ui-z-*): what components read. Components never read a palette value.

A theme is a set of semantic overrides under [data-theme="<name>"]. In the retro theme, a palette sets palette values, and a mode maps them to the semantic tokens. In every palette and mode, text meets WCAG AA contrast (4.5:1), and outlines and focus rings meet 3:1. A consuming project can adjust a theme by overriding semantic tokens in its own CSS. Storybook's "Foundations/Tokens" page lists the tokens, and "Foundations/Palettes" shows every palette in both modes.

Components

Component Notes
Button Variants primary, secondary (default), ghost, danger. ghost takes the text color of what it sits on. Sizes sm, md (default), icon, icon-sm.
Input, InputGroup Input's ref reaches the native <input>. InputGroup adds a decorative leading icon.
Textarea, Label, Separator, Badge
Text Body text without margins. size xs / sm (default) / md; tone default / muted; as p (default) / span / div.
Overline Small uppercase label above a section or a value, in the heading font. as can be a heading level when it titles a section.
Window A panel with a title bar, in the page flow. onClose adds a close button.
Dialog* Modal window. DialogHeader is the title bar and holds DialogTitle. Put DialogDescription in the body.
AlertDialog* Modal confirmation without a close button. AlertDialogAction and AlertDialogCancel close it.
Sheet* Modal panel on the left or right edge. SheetHeader is the title bar.
DockedPanel Non-modal panel attached to the left or right edge of its parent, in the page flow. It takes the parent's height, and its body scrolls. Its header has the page's colors, and its background is the raised surface. onClose adds a close button, and Escape inside the panel calls it.
DropdownMenu* DropdownMenuRadioItem closes the menu when selected.
Toolbar, ToolbarButton Framed row of controls. Arrow keys move focus between them. Pass each control to ToolbarButton as render, and give the toolbar an aria-label.
ToastProvider, createToastManager Toasts in the bottom-right corner. Create a manager, pass it to ToastProvider, and call manager.add({ title, description }) from anywhere. type: 'error' colors the title bar; give errors priority: 'high'. timeout: 0 keeps a toast until it is closed.
Tooltip* TooltipTrigger requires a render element, so it never nests a button in a button.
ScrollArea, Slider Slider's thumbLabel names its thumbs for assistive technology.
Select* Single-choice select. Pass items (value → label) so SelectValue shows the label. The list opens below the trigger. showIcon={false} on SelectTrigger hides the chevron.
Toggle, ToggleGroup Toggle is a button with a pressed state (aria-pressed). In a ToggleGroup, at most one toggle is pressed unless multiple is set.

Every component accepts className. Base UI components also accept a function of their state. Storybook shows each component and its states.

Contract

  • The public API is the exports of src/index.ts, @throw-if-null/ui/styles.css, the semantic token names, and the data-theme, data-palette and data-mode values. Palette token names and ui-* class names are internal and may change in any release.
  • Versions follow semver.
  • The package raises no errors of its own and does not declare an error model. Base UI's behavior, including its errors, passes through unchanged.
  • Trust: the package trusts its caller's props. It renders React nodes, never strings as HTML. It makes no network requests, reads no environment or storage, and keeps no module-level state.

Development

npm ci
npx playwright install chromium   # browser for the story tests
npm run storybook                 # http://localhost:6006
npm test                          # every story as a browser test, with accessibility checks
npm run lint
npm run typecheck
npm run build                     # dist/index.js, dist/index.d.ts, dist/styles.css, dist/fonts/, dist/native/
npm run test:native               # the unpublished native build in dist/native/; run the build first
npm run test:deploy               # the deploy script against an HTTP stub
npm run capture:dom               # rewrites the legacy DOM capture in docs/migration/dom-baseline/
npm run test:visual               # screenshot comparison; skipped unless CI or UI_VISUAL=1 is set

Legacy baseline

legacy-baseline/ records how the React components render, as evidence for the native migration (docs/migration/component-inventory.md). It renders every story without its play function, plus a few fixtures for usages no story shows, and drives each through the states listed in legacy-baseline/states.ts: open, highlighted, pressed and so on.

  • DOM capture: npm run capture:dom rewrites one file per component family in docs/migration/dom-baseline/. Review the diff before committing it.
  • Screenshots: every story state in the default theme and the ten retro combinations, compared with legacy-baseline/__screenshots__/ by the Visual workflow on every pull request and push to main. Font rendering differs between machines, so baselines come only from CI. A failed comparison uploads the visual-diffs artifact with the reference, actual and diff images. Locally, UI_VISUAL=1 npm run test:visual compares against the CI baselines and writes none.

To update the baselines, for a new story or state or an intended visual change, run the Visual workflow manually on the branch (Actions → Visual → Run workflow). It renders every screenshot in CI and opens a pull request with them against that branch. Review the images and merge it. GitHub runs no checks on that pull request, because GITHUB_TOKEN opened it.

Deployment

Three systems share the deployment of the Storybook site:

System Owns
Proton Pass Secrets, in the vault throw-if-null, folder ui
GitHub Code, environment variables, image builds and deploys
Coolify Cloud The UpCloud server, the Caddy proxy, TLS, and the app tin-ui

deploy/.env.production holds the deploy settings and is committed. A secret in it is a pass:// reference, which pass-cli run replaces with the value from Proton Pass when the command starts. A reference names the vault, the item title and the field. It cannot name a folder, so item titles must be unique in the vault: with two matching titles, Proton Pass uses one of them without an error.

On every push to main, after the checks pass, the CI workflow's deploy job:

  1. Writes the commit hash to storybook-static/version.txt and builds the image ghcr.io/throw-if-null/ui-storybook from deploy/Dockerfile.
  2. Runs deploy/image.test.mjs against the image.
  3. Logs in to Proton Pass and checks that the secrets resolve, before anything is pushed.
  4. Pushes the image as sha-<commit hash>. Image tags are never moved.
  5. Runs deploy/deploy.sh, which sets the Coolify app's image tag to sha-<commit hash>, asks Coolify to deploy it, and waits until the site's /version.txt serves the commit hash.

The app's image tag in Coolify always names the deployed build. The deploy sets it, so a tag edited by hand in Coolify lasts until the next deploy.

To deploy from a machine that is logged in to pass-cli, pass a commit whose image is in GHCR:

pass-cli run --env-file deploy/.env.production -- deploy/deploy.sh <commit hash>

To deploy an earlier build, run the Rollback workflow with its full commit hash. It checks that sha-<commit hash> exists in GHCR, then runs the same script. The next push to main deploys the new commit again.

Secret Stored in Scope
Coolify API token Proton Pass item coolify (folder ui), field ui_deploy_token deploy and write permissions, app tin-ui only
Proton Pass token gh-actions-ui GitHub secret PASS_CLI_PAT Viewer on the vault throw-if-null

GHCR pushes use the workflow's GITHUB_TOKEN. Coolify pulls the image with the registry credentials configured on the server.

One-time setup, for a new server or app:

  1. DNS: an A record from ui.appsandtools.work to the server's IP address, DNS only, so that Coolify's Caddy obtains the certificate.

  2. Coolify: a Docker Image application with the image ghcr.io/throw-if-null/ui-storybook, any tag (the first deploy replaces it), exposed port 80 and the domain https://ui.appsandtools.work. Its UUID goes in deploy/.env.production. The server needs registry credentials for ghcr.io.

  3. Coolify: an API token with the deploy and write permissions, limited to the app. write lets the deploy set the image tag. Store it in the field ui_deploy_token of the Proton Pass item coolify in the folder ui.

  4. Proton Pass: a token for GitHub with read access to the vault. A grant on a single item fails with Error decrypting item key (pass-cli 2.7.1), so the token can read every item in throw-if-null:

    pass-cli personal-access-token create --name gh-actions-ui --expiration 1y
    pass-cli personal-access-token access grant --personal-access-token-name gh-actions-ui \
      --vault-name throw-if-null --role viewer
  5. GitHub: store that token with gh secret set PASS_CLI_PAT.

Both tokens expire after one year:

  • Coolify API token: create a new one with the same scope, and replace the ui_deploy_token field of the Proton Pass item.
  • Proton Pass token: pass-cli personal-access-token renew --personal-access-token-name gh-actions-ui --expiration 1y issues a new token and invalidates the old one. Store it with gh secret set PASS_CLI_PAT.

Release

  1. Add a changeset to each PR that changes the public contract or the styles: npx changeset.
  2. After the PR is merged, the Release workflow opens or updates the "Version packages" PR.
  3. Merging that PR publishes the new version to GitHub Packages.

The Release workflow opens PRs with GITHUB_TOKEN. The repository setting "Allow GitHub Actions to create and approve pull requests" must be on. GitHub does not run workflows on PRs that GITHUB_TOKEN opens, so CI does not run on the "Version packages" PR.

Legacy 0.x fixes

Once main releases 1.x, a 0.x fix ships from the branch legacy/0.x under the dist-tag legacy (D-03). Publishing under legacy leaves latest on 1.x. A consumer that pins ^0.7.0 gets the fix through its version range. The Release workflow runs only on pushes to main, so a maintainer versions and publishes the fix by hand. While main releases 0.x, a 0.x fix follows the steps above.

  1. Cut legacy/0.x from the last 0.x tag. Later fixes reuse the branch.

    git fetch origin --tags
    git switch -c legacy/0.x "$(git tag --list 'v0.*' --sort=-v:refname | head -n 1)"
    git push -u origin legacy/0.x
  2. Make the fix on a branch from legacy/0.x, add a patch changeset with npx changeset, and open the PR against the legacy branch: gh pr create --base legacy/0.x. CI checks the PR.

  3. After the PR is merged, version the package on legacy/0.x. changeset version raises the version in package.json and writes CHANGELOG.md.

    git switch legacy/0.x
    git pull
    npx changeset version
    git commit -am "Version packages"
    git push
  4. Check the package. The output ends with the registry https://npm.pkg.github.com, the tag legacy and the new version.

    npm ci
    npm run build
    npm publish --dry-run --tag legacy
  5. Only after the maintainer approves the release, publish it and push the git tag that changeset publish creates. Publishing needs a token with the write:packages scope. npm reads it from NODE_AUTH_TOKEN through the .npmrc lines from Install, placed in the user ~/.npmrc.

    gh auth refresh -s write:packages
    export NODE_AUTH_TOKEN=$(gh auth token)
    npm run release -- --tag legacy
    git push origin "v$(node -p "require('./package.json').version")"

    npm run release builds the package and runs changeset publish. Without --tag legacy, Changesets publishes under latest, and latest moves from 1.x to the 0.x fix.

  6. Check the dist-tags with npm view @throw-if-null/ui dist-tags: latest names the 1.x version and legacy the new 0.x version.

About

Design system: tokens, themes and React components

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages