Last active
October 28, 2025 15:07
-
-
Save albingroen/e7d00366d25a5bc92c8fe0868a391184 to your computer and use it in GitHub Desktop.
Glass switch component based on shadcn/ui
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use client"; | |
| import * as React from "react"; | |
| import * as SwitchPrimitive from "@radix-ui/react-switch"; | |
| import { cn } from "@/lib/utils"; | |
| function Switch({ | |
| className, | |
| ...props | |
| }: React.ComponentProps<typeof SwitchPrimitive.Root>) { | |
| return ( | |
| <SwitchPrimitive.Root | |
| data-slot="switch" | |
| className={cn( | |
| "group/switch cursor-pointer peer data-[state=checked]:bg-indigo-400 dark:data-[state=checked]:bg-indigo-500 data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[18px] w-10 shrink-0 items-center rounded-full border border-transparent transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 duration-500", | |
| className, | |
| )} | |
| {...props} | |
| > | |
| <SwitchPrimitive.Thumb | |
| data-slot="switch-thumb" | |
| className={cn( | |
| "shadow-xs group-active/switch:bg-white/20 border border-white group-active/switch:border-white/50 dark:group-active/switch:border-white/20 group-active/switch:backdrop-blur-xs bg-white pointer-events-none block h-3.5 w-[22px] rounded-full ring-0 transition-all data-[state=checked]:translate-x-[calc(100%-7px)] data-[state=unchecked]:translate-x-px group-active/switch:scale-125 origin-top duration-300", | |
| )} | |
| /> | |
| </SwitchPrimitive.Root> | |
| ); | |
| } | |
| export { Switch }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment