diff --git a/src/app/page.tsx b/src/app/page.tsx index 9e5158e..81113df 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,11 +1,18 @@ 'use client' +import { BreadcrumbItemType } from '@/components/common/Breadcrumb/Breadcrumb' import Pagination from '@/components/common/pagination/Pagination' import BreakpointTest from '@/components/design-system/BreakpointTest' -import ButtonTest from '@/components/design-system/ButtonTest' import ColorPalette from '@/components/design-system/ColorPalette' import TypoSystem from '@/components/design-system/TypoSystem' +import Breadcrumb from '@/components/common/Breadcrumb/Breadcrumb' import { useState } from 'react' +export const mockBreadcrumbData: BreadcrumbItemType[] = [ + { label: 'Home', href: '/' }, + { label: 'Category', href: '/category' }, + { label: 'Product', href: '/product' }, +] + export default function Home() { //현재 페이지 const [currentPage, setCurrentPage] = useState(1) @@ -27,7 +34,6 @@ export default function Home() { {/* 공통 버튼 */} - {/* 페이지네이션 */} + ) } diff --git a/src/components/common/Breadcrumb/Breadcrumb.tsx b/src/components/common/Breadcrumb/Breadcrumb.tsx new file mode 100644 index 0000000..73b54b9 --- /dev/null +++ b/src/components/common/Breadcrumb/Breadcrumb.tsx @@ -0,0 +1,85 @@ +import React from 'react' +import Link from 'next/link' +import { usePathname } from 'next/navigation' +import { cn } from '@/lib/utils' +export interface BreadcrumbItemType { + label: string + href?: string +} + +interface BreadcrumbProps { + items: BreadcrumbItemType[] + showHomeIcon?: boolean + className?: string +} + +const Breadcrumb: React.FC = ({ items, showHomeIcon = true, className }) => { + const pathname = usePathname() + console.log(pathname) + const breadcrumbItems = items.length > 0 ? items : generateBreadcrumbItems(pathname) + return ( + + + {showHomeIcon && ( + + + 홈 + + + {'>'} + + + )} + + {breadcrumbItems.map((item, index) => { + const isLast = index === breadcrumbItems.length - 1 + + return ( + + {isLast ? ( + + {item.label} + + ) : ( + <> + + {item.label} + + + {'>'} + + > + )} + + ) + })} + + + ) +} + +const generateBreadcrumbItems = (pathname: string): BreadcrumbItemType[] => { + const pathSegments = pathname.split('/').filter((segment) => segment && !segment.includes('?')) + return pathSegments.map((segment, index) => { + const href = '/' + pathSegments.slice(0, index + 1).join('/') + + const label = segment.replace(/-/g, ' ').replace(/\b\w/g, (char) => char.toUpperCase()) + + return { label, href } + }) +} + +export default Breadcrumb diff --git a/src/components/design-system/ButtonTest.tsx b/src/components/design-system/ButtonTest.tsx index ea622ad..d9a827c 100644 --- a/src/components/design-system/ButtonTest.tsx +++ b/src/components/design-system/ButtonTest.tsx @@ -11,10 +11,10 @@ const ButtonTest = () => { return ( 기본 버튼 - {defaultButtonVars.map((variant) => ( + {defaultButtonVars.map((variant, index) => ( {variant} - + {defaultButtonSizes.map((s) => ( <> diff --git a/src/components/ui/breadcrumb.stories.tsx b/src/components/ui/breadcrumb.stories.tsx deleted file mode 100644 index bac6658..0000000 --- a/src/components/ui/breadcrumb.stories.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import type { Meta, StoryObj } from '@storybook/react' - -import { Breadcrumb } from './breadcrumb' - -const meta = { - component: Breadcrumb, -} satisfies Meta - -export default meta - -type Story = StoryObj - -export const Default: Story = {} diff --git a/src/stories/breadcrumb.stories.tsx b/src/stories/breadcrumb.stories.tsx new file mode 100644 index 0000000..3d88e5d --- /dev/null +++ b/src/stories/breadcrumb.stories.tsx @@ -0,0 +1,39 @@ +import type { Meta, StoryObj } from '@storybook/react' + +import Breadcrumb from '@/components/common/Breadcrumb/Breadcrumb' + +const meta: Meta = { + title: 'Components/Breadcrumb', + component: Breadcrumb, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], + argTypes: { + items: { + description: 'Breadcrumb items', + control: 'object', + }, + showHomeIcon: { + description: 'Show home icon', + control: 'boolean', + }, + className: { + description: 'Additional CSS classes', + control: 'text', + }, + }, +} + +export default meta +type Story = StoryObj + +export const Default: Story = { + args: { + items: [ + { label: 'Dashboard', href: '/dashboard' }, + { label: 'Settings', href: '/dashboard/settings' }, + { label: 'Profile' }, + ], + }, +}
{variant}