<sessions-switch>
An on/off toggle with a label.
Preact & React
<Switch>GroupFormsDrawn asSwitchPreview
Drawn by the same renderers Sessions uses for your extension, from the DOM example beside it, without its event handlers.
When to use it
Controlled: keep checked in your state and flip it in the change handler.
In Preact and React, import the component of the same name from @sessions/apps/preact or @sessions/apps/react. Attributes become camelCase props, a boolean attribute is a boolean prop, and an event is an on prop that receives the event’s detail.
Attributes
Attribute
labelThe switch label.Prop
labelcheckedbooleanOn.Prop
checkedhelp-textA line under the label.Prop
helpTextdisabledbooleanNon-interactive.Prop
disabledEvents
changedetail: boolean — the new stateThe switch was flipped.Prop
onChangeExample
import {Switch} from '@sessions/apps/preact';
<Switch
label="Show to buyers"
checked={visible.value}
onChange={(checked) => (visible.value = checked)}
/>