부품 머리글·바닥글

머리글 site-header

두 줄 머리글. 위 얇은 줄(대표전화·작은 링크·언어)과 아래 줄(로고·메인 메뉴·주 버튼). overlay 를 켜면 첫 화면 사진 위에 투명하게 얹혔다가 내려가면 바탕이 깔리고 위 줄이 접힌다. 하위 메뉴는 드롭다운, 좁은 화면은 햄버거로 여는 오른쪽 서랍.

  • 나온 곳 한결정밀
  • 헤더
  • 내비게이션
  • 드롭다운
  • 모바일 메뉴
  • 투명 헤더
  • 언어 선택

설치

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

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

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

AI에게 맡기기

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

bpublish UI의 머리글(site-header) 부품으로 만들어 줘. 설치: npx shadcn@latest add https://www.bpublish.com/r/site-header.json · 문서: https://www.bpublish.com/designs/components/site-header

사용 예시

app/page.tsx
import { HeroPhoto } from '@/components/bpublish/hero-photo'
import { SiteHeader } from '@/components/bpublish/site-header'

const logo = (
  <span className="inline-flex items-center gap-2.5">
    <svg viewBox="0 0 40 40" className="size-9 shrink-0" aria-hidden>
      <circle cx="20" cy="20" r="17" fill="none" stroke="currentColor" strokeWidth="4" className="text-primary" />
      <circle cx="20" cy="20" r="8.5" fill="none" stroke="currentColor" strokeWidth="3" />
      <path d="M2 20h36" stroke="currentColor" strokeWidth="3" />
    </svg>
    <span className="flex flex-col leading-none">
      <span className="heading text-[20px]">한결정밀</span>
      <span className="mt-1 text-[9px] font-semibold tracking-[0.22em] opacity-70">HANGYEOL PRECISION</span>
    </span>
  </span>
)

export default function Example() {
  return (
    <>
      <SiteHeader
        overlay
        name="한결정밀"
        logo={logo}
        topbar={{
          note: '대표전화 031-000-0000 · 평일 08:30 – 17:30',
          links: [
            { label: '오시는 길', href: '/company#location' },
            { label: '채용 안내', href: '/careers' },
          ],
          languages: [
            { label: 'KR', href: '/', active: true },
            { label: 'EN', href: '/en' },
          ],
        }}
        menu={[
          {
            label: '회사소개',
            href: '/company',
            children: [
              { label: '인사말', href: '/company#greeting' },
              { label: '연혁', href: '/company#history' },
              { label: '보유 설비', href: '/company#equipment' },
              { label: '오시는 길', href: '/company#location' },
            ],
          },
          {
            label: '사업 분야',
            href: '/business',
            children: [
              { label: '정밀 가공', href: '/business#machining' },
              { label: '반도체 장비 부품', href: '/business#semiconductor' },
              { label: '2차전지 설비 부품', href: '/business#battery' },
              { label: '의료·로봇 부품', href: '/business#medical' },
            ],
          },
          { label: '제품', href: '/products' },
          { label: '품질·인증', href: '/company#quality' },
          {
            label: '고객지원',
            href: '/contact',
            children: [
              { label: '견적 문의', href: '/contact' },
              { label: '자주 묻는 질문', href: '/contact#faq' },
            ],
          },
        ]}
        cta={{ label: '견적 문의', href: '/contact' }}
      />
      <HeroPhoto
        image={'/images/hero.webp'}
        eyebrow="Precision Machining Since 1998"
        title="0.005mm의 약속을 지키는 정밀 가공"
        description="반도체 장비부터 의료기기까지, 도면 한 장에서 양산까지 한결정밀이 책임집니다."
        primary={{ label: '견적 문의', href: '/contact' }}
        secondary={{ label: '사업 분야 보기', href: '/business' }}
        scrollHref="#business"
      />
    </>
  )
}

속성

이름형식기본값설명
name필수string—회사·가게 이름. logo 가 없으면 이 글자가 로고 자리에 선다
logoReactNode—로고 그림. currentColor 로 그리면 사진 위에서 흰색으로 바뀐다
homeHrefstring'/'로고 링크
menu필수{ label: string; href: string; children?: { label; href }[] }[]—메인 메뉴. children 이 있으면 드롭다운
currentstring—지금 페이지 주소. 같은 href 의 메뉴(또는 그 하위 메뉴를 가진 메뉴)에 표시가 붙는다
cta{ label: string; href: string }—오른쪽 주 버튼
topbar{ note?: string; links?: { label; href }[]; languages?: { label; href; active? }[] }—위 얇은 줄. 넓은 화면에서만 보이고 좁은 화면에서는 서랍 아래로 간다
overlaybooleanfalse첫 화면 사진 위에 투명하게 띄운다(fixed). 끄면 바탕이 깔린 채 위에 붙는다(sticky)

원본 코드

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

components/bpublish/site-header.tsx
/**
 * bpublish UI — 머리글. https://www.bpublish.com/designs/components/site-header
 * 두 줄 머리글. 위 얇은 줄(대표전화·작은 링크·언어)과 아래 줄(로고·메인 메뉴·주 버튼).
 * overlay 를 켜면 첫 화면 사진 위에 투명하게 얹히고, 내려가면 바탕이 깔리며 위 줄이 접힌다.
 * 메뉴는 하위 메뉴(드롭다운)를 가질 수 있고, 좁은 화면에서는 햄버거 단추가 오른쪽 서랍을 연다.
 */
'use client'

import { useEffect, useState, type ReactNode } from 'react'

export type HeaderLink = { label: string; href: string }
export type HeaderMenu = HeaderLink & { children?: HeaderLink[] }

export type SiteHeaderProps = {
  /** 회사·가게 이름. logo 가 없으면 이 글자가 로고 자리에 선다 */
  name: string
  /** 로고 그림. 글자색(currentColor)을 따르게 그리면 사진 위에서 흰색으로 바뀐다 */
  logo?: ReactNode
  /** 로고를 눌렀을 때 갈 곳 */
  homeHref?: string
  menu: HeaderMenu[]
  /** 지금 페이지의 주소. 같은 href 의 메뉴에 표시가 붙는다 */
  current?: string
  /** 오른쪽 주 버튼 */
  cta?: HeaderLink
  /** 위 얇은 줄. 넓은 화면에서만 보이고, 좁은 화면에서는 서랍 아래로 간다 */
  topbar?: {
    note?: string
    links?: HeaderLink[]
    languages?: (HeaderLink & { active?: boolean })[]
  }
  /** 첫 화면 사진 위에 투명하게 얹는다. 끄면 처음부터 바탕이 깔린 채 위에 붙는다 */
  overlay?: boolean
  className?: string
}

const focus = 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring'

function Chevron({ className = '' }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.5" aria-hidden className={className}>
      <path d="m6 9 6 6 6-6" />
    </svg>
  )
}

export function SiteHeader({ name, logo, homeHref = '/', menu, current, cta, topbar, overlay = false, className = '' }: SiteHeaderProps) {
  const [scrolled, setScrolled] = useState(false)
  const [open, setOpen] = useState(false)

  useEffect(() => {
    const on = () => setScrolled(window.scrollY > 40)
    on()
    window.addEventListener('scroll', on, { passive: true })
    return () => window.removeEventListener('scroll', on)
  }, [])

  useEffect(() => {
    if (!open) return
    const onKey = (e: KeyboardEvent) => e.key === 'Escape' && setOpen(false)
    const prev = document.body.style.overflow
    document.body.style.overflow = 'hidden'
    window.addEventListener('keydown', onKey)
    return () => {
      document.body.style.overflow = prev
      window.removeEventListener('keydown', onKey)
    }
  }, [open])

  const clear = overlay && !scrolled
  const hasTop = Boolean(topbar && (topbar.note || topbar.links?.length || topbar.languages?.length))
  const isCurrent = (m: HeaderMenu) => Boolean(current && (m.href === current || m.children?.some((c) => c.href === current)))

  const brand = (
    <a href={homeHref} aria-label={`${name} 처음으로`} className={`flex shrink-0 items-center rounded-sm ${focus}`}>
      {logo ?? <span className="heading text-xl md:text-[22px]">{name}</span>}
    </a>
  )

  return (
    <>
      <header
        className={`${overlay ? 'fixed' : 'sticky'} inset-x-0 top-0 z-50 transition-[background-color,color,border-color] duration-300 ${
          clear ? 'border-b border-white/15 bg-transparent text-white' : 'border-b border-border bg-background text-foreground'
        } ${className}`}
      >
        {/* 위 얇은 줄 — 내려가면 접힌다 */}
        {hasTop ? (
          <div
            className={`hidden overflow-hidden text-[13px] transition-[height] duration-300 md:block ${scrolled ? 'h-0' : 'h-9'} ${
              clear ? 'border-b border-white/15 text-white/75' : 'border-b border-border text-muted-foreground'
            }`}
          >
            <div className="shell flex h-9 items-center justify-between gap-6">
              <p className="tabular-nums">{topbar?.note}</p>
              <div className="flex items-center gap-5">
                {topbar?.links?.map((l) => (
                  <a key={l.href} href={l.href} className={`transition-colors ${clear ? 'hover:text-white' : 'hover:text-foreground'} ${focus}`}>
                    {l.label}
                  </a>
                ))}
                {topbar?.languages?.length ? (
                  <ul className="flex items-center gap-2 font-semibold tracking-wide">
                    {topbar.languages.map((g, i) => (
                      <li key={g.label} className="flex items-center gap-2">
                        {i > 0 ? (
                          <span aria-hidden className="opacity-40">
                            |
                          </span>
                        ) : null}
                        <a
                          href={g.href}
                          aria-current={g.active ? 'true' : undefined}
                          className={`${g.active ? (clear ? 'text-white' : 'text-foreground') : 'opacity-60 hover:opacity-100'} ${focus}`}
                        >
                          {g.label}
                        </a>
                      </li>
                    ))}
                  </ul>
                ) : null}
              </div>
            </div>
          </div>
        ) : null}

        {/* 아래 줄 — 로고 · 메뉴 · 주 버튼 */}
        <div className="shell flex h-16 items-center gap-8 md:h-20">
          {brand}

          <nav aria-label="주 메뉴" className="hidden h-full flex-1 justify-center lg:flex">
            <ul className="flex h-full items-stretch gap-1 xl:gap-4">
              {menu.map((m) => {
                const on = isCurrent(m)
                return (
                  <li key={m.href} className="group relative flex">
                    <a
                      href={m.href}
                      aria-current={m.href === current ? 'page' : undefined}
                      className={`relative flex items-center gap-1 px-4 text-[16px] font-semibold tracking-tight transition-opacity hover:opacity-70 ${focus}`}
                    >
                      {m.label}
                      {m.children?.length ? <Chevron className="opacity-60" /> : null}
                      {on ? <span aria-hidden className={`absolute inset-x-4 bottom-0 h-0.5 ${clear ? 'bg-white' : 'bg-primary'}`} /> : null}
                    </a>
                    {m.children?.length ? (
                      <div className="invisible absolute top-full left-1/2 z-10 -translate-x-1/2 pt-1 opacity-0 transition-[opacity,visibility] duration-200 group-focus-within:visible group-focus-within:opacity-100 group-hover:visible group-hover:opacity-100">
                        <ul className="min-w-48 rounded-lg border border-border bg-popover py-2 text-popover-foreground shadow-lg">
                          {m.children.map((c) => (
                            <li key={c.href}>
                              <a
                                href={c.href}
                                aria-current={c.href === current ? 'page' : undefined}
                                className={`block px-5 py-2.5 text-[15px] whitespace-nowrap transition-colors hover:bg-muted aria-[current=page]:font-semibold aria-[current=page]:text-primary ${focus}`}
                              >
                                {c.label}
                              </a>
                            </li>
                          ))}
                        </ul>
                      </div>
                    ) : null}
                  </li>
                )
              })}
            </ul>
          </nav>

          <div className="ml-auto flex items-center gap-2 lg:ml-0">
            {cta ? (
              <a
                href={cta.href}
                className={`hidden h-11 items-center rounded-lg bg-primary px-5 text-[15px] font-semibold text-primary-foreground transition-opacity hover:opacity-90 sm:inline-flex ${focus}`}
              >
                {cta.label}
              </a>
            ) : null}
            <button
              type="button"
              onClick={() => setOpen(true)}
              aria-expanded={open}
              aria-controls="bp-header-drawer"
              aria-label="메뉴 열기"
              className={`-mr-2 grid size-11 place-items-center rounded-lg lg:hidden ${focus}`}
            >
              <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeWidth="1.5" aria-hidden>
                <path d="M4 7h16M4 12h16M4 17h16" />
              </svg>
            </button>
          </div>
        </div>
      </header>

      {/* 좁은 화면 서랍 */}
      <div id="bp-header-drawer" className={`fixed inset-0 z-[60] lg:hidden ${open ? '' : 'pointer-events-none'}`} aria-hidden={!open} inert={!open}>
        <button
          type="button"
          tabIndex={-1}
          aria-label="메뉴 닫기"
          onClick={() => setOpen(false)}
          className={`absolute inset-0 bg-black/40 transition-opacity duration-300 ${open ? 'opacity-100' : 'opacity-0'}`}
        />
        <div
          role="dialog"
          aria-modal="true"
          aria-label="전체 메뉴"
          className={`absolute inset-y-0 right-0 flex w-[min(88vw,380px)] flex-col bg-background text-foreground shadow-lg transition-transform duration-300 ${
            open ? 'translate-x-0' : 'translate-x-full'
          }`}
        >
          <div className="flex h-16 shrink-0 items-center justify-between border-b border-border px-5">
            {brand}
            <button type="button" onClick={() => setOpen(false)} aria-label="메뉴 닫기" className={`-mr-2 grid size-11 place-items-center rounded-lg ${focus}`}>
              <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeWidth="1.5" aria-hidden>
                <path d="M6 6l12 12M18 6 6 18" />
              </svg>
            </button>
          </div>

          <nav aria-label="모바일 메뉴" className="flex-1 overflow-y-auto px-5 py-2">
            <ul>
              {menu.map((m) => (
                <li key={m.href} className="border-b border-border py-2">
                  <a
                    href={m.href}
                    onClick={() => setOpen(false)}
                    aria-current={m.href === current ? 'page' : undefined}
                    className={`block py-2.5 text-[17px] font-semibold aria-[current=page]:text-primary ${focus}`}
                  >
                    {m.label}
                  </a>
                  {m.children?.length ? (
                    <ul className="grid grid-cols-2 gap-x-4 pb-2">
                      {m.children.map((c) => (
                        <li key={c.href}>
                          <a
                            href={c.href}
                            onClick={() => setOpen(false)}
                            aria-current={c.href === current ? 'page' : undefined}
                            className={`block py-2 text-[15px] text-muted-foreground aria-[current=page]:font-semibold aria-[current=page]:text-primary ${focus}`}
                          >
                            {c.label}
                          </a>
                        </li>
                      ))}
                    </ul>
                  ) : null}
                </li>
              ))}
            </ul>
          </nav>

          <div className="shrink-0 border-t border-border px-5 py-5">
            {cta ? (
              <a
                href={cta.href}
                onClick={() => setOpen(false)}
                className={`flex h-12 items-center justify-center rounded-lg bg-primary font-semibold text-primary-foreground ${focus}`}
              >
                {cta.label}
              </a>
            ) : null}
            {hasTop ? (
              <div className={`flex flex-wrap items-center justify-between gap-3 text-[13px] text-muted-foreground ${cta ? 'mt-4' : ''}`}>
                {topbar?.note ? <p className="w-full tabular-nums">{topbar.note}</p> : null}
                <div className="flex gap-4">
                  {topbar?.links?.map((l) => (
                    <a key={l.href} href={l.href} className={focus}>
                      {l.label}
                    </a>
                  ))}
                </div>
                <div className="flex gap-3 font-semibold">
                  {topbar?.languages?.map((g) => (
                    <a key={g.label} href={g.href} className={`${g.active ? 'text-foreground' : ''} ${focus}`}>
                      {g.label}
                    </a>
                  ))}
                </div>
              </div>
            ) : null}
          </div>
        </div>
      </div>
    </>
  )
}