PhoenixDuskmoon.Component.Form.Switch (PhoenixDuskmoon v7.2.1)

View Source

Switch component for toggle functionality.

Examples

<.dm_form for={@form} phx-submit="save">
  <.dm_switch field={@form[:notifications]} label="Enable notifications" />
  <.dm_switch field={@form[:dark_mode]} label="Dark mode" size="lg" />
</.dm_form>

Attributes

  • field - Phoenix form field
  • label - Switch label text
  • size - Switch size: xs, sm, md, lg (default: md)
  • color - Switch color: primary, secondary, accent, info, success, warning, error (default: primary)
  • disabled - Disable the switch
  • class - Additional CSS classes
  • label_class - Additional CSS classes for label
  • switch_class - Additional CSS classes for switch element

Summary

Functions

dm_switch(assigns)

Attributes

  • id (:any) - Defaults to nil.
  • name (:any)
  • value (:any)
  • field (Phoenix.HTML.FormField) - a form field struct retrieved from the form.
  • checked (:boolean) - Defaults to false.
  • label (:string) - Defaults to nil.
  • size (:string) - Defaults to "md". Must be one of "xs", "sm", "md", or "lg".
  • color (:string) - Defaults to "primary". Must be one of "primary", "secondary", "accent", "info", "success", "warning", or "error".
  • disabled (:boolean) - Defaults to false.
  • class (:string) - Defaults to nil.
  • label_class (:string) - Defaults to nil.
  • switch_class (:string) - Defaults to nil.
  • Global attributes are accepted.