# `LedgerUI.Components.Switch`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/switch.ex#L1)

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).

# `switch`

## Attributes

* `field` (`Phoenix.HTML.FormField`) - Defaults to `nil`.
* `id` (`:string`) - Defaults to `nil`.
* `name` (`:string`) - Defaults to `nil`.
* `value` (`:any`) - Defaults to `nil`.
* `checked` (`:boolean`) - Defaults to `nil`.
* `checked_value` (`:string`) - Defaults to `"true"`.
* `unchecked_value` (`:string`) - Defaults to `"false"`.
* `hidden_input` (`:boolean`) - Defaults to `true`.
* `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 to `false`.
* `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 to `nil`.Must be one of `nil`, `2`, `3`, `4`, `5`, or `6`.
* `label` (`:string`) - Defaults to `nil`.
* `label_position` (`:string`) - Defaults to `"right"`. Must be one of `"right"`, or `"left"`.
* `label_class` (`:any`) - Defaults to `nil`.
* `description` (`:string`) - Defaults to `nil`.
* `errors` (`:list`) - Defaults to `[]`.
* `disabled` (`:boolean`) - Defaults to `false`.
* `wrapper_class` (`:any`) - Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted. Supports all globals plus: `["form", "required"]`.
## Slots

* `inner_block`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
