Switch

Renders a switch as a button.

Read more Read less

If you want to render a switch as part of a form, use the input/1 component with the type "switch" instead.

Note that this component only renders a button with a label, a state, and <span> with the class switch-control. You will need to style the switch control span with CSS in order to give it the appearance of a switch.

Usage

<.switch
  label="Subscribe"
  checked={true}
  phx-click="toggle-subscription"
/>
Attribute Type Documentation Default Value
checked :boolean false
class :any Any additional classes to be added. Variations of the component should be expressed via modifier attributes, and it is preferable to use styles on the parent container to arrange components on the page, but if you have to, you can use this attribute to pass additional utility classes to the component. The value can be a string or a list of strings. []
Required label * :string
off_text :string "Off"
on_text :string "On"
rest :global