부품 본문 구역
분류 격자 filter-grid
분류 칩으로 거르는 제품·사례 격자. 칸마다 사진, 분류, 이름, 표처럼 줄로 나눈 규격 몇 줄. 위에 「총 N개」 개수가 따라 바뀐다.
설치
shadcn/ui 를 쓰는 Next.js 프로젝트에서 한 줄로 설치됩니다. 파일은 components/bpublish/filter-grid.tsx 로 들어오고, 공통 토큰(base)도 같이 설치됩니다. 테마는 테마에서 하나 고릅니다.
npx shadcn@latest add https://www.bpublish.com/r/filter-grid.json레지스트리를 등록했다면 npx shadcn@latest add @bpublish/filter-grid · 설치 안내
AI에게 맡기기
Claude Code, Cursor 같은 AI 코딩 도구에 붙여 넣으세요. MCP 서버를 연결해 두면 이름만 말해도 됩니다.
bpublish UI의 분류 격자(filter-grid) 부품으로 만들어 줘. 설치: npx shadcn@latest add https://www.bpublish.com/r/filter-grid.json · 문서: https://www.bpublish.com/designs/components/filter-grid사용 예시
import { FilterGrid } from '@/components/bpublish/filter-grid'
const spec = (material: string, tolerance: string, use: string) => [
{ label: '소재', value: material },
{ label: '공차', value: tolerance },
{ label: '적용', value: use },
]
export default function Example() {
return (
<section className="shell py-16 md:py-24">
<FilterGrid
categories={['반도체', '2차전지', '의료', '로봇']}
items={[
{ name: '가스 분배 플레이트', category: '반도체', image: '/images/p-01.webp', specs: spec('AL6061-T6 · 아노다이징', '±0.01mm', 'CVD 증착 장비') },
{ name: '진공 챔버 플랜지', category: '반도체', image: '/images/p-02.webp', specs: spec('SUS316L · 전해 연마', '±0.01mm', '식각 장비 진공부') },
{ name: '웨이퍼 이송 암', category: '반도체', image: '/images/p-03.webp', specs: spec('AL7075 · 경질 아노다이징', '±0.005mm', '웨이퍼 반송 로봇') },
{ name: '전극 압연 롤러', category: '2차전지', image: '/images/p-04.webp', specs: spec('SCM440 · 경질 크롬 도금', '±0.003mm', '전극 압연 설비') },
{ name: '노칭 금형 펀치', category: '2차전지', image: '/images/p-05.webp', specs: spec('SKD11 · 진공 열처리', '±0.002mm', '전극 노칭 공정') },
{ name: '수술 기구 샤프트', category: '의료', image: '/images/p-06.webp', specs: spec('Ti-6Al-4V', '±0.005mm', '복강경 수술 기구') },
{ name: '감속기 하우징', category: '로봇', image: '/images/p-07.webp', specs: spec('AL6082 · 블랙 아노다이징', '±0.008mm', '협동 로봇 관절') },
{ name: '정밀 관절 링크', category: '로봇', image: '/images/p-08.webp', specs: spec('SUS630 (17-4PH)', '±0.005mm', '산업용 로봇 손목') },
]}
/>
</section>
)
}속성
| 이름 | 형식 | 기본값 | 설명 |
|---|---|---|---|
items필수 | { name: string; category: string; image: string; imageAlt?: string; specs?: { label; value }[]; href?: string }[] | — | 항목들 |
categories | string[] | — | 칩 순서. 비우면 items 에 나온 순서대로 |
allLabel | string | '전체' | 전체 칩 이름 |
noun | string | '제품' | 「총 8개 제품」의 「제품」 |
columns | 2 | 3 | 4 | 4 | 넓은 화면의 칸 수 |
emptyText | string | '이 분류에는 아직 항목이 없습니다.' | 거른 결과가 없을 때 문구 |
원본 코드
설치 명령 없이 그대로 복사해 넣어도 됩니다. React 외의 패키지는 쓰지 않습니다.
/**
* bpublish UI — 분류 격자. https://www.bpublish.com/designs/components/filter-grid
* 분류 칩으로 거르는 제품·사례 격자. 칸마다 사진, 분류, 이름, 그리고 표처럼 줄로 나눈 규격 몇 줄.
*/
'use client'
import { useState } from 'react'
export type FilterGridItem = {
name: string
category: string
image: string
imageAlt?: string
/** 표처럼 줄로 나뉘는 규격. 3줄 안팎이 보기 좋다 */
specs?: { label: string; value: string }[]
href?: string
}
export type FilterGridProps = {
items: FilterGridItem[]
/** 칩 순서. 비우면 items 에 나온 순서대로 */
categories?: string[]
allLabel?: string
/** 「총 8개 제품」의 「제품」 */
noun?: string
columns?: 2 | 3 | 4
emptyText?: string
className?: string
}
const grid = {
2: 'grid-cols-1 sm:grid-cols-2',
3: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3',
4: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-4',
}
const focus = 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring'
export function FilterGrid({ items, categories, allLabel = '전체', noun = '제품', columns = 4, emptyText = '이 분류에는 아직 항목이 없습니다.', className = '' }: FilterGridProps) {
const cats = categories ?? [...new Set(items.map((p) => p.category))]
const [cat, setCat] = useState<string | null>(null)
const list = cat ? items.filter((p) => p.category === cat) : items
return (
<div className={className}>
<div role="group" aria-label="분류" className="-mx-1 mb-10 flex gap-2 overflow-x-auto px-1 pt-1 pb-1">
{[null, ...cats].map((c) => {
const on = cat === c
return (
<button
key={c ?? '__all'}
type="button"
aria-pressed={on}
onClick={() => setCat(c)}
className={`h-11 shrink-0 rounded-lg border px-5 text-[15px] font-semibold transition-colors ${
on ? 'border-foreground bg-foreground text-background' : 'border-border text-muted-foreground hover:border-foreground hover:text-foreground'
} ${focus}`}
>
{c ?? allLabel}
</button>
)
})}
</div>
<p className="mb-5 text-sm text-muted-foreground" aria-live="polite">
총 <b className="font-semibold text-foreground tabular-nums">{list.length}</b>개 {noun}
</p>
{list.length ? (
<ul className={`grid gap-x-4 gap-y-12 md:gap-x-6 ${grid[columns]}`}>
{list.map((p) => {
const body = (
<>
<span className="block aspect-square overflow-hidden rounded-lg bg-muted">
<img
src={p.image}
alt={p.imageAlt ?? p.name}
loading="lazy"
className={`h-full w-full object-cover ${p.href ? 'transition-transform duration-500 group-hover:scale-105' : ''}`}
/>
</span>
<span className="mt-5 block text-xs font-semibold text-primary">{p.category}</span>
<span className="heading mt-1.5 block text-lg leading-snug">{p.name}</span>
</>
)
return (
<li key={`${p.category}-${p.name}`}>
{p.href ? (
<a href={p.href} className={`group block rounded-lg ${focus}`}>
{body}
</a>
) : (
body
)}
{p.specs?.length ? (
<dl className="mt-4 border-t border-foreground text-sm">
{p.specs.map((s) => (
<div key={s.label} className="flex justify-between gap-4 border-b border-border py-2.5">
<dt className="shrink-0 text-muted-foreground">{s.label}</dt>
<dd className="text-right font-medium tabular-nums">{s.value}</dd>
</div>
))}
</dl>
) : null}
</li>
)
})}
</ul>
) : (
<p className="border-t border-foreground py-16 text-center text-muted-foreground">{emptyText}</p>
)}
</div>
)
}