Skip to content

Switch

extends Element

Switch: sliding on/off toggle, fires "change".

Properties

PropertyTypeDefaultDescription
checkedbooleanfalseChecked state; mirrored to the "checked" element state for styling
onColornumbercolors.greentrack color while on
offColornumbercolors.graytrack color while off
knobColornumbercolors.whiteColor of the knob
widthnumber4Width in terminal cells

Events

EventRegistrarDescription
change:onChange(fn)Fired after every toggle with the new checked state

Methods

Switch:setup()

Registers the click handler that toggles the switch.

Switch:render(buf)

Renders the track and the sliding knob.

  • buf (Render) The render buffer

Last updated:

Released under the MIT License.