-
Notifications
You must be signed in to change notification settings - Fork 2
[#9] 버튼 컴포넌트 구현 #33
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
[#9] 버튼 컴포넌트 구현 #33
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f38e1a
feat: 버튼 컴포넌트 구현 및 버튼 컴포넌트 분리 작업 세팅
suuuuya 7220fbb
style: 버튼 스타일 상수 및 타입 추가 #9
suuuuya 3eadfe8
chore: 인덱스 파일에 버튼 컴포넌트 정리 #9
suuuuya f848065
feat: 화살표 이동 버튼 컴포넌트 추가 #9
suuuuya 5e7a523
feat: 아이콘 버튼 컴포넌트 추가 #9
suuuuya 21c7b53
refactor: 화살표 버튼 컴포넌트 direction 타입 명칭 개선 및 ariaLabel 변수로 분리 #9
suuuuya acfc7d1
feat: 기본 버튼 컴포넌트 구현 및 스토리북 추가, 기타 스타일 개선
suuuuya 72319c6
Merge branch 'develop' into design/button-component
suuuuya f3356ed
fix: 컴포넌트명 컨벤션 통일 (kebab case) #9
suuuuya 32bc7d7
fix: ButtonProps에 ButtonHTMLAttributes 추가해 누락된 기본 속성(disabled 등) 타입 보…
suuuuya 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
There are no files selected for viewing
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,33 @@ | ||
| import { cn } from "@/lib/utils"; | ||
| import Icon from "../icon/Icon"; | ||
| import { | ||
| COMMON_BUTTON_STYLES, | ||
| BUTTON_SHAPE_VARIANTS, | ||
| BUTTON_STATE_VARIANTS, | ||
| } from "./style"; | ||
|
|
||
| interface ArrowButtonProps { | ||
| direction: "prev" | "next"; | ||
| className?: string; | ||
| } | ||
|
|
||
| const ArrowButton = ({ direction, className, ...props }: ArrowButtonProps) => { | ||
| const iconName = direction === "prev" ? "ArrowLeftIcon" : "ArrowRightIcon"; | ||
| const ariaLabel = direction === "prev" ? "이전으로 이동" : "다음으로 이동"; | ||
| return ( | ||
| <button | ||
| aria-label={ariaLabel} | ||
| className={cn( | ||
| COMMON_BUTTON_STYLES, | ||
| BUTTON_SHAPE_VARIANTS.round, | ||
| BUTTON_STATE_VARIANTS.secondary, | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| <Icon icon={iconName} /> | ||
| </button> | ||
| ); | ||
| }; | ||
|
|
||
| export default ArrowButton; |
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,141 @@ | ||
| import type { Meta, StoryObj } from "@storybook/nextjs"; | ||
| import Button from "./Button"; | ||
| import IconButton from "./IconButton"; | ||
| import ArrowButton from "./ArrowButton"; | ||
| import ICON_MAP from "../icon/icon-map"; | ||
|
|
||
| const meta: Meta<typeof Button> = { | ||
| title: "Components/Button", | ||
| component: Button, | ||
| parameters: { | ||
| layout: "centered", | ||
| docs: { | ||
| description: { | ||
| component: "공통으로 사용되는 버튼 컴포넌트입니다.", | ||
| }, | ||
| }, | ||
| }, | ||
| tags: ["autodocs"], | ||
| argTypes: { | ||
| type: { | ||
| control: "select", | ||
| options: ["default", "outline", "secondary"], | ||
| description: "버튼 상태", | ||
| }, | ||
| icon: { | ||
| control: "select", | ||
| options: Object.keys(ICON_MAP), | ||
| description: "버튼 아이콘", | ||
| }, | ||
|
|
||
| className: { | ||
| control: "text", | ||
| description: "추가 CSS 클래스", | ||
| }, | ||
| shape: { | ||
| control: "text", | ||
| description: "-", | ||
| table: { | ||
| category: "X", | ||
| }, | ||
| }, | ||
| label: { | ||
| control: "text", | ||
| description: "버튼에 들어가는 텍스트", | ||
| }, | ||
| textColor: { | ||
| description: "-", | ||
| table: { | ||
| category: "X", | ||
| }, | ||
| }, | ||
| disabled: { | ||
| control: "boolean", | ||
| description: "비활성화 여부", | ||
| table: { | ||
| category: "X", | ||
| }, | ||
| }, | ||
| direction: { | ||
| control: "select", | ||
| options: ["prev", "next"], | ||
| description: "이동 방향", | ||
| table: { | ||
| category: "X", | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| type: "default", | ||
| label: "버튼 이름을 입력해보세요", | ||
| }, | ||
| }; | ||
|
|
||
| export const Outline: Story = { | ||
| args: { | ||
| type: "outline", | ||
| label: "버튼 이름을 입력해보세요", | ||
| }, | ||
| }; | ||
|
|
||
| export const Icon: Story = { | ||
| render: () => ( | ||
| <div className="flex flex-wrap gap-4"> | ||
| <IconButton icon="FilterIcon" aria-label="필터 버튼" /> | ||
| <IconButton icon="HamburgerIcon" aria-label="햄버거 버튼" /> | ||
| <IconButton icon="LikeOnIcon" aria-label="찜 버튼" /> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| export const Arrow: Story = { | ||
| render: () => ( | ||
| <div className="flex flex-col gap-4 p-4"> | ||
| <ArrowButton direction="prev" /> | ||
| <ArrowButton direction="next" /> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| export const Disabled: Story = { | ||
| args: { | ||
| type: "default", | ||
| label: "비활성 버튼", | ||
| disabled: true, | ||
| }, | ||
| }; | ||
|
|
||
| export const Variations: Story = { | ||
| render: () => ( | ||
| <div className="flex flex-col gap-4 p-4"> | ||
| <h3 className="text-lg font-bold">대표 버튼</h3> | ||
|
|
||
| <div className="grid gap-4"> | ||
| <Button label="기본" /> | ||
| <Button type="outline" label="아웃라인" /> | ||
| </div> | ||
|
|
||
| <h3 className="text-lg font-bold">아이콘이 들어간 버튼</h3> | ||
| <div className="grid gap-4"> | ||
| <Button type="outline" label="카카오 로그인" icon="KakaoIcon" /> | ||
| <Button type="outline" label="구글 로그인" icon="GoogleIcon" /> | ||
| <div className="flex flex-wrap gap-4"> | ||
| <IconButton icon="FilterIcon" aria-label="필터 버튼" /> | ||
| <IconButton icon="HamburgerIcon" aria-label="햄버거 버튼" /> | ||
| <IconButton icon="LikeOnIcon" aria-label="찜 버튼" /> | ||
| <ArrowButton direction="prev" /> | ||
| <ArrowButton direction="next" /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ), | ||
| parameters: { | ||
| layout: "fullscreen", | ||
| }, | ||
| }; |
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,49 @@ | ||
| import { cn } from "@/lib/utils"; | ||
| import { | ||
| COMMON_BUTTON_STYLES, | ||
| BUTTON_SHAPE_VARIANTS, | ||
| BUTTON_STATE_VARIANTS, | ||
| BUTTON_TEXT_COLOR_VARIANTS, | ||
| ButtonShape, | ||
| ButtonState, | ||
| ButtonTextColor, | ||
| } from "./style"; | ||
| import Icon from "../icon/Icon"; | ||
| import type { IconName } from "../icon/icon-map"; | ||
|
|
||
| interface ButtonProps { | ||
| icon?: IconName; | ||
| type?: ButtonState; | ||
| label?: string; | ||
| shape?: ButtonShape; | ||
| textColor?: ButtonTextColor; | ||
| className?: string; | ||
| children?: React.ReactNode; | ||
| } | ||
|
|
||
| const Button = ({ | ||
| type = "default", | ||
| icon, | ||
| label, | ||
| className, | ||
| children, | ||
| ...props | ||
| }: ButtonProps) => { | ||
| return ( | ||
| <button | ||
| className={cn( | ||
| COMMON_BUTTON_STYLES, | ||
| BUTTON_SHAPE_VARIANTS.default, | ||
| BUTTON_STATE_VARIANTS[type], | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| {icon && <Icon icon={icon} />} | ||
| <span className={BUTTON_TEXT_COLOR_VARIANTS[type]}>{label}</span> | ||
| {children} | ||
| </button> | ||
| ); | ||
| }; | ||
|
|
||
| export default 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { cn } from "@/lib/utils"; | ||
| import Icon from "../icon/Icon"; | ||
| import type { IconName } from "../icon/icon-map"; | ||
|
|
||
| import { | ||
| COMMON_BUTTON_STYLES, | ||
| BUTTON_SHAPE_VARIANTS, | ||
| BUTTON_STATE_VARIANTS, | ||
| } from "./style"; | ||
|
|
||
| interface IconButtonProps { | ||
| icon: IconName; | ||
| className?: string; | ||
| } | ||
|
|
||
| const IconButton = ({ icon, className, ...props }: IconButtonProps) => { | ||
| return ( | ||
| <button | ||
| className={cn( | ||
| COMMON_BUTTON_STYLES, | ||
| BUTTON_SHAPE_VARIANTS.square, | ||
| BUTTON_STATE_VARIANTS.secondary, | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| <Icon icon={icon} /> | ||
| </button> | ||
| ); | ||
| }; | ||
|
|
||
| export default IconButton; |
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,30 @@ | ||
| export type ButtonShape = "default" | "round" | "square"; | ||
| export type ButtonState = "default" | "outline" | "secondary"; | ||
| export type ButtonTextColor = "default" | "outline" | "secondary"; | ||
|
|
||
| export const COMMON_BUTTON_STYLES = | ||
| "group w-full h-[42px] tablet:h-[50px] pc:h-[50px] inline-flex flex-center gap-x-[8px] tablet:gap-x-[12px] pc:gap-x-[12px] whitespace-nowrap transition-colors disabled:pointer-events-none"; | ||
|
|
||
| export const BUTTON_SHAPE_VARIANTS = { | ||
| default: "rounded-[4px] px-[23px]", | ||
| round: "rounded-full w-[48px] h-[48px] active:text-gray-100", | ||
| square: | ||
| "rounded-[8px] w-[42px] tablet:w-[50px] pc:w-[50px] active:text-gray-100", | ||
| }; | ||
|
|
||
| export const BUTTON_STATE_VARIANTS = { | ||
| default: | ||
| "bg-black hover:bg-default active:bg-gray-800 disabled:bg-gray-300 disabled:text-gray-600", | ||
| outline: | ||
| "bg-white border border-gray-300 hover:bg-gray-100 active:bg-gray-200 disabled:border-gray-300", | ||
| secondary: | ||
| "bg-white border border-gray-200 hover:bg-gray-100 active:bg-gray-600 disabled:border-gray-300 disabled:text-gray-400", | ||
| }; | ||
|
|
||
| export const BUTTON_TEXT_COLOR_VARIANTS = { | ||
| default: | ||
| "text-gray-100 mobile:text-button-md tablet:text-button-lg pc:text-button-lg group-disabled:text-gray-600 group-disabled:bg-gray-300", | ||
| outline: | ||
| "text-default mobile:text-button-md tablet:text-button-lg pc:text-button-lg group-disabled:text-gray-400", | ||
| secondary: "text-gray-800 group-disabled:text-gray-400", | ||
| }; |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 스토리북 파일에서 disabled props 사용중인데, ButtonProps에 선언이 되어있지않아서 오류가 발생하는 것 같습니다!