A switch (lu-sw): a checkbox drawn as a track and thumb, for an effect that is immediate.
<.switch name="notify" label="Notifications" color="primary" />
<.switch field={@form[:public]} label="Public" variant="outline" color="success" filled />
<.switch name="dense" size="sm" shape="pill" thumb_inset={4} checked />
<.switch name="email" label="Email" label_position="left" wrapper_class="w-full justify-between" />With a name (or field) the switch holds a real, visually hidden checkbox (so the form,
the keyboard and phx-change work) and, like checkbox/1, sends unchecked_value through a
hidden input when off. The track and aria-checked flip in the browser with
Phoenix.LiveView.JS, no round trip; without a name the label itself is the click target.
shape is squircle (the default look) or pill. thumb_inset (2..6 px) puts the thumb away
from the edge: the higher, the smaller it is; left nil it is the stylesheet's 3px. Extra
HTML attributes go to the <input> (or to the label when there is no name).
Summary
Functions
Attributes
field(Phoenix.HTML.FormField) - Defaults tonil.id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any) - Defaults tonil.checked(:boolean) - Defaults tonil.checked_value(:string) - Defaults to"true".unchecked_value(:string) - Defaults to"false".hidden_input(:boolean) - Defaults totrue.color(:string) - Defaults to"neutral". Must be one of"neutral","primary","secondary","info","success","warning", or"error".variant(:string) - Defaults to"basic". Must be one of"basic", or"outline".filled(:boolean) - Defaults tofalse.shape(:string) - Defaults to"squircle". Must be one of"pill", or"squircle".size(:string) - Defaults to"md". Must be one of"sm","md", or"lg".thumb_inset(:integer) - Defaults tonil.Must be one ofnil,2,3,4,5, or6.label(:string) - Defaults tonil.label_position(:string) - Defaults to"right". Must be one of"right", or"left".label_class(:any) - Defaults tonil.description(:string) - Defaults tonil.errors(:list) - Defaults to[].disabled(:boolean) - Defaults tofalse.wrapper_class(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["form", "required"].
Slots
inner_block