Skip to content

Toggle

Toggle components are Input Fields that act as visual switches, allowing the user to turn a setting on or off. They represent a boolean value.

toggle.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'toggle',
path: 'notificationsEnabled',
label: 'Enable push notifications',
},
],
});

Use these props to customize your Toggle component.

proptypedescription
hintstringA description to display below the toggle control
togglePositionstringPosition of the toggle switch relative to its label. Possible values are left (default) or right.

Use the property hint to add a description.

toggle.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'toggle',
path: 'marketingEmails',
label: 'Receive marketing emails',
props: {
hint: 'We\'ll only send you relevant product updates.',
},
},
],
});

Use the property togglePosition to align the toggle switch to the left (default) or right of its label.

toggle.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'toggle',
path: 'darkMode',
label: 'Dark mode',
props: {
togglePosition: 'left',
},
},
],
});

Toggles can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables and a quick description of what you will style.

CSS VariableDescription
--gui-toggle-widthTotal width of the toggle switch
--gui-toggle-heightTotal height of the toggle switch
--gui-toggle-slider-widthWidth of the round slider knob thumb
--gui-toggle-slider-heightHeight of the round slider knob thumb
--gui-toggle-slider-transformX-axis transform value distance for the knob when checked
--gui-bg-defaultBackground color of slider container when off
--gui-bg-disabledBackground color of slider container when disabled
--gui-border-defaultDefault border of the off-state slider background
--gui-intent-primarySlider background and border color when checked / on
--gui-text-defaultBorder color when focused
--gui-intent-errorBorder and shadow color when invalid

This is the anatomy of the Toggle Component in case you want to use your CSS styles.

toggle-anatomy.html
<gui-toggle class="gui-toggle gui-toggle--left">
<label for="fieldUid">
Label
<div class="gui-toggle__hint" id="fieldUid_hint">Hint</div>
</label>
<div class="gui-widget gui-widget--horizontal gui-toggle--switch">
<input
type="checkbox"
id="fieldUid"
checked
aria-required="true"
aria-describedby="fieldUid_hint"
/>
<span class="gui-toggle--slider" role="presentation"></span>
</div>
</gui-toggle>