Component variants

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

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

In TeleportHQ, a button with four looks is one component, not four. Its button element always wears a base class, btn, with what every look shares, plus four look classes, btn-primary, btn-secondary, btn-outline and btn-link, with only what makes each look different. Each look class has a rendering condition: it applies only when the component's buttonType setting equals its name. Every copy of the button then picks its look from a list, and you still edit the button in one place.

Before you start

  • You need a component made from a Button element. See How to create a component. Button is a reserved name, so call the component something else, for example ActionButton.
  • You need the Owner, Admin or Designer role.
  • It helps to know how a CSS class is created. See How to create a CSS class.

What you're building

ActionButton                      (component)
  settings (props)
    buttonType   string     default "primary"       ← picks the look
    label        richtext   default "Get started"   ← the text
  button element
    .btn             always
    .btn-primary     when buttonType = primary
    .btn-secondary   when buttonType = secondary
    .btn-outline     when buttonType = outline
    .btn-link        when buttonType = link

Two kinds of setting, two kinds of prop:

  • A setting that picks a look is a string prop, and its values are short lowercase words: primary, secondary, outline, link.
  • Text that changes from copy to copy is a richtext prop, so each copy keeps its own words and formatting.

Steps

1. Give the button its base class

  1. In the left sidebar, open Pages, Components & Tree View, and in the Components folder click ActionButton. The component opens in its own tab above the canvas.
  2. On the component canvas, click the button to select it.
  3. In the right panel, find the Classes section. A new Button arrives wearing the class .button, a ready-made grey look. On the .button row, click Remove class. The class stays in your project; only this button stops using it.
  4. In the Classes section, click the field Type to search or create new class, type btn and click Create class btn. The Create class panel opens.
  5. In the Create class panel, turn off Extract element styles, so the class starts empty.
  6. In the panel's Properties, add one row per line below. In the empty property box, type the name and press Enter (or pick it from the list). The cursor moves to value: type the value and press Enter, and the cursor moves to the next empty row.
propertyvalue
displayinline-flex
align-itemscenter
justify-contentcenter
padding12px 24px
border-width2px
border-stylesolid
border-colortransparent
border-radius8px
font-size16px
font-weight600
cursorpointer

btn holds everything the four looks share. Create it before the look classes: when two classes set the same property, the one created later wins, so each look's border color beats the transparent one here.

2. Make one class per look

Back in the Classes section, create four more classes the same way (type the name, click Create class …, turn off Extract element styles, add the rows). Each holds only what differs.

classpropertyvalue
btn-primarybackground-color#2563eb
border-color#2563eb
color#ffffff
btn-secondarybackground-color#e0e7ff
border-color#e0e7ff
color#1e3a8a
btn-outlinebackground-colortransparent
border-color#2563eb
color#2563eb
btn-linkbackground-colortransparent
border-colortransparent
color#2563eb
text-decorationunderline

The button now wears all five classes at once. The next step makes each look class apply only for its own look.

3. Add the buttonType setting and switch each look on

  1. In the Classes section, on the .btn-primary row, click Add rendering condition. A condition row appears under the class, with a Bind button and an Operand list. The value box appears once the condition is bound to a prop.
  2. Click Bind, then Create Conditional Prop. The Create Conditional Prop window opens.
  3. In Name, replace the suggested name with buttonType.
  4. In Type, pick string. A Validation Type list appears: leave it on text.
  5. In Default, replace newProp with primary. Copies that don't pick a look get this one.
  6. Click Create.
  7. In the Operand list, pick =. In the value box, type primary, then press Enter or click outside the box. The value is saved when you leave the box.
  8. On the .btn-secondary row, click Add rendering condition, then Bind → Dynamic Properties Assignment Panel. In the Select Dynamic Property panel, open props, click buttonType and click Bind property. Pick = and type secondary.
  9. Do the same on the .btn-outline row with outline, and on the .btn-link row with link.

On the component canvas, the button shows the primary look. The other three rows show a warning icon, Rendering condition is not met: their look is off, which is what you want. Click one to preview that look while you design. It only changes the value the editor uses for its preview, never your copies.

4. Make the label editable on every copy

  1. With the button still selected, find the Text Content section in the right panel.
  2. Click the plug icon next to the text, then Bind value, then Create Richtext Prop. The Props panel opens with the new prop.
  3. In the new prop's Name box, type label and press Enter.
  4. In its Default value box, type Get started and press Enter.

The button's text now comes from label, and every copy can change it.

5. Pick the look on each copy

  1. Go back to a page and place your copies. To show the four looks side by side, put four copies in one container.
  2. Click a copy. In the right panel, under Component Properties, open the Conditional group. buttonType is a list of the four looks: link, outline, primary, secondary. The list holds every value a condition in the component compares buttonType with, plus its default.
  3. Pick a look.
  4. To change a copy's text, open the Content group and edit label.

Check that it worked

  • The four copies show four different looks, each with its own text.
  • Click Preview in the bottom toolbar: the published page shows the same four buttons.
  • Change the corner radius in btn once: every copy, in every look, follows.

Troubleshooting

A copy keeps the primary look after I pick another one. Open the component and check the look class's condition row: the value must be the exact word, lowercase, with no space (outline, not Outline or outline ).

The value I typed in a condition disappeared. The value box saves when you press Enter or leave the box. Type it again and press Enter.

Two looks mix (for example a blue background with an underline). Two look classes are on at once. Each look class needs its own condition with = and its own word.

A look ignores its color. A style set on the button itself always wins over classes. Select the button, and in the right panel clear any background, border or text color that is set on the element (shown in normal text, not grey).

The button has no Text Content section. Its text sits in a text element of its own inside the button. In Pages, Components & Tree View, expand the button in the tree, select its text, and do step 4 there.

The look classes lose to btn. btn was created after them. Set the conflicting property only in the look classes, or create the look classes again after btn.

Good to know

  • In the exported Next.js code, the button's class list is built from the setting, for example btn plus btn-outline when buttonType is outline. In the HTML download, each copy's look is worked out when the site is built.
  • To add a fifth look later, create one more class, give it a condition with its own word, and every copy can pick it.
  • A setting that's only on or off, like "full width", is a boolean prop instead of a string prop.
Share

Related Articles

How to add sizes to a button (small, medium, large)

In TeleportHQ, a button gets sizes the same way it gets looks: a second text prop called size (default medium) and two size classes, btn-small and btn-large, that apply only when size equals their name; medium is the base class's own size, so it needs no class, and every copy picks a look and a size.

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.

How to create a component

In TeleportHQ, create a component by right-clicking elements you already designed and choosing Make Component, or start a blank one with the + button on the Components folder and New Component (Ctrl+Alt+K).

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.

How to apply or remove a CSS class

In TeleportHQ, select an element, type the class name in the Classes section of the right panel and pick it from the list to apply it; click Remove class (−) on the class's row to take it off that element only.

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 edit a component and update every copy

In TeleportHQ, double-click a component instance (or click the component in the Components folder) to open the main component in its own tab; every change you make there updates all its copies on every page.