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
- Build the button with four looks first. See How to build a button with four looks. This article adds to that component,
ActionButton. - You need the Owner, Admin or Designer role.
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
- In the left sidebar, open Pages, Components & Tree View, and in the Components folder click
ActionButton. - On the component canvas, click the button to select it.
- In the right panel, in the Classes section, click the field Type to search or create new class, type
btn-smalland click Create class btn-small. - 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.
- Create
btn-largethe same way.
| class | property | value |
|---|---|---|
btn-small | padding | 8px 16px |
font-size | 14px | |
border-radius | 6px | |
btn-large | padding | 16px 32px |
font-size | 18px | |
border-radius | 10px |
Both are created after btn, so their padding and text size win over btn's.
2. Add the size setting
- On the
.btn-smallrow, click Add rendering condition, then Bind, then Create Conditional Prop. - In Name, type
size. In Type, pickstringand leave Validation Type ontext. In Default, replacenewPropwithmedium. Click Create. - In the Operand list, pick
=. In the value box, typesmalland press Enter. - On the
.btn-largerow, click Add rendering condition, then Bind → Dynamic Properties Assignment Panel. In the Select Dynamic Property panel, open props, clicksizeand click Bind property. Pick=and typelarge, 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
- Go back to a page. To show the three sizes side by side, put three copies in one container.
- Click a copy. In the right panel, under Component Properties, open the Conditional group.
sizeis a list:large,medium,small.mediumis there because it's the default, even though no class comparessizewith it. - Pick a size.
buttonTypeis 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
buttonTypeset tooutlineandsizetolargeshows 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.