부품 본문 구역

사진 모음 photo-gallery

가는 틈으로 붙인 사진 격자. mosaic 은 큰 정사각과 작은 정사각이 섞여 여섯 장이 두 줄을 꽉 채우고, row 는 같은 크기 정사각을 3열(넓은 화면 6열)로 늘어놓는다. 캡션은 사진 왼쪽 아래 검정 막 위에.

설치

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

npx shadcn@latest add https://www.bpublish.com/r/photo-gallery.json

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

AI에게 맡기기

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

bpublish UI의 사진 모음(photo-gallery) 부품으로 만들어 줘. 설치: npx shadcn@latest add https://www.bpublish.com/r/photo-gallery.json · 문서: https://www.bpublish.com/designs/components/photo-gallery

사용 예시

app/page.tsx
import { PhotoGallery } from '@/components/bpublish/photo-gallery'
import { SectionHead } from '@/components/bpublish/section-head'

const insta = 'https://www.instagram.com/'

export default function Example() {
  return (
    <section className="py-16 md:py-24">
      <div className="shell">
        <SectionHead eyebrow="Instagram" title="오늘의 진열대" description="그날 나온 빵과 바뀐 시간표는 인스타그램에 먼저 올립니다." />
        <PhotoGallery
          className="mt-10 md:mt-14"
          photos={[
            { src: '/images/window.webp', alt: '골목에서 본 빵집 창문과 진열대', caption: '연남동 골목의 창' },
            { src: '/images/scoring.webp', alt: '굽기 직전 반죽 표면에 칼집을 내는 손' },
            { src: '/images/coffee.webp', alt: '창가 자리의 카페라테와 크루아상' },
            { src: '/images/crumb.webp', alt: '반으로 자른 시골빵의 속살', caption: '밀담 시골빵의 속' },
            { src: '/images/pastry.webp', alt: '나무 쟁반에 담긴 휘낭시에와 카눌레' },
            { src: '/images/giftbox.webp', alt: '끈으로 묶은 크라프트 선물 상자' },
          ]}
        />
      </div>

      <PhotoGallery
        layout="row"
        className="mt-16 md:mt-24"
        photos={[
          { src: '/images/scoring.webp', alt: '굽기 직전 반죽 표면에 칼집을 내는 손', href: insta },
          { src: '/images/pastry.webp', alt: '나무 쟁반에 담긴 휘낭시에와 카눌레', href: insta },
          { src: '/images/coffee.webp', alt: '창가 자리의 카페라테와 크루아상', href: insta },
          { src: '/images/crumb.webp', alt: '반으로 자른 시골빵의 속살', href: insta },
          { src: '/images/window.webp', alt: '골목에서 본 빵집 창문과 진열대', href: insta },
          { src: '/images/giftbox.webp', alt: '끈으로 묶은 크라프트 선물 상자', href: insta },
        ]}
      />
    </section>
  )
}

속성

이름형식기본값설명
photos필수{ src: string; alt: string; caption?: string; href?: string }[]—사진. mosaic 은 여섯 장 단위로 가장 잘 맞고, 남는 장은 마지막 줄을 나눠 채운다
layout'mosaic' | 'row''mosaic'mosaic: 큰 칸·작은 칸 섞음 / row: 정사각 한 줄

원본 코드

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

components/bpublish/photo-gallery.tsx
/**
 * bpublish UI — 사진 모음. https://www.bpublish.com/designs/components/photo-gallery
 * 가는 틈으로 붙인 사진 격자. mosaic 은 큰 칸과 작은 칸이 섞이고(여섯 장이 한 묶음), row 는 같은 크기 정사각 한 줄.
 * 캡션을 주면 사진 왼쪽 아래에 검정 막을 깔고 적는다.
 */
export type GalleryPhoto = { src: string; alt: string; caption?: string; href?: string }

export type PhotoGalleryProps = {
  photos: GalleryPhoto[]
  /** mosaic: 큰 칸·작은 칸 섞음 / row: 정사각 3열(넓은 화면 6열) */
  layout?: 'mosaic' | 'row'
  className?: string
}

/*
 * mosaic 칸 크기. 넓은 화면 6열에서 [큰 칸, 작은 칸 둘, 큰 칸, 작은 칸 둘] 여섯 장이 두 줄을 꽉 채운다.
 * 묶음에서 남는 사진은 마지막 한 줄을 나눠 채운다.
 */
const TAIL: Record<number, string[]> = {
  1: ['col-span-2 md:col-span-6'],
  2: ['md:col-span-3', 'md:col-span-3'],
  3: ['md:col-span-2', 'md:col-span-2', 'col-span-2 md:col-span-2'],
  4: ['md:col-span-2', '', '', 'md:col-span-2'],
  5: ['md:col-span-2', '', '', '', 'col-span-2 md:col-span-1'],
}

function mosaicCell(i: number, n: number) {
  const full = n - (n % 6)
  if (i < full) return i % 6 === 0 || i % 6 === 3 ? 'col-span-2 row-span-2' : ''
  return TAIL[n - full][i - full]
}

export function PhotoGallery({ photos, layout = 'mosaic', className = '' }: PhotoGalleryProps) {
  const mosaic = layout === 'mosaic'
  return (
    <div className={`@container ${className}`}>
      <ul
        className={
          mosaic
            ? 'grid grid-flow-dense grid-cols-2 auto-rows-[calc((100cqw_-_3px)/2)] gap-[3px] md:grid-cols-6 md:auto-rows-[calc((100cqw_-_15px)/6)]'
            : 'grid grid-cols-3 gap-[3px] md:grid-cols-6'
        }
      >
        {photos.map((p, i) => {
          const inner = (
            <figure className={`relative h-full overflow-hidden bg-muted ${mosaic ? '' : 'aspect-square'}`}>
              <img src={p.src} alt={p.alt} loading="lazy" className="absolute inset-0 h-full w-full object-cover" />
              {p.caption ? (
                <figcaption className="absolute bottom-2 left-2 max-w-[calc(100%-1rem)] bg-black/40 px-2 py-1 text-[12px] leading-snug text-white md:bottom-3 md:left-3">
                  {p.caption}
                </figcaption>
              ) : null}
            </figure>
          )
          return (
            <li key={p.src + i} className={mosaic ? mosaicCell(i, photos.length) : ''}>
              {p.href ? (
                <a href={p.href} className="block h-full transition-opacity hover:opacity-85 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring">
                  {inner}
                </a>
              ) : (
                inner
              )}
            </li>
          )
        })}
      </ul>
    </div>
  )
}