Components and classes
A component is a DOM structure and a set of classes, all rooted in one name. Knowing the five kinds of class is enough to read any component page, and to write any component by hand.
The namespace
Every class of a component starts with its namespace: btn yields .btn, .btn-primary, .btn-ripple-wave. A namespace has one owner, so
a class tells you at a glance which component it belongs to. A component may still reach into another one:
a validator colours the input it checks, a join glues buttons together.
Five kinds of class
<button class="btn btn-primary btn-sm btn-outline">Save</button> <!-- root axis color size variant --> <div class="card"> <div class="card-body"> <!-- a part --> <h2 class="card-title">Plan</h2> <!-- a part --> </div> </div>
- Root
- The component itself:
.btn,.card. Alone, it draws the default look. - Axis
- A group of mutually exclusive variants, named after what it changes:
color,size,shape,width. At most one value of an axis applies at a time, so the component pages list an axis as one row.variantis the name kept for an exclusive group with no better one (outline,ghost,link…). - Flag
- A variant that excludes nothing:
.btn-active,.menu-sub-closed. Two flags at once are a legal state. - Part
- A piece the component is made of, on the element that plays it:
.card-body,.menu-title. A part is never opted into; it belongs to the structure. - Plain class
- A few components are a single class with nothing to wrap:
text,link,validator. They have no Svelte wrapper; you write the class.
A family ships what it draws
An axis belongs to the component, not to the family, but a family may ship only part of it. The component pages show what the family picked in the sidebar ships: switch family and the tables change. In Svelte, the types follow the same way.
States come from the DOM
A state is read from the element itself whenever the DOM can say it — :hover, :focus-visible, :disabled, :checked, aria-expanded —
and only otherwise from a class, a flag or a part (.btn-active, .tabs-item-active). The DOM tab of a component page lists the states each family draws.
<button class="btn" disabled>…</button> <!-- the DOM says it: drawn disabled --> <input type="checkbox" class="checkbox" checked /> <!-- drawn checked --> <button class="btn btn-active">…</button> <!-- a flag: held pressed by the app -->
Reading a component page
- CSS: every class the family ships for it, by kind, axes grouped.
- Svelte: the props of its wrapper; an axis is a prop that takes one of its values.
- DOM: the structure each example renders, its states, the custom properties it exposes (its hooks) and how it moves.
Start with the list of components.