Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
95 changes: 78 additions & 17 deletions src/components/common/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { cva, type VariantProps } from "class-variance-authority";
import { forwardRef, ReactNode, type ButtonHTMLAttributes } from "react";
import Link, { type LinkProps } from "next/link";
import {
forwardRef,
type AnchorHTMLAttributes,
type ButtonHTMLAttributes,
type ForwardedRef,
type MouseEvent,
type MouseEventHandler,
type ReactNode,
} from "react";

import { Text, type TextVariantProp } from "@/components/common/Text";
import { cn } from "@/lib/utils/cn";
Expand Down Expand Up @@ -56,37 +65,89 @@ const buttonTextVariant = {
} as const satisfies Record<string, TextVariantProp>;

export interface ButtonProps
extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
extends
Comment thread
yooseohyeon marked this conversation as resolved.
Resolved
Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onClick">,
VariantProps<typeof buttonVariants> {
href?: LinkProps["href"];
onClick?: MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
rightIcon?: ReactNode;
}

const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
{ variant, size, fullWidth, type = "button", className, rightIcon, children, ...props },
const Button = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(function Button(
{
variant,
size,
fullWidth,
type = "button",
href,
className,
rightIcon,
children,
disabled,
onClick,
...props
},
ref,
) {
// 2026.07.26 정슬기 - [수정] null이면 cva defaultVariants를 타지 않으므로 resolved*로 통일
const resolvedVariant = variant ?? "solid";
const resolvedSize = size ?? "md";
const resolvedFullWidth = fullWidth ?? false;

const classNames = cn(
buttonVariants({
variant: resolvedVariant,
size: resolvedSize,
fullWidth: resolvedFullWidth,
}),
className,
);

const content = (
<>
<Text as="span" variant={buttonTextVariant[resolvedSize]}>
{children}
</Text>
{rightIcon}
</>
);

if (href) {
const linkProps = props as AnchorHTMLAttributes<HTMLAnchorElement>;
const handleClick = (event: MouseEvent<HTMLAnchorElement>) => {
if (disabled) {
event.preventDefault();
return;
}

onClick?.(event);
};

return (
<Link
ref={ref as ForwardedRef<HTMLAnchorElement>}
href={href}
{...linkProps}
className={classNames}
aria-disabled={disabled || undefined}
tabIndex={disabled ? -1 : undefined}
onClick={handleClick}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
>
{content}
</Link>
);
}

return (
<button
ref={ref}
ref={ref as ForwardedRef<HTMLButtonElement>}
type={type}
className={cn(
buttonVariants({
variant: resolvedVariant,
size: resolvedSize,
fullWidth: resolvedFullWidth,
}),
className,
)}
className={classNames}
disabled={disabled}
onClick={onClick}
{...props}
>
<Text as="span" variant={buttonTextVariant[resolvedSize]}>
{children}
</Text>
{rightIcon}
{content}
</button>
);
});
Expand Down
44 changes: 5 additions & 39 deletions src/components/common/EmptyState/EmptyState.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import Image from "next/image";
import Link from "next/link";
import type { MouseEventHandler, ReactNode } from "react";

import Button from "@/components/common/Button/Button";
import { Text } from "@/components/common/Text";
import { cn } from "@/lib/utils/cn";

Expand All @@ -16,7 +16,7 @@ export interface EmptyStateProps {
buttonLabel?: string;
/** CTA 클릭 시 이동 경로 */
href?: string;
onButtonClick?: MouseEventHandler<HTMLAnchorElement>;
onButtonClick?: MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
imageAlt?: string;
className?: string;
/**
Expand Down Expand Up @@ -108,43 +108,9 @@ export default function EmptyState({
) : null}

{showButton && (
<Link
href={href!}
onClick={onButtonClick}
className={cn(
"bg-background-brand hover:bg-background-brand-hover flex items-center justify-center px-16 transition-colors",
isSm
? "rounded-12 h-[54px]"
: isLg
? "rounded-16 h-64"
: "rounded-12 md:rounded-16 h-[54px] md:h-64",
)}
>
{isSm ? (
<Text as="span" variant="lg-semibold" className="text-text-inverse">
{buttonLabel}
</Text>
) : null}
{isLg ? (
<Text as="span" variant="2lg-semibold" className="text-text-inverse">
{buttonLabel}
</Text>
) : null}
{!size ? (
<>
<Text as="span" variant="lg-semibold" className="text-text-inverse md:hidden">
{buttonLabel}
</Text>
<Text
as="span"
variant="2lg-semibold"
className="text-text-inverse hidden md:inline"
>
{buttonLabel}
</Text>
</>
) : null}
</Link>
<Button href={href!} onClick={onButtonClick} size="cta" className="w-auto">
{buttonLabel}
</Button>
)}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/estimate/request/ActiveEstimateBlocked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ActiveEstimateBlockedProps {
description?: ReactNode;
buttonLabel?: string;
href?: string;
onButtonClick?: MouseEventHandler<HTMLAnchorElement>;
onButtonClick?: MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
}

const DEFAULT_DESCRIPTION = (
Expand Down
19 changes: 8 additions & 11 deletions src/components/mover/detail/MoverDetailActions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use client";

import Link from "next/link";

import Button from "@/components/common/Button/Button";
import { Skeleton } from "@/components/common/Skeleton/Skeleton";
import { Text } from "@/components/common/Text";
Expand Down Expand Up @@ -54,12 +52,15 @@ export default function MoverDetailActions({
>
{requestButtonLabel}
</Button>
<Link
<Button
href={calendarHref}
className="border-border-brand text-text-brand rounded-16 flex h-54 min-w-0 flex-1 items-center justify-center border text-[16px] font-semibold"
variant="outline"
size="cta"
fullWidth
className="rounded-16 min-w-0 flex-1 shadow-none"
>
일정 확인
</Link>
</Button>
</div>
</div>
);
Expand All @@ -83,13 +84,9 @@ export default function MoverDetailActions({
{requestButtonLabel}
</Button>

{/* href={calendarHref} */}
<Link
href={calendarHref}
className="border-border-brand bg-background-surface text-text-brand hover:bg-background-brand-muted rounded-16 inline-flex h-64 w-full items-center justify-center border p-16 text-[18px] font-semibold transition-colors"
>
<Button href={calendarHref} variant="outline" size="detail" fullWidth>
기사님 일정 확인하기
</Link>
</Button>

<LikeOutlineButton
size="lg"
Expand Down
11 changes: 3 additions & 8 deletions src/components/mover/favorites/FavoriteMoversSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ function FavoriteMoversSidebarStatus({
</div>

{action?.type === "link" ? (
<Link
href={action.href}
className="bg-background-brand hover:bg-background-brand-hover rounded-12 flex h-54 w-full items-center justify-center px-16 transition-colors"
>
<Text as="span" variant="lg-semibold" className="text-text-inverse">
{action.label}
</Text>
</Link>
<Button href={action.href} size="cta" fullWidth>
{action.label}
</Button>
) : null}

{action?.type === "button" ? (
Expand Down
37 changes: 37 additions & 0 deletions src/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const BUTTON_DESCRIPTION = `서비스 전반의 주요 액션에 사용하는
| \`detail\` | 64px / full width | 데스크톱 상세 화면의 주요 CTA |
| \`auth\` | Mobile 54px, Tablet+ 60px / full width | 로그인·회원가입 CTA |

### Link

- \`href\`를 전달하면 동일한 디자인을 유지한 채 Next.js \`Link\`로 렌더링합니다.
- 링크에도 \`disabled\`를 사용할 수 있으며, 이 경우 이동과 키보드 포커스가 차단됩니다.

`;

const PLAYGROUND_SOURCE = `<Button variant="solid" size="cta" onClick={handleClick}>
Expand Down Expand Up @@ -48,6 +53,10 @@ const AUTH_SOURCE = `<Button type="submit" size="auth" fullWidth disabled={isPen
{isPending ? "로그인 중..." : "로그인"}
</Button>`;

const LINK_SOURCE = `<Button href="/movers" variant="outline" size="detail" fullWidth>
기사님 목록 보기
</Button>`;

const meta = {
title: "UI/Button",
component: Button,
Expand Down Expand Up @@ -84,6 +93,11 @@ const meta = {
description: "부모 영역의 전체 너비를 사용할지 여부",
table: { type: { summary: "boolean" }, defaultValue: { summary: "false" } },
},
href: {
control: "text",
description: "전달하면 Next.js Link로 렌더링할 이동 경로",
table: { type: { summary: "LinkProps['href']" } },
},
rightIcon: {
control: false,
description: "버튼 텍스트 오른쪽에 표시할 아이콘 또는 콘텐츠",
Expand Down Expand Up @@ -190,6 +204,29 @@ export const WithRightIcon: Story = {
},
};

export const WithLink: Story = {
args: {
href: "/movers",
variant: "outline",
size: "detail",
fullWidth: true,
children: "기사님 목록 보기",
},
parameters: {
docs: {
description: { story: "href를 전달하면 버튼 디자인의 링크로 사용할 수 있습니다." },
source: { code: LINK_SOURCE, language: "tsx" },
},
},
decorators: [
(Story) => (
<div className="w-[min(600px,calc(100vw-48px))]">
<Story />
</div>
),
],
};

export const ResponsiveAuth: Story = {
args: { size: "auth", fullWidth: true, children: "로그인" },
parameters: {
Expand Down