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.
The package is private and published to GitHub Packages.
-
Add an
.npmrcto the consuming project:@throw-if-null:registry=https://npm.pkg.github.com //npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}
-
Set
NODE_AUTH_TOKENto a token with theread:packagesscope:- Locally, with the GitHub CLI:
export NODE_AUTH_TOKEN=$(gh auth token). If the token lacks the scope, rungh auth refresh -s read:packagesfirst. - 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.
- Locally, with the GitHub CLI:
-
Install the package. It needs
reactandreact-dom19 as peer dependencies.npm install @throw-if-null/ui
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-paletteteal,blue,lavender,orange,browntealdata-modelight,darklight<html data-theme="retro" data-palette="blue" data-mode="dark">
retroPalettesexports the palette values. To follow the operating system's dark setting, setdata-modefrommatchMedia('(prefers-color-scheme: dark)'). -
Importing the JS loads no CSS. Only the explicit
styles.cssimport does.
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 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.
| 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.
- The public API is the exports of
src/index.ts,@throw-if-null/ui/styles.css, the semantic token names, and thedata-theme,data-paletteanddata-modevalues. Palette token names andui-*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.
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 setlegacy-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:domrewrites one file per component family indocs/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 tomain. Font rendering differs between machines, so baselines come only from CI. A failed comparison uploads thevisual-diffsartifact with the reference, actual and diff images. Locally,UI_VISUAL=1 npm run test:visualcompares 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.
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:
- Writes the commit hash to
storybook-static/version.txtand builds the imageghcr.io/throw-if-null/ui-storybookfromdeploy/Dockerfile. - Runs
deploy/image.test.mjsagainst the image. - Logs in to Proton Pass and checks that the secrets resolve, before anything is pushed.
- Pushes the image as
sha-<commit hash>. Image tags are never moved. - Runs
deploy/deploy.sh, which sets the Coolify app's image tag tosha-<commit hash>, asks Coolify to deploy it, and waits until the site's/version.txtserves 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:
-
DNS: an
Arecord fromui.appsandtools.workto the server's IP address, DNS only, so that Coolify's Caddy obtains the certificate. -
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 domainhttps://ui.appsandtools.work. Its UUID goes indeploy/.env.production. The server needs registry credentials forghcr.io. -
Coolify: an API token with the
deployandwritepermissions, limited to the app.writelets the deploy set the image tag. Store it in the fieldui_deploy_tokenof the Proton Pass itemcoolifyin the folderui. -
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 inthrow-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
-
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_tokenfield of the Proton Pass item. - Proton Pass token:
pass-cli personal-access-token renew --personal-access-token-name gh-actions-ui --expiration 1yissues a new token and invalidates the old one. Store it withgh secret set PASS_CLI_PAT.
- Add a changeset to each PR that changes the public contract or the styles:
npx changeset. - After the PR is merged, the Release workflow opens or updates the "Version packages" PR.
- 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.
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.
-
Cut
legacy/0.xfrom 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 -
Make the fix on a branch from
legacy/0.x, add a patch changeset withnpx changeset, and open the PR against the legacy branch:gh pr create --base legacy/0.x. CI checks the PR. -
After the PR is merged, version the package on
legacy/0.x.changeset versionraises the version inpackage.jsonand writesCHANGELOG.md.git switch legacy/0.x git pull npx changeset version git commit -am "Version packages" git push -
Check the package. The output ends with the registry
https://npm.pkg.github.com, the taglegacyand the new version.npm ci npm run build npm publish --dry-run --tag legacy
-
Only after the maintainer approves the release, publish it and push the git tag that
changeset publishcreates. Publishing needs a token with thewrite:packagesscope. npm reads it fromNODE_AUTH_TOKENthrough the.npmrclines 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 releasebuilds the package and runschangeset publish. Without--tag legacy, Changesets publishes underlatest, andlatestmoves from 1.x to the 0.x fix. -
Check the dist-tags with
npm view @throw-if-null/ui dist-tags:latestnames the 1.x version andlegacythe new 0.x version.