Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement switch component #13

Merged
merged 5 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"lucide-react": "^0.367.0",
Expand Down
3 changes: 3 additions & 0 deletions public/icons/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/left-nav-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export const LeftNavLayout = ({ children }: PropsWithChildren) => {
return (
<div className={cn('flex', activeItem && 'pl-[240px]')}>
{activeItem && (
<div className="fixed left-0 z-50 flex h-screen w-[240px] flex-col items-center border-r border-gray-03 bg-white p-5">
<div className="fixed left-0 z-50 flex h-screen w-[240px] flex-col items-center border-r border-gray-04 bg-white p-5">
<div className="flex items-center gap-[14px]">
<div className="size-9 rounded-lg bg-gray-03" />
<div className="size-9 rounded-lg bg-gray-04" />
<LogoIcon />
</div>
<div className="mb-[26px] mt-[30px] w-full">
Expand Down
37 changes: 37 additions & 0 deletions src/components/ui/switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use client'

import * as React from 'react'
import * as SwitchPrimitives from '@radix-ui/react-switch'
import { cn } from '@/lib/utils'
import Image from 'next/image'

const Switch = React.forwardRef<
React.ElementRef<typeof SwitchPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
className={cn(
'peer inline-flex h-[20px] w-[40px] 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-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=unchecked]:bg-gray-04 data-[state=checked]:bg-orange-05',
className,
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb
className={cn(
'pointer-events-none size-4 rounded-full bg-gray-01 shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0 block *:data-[state=unchecked]:hidden relative',
)}
>
<Image
src="/icons/check.svg"
alt=""
width={9}
height={7}
className="absolute bottom-1/2 right-1/2 translate-x-1/2 translate-y-1/2"
/>
</SwitchPrimitives.Thumb>
</SwitchPrimitives.Root>
))
Switch.displayName = SwitchPrimitives.Root.displayName

export { Switch }
4 changes: 2 additions & 2 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ const config = {
gray: {
'01': '#F6FAFD',
'02': '#EFF1F3',
'03': '#D2D6DB',
'04': '',
'03': '',
'04': '#D2D6DB',
'05': '#A2A6AB',
'06': '#797D81',
'07': '#4B4F54',
Expand Down