defmodule PhiaUi.Components.Switch do @moduledoc """ Accessible on/off switch component for Phoenix LiveView. A two-state toggle rendered as a pill-shaped track with an animated sliding thumb. Uses `role="switch"` and `aria-checked` for full WAI-ARIA compliance. The animation is pure CSS (`translate-x` transition) — zero JavaScript required. ## Sub-components | Function | Purpose | |----------------|----------------------------------------------------------------------| | `switch/1` | Standalone switch button — manage state in your LiveView | | `form_switch/1`| Switch integrated with `Phoenix.HTML.FormField` and Ecto changesets | ## When to use Use a switch for binary settings that take effect immediately or are submitted as part of a form. Switches communicate an on/off state more clearly than checkboxes for settings like "Enable notifications", "Public profile", or "Auto-renew subscription". Use a `checkbox/1` instead when the control is part of a list of options, or when the action requires explicit confirmation (e.g. "I agree to the terms"). ## Standalone usage <%!-- Server-state switch: the LiveView owns the boolean --%> <.switch checked={@notifications_enabled} phx-click="toggle_notifications" /> <%!-- Labelled by wrapping in a