Repository navigation
[FEAT] 공용 Button 컴포넌트 추가 #306
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
27949f8
feat(ui): 공용 Button 컴포넌트 추가 (#305)
ehye1 c2e014b
refactor(ui): Button 높이·패딩 스타일을 BUTTON_SIZE로 통합 (#305)
ehye1 4ef3d89
feat(ui): 흰색 휴지통 아이콘 추가 (#305)
ehye1 6eb2361
refactor(ui): Button 아이콘 색 지정 제거 및 접근성 보완 (#305)
ehye1 c75e8a8
feat(ui): Button 오른쪽 아이콘 지원 및 너비를 부모 기준으로 변경 (#305)
ehye1 52e76e3
refactor(ui): Button 스토리 구성 및 리뷰 반영 (#305)
ehye1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
packages/timo-design-system/src/components/button/button/Button.stories.tsx
This file contains hidden or 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,120 @@ | ||
| import { Button } from "./Button"; | ||
| import { TrashDisableIcon, TrashOnIcon, TrashWhiteIcon } from "../../../icons"; | ||
|
|
||
| import type { Meta, StoryObj } from "@storybook/react"; | ||
|
|
||
| const VARIANTS = ["primary", "secondary"] as const; | ||
| const APPEARANCES = ["fill", "outline"] as const; | ||
| const SIZES = ["m", "lg"] as const; | ||
|
|
||
| const getTrashIcon = ( | ||
| variant: (typeof VARIANTS)[number], | ||
| disabled: boolean, | ||
| ) => { | ||
| if (variant === "primary") return <TrashWhiteIcon />; | ||
| return disabled ? <TrashDisableIcon /> : <TrashOnIcon />; | ||
| }; | ||
|
|
||
| const meta = { | ||
| title: "Components/Button/Button", | ||
| component: Button, | ||
| parameters: { | ||
| layout: "centered", | ||
| }, | ||
| argTypes: { | ||
| variant: { control: "select", options: VARIANTS }, | ||
| appearance: { control: "select", options: APPEARANCES }, | ||
| size: { control: "select", options: SIZES }, | ||
| disabled: { control: "boolean" }, | ||
| children: { control: "text" }, | ||
| }, | ||
| args: { | ||
| variant: "primary", | ||
| appearance: "fill", | ||
| size: "m", | ||
| disabled: false, | ||
| children: "생성하기", | ||
| }, | ||
| } satisfies Meta<typeof Button>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| export const AllVariants: Story = { | ||
| parameters: { controls: { disable: true } }, | ||
| render: () => ( | ||
| <div className="flex flex-col gap-6"> | ||
| {SIZES.map((size) => ( | ||
| <div key={size} className="flex flex-col gap-3"> | ||
| {[false, true].map((disabled) => ( | ||
| <div key={String(disabled)} className="flex items-center gap-3"> | ||
| {VARIANTS.map((variant) => | ||
| APPEARANCES.map((appearance) => ( | ||
| <Button | ||
| key={`${variant}-${appearance}`} | ||
| variant={variant} | ||
| appearance={appearance} | ||
| size={size} | ||
| disabled={disabled} | ||
| > | ||
| {size === "m" ? "생성하기" : "시간 추가하기"} | ||
| </Button> | ||
| )), | ||
| )} | ||
| {VARIANTS.map((variant) => ( | ||
| <Button | ||
| key={`${variant}-icon`} | ||
| variant={variant} | ||
| appearance="fill" | ||
| size={size} | ||
| disabled={disabled} | ||
| icon={getTrashIcon(variant, disabled)} | ||
| > | ||
| 삭제하기 | ||
| </Button> | ||
| ))} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| export const WithIcon: Story = { | ||
| args: { | ||
| icon: <TrashWhiteIcon />, | ||
|
ehye1 marked this conversation as resolved.
Outdated
|
||
| children: "삭제하기", | ||
| }, | ||
| }; | ||
|
|
||
| export const FullWidth: Story = { | ||
| parameters: { controls: { disable: true } }, | ||
| render: () => ( | ||
| <div className="flex w-100 flex-col gap-3"> | ||
| <Button variant="primary" appearance="fill" size="m" className="w-full"> | ||
| w-full | ||
| </Button> | ||
| <div className="flex gap-3"> | ||
| <Button | ||
| variant="secondary" | ||
| appearance="outline" | ||
| size="lg" | ||
| className="flex-1" | ||
| > | ||
| 닫기 | ||
| </Button> | ||
| <Button | ||
| variant="primary" | ||
| appearance="fill" | ||
| size="lg" | ||
| className="flex-1" | ||
| > | ||
| 시간 추가하기 | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ), | ||
| }; | ||
75 changes: 75 additions & 0 deletions
75
packages/timo-design-system/src/components/button/button/Button.tsx
This file contains hidden or 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,75 @@ | ||
| import { cn } from "../../../lib"; | ||
|
|
||
| import type { ButtonHTMLAttributes, ReactNode } from "react"; | ||
|
|
||
| type ButtonVariantTypes = "primary" | "secondary"; | ||
| type ButtonAppearanceTypes = "fill" | "outline"; | ||
| type ButtonSizeTypes = "m" | "lg"; | ||
|
|
||
| const BUTTON_VARIANTS: Record< | ||
| ButtonVariantTypes, | ||
| Record<ButtonAppearanceTypes, string> | ||
| > = { | ||
| primary: { | ||
| fill: "bg-timo-blue-300 text-white disabled:bg-timo-blue-65", | ||
| outline: | ||
| "border-timo-blue-300 text-timo-blue-300 border bg-white disabled:border-timo-gray-500 disabled:text-timo-gray-700", | ||
| }, | ||
| secondary: { | ||
| fill: "bg-timo-gray-300 text-timo-gray-900 disabled:text-timo-gray-700", | ||
| outline: | ||
| "border-timo-gray-500 text-timo-gray-900 border bg-white disabled:text-timo-gray-700", | ||
| }, | ||
| }; | ||
|
|
||
| const BUTTON_SIZE: Record< | ||
| ButtonSizeTypes, | ||
| { height: string; padding: { text: string; icon: string } } | ||
| > = { | ||
| m: { height: "h-8.5", padding: { text: "px-4", icon: "px-2" } }, | ||
| lg: { height: "h-11.5", padding: { text: "px-12", icon: "px-12" } }, | ||
| }; | ||
|
|
||
| export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
| variant: ButtonVariantTypes; | ||
| appearance: ButtonAppearanceTypes; | ||
| size: ButtonSizeTypes; | ||
| icon?: ReactNode; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export const Button = ({ | ||
| variant, | ||
| appearance, | ||
| size, | ||
| icon, | ||
| type = "button", | ||
| className, | ||
| children, | ||
| ...rest | ||
| }: ButtonProps) => { | ||
| return ( | ||
| <button | ||
| type={type} | ||
| className={cn( | ||
| "typo-headline-m-14 inline-flex items-center justify-center gap-0.5 rounded-[4px] whitespace-nowrap outline-hidden", | ||
| "focus-visible:ring-timo-blue-300 focus-visible:ring-2 focus-visible:ring-offset-2", | ||
| "disabled:cursor-not-allowed", | ||
| BUTTON_VARIANTS[variant][appearance], | ||
| BUTTON_SIZE[size].height, | ||
| BUTTON_SIZE[size].padding[icon ? "icon" : "text"], | ||
| className, | ||
| )} | ||
| {...rest} | ||
| > | ||
| {icon && ( | ||
| <span | ||
| aria-hidden="true" | ||
| className="flex size-5.5 shrink-0 items-center justify-center" | ||
| > | ||
| {icon} | ||
| </span> | ||
| )} | ||
| {children} | ||
| </button> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.