How to turn a part of a component on or off
In TeleportHQ, a setting that is only on or off is a boolean prop. It can do two things: switch a class on, for example a full-width look for a button, or show and hide an element, for example an icon inside the button. Every copy then turns the setting on or off with a False | True switch.
Before you start
- Build the button with looks and sizes first. See How to build a button with four looks and How to add sizes to a button. 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"
size string default "medium"
fullWidth boolean default false ← new: stretch the button
showIcon boolean default false ← new: show the arrow
label richtext default "Get started"
button element
.btn always (+ gap 8px between text and icon)
.btn-<look>, .btn-<size> as before
.btn-full when fullWidth = true (new)
label text
arrow icon 24 × 24, shown when showIcon = true (new)A class turns a look on; Conditional Rendering turns a whole element on. Both read the same kind of setting.
Steps
1. Make the button stretch when fullWidth is on
- 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 Type to search or create new class, type
btn-fulland click Create class btn-full. In the Create class panel, turn off Extract element styles and add one row:width100%. - On the
.btn-fullrow, click Add rendering condition (the eye with a small C). Click Bind, then Create Conditional Prop. - In Name, replace the suggested name with
fullWidth. Type is alreadybooleanand Default is already False: leave both. Click Create. - Click the value box (Pick a value) and pick
truefrom the list. The condition is saved as soon as you pick it.
The .btn-full row shows Rendering condition is not met: the button only stretches on copies that turn fullWidth on.
2. Add an arrow that shows when showIcon is on
- Space the text and the icon: on the
.btnrow in the Classes section, click Edit class (the expand icon) and add the rowgap8px. The value box may showHalfUnit, the spacing token that equals 8px; the class keeps 8px. - Select the button's text: in Pages, Components & Tree View, expand the button in the tree and click its text row.
- In the left sidebar, open Assets Manager, then the Icons tab. In Search, type
arrow right: every section with a matching icon opens. In the Arrows section, click the icon namedarrow right(point at an icon to see its name). The icon goes into the button, after the text. - Select the new icon (click it in the tree). Icons arrive at 48 × 48, too big for a button: in the right panel, open the Attributes section and set
widthandheightto24. - In the right panel, find Conditional Rendering and turn on its switch.
- Click Bind, then Create Conditional Prop. In Name, type
showIcon; leave Type onbooleanand Default on False. Click Create. - Leave the operator on
=, click the value box (Pick a value) and picktrue.
The section now says Element not visible in the canvas! The current value of showIcon is false. That's expected: copies show the arrow only when they turn showIcon on. Click Set showIcon to true to see the arrow while you design the component. It changes only this preview: copies on your pages keep their own setting.
3. Turn the settings on, copy by copy
- Go back to the page with your copies and click a copy.
- In the right panel, under Component Properties, open the Conditional group.
fullWidthandshowIconeach have a False | True switch. - Click True to turn a setting on for that copy.
Check that it worked
- A copy with
showIconon shows the arrow after its text; the others don't. - A copy with
fullWidthon fills the width of its container. In a grid, it fills its column, so it only looks wider when that column is wider than the button. - Click Preview in the bottom toolbar and wait for the preview to build (about a minute): the same buttons show.
Troubleshooting
The icon landed next to the button, not inside it. The button itself was selected when you clicked the icon. Delete the icon, select the button's text in the tree, and click the icon again.
The setting is listed under Unassigned, not Conditional. No value was picked in its condition. Open the component, select the element, and pick true in the condition's value box.
The arrow shows on every copy. The icon's Conditional Rendering switch is off, or its condition isn't bound to showIcon. Select the icon and check its Conditional Rendering section.
Good to know
- On/off settings mix with looks and sizes: one copy can be a large outline button with an arrow, stretched to full width.
- The arrow takes the look's text color only if the icon uses the current text color; otherwise set its color in the icon's Color section.