-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: storybook과 shadcn을 이용하여 button 컴포넌트 생성 (#3)
* chore: story 폴더 삭제 * chore: storybook 작업으로 인한 eslint config 수정 * feat: shadcn button with storybook * chore: 중복 rule 수정
- Loading branch information
Showing
35 changed files
with
390 additions
and
947 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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import '../app/globals.css'; | ||
|
||
import type { Preview } from '@storybook/react'; | ||
|
||
const preview: Preview = { | ||
|
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
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,101 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Button } from './button'; | ||
|
||
const meta: Meta<typeof Button> = { | ||
title: 'Components/ui/button', | ||
component: Button, | ||
tags: ['autodocs'], | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
argTypes: { | ||
variant: { | ||
control: 'select', | ||
description: 'Button variants', | ||
options: [ | ||
'default', | ||
'destructive', | ||
'outline', | ||
'secondary', | ||
'ghost', | ||
'link', | ||
], | ||
}, | ||
size: { | ||
control: 'select', | ||
description: 'Button sizes', | ||
options: ['default', 'sm', 'lg', 'icon'], | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
variant: 'default', | ||
size: 'default', | ||
disabled: false, | ||
onClick: action('default click'), | ||
children: 'Default button', | ||
className: 'shadow-lg', | ||
}, | ||
}; | ||
|
||
export const Destructive: Story = { | ||
args: { | ||
variant: 'destructive', | ||
size: 'default', | ||
disabled: false, | ||
onClick: action('destructive click'), | ||
children: 'Destructive button', | ||
className: 'shadow-lg', | ||
}, | ||
}; | ||
|
||
export const Outline: Story = { | ||
args: { | ||
variant: 'outline', | ||
size: 'default', | ||
disabled: false, | ||
onClick: action('outline click'), | ||
children: 'Outline button', | ||
className: 'shadow-lg', | ||
}, | ||
}; | ||
|
||
export const Secondary: Story = { | ||
args: { | ||
variant: 'secondary', | ||
size: 'default', | ||
disabled: false, | ||
onClick: action('secondary click'), | ||
children: 'Secondary button', | ||
className: 'shadow-lg', | ||
}, | ||
}; | ||
|
||
export const Ghost: Story = { | ||
args: { | ||
variant: 'ghost', | ||
size: 'default', | ||
disabled: false, | ||
onClick: action('ghost click'), | ||
children: 'Ghost button', | ||
className: 'shadow-lg', | ||
}, | ||
}; | ||
|
||
export const Link: Story = { | ||
args: { | ||
variant: 'link', | ||
size: 'default', | ||
disabled: false, | ||
onClick: action('link click'), | ||
children: 'Link button', | ||
className: 'shadow-lg', | ||
}, | ||
}; |
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,56 @@ | ||
import * as React from 'react'; | ||
import { Slot } from '@radix-ui/react-slot'; | ||
import { cva, type VariantProps } from 'class-variance-authority'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
|
||
const buttonVariants = cva( | ||
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50', | ||
{ | ||
variants: { | ||
variant: { | ||
default: 'bg-primary text-primary-foreground hover:bg-primary/90', | ||
destructive: | ||
'bg-destructive text-destructive-foreground hover:bg-destructive/90', | ||
outline: | ||
'border border-input bg-background hover:bg-primary/90 hover:text-primary-foreground', | ||
secondary: | ||
'bg-secondary text-secondary-foreground hover:bg-secondary/80', | ||
ghost: 'hover:bg-primary/90 hover:text-primary-foreground', | ||
link: 'text-primary underline-offset-4 hover:underline', | ||
}, | ||
size: { | ||
default: 'h-10 px-4 py-2', | ||
sm: 'h-9 rounded-md px-3', | ||
lg: 'h-11 rounded-md px-8', | ||
icon: 'h-10 w-10', | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'default', | ||
size: 'default', | ||
}, | ||
}, | ||
); | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean; | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : 'button'; | ||
return ( | ||
<Comp | ||
className={cn(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
}, | ||
); | ||
Button.displayName = 'Button'; | ||
|
||
export { Button, buttonVariants }; |
Oops, something went wrong.