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 ( + + ) +} + +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) => ( <>