6.7 KiB
Components
Recipes in plain CSS on the tokens. Port them to CSS Modules, Tailwind (tailwind.md) or a component library's styling API as the project requires. Every interactive element has hover, active, :focus-visible and disabled states.
Buttons
Three variants and two sizes cover almost everything. One primary button per view.
.btn {
display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
height: 2.5rem; padding-inline: var(--space-4);
font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1;
border: 1px solid transparent; border-radius: var(--radius-md); cursor: pointer;
transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--fg); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--fg-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn-danger { background: var(--danger); color: var(--accent-fg); }
.btn-sm { height: 2rem; padding-inline: var(--space-3); font-size: var(--text-xs); border-radius: var(--radius-sm); }
Icon-only buttons are square (width = height) and need aria-label.
Inputs
.field { display: grid; gap: var(--space-2); }
.field > label { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.field > .hint { font-size: var(--text-xs); color: var(--fg-muted); }
.field > .error { font-size: var(--text-xs); color: var(--danger); display: flex; gap: var(--space-1); }
.input {
height: 2.5rem; padding-inline: var(--space-3); width: 100%;
background: var(--surface); color: var(--fg);
border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.input::placeholder { color: var(--fg-subtle); }
.input:hover { border-color: var(--fg-subtle); }
.input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.input[aria-invalid="true"] { border-color: var(--danger); }
textarea.input { height: auto; min-height: 6rem; padding-block: var(--space-2); resize: vertical; }
Placeholders show an example value, never the label.
Cards and surfaces
Use a card only when the thing is a separate object (an item in a collection, a self-contained panel). A section of a page is not a card.
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-5); }
.card-interactive { transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
.card-interactive:hover { border-color: var(--border-strong); box-shadow: var(--shadow-raised); }
.well { background: var(--surface-2); border-radius: var(--radius-md); padding: var(--space-4); }
In a row of cards: same padding, title in the same place, actions pinned to the same edge (display: flex; flex-direction: column with margin-top: auto on the footer).
Badges, pills, status
.badge { display: inline-flex; align-items: center; gap: var(--space-1); height: 1.375rem; padding-inline: var(--space-2);
font-size: var(--text-xs); font-weight: var(--weight-medium); border-radius: var(--radius-full);
background: var(--surface-2); color: var(--fg-muted); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: oklch(from var(--warn) calc(l - 0.15) c h); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: currentColor; }
Status always pairs color with a word or icon.
Tables
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: var(--weight-medium);
color: var(--fg-muted); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: var(--space-3); border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
No zebra stripes and borders together; pick one. Truncate long cells with a tooltip rather than letting a row explode.
Navigation
- Top nav: logo/name left, 3 to 6 links, one action right. Active link marked by weight or color plus
aria-current="page", not just an underline that is hard to see. - Side nav: items 2.25rem tall, icon + label, active item
background: var(--accent-soft); color: var(--accent-text). Group headings use.label. - Tabs: underline style (2px
--accentbar under the active tab) for page sections; segmented control (pill group on--surface-2) for view switches.
Overlays
- Popovers/menus:
--surface,--shadow-popover,--radius-md, 4px inner padding, items 2rem tall. Animate opacity + 4px translate in--dur-base. - Modals: max-width 32rem (forms) or 48rem (content),
--shadow-modal,--radius-lg, backdropoklch(0 0 0 / 0.4). Focus trapped, Escape closes, title in anh2. Use the native<dialog>or Radix Dialog. - Toasts: bottom-right on desktop, bottom-center on phones; short past-tense message ("Invoice sent"); an Undo action for destructive operations instead of a confirm dialog where possible.
States
- Loading: skeletons shaped like the real content (
--surface-2blocks with a subtle shimmer that stops under reduced motion) for page loads; inline spinners only inside buttons. - Empty: say what will appear here and how to add the first one, with the primary action. A small icon at most, no large illustration unless the product has an illustration style.
- Error: what failed, why if known, and a retry. Keep the rest of the page usable.
Data display details
- Numbers:
tabular-nums, right-aligned in columns, units in--fg-muted, thousands separators viaIntl.NumberFormat. - Dates: relative for recent ("3 min ago") with the absolute date in a
title/tooltip; absolute in tables. - Code and IDs:
--font-mono,--surface-2background, copy button on hover.