Component variants

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

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

In TeleportHQ, a button gets sizes the same way it gets looks: one more setting, size, and one class per size that applies only when size equals its name. Medium is the size the base class btn already has, so only btn-small and btn-large are new. Every copy then picks a look and a size, so one component gives you all twelve buttons.

Before you start

What you're building

ActionButton                      (component)
  settings (props)
    buttonType   string     default "primary"       ← picks the look
    size         string     default "medium"        ← picks the size (new)
    label        richtext   default "Get started"   ← the text
  button element
    .btn             always            ← medium padding and text size
    .btn-primary     when buttonType = primary
    …
    .btn-small       when size = small     (new)
    .btn-large       when size = large     (new)

Looks and sizes don't overlap: look classes set colors, size classes set spacing and text size. That's why any look combines with any size.

Steps

1. Make the two size classes

  1. In the left sidebar, open Pages, Components & Tree View, and in the Components folder click ActionButton.
  2. On the component canvas, click the button to select it.
  3. In the right panel, in the Classes section, click the field Type to search or create new class, type btn-small and click Create class btn-small.
  4. In the Create class panel, turn off Extract element styles, then add the rows below: type the property, press Enter, type the value, press Enter.
  5. Create btn-large the same way.
classpropertyvalue
btn-smallpadding8px 16px
font-size14px
border-radius6px
btn-largepadding16px 32px
font-size18px
border-radius10px

Both are created after btn, so their padding and text size win over btn's.

2. Add the size setting

  1. On the .btn-small row, click Add rendering condition, then Bind, then Create Conditional Prop.
  2. In Name, type size. In Type, pick string and leave Validation Type on text. In Default, replace newProp with medium. Click Create.
  3. In the Operand list, pick =. In the value box, type small and press Enter.
  4. On the .btn-large row, click Add rendering condition, then Bind → Dynamic Properties Assignment Panel. In the Select Dynamic Property panel, open props, click size and click Bind property. Pick = and type large, then press Enter.

Both size rows now show Rendering condition is not met: the button is medium, which is what you want.

3. Pick a size on each copy

  1. Go back to a page. To show the three sizes side by side, put three copies in one container.
  2. Click a copy. In the right panel, under Component Properties, open the Conditional group. size is a list: large, medium, small. medium is there because it's the default, even though no class compares size with it.
  3. Pick a size. buttonType is in the same group, so you can pick the look on the same copy.

Check that it worked

  • Three copies show three sizes; a fourth with buttonType set to outline and size to large shows a large outline button.
  • Click Preview in the bottom toolbar: the published page shows the same buttons. Building the preview can take a minute.
  • A link look has no fill and no border, so its size shows only in its text size and the space around it.

Troubleshooting

A size has no effect. The size class was created before btn, so btn wins. Remove the size class from the button, delete it, and create it again: it then comes after btn.

A copy is stuck on small or large. Open the Conditional group and pick medium.

Good to know

  • Each setting you add multiplies what one component can show: four looks and three sizes are twelve buttons, and you still edit one component.
  • In the exported Next.js code, the button's class list is built from both settings, for example btn btn-outline btn-large.
Share

Related Articles

How to turn a part of a component on or off

In TeleportHQ, an on/off setting on a component is a boolean prop; it can switch a class on (a full-width button) through the class's rendering condition, or show and hide an element (an icon inside the button) through the element's Conditional Rendering, and every copy turns it on or off with a False | True switch.

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.

What are component variants?

In TeleportHQ, a component variant is one component whose copies can look or behave differently, picked per copy with a setting (a prop); the component keeps a base class with what every version shares and a class per version that switches on when the setting matches.

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 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.