Toggle switch for binary settings. Mirrors Fluxon's switch/1 surface.
<.switch field={@form[:notifications]} label="Enable notifications" />
<.switch name="dark" checked={@dark} label="Dark mode" size="sm" color="accent" />A hidden input always submits unchecked_value so forms receive a param even
when the switch is off.
Summary
Functions
Attributes
id(:any) - Element id; derived from field when omitted. Defaults tonil.name(:string) - Form input name; derived from field when omitted. Defaults tonil.value(:any) - Current value used to derive checked state. Defaults tonil.checked(:boolean) - Force on/off; else compares value to checked_value. Defaults tonil.checked_value(:any) - Value submitted when the switch is on. Defaults to"true".unchecked_value(:any) - Hidden input value submitted when off. Defaults to"false".label(:string) - Primary label text beside the switch. Defaults tonil.sublabel(:string) - Secondary label line under the primary label. Defaults tonil.description(:string) - Helper text under the label stack. Defaults tonil.errors(:list) - Validation messages; derived from field when used. Defaults to[].size(:string) - Track and thumb size. Defaults to"md". Must be one of"sm","md", or"lg".color(:string) - On-state track color token. Defaults to"accent".class(:any) - Extra classes merged onto the root element. Defaults tonil.field(Phoenix.HTML.FormField) - Form field; derives id, name, value, and errors. Defaults tonil.disabled(:boolean) - Render disabled and non-interactive. Defaults tofalse.- Global attributes are accepted. Arbitrary HTML/
phx-*attributes passed through. Supports all globals plus:["form", "phx-change", "phx-target", "phx-click"].