What are component variants?
A component variant in TeleportHQ is one version of a component that can look different from copy to copy: a primary or an outline button, a normal or a featured card, a Basic, Pro or Premium pricing card. You build one component, give it a setting that names the version, and each copy picks its version from a list. You still edit the component in one place, and every copy follows.
The three parts
Every variant in TeleportHQ is built from the same three parts:
- A setting (a prop). A
stringprop, for examplebuttonType, holds the name of the version:primary,secondary,outlineorlink. It has a default, so a copy that doesn't pick a version still gets one. A setting that is only on or off, like "full width", is abooleanprop. - A base class. One class, for example
btn, holds everything the versions share: size, spacing, font, corner radius. It's always on. - One class per version. Each version gets its own class, for example
btn-outline, holding only what makes it different: colors, borders, an underline. Each of these classes has a rendering condition, so it applies only when the setting equals its name.
ActionButton
buttonType string default "primary"
label richtext default "Get started"
button element
.btn always
.btn-primary when buttonType = primary
.btn-outline when buttonType = outline
…Text that changes from copy to copy, like a button's label or a card's title, is a richtext prop, so every copy keeps its own words and formatting. Settings pick a version; rich text props carry the content.
Variants, states and separate components
| You want | Use |
|---|---|
| Copies that look different, chosen by you in the editor | A variant: a setting plus classes with conditions |
| Something that changes while a visitor uses the site (an FAQ that opens, a menu that toggles) | A state. See How to use states in a component |
| Two pieces with different elements and different jobs | Two components |
A variant can also show or hide an element: a "Most popular" badge that only the featured card has. That uses Conditional Rendering on the element instead of a class.
Good habits
- Keep the look in classes, never as styles on the element itself: an element's own styles always win over its classes, so they can't be switched off.
- Create the base class before the version classes: when two classes set the same property, the one created later wins.
- Name versions with short lowercase words (
primary,outline,large), and type them exactly the same in every condition.