부품 데이터·관리 화면

관리 화면 제목 줄 page-header

관리 화면 맨 위의 제목과 설명 한 줄. 넓은 화면에서는 오른쪽에 기간 선택(7일·30일·90일 같은 짧은 선택지)과 버튼들이 서고, 좁은 화면에서는 아래로 내려간다.

  • 나온 곳 대시보드
  • 제목
  • 기간 선택
  • 버튼
  • 관리 화면
  • 대시보드

설치

shadcn/ui 를 쓰는 Next.js 프로젝트에서 한 줄로 설치됩니다. 파일은 components/bpublish/page-header.tsx 로 들어오고, 공통 토큰(base)도 같이 설치됩니다. 테마는 테마에서 하나 고릅니다.

npx shadcn@latest add https://www.bpublish.com/r/page-header.json

레지스트리를 등록했다면 npx shadcn@latest add @bpublish/page-header · 설치 안내

AI에게 맡기기

Claude Code, Cursor 같은 AI 코딩 도구에 붙여 넣으세요. MCP 서버를 연결해 두면 이름만 말해도 됩니다.

bpublish UI의 관리 화면 제목 줄(page-header) 부품으로 만들어 줘. 설치: npx shadcn@latest add https://www.bpublish.com/r/page-header.json · 문서: https://www.bpublish.com/designs/components/page-header

사용 예시

app/page.tsx
'use client'

import { PageHeader } from '@/components/bpublish/page-header'

export default function Example() {
  return (
    <PageHeader
      title="개요"
      description="10월 22일 – 11월 20일 · 이전 기간 대비"
      period={{
        defaultValue: '30d',
        options: [
          { value: '7d', label: '7일' },
          { value: '30d', label: '30일' },
          { value: '90d', label: '90일' },
        ],
      }}
      actions={[{ label: '내보내기', icon: 'download' }]}
    />
  )
}

속성

이름형식기본값설명
title필수string—화면 제목
descriptionReactNode—기간·기준 한 줄
period{ options: { value: T; label: string }[]; value?: T; defaultValue?: T; onChange?: (v: T) => void; label?: string }—기간 선택. value 를 주면 바깥에서 쥔다
actions{ label: string; href?: string; onClick?: () => void; variant?: 'primary' | 'outline'; icon?: 'download' | 'plus' | 'filter' | 'calendar' | ReactNode }[]—오른쪽 버튼들. primary 는 하나만
childrenReactNode—버튼 자리에 직접 넣을 것

원본 코드

설치 명령 없이 그대로 복사해 넣어도 됩니다. React 외의 패키지는 쓰지 않습니다.

components/bpublish/page-header.tsx
'use client'

/**
 * bpublish UI — 관리 화면 제목 줄. https://www.bpublish.com/designs/components/page-header
 * 관리 화면 맨 위의 제목과 설명 한 줄, 오른쪽에 기간 선택(7일·30일·90일)과 버튼들.
 * 기간은 value·onChange 로 바깥에서 쥐거나, defaultValue 만 주고 맡겨도 된다.
 */
import * as React from 'react'

export type PageHeaderAction = {
  label: string
  href?: string
  onClick?: () => void
  /** 주 버튼(primary)은 한 화면에 하나만 */
  variant?: 'primary' | 'outline'
  icon?: 'download' | 'plus' | 'filter' | 'calendar' | React.ReactNode
}

export type PageHeaderPeriod<T extends string = string> = {
  options: ReadonlyArray<{ value: T; label: string }>
  value?: T
  defaultValue?: T
  onChange?: (value: T) => void
  /** 화면 읽기 프로그램용 이름 */
  label?: string
}

export type PageHeaderProps<T extends string = string> = {
  title: string
  description?: React.ReactNode
  period?: PageHeaderPeriod<T>
  actions?: PageHeaderAction[]
  /** 버튼 자리에 직접 넣을 것(검색칸, 메뉴 등) */
  children?: React.ReactNode
  className?: string
}

const cx = (...v: Array<string | false | null | undefined>) => v.filter(Boolean).join(' ')
const ring = 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring'

export function PageHeader<T extends string = string>({ title, description, period, actions, children, className }: PageHeaderProps<T>) {
  const hasRight = period || actions?.length || children
  return (
    <div className={cx('mb-6 flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between', className)}>
      <div className="min-w-0">
        <h1 className="heading text-2xl text-foreground">{title}</h1>
        {description ? <p className="mt-1 text-sm text-muted-foreground tabular-nums">{description}</p> : null}
      </div>
      {hasRight ? (
        <div className="flex flex-wrap items-center gap-2">
          {period ? <Segmented {...period} /> : null}
          {children}
          {actions?.map((a) => <ActionButton key={a.label} {...a} />)}
        </div>
      ) : null}
    </div>
  )
}

function Segmented<T extends string>({ options, value, defaultValue, onChange, label = '기간' }: PageHeaderPeriod<T>) {
  const [inner, setInner] = React.useState<T | undefined>(defaultValue ?? options[0]?.value)
  const current = value ?? inner
  const choose = (v: T) => {
    setInner(v)
    onChange?.(v)
  }
  return (
    <div role="radiogroup" aria-label={label} className="inline-flex h-9 items-center rounded-lg border border-border bg-muted p-0.5">
      {options.map((o) => {
        const on = o.value === current
        return (
          <button
            key={o.value}
            type="button"
            role="radio"
            aria-checked={on}
            onClick={() => choose(o.value)}
            className={cx(
              'h-full rounded-md px-3 text-[13px] font-medium tabular-nums transition-colors',
              ring,
              on ? 'bg-card text-foreground ring-1 ring-border' : 'text-muted-foreground hover:text-foreground',
            )}
          >
            {o.label}
          </button>
        )
      })}
    </div>
  )
}

function ActionButton({ label, href, onClick, variant = 'outline', icon }: PageHeaderAction) {
  const cls = cx(
    'inline-flex h-9 shrink-0 items-center justify-center gap-2 rounded-lg px-3.5 text-sm font-medium whitespace-nowrap transition-colors',
    ring,
    variant === 'primary' ? 'bg-primary text-primary-foreground hover:bg-primary/90' : 'border border-border bg-card text-foreground hover:bg-accent',
  )
  const body = (
    <>
      {typeof icon === 'string' ? <Icon name={icon} /> : icon}
      {label}
    </>
  )
  return href ? (
    <a href={href} className={cls}>
      {body}
    </a>
  ) : (
    <button type="button" onClick={onClick} className={cls}>
      {body}
    </button>
  )
}

const PATHS: Record<string, React.ReactNode> = {
  download: <path d="M12 4v11m-4.5-4.5L12 15l4.5-4.5M5 19.5h14" />,
  plus: <path d="M12 5v14M5 12h14" />,
  filter: <path d="M4 6h16M7 12h10M10 18h4" />,
  calendar: <path d="M5.5 5h13a2 2 0 0 1 2 2v11.5a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2ZM3.5 10h17M8 3v4M16 3v4" />,
}

function Icon({ name }: { name: string }) {
  return (
    <svg aria-hidden viewBox="0 0 24 24" className="size-4 shrink-0" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round">
      {PATHS[name]}
    </svg>
  )
}