LanternUI.Components.Switch (LanternUI v0.8.2)

Copy Markdown View Source

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

switch(assigns)

Attributes

  • id (:any) - Element id; derived from field when omitted. Defaults to nil.
  • name (:string) - Form input name; derived from field when omitted. Defaults to nil.
  • value (:any) - Current value used to derive checked state. Defaults to nil.
  • checked (:boolean) - Force on/off; else compares value to checked_value. Defaults to nil.
  • 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 to nil.
  • sublabel (:string) - Secondary label line under the primary label. Defaults to nil.
  • description (:string) - Helper text under the label stack. Defaults to nil.
  • 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 to nil.
  • field (Phoenix.HTML.FormField) - Form field; derives id, name, value, and errors. Defaults to nil.
  • disabled (:boolean) - Render disabled and non-interactive. Defaults to false.
  • Global attributes are accepted. Arbitrary HTML/phx-* attributes passed through. Supports all globals plus: ["form", "phx-change", "phx-target", "phx-click"].