부품 데이터·관리 화면
막대 목록 bar-list
이름과 값을 막대 길이로 견주는 순위 목록. 유입 채널처럼 이름 뒤에 막대를 까는 fill, 많이 팔린 상품처럼 순위 칸과 가는 막대를 쓰는 rank 두 가지. title 을 주면 카드가 되고 summary 로 아래 숫자 칸을 단다.
설치
shadcn/ui 를 쓰는 Next.js 프로젝트에서 한 줄로 설치됩니다. 파일은 components/bpublish/bar-list.tsx 로 들어오고, 공통 토큰(base)도 같이 설치됩니다. 테마는 테마에서 하나 고릅니다.
npx shadcn@latest add https://www.bpublish.com/r/bar-list.json레지스트리를 등록했다면 npx shadcn@latest add @bpublish/bar-list · 설치 안내
AI에게 맡기기
Claude Code, Cursor 같은 AI 코딩 도구에 붙여 넣으세요. MCP 서버를 연결해 두면 이름만 말해도 됩니다.
bpublish UI의 막대 목록(bar-list) 부품으로 만들어 줘. 설치: npx shadcn@latest add https://www.bpublish.com/r/bar-list.json · 문서: https://www.bpublish.com/designs/components/bar-list사용 예시
import { BarList } from '@/components/bpublish/bar-list'
const channels = [
{ label: '검색 광고', value: 26805 },
{ label: '자연 검색', value: 20498 },
{ label: '인스타그램', value: 14191 },
{ label: '직접 방문', value: 10249 },
{ label: '이메일', value: 7096 },
]
const products = [
{ label: '리넨 오버셔츠', value: 28_428_000, meta: '상의 · 412개' },
{ label: '코튼 니트 가디건', value: 25_122_000, meta: '상의 · 318개' },
{ label: '와이드 치노 팬츠', value: 20_424_000, meta: '하의 · 296개' },
{ label: '캔버스 토트백', value: 10_668_000, meta: '잡화 · 254개' },
{ label: '울 블렌드 머플러', value: 10_089_000, meta: '잡화 · 171개' },
]
const manwon = (v: number) => `${Math.round(v / 1e4).toLocaleString('ko-KR')}만원`
export default function Example() {
return (
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
<BarList
title="유입 채널"
description="방문자 기준"
items={channels}
summary={[
{ label: '신규 방문', value: '48,880' },
{ label: '재방문', value: '29,959' },
]}
/>
<BarList title="많이 팔린 상품" description="10월 22일 – 11월 20일" variant="rank" items={products} format={manwon} />
</div>
)
}속성
| 이름 | 형식 | 기본값 | 설명 |
|---|---|---|---|
items필수 | { label: string; value: number; meta?: string; href?: string }[] | — | 항목. meta 는 rank 모양의 보조 글, href 를 주면 줄 전체가 링크 |
variant | 'fill' | 'rank' | 'fill' | 모양 |
format | (v: number) => string | — | 값 표기. 기본은 천 단위 쉼표 |
showShare | boolean | true | fill 모양에서 전체 대비 비율 칸 |
title | string | — | 주면 카드로 감싸고 제목을 단다 |
description | string | — | 제목 아래 기준 한 줄 |
action | ReactNode | — | 머리 오른쪽(전체 보기 등) |
summary | { label: string; value: string }[] | — | 카드 아래 숫자 칸 |
원본 코드
설치 명령 없이 그대로 복사해 넣어도 됩니다. React 외의 패키지는 쓰지 않습니다.
/**
* bpublish UI — 막대 목록. https://www.bpublish.com/designs/components/bar-list
* 이름과 값을 막대 길이로 견주는 순위 목록. 유입 채널(fill: 이름 뒤에 막대, 값, 비율)과
* 많이 팔린 상품(rank: 순위 칸, 이름, 값, 가는 막대, 보조 글) 두 가지 모양.
* title 을 주면 카드로 감싸고, summary 를 주면 카드 아래에 작은 숫자 칸을 단다.
*/
import type { ReactNode } from 'react'
export type BarListItem = {
label: string
value: number
/** rank 모양에서 막대 옆 보조 글: "상의 · 412개" */
meta?: string
href?: string
}
export type BarListProps = {
items: BarListItem[]
/** fill: 이름 뒤에 막대를 깐다 / rank: 순위 칸과 가는 막대 */
variant?: 'fill' | 'rank'
/** 값 표기. 기본은 천 단위 쉼표 */
format?: (v: number) => string
/** fill 모양에서 전체 대비 비율(%) 칸 */
showShare?: boolean
/** 주면 카드로 감싸고 머리에 제목을 단다 */
title?: string
description?: string
/** 머리 오른쪽(전체 보기 링크 등) */
action?: ReactNode
/** 카드 아래 숫자 칸: [{ label: '신규 방문', value: '48,880' }] */
summary?: Array<{ label: string; value: string }>
className?: string
}
const cx = (...v: Array<string | false | null | undefined>) => v.filter(Boolean).join(' ')
const n0 = new Intl.NumberFormat('ko-KR', { maximumFractionDigits: 0 })
export function BarList({ title, description, action, summary, className, ...list }: BarListProps) {
if (!title) return <List {...list} className={className} />
return (
<section className={cx('flex flex-col rounded-lg border border-border bg-card text-card-foreground', className)}>
<header className="flex items-start justify-between gap-4 px-5 pt-5">
<div className="min-w-0">
<h2 className="text-sm font-semibold tracking-tight">{title}</h2>
{description ? <p className="mt-1 text-[13px] leading-5 text-muted-foreground">{description}</p> : null}
</div>
{action ? <div className="flex shrink-0 items-center gap-2">{action}</div> : null}
</header>
<List {...list} className={list.variant === 'rank' ? 'px-3 py-3' : 'px-5 pt-5 pb-5'} />
{summary?.length ? (
<dl className="mt-auto grid border-t border-border" style={{ gridTemplateColumns: `repeat(${summary.length}, minmax(0, 1fr))` }}>
{summary.map((s, i) => (
<div key={s.label} className={cx('px-5 py-4', i > 0 && 'border-l border-border')}>
<dt className="text-xs text-muted-foreground">{s.label}</dt>
<dd className="mt-1 text-base font-semibold tabular-nums">{s.value}</dd>
</div>
))}
</dl>
) : null}
</section>
)
}
function List({
items,
variant = 'fill',
format = (v) => n0.format(v),
showShare = true,
className,
}: Pick<BarListProps, 'items' | 'variant' | 'format' | 'showShare' | 'className'>) {
const total = items.reduce((a, b) => a + b.value, 0) || 1
const max = Math.max(0, ...items.map((i) => i.value)) || 1
if (variant === 'rank') {
return (
<ol className={cx('flex flex-col gap-1', className)}>
{items.map((it, i) => (
<li key={it.label}>
<Row href={it.href} className="flex items-center gap-3 rounded-lg px-2 py-2.5">
<span aria-hidden className="grid size-10 shrink-0 place-items-center rounded-lg bg-muted text-sm font-semibold text-muted-foreground tabular-nums">
{i + 1}
</span>
<div className="min-w-0 flex-1">
<div className="flex items-baseline justify-between gap-3">
<p className="truncate text-[13px] font-medium">{it.label}</p>
<p className="shrink-0 text-[13px] font-semibold tabular-nums">{format(it.value)}</p>
</div>
<div className="mt-1.5 flex items-center gap-3">
<div className="h-1 flex-1 overflow-hidden rounded-full bg-muted">
<div className="h-full rounded-full bg-chart-1/70" style={{ width: `${(it.value / max) * 100}%` }} />
</div>
{it.meta ? <p className="shrink-0 text-xs text-muted-foreground tabular-nums">{it.meta}</p> : null}
</div>
</div>
</Row>
</li>
))}
</ol>
)
}
return (
<ul className={cx('space-y-2.5', className)}>
{items.map((it, i) => (
<li key={it.label}>
<Row href={it.href} className="flex items-center gap-3 rounded-md">
<div className="relative flex h-9 min-w-0 flex-1 items-center">
<div
aria-hidden
className={cx('absolute inset-y-0 left-0 rounded-md', i === 0 ? 'bg-chart-1/15' : 'bg-chart-1/10')}
style={{ width: `${(it.value / max) * 100}%` }}
/>
<span className="relative truncate px-2.5 text-[13px]">{it.label}</span>
</div>
<span className="min-w-14 shrink-0 text-right text-[13px] font-medium tabular-nums">{format(it.value)}</span>
{showShare ? (
<span className="w-11 shrink-0 text-right text-xs text-muted-foreground tabular-nums">{((it.value / total) * 100).toFixed(0)}%</span>
) : null}
</Row>
</li>
))}
</ul>
)
}
function Row({ href, className, children }: { href?: string; className: string; children: ReactNode }) {
if (!href) return <div className={className}>{children}</div>
return (
<a
href={href}
className={cx(className, 'transition-colors hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring')}
>
{children}
</a>
)
}