Documenting a Design System
Turn a theme into a design system: pages of live specimens that show its colors, type, spacing and components, built with the vb-design-system package.
A theme with documentation
In Vanilla Breeze the look of a site is a theme: a set of token values. A design system is that theme plus the pages that explain it, so that the people who use it know which colors, sizes and components exist and when to choose each.
Those pages are usually drawn by hand and go out of date when a value changes. @profpowell/vb-design-system is a separate npm package of specimen elements that read the token values from the page they are on. Change --radius-m in the theme and the radius specimen shows the new corner. Switch the theme and every specimen follows.
What the package provides
Each name links to its page on the package's documentation site.
| Purpose |
Elements |
| Show the tokens |
<token-specimen> (colors, sizes, radii, borders, shadows, icons),
<type-specimen>,
<spacing-specimen>,
<motion-specimen>,
<breakpoint-specimen>
|
| Show what is built from them |
<component-sampler>,
<layout-specimen>,
<accessibility-specimen>
|
| Choose colors and fonts |
<color-palette>,
<semantic-palette>,
<palette-generator>,
<gradient-builder>,
<font-pairer>
|
| Show icons and the brand mark |
<icon-set>,
<icon-specimen>,
<brand-specimen>
|
| Move a theme in and out |
<theme-catalog>,
<theme-import>,
<theme-export>
|
The package's stylesheet also has two patterns that need no script: a list of things to do and not to do (<ul data-list="do-dont"> with data-do and data-dont on the items) and a token reference table (the ds-token-table class on a <table>).
Install and load
Load Vanilla Breeze first, then the package's stylesheet and script.
<link rel="stylesheet" href="https://unpkg.com/vanilla-breeze/dist/cdn/vanilla-breeze.css"><link rel="stylesheet" href="https://unpkg.com/@profpowell/vb-design-system/dist/vb-design-system.min.css"> <script type="module" src="https://unpkg.com/vanilla-breeze/dist/cdn/vanilla-breeze.js"></script><script type="module" src="https://unpkg.com/@profpowell/vb-design-system/dist/vb-design-system.min.js"></script>
import 'vanilla-breeze/css';import 'vanilla-breeze'; import '@profpowell/vb-design-system/css';import '@profpowell/vb-design-system'; import '@profpowell/vb-design-system/token-specimen';
Vanilla Breeze is an optional peer dependency. Without it the specimens render with fallback values of their own, which defeats their purpose. Three elements also use a Vanilla Breeze component when it is on the page: <palette-generator> uses <color-picker>, <token-specimen type="icon"> uses <icon-wc>, and <brand-specimen> uses <brand-mark>. The full Vanilla Breeze bundle has all three.
A design system page
Write the page as ordinary sections. The specimens need no values: each reads the tokens of the theme in force where it sits.
<html lang="en" data-theme="harbour">...<main data-layout="stack" data-layout-gap="xl"> <h1>Harbour Books design system</h1> <section> <h2>Color</h2> <token-specimen type="color" tokens="primary,secondary,accent" label="Brand"></token-specimen> <token-specimen type="color" tokens="success,warning,error,info" label="Status"></token-specimen> <ul data-list="do-dont"> <li data-do>Use the accent color for one action on a page.</li> <li data-dont>Do not use status colors for decoration.</li> </ul> </section> <section> <h2>Type</h2> <type-specimen font-family="Georgia" label="Headings" show-scale show-weights></type-specimen> </section> <section> <h2>Space and shape</h2> <spacing-specimen label="Spacing scale"></spacing-specimen> <token-specimen type="radius" label="Corners"></token-specimen> <token-specimen type="shadow" label="Elevation"></token-specimen> </section> <section> <h2>Components</h2> <component-sampler components="button,input,select,badge"></component-sampler> </section></main>
The prose between the specimens is the part only you can write: what each color is for, which size to use where, how the brand speaks.
Building the theme on the page
The token, type and spacing specimens take an editable attribute. Their values become inputs, and a change is written as a custom property on :root, or on the element named by target. <theme-export live> collects those changes and shows them as a block of CSS to copy into a theme file.
<token-specimen type="radius" editable></token-specimen><spacing-specimen editable></spacing-specimen> <theme-export live label="Your theme"></theme-export>
The Theme Composer on the package's site is this arrangement with every specimen, the catalog and the import element on one page. The export can also be a token file for other design tools: see Design Token Exchange.