Toggle Glass
shadcn-glass-ui/toggle-glassFreeComponent
Glass-themed toggle switch with shadcn/ui compatible API:
Install it
npx shadcn@latest add https://raw.githubusercontent.com/artyhoo/shadcn-glass-ui-library/main/public/r/toggle-glass.jsonSource
1/**2 * ToggleGlass Component3 *4 * Glass-themed toggle switch with shadcn/ui compatible API:5 * - Theme-aware styling (glass/light/aurora)6 * - Glow effect when active7 * - Size variants (default, sm, lg)8 * - Variant styles (default, outline)9 * - Optional label10 *11 * **shadcn/ui compatible props:**12 * - `pressed` / `defaultPressed` - Control pressed state13 * - `onPressedChange` - Callback when state changes14 * - `variant` - 'default' | 'outline'15 * - `size` - 'default' | 'sm' | 'lg'16 *17 * @example18 * ```tsx19 * // Controlled20 * <ToggleGlass pressed={isOn} onPressedChange={setIsOn} />21 *22 * // Uncontrolled23 * <ToggleGlass defaultPressed={true} />24 *25 * // With variant26 * <ToggleGlass variant="outline" pressed={isOn} onPressedChange={setIsOn} />27 * ```28 */2930import { forwardRef, useState, type CSSProperties } from 'react';31import { type VariantProps } from 'class-variance-authority';32import { cn } from '@/lib/utils';33import { useFocus } from '@/lib/hooks/use-focus';34import { toggleSizes, type ToggleGlassVariant } from '@/lib/variants/toggle-glass-variants';35import '@/glass-theme.css';3637// ========================================38// SIZE CONFIG39// ========================================4041const sizesConfig = {42 sm: { track: 'w-8 h-4', knob: 'w-3 h-3', translate: 'translate-x-4' },43 default: { track: 'w-11 h-6', knob: 'w-5 h-5', translate: 'translate-x-5' },44 lg: { track: 'w-14 h-7', knob: 'w-6 h-6', translate: 'translate-x-7' },45} as const;4647// ========================================48// PROPS INTERFACE49// ========================================5051export interface ToggleGlassProps52 extends53 Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onChange' | 'defaultValue'>,54 VariantProps<typeof toggleSizes> {55 /**56 * Controlled pressed state (shadcn/ui compatible)57 */58 readonly pressed?: boolean;59 /**60 * Default pressed state for uncontrolled usage61 */62 readonly defaultPressed?: boolean;63 /**64 * Callback when pressed state changes (shadcn/ui compatible)65 */66 readonly onPressedChange?: (pressed: boolean) => void;67 /**68 * Visual variant (shadcn/ui compatible)69 * @default "default"70 */71 readonly variant?: ToggleGlassVariant;72 /**73 * Optional label text74 */75 readonly label?: string;76 /**77 * className for the wrapper label element (when label is provided).78 * Use this for spacing, layout, or wrapper-specific styling.79 * Note: `className` always applies to the toggle button (shadcn/ui pattern).80 * @since v2.6.081 */82// … 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 |
