Switcher
Switcher component.
Switcher, Customization Blocks
A two-state control that swaps its own content, a text, an icon or both, between the on and off states. It is a native checkbox under the hood, so it binds to a boolean like any checkbox. Use the Toggle for a labelled on/off field and the Swap to cycle through a list of values.
<x-switcher on="Following" off="Follow" />
<!-- Icons only --><x-switcher icon-when-on="speaker-x-mark" icon-when-off="speaker-wave" aria-label="Mute" /> <!-- Text and icons --><x-switcher on="Pause" off="Play" icon-when-on="pause" icon-when-off="play" />
<x-switcher on="Pause" off="Play" icon-when-on="pause" icon-when-off="play" position="right" />
<!-- Fade, the default --><x-switcher icon-when-on="moon" icon-when-off="sun" aria-label="Dark mode" /> <!-- Rotate --><x-switcher icon-when-on="moon" icon-when-off="sun" rotate aria-label="Dark mode" /> <!-- Flip --><x-switcher icon-when-on="moon" icon-when-off="sun" flip aria-label="Dark mode" />
<x-switcher xs on="Pause" off="Play" icon-when-on="pause" icon-when-off="play" /><x-switcher sm on="Pause" off="Play" icon-when-on="pause" icon-when-off="play" /><x-switcher md on="Pause" off="Play" icon-when-on="pause" icon-when-off="play" /><x-switcher lg on="Pause" off="Play" icon-when-on="pause" icon-when-off="play" />
An option to use any content for each state.
<x-switcher aria-label="Like"> <x-slot:on> <x-icon name="heart" solid class="h-6 w-6 text-red-500" /> </x-slot:on> <x-slot:off> <x-icon name="heart" outline class="h-6 w-6" /> </x-slot:off></x-switcher>
An option to color each state. Without it, the state inherits the color of where it sits.
<x-switcher on="Active" off="Inactive" color-when-on="green" color-when-off="red" /> <!-- Off state inherits the color around it --><x-switcher on="Following" off="Follow" color-when-on="primary" />
<x-switcher readonly on="Pause" off="Play" /><x-switcher disabled on="Pause" off="Play" />
<x-switcher on="Pause" off="Play" x-on:switch="console.log($event.detail.value)" />
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<div x-data="{ open: false }"> <x-switcher x-model="open" on="Hide details" off="Show details" /> <div x-show="open">...</div></div>