How the design kit works
The design kit is one package the demos on jasonsdevspace.com share. It holds their colors and type, the theme a visitor chose, the links around each page, the buttons, fields and callouts, and the page that explains each demo. ShelfLens is built on it. A fix to a button is made once, and reaches every demo that installs the version with it.
It is built for two people. The person building a demo wants it to look like the rest without copying files from the last one. The reviewer with two minutes wants to know whether the person who built it understands styles, accessibility and shipping a package.
What happens as a page loads
- The theme script runs first. Inline in the page’s head, before anything is drawn, it reads the theme you saved on the portfolio, or your system’s, and marks the page with it.
- Each color picks its theme. Every color holds a light value and a dark one, and the browser draws the one for the theme the page is marked with.
- The base styles set the page. Its type and colors, the accent behind the text you select, one focus ring for every link and control, and less motion if you ask your system for it.
- Each control looks like what it tells a screen reader. A pressed button looks pressed because of the attribute a screen reader reads as pressed, so what you see and what you hear come from one place.
- The demo's own styles win. Every one of the kit’s rules sits in a cascade layer, which the browser ranks below a demo’s own styles outside a layer, so those win without having to outweigh the kit’s. The exception is less motion: when a visitor asks for it, the kit’s rule holds over a demo’s ordinary styles.
What usually goes wrong, and does not here
Each of these is a mistake shared styles often make. Each has a test that fails when the mistake comes back, and where this site shows one, a link opens it.
The flash of the wrong theme
A theme set by a script that runs after the page is drawn paints it light, then dark. Here the script runs inline before the first paint, and a page built with the kit’s Vite plugin fails its build if it leaves the script out. How the theme is chosen.
Shared styles that take over the page
A style library usually wins by the weight of its selectors, so a demo has to outweigh it to change anything. Here every value the kit names starts with --dk-, every value it works out for itself with --_dk-, and every class with dk-, so a demo keeps its own names. Every rule sits in a layer of the kit’s, so a demo’s own styles outside a layer win whatever their selectors. A demo with layers of its own chooses where the kit’s layer sits among them. The one exception is the kit’s rule for a visitor who asks for less motion, which holds over a demo’s ordinary styles. A test fails if a rule slips out of its layer.
A state you can see but not hear
A class such as “active” can make a button look pressed while a screen reader hears an ordinary button. Here pressed, open, invalid and unavailable are each drawn from the attribute a screen reader reads. A button the kit marks unavailable can still be reached with the keyboard, so a keyboard user lands on it and hears the words beside it that say why. Each state of the buttons.
A security policy that refuses the styles
A page can tell the browser to load styles only from its own site, which stops an injected style from changing what it shows. Libraries that write their styles from a script while the page runs are refused under it, unless the page loosens the policy to let them in. The kit’s styles load as files from the page’s own site and its components write markup alone, with no style attribute, so every page of this site runs under that policy.
Colors that fail in the dark
A palette checked in the light theme alone can leave text too faint to read in the dark theme. Here each pairing the palette is meant for, text on every background it sits on and the edge of every control, is measured in both themes. Every change and every release has to pass that test, whose figures are under Contrast on the tokens page.
Docs that drift from the code
Examples written by hand stop matching the code a release or two later. Here each block of markup in the kit’s reference is written from the examples the browser tests draw, and a test fails when a block differs from what its example draws. This site is built from the version on npm, so what you see is what a demo installs.
Under the hood, briefly
The rest is for engineers.
The kit is three sheets of plain CSS, built on custom properties, cascade layers and light-dark(), with React components that draw the same markup a page without React writes by hand, and a Vite plugin that puts the theme script inline. It is published on npm as @jasonsdevspace/design-kit, and each version is staged from a tag and goes live when it is promoted. It needs Chrome or Edge 123, Firefox 120 or Safari 17.5, or later, the first versions that draw light-dark(). This site is built with Vite and React’s static render, and its only scripts are the theme script and one of its own, which attaches the kit’s theme switch, copy buttons, steppers, dialogs and toast and runs the live examples.
The README is the case study, and the decision records are beside it, each with the options turned down and the test behind the choice.
This page is itself an explainer, in the layout and with the pieces shown on Explainer pieces.
Who made it
Jason Poteet, as a portfolio project. If this is the kind of work you are hiring for, get in touch.