Skip to content

Commit

Permalink
Merge pull request #5 from team-nabi/NABI-25
Browse files Browse the repository at this point in the history
🎉 switch 토글 컴포넌트 생성
  • Loading branch information
oaoong authored Oct 27, 2023
2 parents 168eaec + 7183a70 commit ecc6e2f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@tanstack/react-query": "^5.0.0",
"autoprefixer": "^10.4.16",
"class-variance-authority": "^0.7.0",
Expand Down
39 changes: 30 additions & 9 deletions pnpm-lock.yaml

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

20 changes: 20 additions & 0 deletions src/components/ui/Switch/Switch.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Switch } from './Switch'

const meta = {
title: 'UI/Switch',
component: Switch,
tags: ['autodocs'],
argTypes: {},
} satisfies Meta<typeof Switch>

export default meta
type Story = StoryObj<typeof meta>

export const Normal: Story = {
args: {},
}

export const Disabled: Story = {
args: {},
}
28 changes: 28 additions & 0 deletions src/components/ui/Switch/Switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client'

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

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-[36px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm 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=checked]:bg-primary data-[state=unchecked]:opacity-50 bg-primary-color',
className,
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb
className={cn(
'pointer-events-none block h-4 w-4 rounded-full bg-white shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0',
)}
/>
</SwitchPrimitives.Root>
))
Switch.displayName = SwitchPrimitives.Root.displayName

export { Switch }
3 changes: 3 additions & 0 deletions src/components/ui/Switch/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Switch } from './Switch'

export default Switch

0 comments on commit ecc6e2f

Please sign in to comment.