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.
Buttonis a reserved name, so call the component something else, for exampleActionButton. - 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 = linkTwo kinds of setting, two kinds of prop:
- A setting that picks a look is a
stringprop, and its values are short lowercase words:primary,secondary,outline,link. - Text that changes from copy to copy is a
richtextprop, so each copy keeps its own words and formatting.
Steps
1. Give the button its base class
- 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. - On the component canvas, click the button to select it.
- In the right panel, find the Classes section. A new Button arrives wearing the class
.button, a ready-made grey look. On the.buttonrow, click Remove class. The class stays in your project; only this button stops using it. - In the Classes section, click the field Type to search or create new class, type
btnand click Create class btn. The Create class panel opens. - In the Create class panel, turn off Extract element styles, so the class starts empty.
- 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.
| property | value |
|---|---|
display | inline-flex |
align-items | center |
justify-content | center |
padding | 12px 24px |
border-width | 2px |
border-style | solid |
border-color | transparent |
border-radius | 8px |
font-size | 16px |
font-weight | 600 |
cursor | pointer |
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.
| class | property | value |
|---|---|---|
btn-primary | background-color | #2563eb |
border-color | #2563eb | |
color | #ffffff | |
btn-secondary | background-color | #e0e7ff |
border-color | #e0e7ff | |
color | #1e3a8a | |
btn-outline | background-color | transparent |
border-color | #2563eb | |
color | #2563eb | |
btn-link | background-color | transparent |
border-color | transparent | |
color | #2563eb | |
text-decoration | underline |
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
- In the Classes section, on the
.btn-primaryrow, 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. - Click Bind, then Create Conditional Prop. The Create Conditional Prop window opens.
- In Name, replace the suggested name with
buttonType. - In Type, pick
string. A Validation Type list appears: leave it ontext. - In Default, replace
newPropwithprimary. Copies that don't pick a look get this one. - Click Create.
- In the Operand list, pick
=. In the value box, typeprimary, then press Enter or click outside the box. The value is saved when you leave the box. - On the
.btn-secondaryrow, click Add rendering condition, then Bind → Dynamic Properties Assignment Panel. In the Select Dynamic Property panel, open props, clickbuttonTypeand click Bind property. Pick=and typesecondary. - Do the same on the
.btn-outlinerow withoutline, and on the.btn-linkrow withlink.
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
- With the button still selected, find the Text Content section in the right panel.
- Click the plug icon next to the text, then Bind value, then Create Richtext Prop. The Props panel opens with the new prop.
- In the new prop's Name box, type
labeland press Enter. - In its Default value box, type
Get startedand press Enter.
The button's text now comes from label, and every copy can change it.
5. Pick the look on each copy
- Go back to a page and place your copies. To show the four looks side by side, put four copies in one container.
- Click a copy. In the right panel, under Component Properties, open the Conditional group.
buttonTypeis a list of the four looks:link,outline,primary,secondary. The list holds every value a condition in the component comparesbuttonTypewith, plus its default. - Pick a look.
- 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
btnonce: 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
btnplusbtn-outlinewhenbuttonTypeisoutline. 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
booleanprop instead of astringprop.