Switch
Live Demos HubSwitch
Interactive production-grade hypermedia component for HTMXUI.
Interactive Preview
HTML Source
<!--
Component: switch.html
Configurable State: themeColor ('primary'|'secondary'|'destructive'), size ('sm'|'md'|'lg'), isOpen (boolean)
Usage: Bind styles dynamically using hx-class="{ 'bg-primary': themeColor === 'primary' }" or hx-style="{ width: size === 'lg' ? '100%' : 'auto' }"
-->
<label hx-ext="reactive" hx-state="{ themeColor: \'primary\', size: \'md\', isOpen: false }" class="flex items-center space-x-2 cursor-pointer">
<!-- Checkbox Hack for Switch -->
<div class="relative inline-block w-11 h-6 align-middle select-none transition duration-200 ease-in">
<input type="checkbox" name="{name}" id="{id}" class="peer absolute block w-6 h-6 rounded-full bg-background border-4 border-input appearance-none cursor-pointer transition-transform duration-200 ease-in-out checked:translate-x-full checked:border-primary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2" {checked} hx-post="{toggle_url}" hx-trigger="change" />
<label for="{id}" class="block overflow-hidden h-6 rounded-full bg-input cursor-pointer peer-checked:bg-primary"></label>
</div>
<span class="text-sm font-medium text-foreground">{label}</span>
</label>