Switch Glass
shadcn-glass-ui/switch-glassFreeComponent
Glass-themed toggle switch with smooth animations and accessibility features. * Built on @radix-ui/react-switch for robust state management and keyboard navigation. * * ## Features
Install it
npx shadcn@latest add https://raw.githubusercontent.com/artyhoo/shadcn-glass-ui-library/main/public/r/switch-glass.jsonSource
1/**2 * SwitchGlass Component3 *4 * Glass-themed toggle switch with smooth animations and accessibility features.5 * Built on @radix-ui/react-switch for robust state management and keyboard navigation.6 *7 * ## Features8 * - Full shadcn/ui API compatibility (drop-in replacement)9 * - Smooth sliding thumb animation (300ms duration)10 * - Optional integrated label with proper touch targets (44px minimum)11 * - Glass morphism styling with gradient backgrounds when active12 * - Controlled and uncontrolled modes13 * - Accessible ARIA attributes and keyboard support (Space/Enter)14 * - Disabled state with visual feedback15 * - Active state glow effect via CSS variables16 *17 * ## CSS Variables18 * - `--toggle-bg` - Background when unchecked19 * - `--toggle-active-bg` - Gradient background when checked20 * - `--toggle-knob` - Thumb/knob color21 * - `--toggle-glow` - Box shadow when checked22 * - `--text-secondary` - Label text color23 *24 * @example Basic usage (controlled)25 * ```tsx26 * import { SwitchGlass } from 'shadcn-glass-ui'27 * import { useState } from 'react'28 *29 * function Settings() {30 * const [enabled, setEnabled] = useState(false)31 *32 * return (33 * <SwitchGlass34 * checked={enabled}35 * onCheckedChange={setEnabled}36 * />37 * )38 * }39 * ```40 *41 * @example Uncontrolled with default value42 * ```tsx43 * <SwitchGlass defaultChecked />44 * ```45 *46 * @example With integrated label47 * ```tsx48 * <SwitchGlass49 * label="Airplane Mode"50 * checked={isOn}51 * onCheckedChange={setIsOn}52 * />53 * ```54 *55 * @example shadcn/ui compatible alias56 * ```tsx57 * import { Switch } from 'shadcn-glass-ui'58 *59 * <Switch checked={enabled} onCheckedChange={setEnabled} />60 * ```61 *62 * @accessibility63 * - WCAG 2.1 AA compliant via Radix UI primitives64 * - Keyboard navigation: Space and Enter keys toggle state65 * - Proper ARIA role: `switch` with `aria-checked` attribute66 * - Focus visible indicator for keyboard navigation67 * - 44px minimum touch target (Apple HIG compliant) when label is used68 * - Disabled state properly communicated to screen readers69 *70 * @since v1.0.071 * @see https://www.radix-ui.com/primitives/docs/components/switch72 */7374'use client';7576import * as React from 'react';77import * as SwitchPrimitive from '@radix-ui/react-switch';78import { cn } from '@/lib/utils';79import '@/glass-theme.css';8081// ========================================82// PROPS INTERFACE83// ========================================8485/**86 * Props for SwitchGlass component.87 *88// … truncated
More from shadcn-glass-ui
All 76 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Alert Glassalert-glass | shadcn-glass-ui | Components | Free | no deps | |
| Animated Background Glassanimated-background-glass | shadcn-glass-ui | Components | Free | no deps | |
| Avatar Glassavatar-glass | shadcn-glass-ui | Components | Free | no deps | |
| Badge Glassbadge-glass | shadcn-glass-ui | Components | Free | no deps | |
| Base Progress Glassbase-progress-glass | shadcn-glass-ui | Components | Free | no deps | |
| Button Glassbutton-glass | shadcn-glass-ui | Components | Free | no deps | |
| Card Glasscard-glass | shadcn-glass-ui | Components | Free | no deps | |
| Checkbox Glasscheckbox-glass | shadcn-glass-ui | Components | Free | no deps |
