generated from yun-cheng/my-react-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 } |