Breadcrumb
Navigation header
Transparent at the top, solid hairline bar after scrolling, labels in normal case. Optional mega menu with text-led items and one short description each, or a minimal wordmark and one action for single-purpose pages.
실제로 돌아가는 부품입니다. 눌러 보고 입력해 보세요.
내 앱에 넣기
아직 npm 패키지가 없어서 Taster 리포를 받아 그 안의 명령을 씁니다. 내 앱 폴더가 들어 있는 폴더에서 한 번만 받습니다.
git clone https://github.com/makim-414/taster.git && npm ci --prefix taster/packages/engine내 앱 폴더에서 이 부품을 넣습니다. 부품 파일과 토큰 파일이
src/components/taster에 들어갑니다.node ../taster/packages/engine/cli.mjs add marketing/breadcrumb --from https://taster-six.vercel.app --dir src/components/taster부품은 Tailwind 클래스로 그리고, Taster 프리셋이 그 클래스를 토큰에 연결합니다. Tailwind CSS 를 설치하고,
tokens.css를 앱 루트에서 한 번 불러온 뒤, 앱 루트에 이 설정을 둡니다. 프리셋이 없으면 빌드는 되어도 부품이 스타일 없이 나옵니다.// tailwind.config.cjs module.exports = { presets: [require('./src/components/taster/tailwind-preset.cjs')], content: ['./index.html', './src/**/*.{ts,tsx}'], };Tailwind v3 는 이 파일을 그대로 읽습니다. v4 는 Tailwind 를 불러오는
src/의 스타일시트 맨 위에 이 두 줄을 넣습니다.@import "tailwindcss"; @config "../tailwind.config.cjs";tokens.css는:root에--bg,--text,--border,--accent를 정의합니다. 내 앱의 스타일시트가 같은 이름을 뒤에서 다시 정의하면 그쪽 색이 이깁니다. 새 Vite 앱의 스타터 CSS 처럼 그런 변수가 있으면 지우거나 이름을 바꾸세요.
언제 쓰나요
- Site headerTransparent at the top, solid hairline bar after scrolling, labels in normal case. Optional mega menu with text-led items and one short description each, or a minimal wordmark and one action for single-purpose pages.
- App barsA thin sticky top bar with title, sidebar toggle and page actions, plus a bottom tab bar of three to five destinations on phones.
대신 없애 주는 AI 티
- All-caps label with wide letter spacing (AC-01)
- Glass panels everywhere (CMP-05)
- The same few stock icons on repeat (ICO-01)
- Every gap is the same (LAY-06)
정보
코드 보기
import * as React from 'react'
import { cn } from '../blocks/_cn'
import { safeHref } from '../blocks/_url'
// Breadcrumb: the trail from the top of the site to the current page, above the page title. Links in
// muted ink, a thin slash between them drawn as a line so it is not read aloud, the current page in full
// ink with aria-current and no link. On phones a long trail keeps the first and the last two steps and
// folds the middle into one "..." button that unfolds it, instead of wrapping to three lines.
// Follows patterns/site-header (normal case, no icons per item) and the WAI-ARIA breadcrumb pattern.
// Original code, MIT.
export interface Crumb {
label: string
href?: string
}
export interface BreadcrumbProps extends React.HTMLAttributes<HTMLElement> {
/** From the top level to the current page. The last item is the current page. */
items: Crumb[]
label?: string
/** Fold the middle on narrow screens when there are more than this many items. Default 4. */
foldAfter?: number
expandLabel?: string
}
const KEEP = 'break-keep [overflow-wrap:break-word]'
const LINK =
'inline-flex min-h-11 items-center rounded-sm text-label text-text-muted underline-offset-4 outline-none hover:text-text hover:underline focus-visible:ring-2 focus-visible:ring-ring desk:min-h-0'
function Sep() {
return (
<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden className="mx-2 shrink-0 text-text-subtle">
<path d="M15 4 9 20" />
</svg>
)
}
export function Breadcrumb({ items, label = 'Breadcrumb', foldAfter = 4, expandLabel = 'Show the full path', className, ...props }: BreadcrumbProps) {
const [expanded, setExpanded] = React.useState(false)
const fold = items.length > foldAfter && !expanded
return (
<nav aria-label={label} className={cn('min-w-0', className)} {...props}>
<ol className="m-0 flex list-none flex-wrap items-center p-0">
{items.map((c, i) => {
const last = i === items.length - 1
// Folded on narrow screens: keep the first item and the last two.
const middle = i > 0 && i < items.length - 2
const href = safeHref(c.href)
return (
<React.Fragment key={`${i}-${c.label}`}>
{fold && i === 1 ? (
<li className="flex items-center md:hidden">
<button
type="button"
onClick={() => setExpanded(true)}
className="inline-flex h-11 min-w-11 items-center justify-center rounded-sm text-label text-text-muted outline-none hover:text-text focus-visible:ring-2 focus-visible:ring-ring"
>
<span aria-hidden>...</span>
<span className="sr-only">{expandLabel}</span>
</button>
<Sep />
</li>
) : null}
<li className={cn('flex min-w-0 items-center', fold && middle && 'hidden md:flex')}>
{last ? (
<span aria-current="page" className={cn('text-label font-medium text-text', KEEP)}>
{c.label}
</span>
) : href ? (
<a href={href} className={cn(LINK, KEEP)}>
{c.label}
</a>
) : (
<span className={cn('text-label text-text-muted', KEEP)}>{c.label}</span>
)}
{last ? null : <Sep />}
</li>
</React.Fragment>
)
})}
</ol>
</nav>
)
}