본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Gallery — 갤러리

원문 보기 위키 갱신

복합 구성을 갖춘 스타일 없고 접근 가능한 갤러리 컴포넌트예요.

출처: 문서

본문

뷰어 레이아웃, 썸네일, 툴바 동작을 완전히 제어하며 완전히 커스텀한 이미지 갤러리를 만들어 보세요.

기능 (Features)

  • 하위 컴포넌트를 갖춘 복합 컴포넌트 API: Root, Content, Item, Prev, Next, Header, Footer, Backdrop, Thumbnail, ThumbnailContent, ThumbnailItem
  • 동작 하위 컴포넌트: ZoomIn, ZoomOut, ZoomToggle, RotateLeft, RotateRight, FlipX, FlipY, Download, FullScreen
  • React 상태 기반 동작 디스패치를 통한 항목별 줌, 회전, 뒤집기, 다운로드
  • 활성 항목 추적이 있는 썸네일 캐러셀 탐색
  • 뷰포트를 채우는 레이아웃의 전체화면 토글

사용법 (Usage)

import { Gallery } from 'primereact/gallery';
<Gallery.Root>
    <Gallery.Backdrop />
    <Gallery.Prev></Gallery.Prev>
    <Gallery.Next></Gallery.Next>
    <Gallery.Header>
        <Gallery.RotateLeft></Gallery.RotateLeft>
        <Gallery.RotateRight></Gallery.RotateRight>
        <Gallery.ZoomIn></Gallery.ZoomIn>
        <Gallery.ZoomOut></Gallery.ZoomOut>
        <Gallery.FlipX></Gallery.FlipX>
        <Gallery.FlipY></Gallery.FlipY>
        <Gallery.Download></Gallery.Download>
        <Gallery.FullScreen></Gallery.FullScreen>
    </Gallery.Header>
    <Gallery.Content>
        <Gallery.Item></Gallery.Item>
    </Gallery.Content>
    <Gallery.Footer>
        <Gallery.Thumbnail>
            <Gallery.ThumbnailContent>
                <Gallery.ThumbnailItem></Gallery.ThumbnailItem>
            </Gallery.ThumbnailContent>
        </Gallery.Thumbnail>
    </Gallery.Footer>
</Gallery.Root>

동작 (Behavior)

다형성 렌더링 (Polymorphic Rendering)

어느 하위 컴포넌트에서든 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.

<Gallery.Root as="section">
    <Gallery.Content as="main"></Gallery.Content>
</Gallery.Root>

기본 요소: Root=div, Content=div, Item=div, Prev=button, Next=button, Header=div, Footer=div, Backdrop=div, action buttons=button.

렌더 함수 children (Render Function Children)

Item은 children으로 렌더 함수를 받아 변형 상태가 있는 항목 인스턴스에 접근할 수 있게 해줘요.

<Gallery.Item>{(instance) => <span>Scale: {instance.state.scale}</span>}</Gallery.Item>

패스 스루 (Pass Through)

<DocPTViewer name="gallery-pt" components={['GalleryRoot']} />

API

GalleryRoot

Attribute Value
data-fullscreen Present when in fullscreen mode
data-zoomed Present when active item is zoomed
data-rotated Present when active item is rotated
data-flipped Present when active item is flipped
Label Type Description
root GalleryRootPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.
item GalleryRootPassThroughType<HTMLAttributes> Used to pass attributes to the item's DOM element.
thumbnailContent GalleryRootPassThroughType<HTMLAttributes> Used to pass attributes to the thumbnail content's DOM element.
thumbnail GalleryRootPassThroughType<HTMLAttributes> Used to pass attributes to the thumbnail's DOM element.
thumbnailItem GalleryRootPassThroughType<HTMLAttributes> Used to pass attributes to the thumbnail item's DOM element.

GalleryBackdrop

Label Type Description
root GalleryBackdropPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryContent

Label Type Description
root GalleryContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryItem

Attribute Value
data-active Present when this is the active item
data-index The index of the item in the gallery

CSS 커스텀 속성 (CSS Custom Properties)

Item 요소는 변형 제어를 위해 style에 CSS 커스텀 속성을 설정해요.

CSS Variable Description
--position-x Horizontal pan offset in pixels
--position-y Vertical pan offset in pixels
--scale Current zoom scale factor
--rotation Current rotation in degrees
--flip-x Horizontal flip multiplier (1 or -1)
--flip-y Vertical flip multiplier (1 or -1)
Label Type Description
root GalleryItemPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryPrev

Label Type Description
root GalleryPrevPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryNext

Label Type Description
root GalleryNextPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryHeader

Label Type Description
root GalleryHeaderPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryFooter

Label Type Description
root GalleryFooterPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryZoomIn

Attribute Value
disabled Present when item is already zoomed
Label Type Description
root GalleryZoomInPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryZoomOut

Attribute Value
disabled Present when item is not zoomed
Label Type Description
root GalleryZoomOutPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryZoomToggle

Label Type Description
root GalleryZoomTogglePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryRotateLeft

Label Type Description
root GalleryRotateLeftPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryRotateRight

Label Type Description
root GalleryRotateRightPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryFlipX

Label Type Description
root GalleryFlipXPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryFlipY

Label Type Description
root GalleryFlipYPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryDownload

Label Type Description
root GalleryDownloadPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryFullScreen

Attribute Value
data-fullscreen Present when in fullscreen mode
Label Type Description
root GalleryFullScreenPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryThumbnail

Label Type Description
root GalleryThumbnailPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryThumbnailContent

Label Type Description
root GalleryThumbnailContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryThumbnailItem

Attribute Value
data-active Present when thumbnail is selected
Label Type Description
root GalleryThumbnailItemPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryToolbar

Label Type Description
root GalleryToolbarPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

GalleryToolbarItem

Label Type Description
root GalleryToolbarItemPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Gallery는 모든 탐색 및 동작 컨트롤에 의미론적 button 요소를 사용해요. 각 동작 버튼에는 설명적인 aria-label이 포함되어야 해요. 콘텐츠 영역에는 용도를 설명하는 aria-label이 있어야 해요.

<Gallery.Root>
    <Gallery.Prev aria-label="Previous image"></Gallery.Prev>
    <Gallery.Next aria-label="Next image"></Gallery.Next>
    <Gallery.Header>
        <Gallery.ZoomIn aria-label="Zoom in"></Gallery.ZoomIn>
        <Gallery.ZoomOut aria-label="Zoom out"></Gallery.ZoomOut>
        <Gallery.RotateLeft aria-label="Rotate left"></Gallery.RotateLeft>
        <Gallery.RotateRight aria-label="Rotate right"></Gallery.RotateRight>
        <Gallery.Download aria-label="Download image"></Gallery.Download>
        <Gallery.FullScreen aria-label="Toggle fullscreen"></Gallery.FullScreen>
    </Gallery.Header>
    <Gallery.Content aria-label="Image gallery"></Gallery.Content>
</Gallery.Root>

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus between action buttons, navigation, and thumbnails.
enter / space Activates the focused button or thumbnail.

더 알아보기 (Learn more)