Gallery
Image gallery component that displays image thumbnails in a grid and full size images in a modal.
React
Gallery renders a grid of thumbnails that open a modal of the full size
image when clicked. For more advanced control over the behavior, you can pass
isOpen
to put the Gallery into controlled mode to manually open and close
it. For an even more custom layout or behavior see useGallery
.
Images are specified as a list of Image
objects with at least a url
property.
interface Image { url: string; thumbnail?: string; title?: string;}
The title
and thumbnail
properties are optional, but a thumbnail
is
highly recommended so that the full size image doesn't need to be loaded just
to display the thumbnail grid.
Installation
The Gallery component is available as a separate package, @hover/gallery that depends on @hover/blueprint.
yarn add @hover/gallery
Theme
The theme for the Gallery component must also be added to your
DesignSystemProvider
.
Thumbnails
The thumbnail grid composes SimpleGrid
, so
simply pass SimpleGrid
props to control the layout of the thumbnails.
Hover
Set showHover
to false
to disable the thumbnail hover state;
Size
Set size
to control the size of the modal.
Fullscreen
An alternative version of the GalleryModal
component is available,
FullscreenGalleryModal
, which renders the modal as a fullscreen overlay and
supports scroll-based zoom on high resolution images.
Limit
Pass the limit
prop to collapse the thumbnail list to only display the
specified number of thumbnails. When passing limit
, the isExpanded
controlled prop is required to control the expanded state of the thumbnail list.
() => { const [isExpanded, { toggle }] = useBoolean(false); return ( <VStack bg="neutral.50" borderRadius="500" p="300" shadow="inset100" spacing="300" width="700" > <Gallery columns={2} images={[ { url: '/images/kitten--300-300.jpg', thumbnail: '/images/kitten--300-300_thumb.jpg', }, { url: '/images/kitten--400-400.jpg', thumbnail: '/images/kitten--400-400_thumb.jpg', }, { url: '/images/kitten--400-300.jpg', thumbnail: '/images/kitten--400-300_thumb.jpg', }, { url: '/images/kitten--500-150.jpg', thumbnail: '/images/kitten--500-150_thumb.jpg', }, { url: '/images/kitten--300-400.jpg', thumbnail: '/images/kitten--300-400_thumb.jpg', }, ]} isExpanded={isExpanded} limit={2} spacing="300" title="A Gallery Title" width="100%" /> <Button iconBefore={isExpanded ? iArrowUp : iArrowDown} onClick={toggle} shape="box" width="100%" > {isExpanded ? 'Collapse' : 'Expand'} </Button> </VStack> );};
useGalleryContext
For full control over any part of the Gallery interface, you can pass custom
children
that read the gallery state from useGalleryContext
.
Custom Renders
Set renderSlideContent
to render a custom component instead of an image. The
function takes the current image as parameter, whose type is defined as the
generic TImage
.