부품 본문 구역
탭 판 tab-panels
탭을 누르면 아래 판의 제목·설명·내용이 바뀐다. 학년별 강좌, 반 소개, 제품군처럼 같은 꼴의 내용을 나눠 보일 때. 좌우 화살표·Home·End 로 탭을 옮긴다(role=tablist).
설치
shadcn/ui 를 쓰는 Next.js 프로젝트에서 한 줄로 설치됩니다. 파일은 components/bpublish/tab-panels.tsx 로 들어오고, 공통 토큰(base)도 같이 설치됩니다. 테마는 테마에서 하나 고릅니다.
npx shadcn@latest add https://www.bpublish.com/r/tab-panels.json레지스트리를 등록했다면 npx shadcn@latest add @bpublish/tab-panels · 설치 안내
AI에게 맡기기
Claude Code, Cursor 같은 AI 코딩 도구에 붙여 넣으세요. MCP 서버를 연결해 두면 이름만 말해도 됩니다.
bpublish UI의 탭 판(tab-panels) 부품으로 만들어 줘. 설치: npx shadcn@latest add https://www.bpublish.com/r/tab-panels.json · 문서: https://www.bpublish.com/designs/components/tab-panels사용 예시
import { TabPanels } from '@/components/bpublish/tab-panels'
type Row = { name: string; days: string; time: string; fee: string; book: string }
function Classes({ rows }: { rows: Row[] }) {
return (
<ul className="border-t-[3px] border-current">
{rows.map((c) => (
<li key={c.name} className="grid gap-x-6 gap-y-1 border-b border-current/20 py-5 md:grid-cols-[1fr_80px_240px_150px] md:items-center">
<p className="text-lg font-semibold">{c.name}</p>
<p className="font-semibold">{c.days}</p>
<p className="text-[15px] tabular-nums">{c.time}</p>
<p className="heading text-2xl tabular-nums md:text-right">{c.fee}</p>
<p className="text-sm opacity-70 md:col-span-4">{c.book}</p>
</li>
))}
</ul>
)
}
export default function Example() {
return (
<TabPanels
label="학년 선택"
defaultIndex={1}
items={[
{
label: '중등',
title: '중등부 · 심화와 고등 선행',
description: '학교 내신은 학교별 기출로 대비하고, 중3 겨울에는 고1 공통수학1을 한 번 끝까지 마칩니다.',
content: (
<Classes
rows={[
{ name: '중1 정규', days: '월·수', time: '17:00 – 19:30', fee: '380,000원', book: '자체 교재 1권' },
{ name: '중2 심화 A', days: '화·목', time: '17:00 – 20:00', fee: '420,000원', book: '자체 교재 · 최상위 수학' },
{ name: '중3 공통수학1 선행', days: '월·수', time: '18:00 – 21:30', fee: '480,000원', book: '자체 교재 · 개념원리' },
]}
/>
),
},
{
label: '고1',
title: '고1 · 공통수학1·2 내신 완성',
description: '고등학교 첫 내신이 이후 2년의 공부 방식을 정합니다. 겨울방학에 공통수학1을 마치고 공통수학2 앞부분까지 나갑니다.',
content: (
<Classes
rows={[
{ name: '예비 고1 공통수학1 정규', days: '화·금', time: '18:30 – 22:00', fee: '560,000원', book: '자체 교재 · 쎈' },
{ name: '예비 고1 공통수학1 심화', days: '월·목', time: '18:30 – 22:00', fee: '560,000원', book: '자체 교재 · 블랙라벨' },
{ name: '예비 고1 주말반', days: '토', time: '10:00 – 16:00', fee: '520,000원', book: '자체 교재 · 쎈' },
]}
/>
),
},
{
label: '고2',
title: '고2 · 대수·미적분Ⅰ 수능 기초',
description: '2028학년도 수능부터 수학은 대수·미적분Ⅰ·확률과 통계가 공통 범위입니다. 고2 1년 동안 세 과목의 개념과 기출을 모두 한 번 다룹니다.',
content: (
<Classes
rows={[
{ name: '예비 고2 대수 정규', days: '월·목', time: '18:30 – 22:00', fee: '600,000원', book: '자체 교재 · 수능 기출 1권' },
{ name: '예비 고2 대수 심화', days: '화·금', time: '18:30 – 22:00', fee: '600,000원', book: '자체 교재 · 수능 기출 1권' },
{ name: '예비 고2 미적분Ⅰ 선행', days: '토', time: '13:00 – 18:00', fee: '540,000원', book: '자체 교재' },
]}
/>
),
},
{
label: '고3·N수',
title: '고3·N수 · 수능 실전',
description: '기출 분석, 실전 모의고사, 오답 클리닉을 한 주 안에 모두 돌립니다. N수 주간반은 오전 수업 뒤 오후 자습실을 함께 씁니다.',
content: (
<Classes
rows={[
{ name: '예비 고3 수능 공통 실전', days: '수·토', time: '수 18:30 – 22:00 · 토 13:00 – 17:00', fee: '680,000원', book: '자체 교재 · 실전 모의고사' },
{ name: 'N수 정규 (주간)', days: '월·수·금', time: '10:00 – 13:00', fee: '720,000원', book: '자체 교재 · 평가원 기출 전권' },
{ name: 'N수 실전 모의고사', days: '토', time: '09:00 – 12:30', fee: '280,000원', book: '자체 제작 모의고사 매주 1회' },
]}
/>
),
},
]}
/>
)
}속성
| 이름 | 형식 | 기본값 | 설명 |
|---|---|---|---|
items필수 | { label: string; title?: string; description?: string; content?: ReactNode }[] | — | 탭마다 이름과 판 내용. 판 안의 보조 글은 opacity-70, 선은 border-current/20 으로 쓰면 두 바탕 모두에서 맞는다 |
label필수 | string | — | 탭 줄 이름(화면 낭독기용) |
defaultIndex | number | 0 | 처음 열 탭 |
surface | 'inverse' | 'muted' | 'inverse' | 판 바탕. inverse 는 반전 색(오름에서는 밝은 종이색), muted 는 옅은 판 |
onChange | (index: number) => void | — | 탭이 바뀔 때 |
원본 코드
설치 명령 없이 그대로 복사해 넣어도 됩니다. React 외의 패키지는 쓰지 않습니다.
'use client'
/**
* bpublish UI — 탭 판. https://www.bpublish.com/designs/components/tab-panels
* 탭을 누르면 아래 판의 내용이 바뀐다(학년별 강좌, 반 소개, 제품군). 좌우 화살표·Home·End 로 옮겨 다닌다.
*/
import { useId, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
export type TabPanelItem = {
/** 탭 이름 */
label: string
/** 판 맨 위 큰 제목 */
title?: string
/** 제목 오른쪽 설명 */
description?: string
/** 판 내용. 판 안의 보조 글은 opacity-70, 선은 border-current/20 으로 쓰면 어느 바탕에서도 맞는다 */
content?: ReactNode
}
export type TabPanelsProps = {
items: TabPanelItem[]
/** 탭 줄 이름(화면 낭독기용) */
label: string
/** 처음 열 탭 번호 */
defaultIndex?: number
/** inverse: 짙은/밝은 반전 판 / muted: 옅은 판 */
surface?: 'inverse' | 'muted'
onChange?: (index: number) => void
className?: string
}
export function TabPanels({ items, label, defaultIndex = 0, surface = 'inverse', onChange, className = '' }: TabPanelsProps) {
const [active, setActive] = useState(defaultIndex)
const refs = useRef<(HTMLButtonElement | null)[]>([])
const uid = useId()
const item = items[active] ?? items[0]
const panel = surface === 'inverse' ? 'bg-inverse text-inverse-foreground' : 'bg-muted text-foreground'
const idle =
surface === 'inverse'
? 'bg-secondary text-muted-foreground hover:text-foreground'
: 'border border-border bg-background text-muted-foreground hover:text-foreground'
function select(i: number, focus = false) {
setActive(i)
onChange?.(i)
if (focus) refs.current[i]?.focus()
}
function onKey(e: KeyboardEvent<HTMLDivElement>) {
const n = items.length
let next = active
if (e.key === 'ArrowRight') next = (active + 1) % n
else if (e.key === 'ArrowLeft') next = (active - 1 + n) % n
else if (e.key === 'Home') next = 0
else if (e.key === 'End') next = n - 1
else return
e.preventDefault()
select(next, true)
}
return (
<div className={className}>
<div className="shell">
<div
role="tablist"
aria-label={label}
onKeyDown={onKey}
className="grid grid-cols-[repeat(auto-fit,minmax(4.5rem,1fr))] gap-1 md:grid-cols-[repeat(auto-fit,minmax(9rem,1fr))] md:gap-2"
>
{items.map((t, i) => {
const on = i === active
return (
<button
key={t.label}
ref={(el) => {
refs.current[i] = el
}}
role="tab"
type="button"
id={`${uid}-tab-${i}`}
aria-selected={on}
aria-controls={`${uid}-panel-${i}`}
tabIndex={on ? 0 : -1}
onClick={() => select(i)}
className={`flex h-16 items-center justify-center px-2 text-base font-semibold transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring md:h-20 md:text-[22px] ${
on ? panel : idle
}`}
>
{on ? <span aria-hidden className="mr-2 hidden h-3 w-3 shrink-0 bg-primary md:inline-block" /> : null}
{t.label}
</button>
)
})}
</div>
</div>
<div
role="tabpanel"
id={`${uid}-panel-${active}`}
aria-labelledby={`${uid}-tab-${active}`}
tabIndex={0}
className={`${panel} focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring`}
>
<div className="shell py-14 md:py-20">
{item.title || item.description ? (
<div className="grid gap-5 lg:grid-cols-12 lg:gap-10">
{item.title ? <h2 className="heading text-[32px] leading-[1.12] text-balance md:text-5xl lg:col-span-6">{item.title}</h2> : null}
{item.description ? (
<p className="text-base leading-[1.8] opacity-80 md:text-[17px] lg:col-span-6 lg:pt-2">{item.description}</p>
) : null}
</div>
) : null}
{item.content ? <div className={item.title || item.description ? 'mt-12' : ''}>{item.content}</div> : null}
</div>
</div>
</div>
)
}