Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
33 changes: 33 additions & 0 deletions src/components/button/ArrowButton.tsx
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;
141 changes: 141 additions & 0 deletions src/components/button/Button.stories.tsx
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",
},
};
49 changes: 49 additions & 0 deletions src/components/button/Button.tsx
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 스토리북 파일에서 disabled props 사용중인데, 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;
32 changes: 32 additions & 0 deletions src/components/button/IconButton.tsx
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;
30 changes: 30 additions & 0 deletions src/components/button/style.ts
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",
};
1 change: 1 addition & 0 deletions src/components/icon/icon-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ const ICON_MAP = {
VanillaIcon: () => import("/public/icons/flavor/ic-vanilla.svg"),
};

export type IconName = keyof typeof ICON_MAP;
export default ICON_MAP;
3 changes: 3 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ export { default as Flavor } from "./flavor/Flavor";
export { TextInput, ModalTextInput } from "./text-input/text-input";
export { default as SelectType } from "./select-type/select-type";
export { default as Icon } from "./icon/Icon";
export { default as Button } from "./button/Button";
export { default as ArrowButton } from "./button/ArrowButton";
export { default as IconButton } from "./button/IconButton";