// components/ui/Switch.tsx 'use client' import * as React from 'react' import clsx from 'clsx' type SwitchSize = 'default' | 'short' type SwitchVariant = 'simple' | 'icon' export type SwitchProps = { /** Controlled */ checked: boolean onChange: (checked: boolean) => void /** Optional wiring */ id?: string name?: string disabled?: boolean required?: boolean /** Labeling / a11y */ ariaLabel?: string ariaLabelledby?: string ariaDescribedby?: string /** UI */ size?: SwitchSize variant?: SwitchVariant className?: string } /** * Switch / Toggle (Tailwind, ohne Headless UI) * - size="default" (w-11) wie Simple toggle * - size="short" (h-5 w-10) wie Short toggle * - variant="icon" zeigt X/Check Icon im Thumb */ export default function Switch({ checked, onChange, id, name, disabled, required, ariaLabel, ariaLabelledby, ariaDescribedby, size = 'default', variant = 'simple', className, }: SwitchProps) { const handleChange = (e: React.ChangeEvent) => { if (disabled) return onChange(e.target.checked) } const baseInput = clsx( 'absolute inset-0 size-full appearance-none focus:outline-hidden', disabled && 'cursor-not-allowed' ) if (size === 'short') { // Short toggle Beispiel return (
) } // Default size (simple / icon) Beispiele return (
{variant === 'icon' ? ( {/* Off icon */} {/* On icon */} ) : ( )}
) }