Skip to content

UI components ​

@surgijs/ui is a set of accessible web components built with SurgiJS. Each one wraps native elements in a shadow root, takes its look from CSS custom properties, and renders on the server with declarative shadow DOM.

Install and register ​

bash
npm i @surgijs/ui @surgijs/core
ts
import '@surgijs/ui/themes.css'; // design tokens, light and dark
import '@surgijs/ui'; // registers every component, or:
import '@surgijs/ui/button'; // registers <s-button> only
html
<s-button variant="primary">Save</s-button>

Components work without themes.css: every value has a built-in light fallback. The stylesheet adds the dark theme and lets you change tokens in one place.

Themes ​

themes.css defines tokens on :root. Light is the default, data-theme="dark" on any ancestor switches to dark, and without a data-theme on the root the OS preference (prefers-color-scheme) decides.

html
<html data-theme="dark">

Custom properties inherit through shadow roots, so a theme is a set of token values on any element:

css
.brand {
  --s-color-primary: #0b7285;
  --s-color-primary-hover: #095c6b;
  --s-color-primary-active: #074652;
  --s-radius-md: 999px;
}

Tokens ​

Every token, with its light and dark value, is listed on the design tokens page. The page, themes.css and the Figma token files are generated from the same JSON sources.

Component custom properties ​

Each component also has its own properties, named --s-<component>-*. They default to the tokens and win over them, so you can restyle one component, one group or one element without touching the theme. See Button.

Quality checks ​

Every component ships with:

  • unit tests (Vitest, happy-dom) for behavior, ARIA and forms;
  • SSR tests: the server markup, the stylesheet, and hydration that adopts the server nodes;
  • Storybook stories, which are also the source of the browser tests;
  • Playwright tests in Chromium, Firefox and WebKit: keyboard, focus, forms, axe-core accessibility audits (WCAG 2.2 AA) in both themes, and a server-rendered page that must look the same before and after hydration;
  • visual regression screenshots of every story in both themes, taken in the official Playwright container.

MIT License