Skip to content

Commit

Permalink
feat(UI): add Switch component
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-cheng committed Apr 28, 2024
1 parent b43439d commit c25cbf0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/components/ui/Switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as SwitchPrimitives from '@radix-ui/react-switch'
import * as React from 'react'
import cn from 'utils/cn'

const Switch = React.forwardRef<
React.ElementRef<typeof SwitchPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
className={cn(
'h-[22px] w-[43px]',
'peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-950 focus-visible:ring-offset-2 focus-visible:ring-offset-white',
'disabled:cursor-not-allowed disabled:opacity-50',
'data-[state=checked]:bg-soft-cyan data-[state=unchecked]:bg-soft-grayish-blue',
className
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb
className={cn(
'h-[14px] w-[14px]',
'pointer-events-none block rounded-full bg-white shadow-lg ring-0 transition-transform',
'data-[state=checked]:translate-x-[23px] data-[state=unchecked]:translate-x-[2px]'
)}
/>
</SwitchPrimitives.Root>
))
Switch.displayName = SwitchPrimitives.Root.displayName

export { Switch }

0 comments on commit c25cbf0

Please sign in to comment.