SCALE — Build Lab
UI部品 · REACT COMPONENT

パンくずナビ

CATEGORYUI部品 TYPEReact Component EFFORT15〜30分 DIFFICULTY
PRIMARY CODE
tsx
export function Breadcrumb({ items }: { items: { label: string; href?: string }[] }) {
  return (
    <nav aria-label="Breadcrumb" style={{
      display: 'flex', gap: '.5rem', alignItems: 'center',
      fontFamily: 'serif', fontSize: '.7rem', letterSpacing: '.15em',
      textTransform: 'uppercase', color: 'rgba(255,255,255,.22)',
    }}>
      {items.map((it, i) => (
        <span key={i} style={{ display: 'inline-flex', alignItems: 'center', gap: '.5rem' }}>
          {it.href ? (
            <a href={it.href} style={{ color: 'rgba(255,255,255,.5)', textDecoration: 'none' }}>{it.label}</a>
          ) : (
            <span style={{ color: 'rgba(255,255,255,.85)' }}>{it.label}</span>
          )}
          {i < items.length - 1 && <span style={{ color: 'rgba(255,255,255,.07)' }}>/</span>}
        </span>
      ))}
    </nav>
  );
}
前提条件
Tailwind CSS v4TypeScript 5
USE CASES
  • 任意のダッシュボードに組み込み

パンくずナビ

:LiTarget: 用途

階層的なナビゲーション。区切り文字カスタム + 自動省略対応。

:LiSparkle: 特徴

  • 階層リンク
  • 区切り文字カスタム
  • 長すぎる場合省略
  • a11y 対応

:LiCode: コード(コピペ用)

export function Breadcrumb({ items }: { items: { label: string; href?: string }[] }) {
  return (
    <nav aria-label="Breadcrumb" style={{
      display: 'flex', gap: '.5rem', alignItems: 'center',
      fontFamily: 'serif', fontSize: '.7rem', letterSpacing: '.15em',
      textTransform: 'uppercase', color: 'rgba(255,255,255,.22)',
    }}>
      {items.map((it, i) => (
        <span key={i} style={{ display: 'inline-flex', alignItems: 'center', gap: '.5rem' }}>
          {it.href ? (
            <a href={it.href} style={{ color: 'rgba(255,255,255,.5)', textDecoration: 'none' }}>{it.label}</a>
          ) : (
            <span style={{ color: 'rgba(255,255,255,.85)' }}>{it.label}</span>
          )}
          {i < items.length - 1 && <span style={{ color: 'rgba(255,255,255,.07)' }}>/</span>}
        </span>
      ))}
    </nav>
  );
}

:LiHandPointer: 使い方

対象プロジェクトに該当ファイルをコピーして、props を流し込むだけ。

:LiAlertCircle: 注意事項

  • 依存パッケージを忘れず追加