Component variants

What are component variants?

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 string prop, for example buttonType, holds the name of the version: primary, secondary, outline or link. 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 a boolean prop.
  • 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 wantUse
Copies that look different, chosen by you in the editorA 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 jobsTwo 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.

Articles in this section

Share

Related Articles

How to build a button with four looks (primary, secondary, outline, link)

In TeleportHQ, a button with variants is one component whose button element wears a base class, btn, plus four look classes (btn-primary, btn-secondary, btn-outline, btn-link) that each apply only when a text prop called buttonType equals their name; every copy then picks its look from a list.

How to add editable settings to a component (props)

In TeleportHQ, open the main component, click the connect (plug) icon next to a text, image or link field and choose Create Prop (or use Component settings → Props → Create new prop); each copy of the component can then set its own value in Component Properties.

What are components, and when should I use them?

A TeleportHQ component is a reusable block, like a navigation bar, footer or card, that you design once and place on many pages; when you edit the main component, every copy updates, and each copy can still show its own text, images and links.

How to show or hide elements based on a condition

In TeleportHQ, you show an element only when a condition is true, such as "stock equals 0" or "the menu is open", by selecting it, turning on the Conditional Rendering switch near the top of the right panel and building the condition from a value, an operator and a comparison value; it works in every project, website or web app.

How to create a CSS class

In TeleportHQ, select a styled element, type a name in the Classes section of the right panel and choose Create class to turn its styles into a reusable class; or click + in the Classes tab of the Design Language panel to start an empty class.