Gallery
Description
The Gallery is a robust, customizable, and interactive component designed to display a group of images or videos in a grid format. This component is composed of several smaller subcomponents, each providing specific functionality to make the Gallery a comprehensive and interactive image browsing experience.
)
)
)
Importing
_10import {_10 Gallery,_10 GalleryGroup,_10 GalleryGroupsContainer,_10 GalleryModal,_10 GalleryModalContent,_10 GalleryLabel_10} from '@ef-global/backpack/Gallery';
Subcomponents
Gallery
_10<Gallery>_10 <GalleryGroupsContainer>_10 {/* GalleryGroupsContainer subcomponents */}_10 </GalleryGroupsContainer>_10 <GalleryModal>{/* GalleryModal subcomponents */}</GalleryModal>_10 <GalleryLabel>{/* GalleryLabel text */}</GalleryLabel>_10</Gallery>
This is the main Gallery component. It acts as a container for the following components:
- GalleryGroupsContainer
- GalleryModal
- GalleryLabel
Props
| Name | Type | Default | Description |
| id | string | - | A unique identifier for the Gallery |
| className | string | - | Custom classnames to add to the Gallery |
| children | ReactElement | - | Child components inside the Gallery component. It could be GalleryGroupsContainer, GalleryModal, and GalleryLabel |
GalleryGroupsContainer
_10 <Gallery>_10 <GalleryGroupsContainer>_10 {/* GalleryGroup components go here */}_10 </GalleryGroupsContainer>_10 {/* Other optional components */}_10 </Gallery>
The GalleryGroupsContainer is a container for GalleryGroup components.
Props
| Prop | Type | Default | Description |
galleryId | string | - | An identifier for the gallery. |
interactive | boolean | false | A flag indicating if the gallery is interactive. |
className | string | - | The class name to apply to the gallery. |
children | ReactElement<typeof GalleryGroup> or Array of ReactElement<typeof GalleryGroup> | - | The children of the gallery. |
GalleryGroup
_10 <Gallery>_10 <GalleryGroupsContainer>_10 <GalleryGroup {...args}>_10 {/* GalleryGroupAssets go here */}_10 </GalleryGroup>_10 </GalleryGroupsContainer>_10 {/* Other optional components */}_10 </Gallery>
The GalleryGroup component organizes the child elements into a specific layout pattern. Each GalleryGroup could contain multiple Image and Video components. The layout for each GalleryGroup could be different based on the props provided.
The layout prop can take the following types:
- For mobile and tablet devices:
'natural'. - For desktop devices:
'16/9''16/9 - 16/9''1/1 - 1/1''9/16 - 4/3''3/4 - 4/3 - 16/9''4/3 - 4/3 - 4/3''1/1 - 1/1 - 1/1'
Props
| Prop | Type | Default | Description |
children | node | - | The content of the GalleryGroup: Image or Video components. |
layout | string | 'natural' | Determines the layout pattern of the gallery. Can take different formats for mobile and desktop devices. |
GalleryModal
_10 <Gallery>_10 {/* Other components */}_10 <GalleryModal>_10 <GalleryModalContent />_10 </GalleryModal>_10 </Gallery>
The GalleryModal is a component that displays a larger version of an image or video when clicked on. The GalleryModalContent component goes within this and displays the larger content.
Props
| Prop | Type | Default | Description |
children | ReactElement<typeof GalleryModalContent> | - | The content of the GalleryModal, typically a GalleryModalContent component. |
className | string | - | Optional. Additional CSS class to apply to the component. |
...rest | Omit<ModalProps, 'children'> | - | Other props are passed down to the underlying Modal component. |
GalleryLabel
_10 <Gallery>_10 {/* Other components */}_10 <GalleryLabel variant={'link'}>_10 See all_10 </GalleryLabel>_10 </Gallery>
GalleryLabel is a component that functions as a trigger for opening a modal gallery. It comes in two variants: 'link' and 'tag'. The 'link' variant is a simple text link, while the 'tag' variant is a labeled tag.
The label shows the count of images in the associated gallery. When clicked, the label triggers the opening of the associated gallery at the first image.
Props
| Prop | Type | Default | Description |
| variant | GalleryLabelVariant | 'link' | The variant of the gallery label. It can be either 'link' or 'tag'. |
| className | string | - | Optional. An additional CSS class to apply to the component. |
| children | ReactNode | - | Optional. Any child nodes will be rendered inside the gallery label. This is typically text content. |
Usage
Non-interactive gallery
This is a simple example of how to use the GalleryGroup component with a set layout and Images as children. Since no GalleryModal is passed, the gallery will be rendered as a non-interactive gallery.
)
)
)
_18<Gallery>_18 <GalleryGroupsContainer>_18 <GalleryGroup layout='1/1 - 1/1 - 1/1'>_18 <Image_18 alt='Image alternate'_18 src='https://a.storyblok.com/f/185562/1396x2368/5b940958e6/pisa.jpg'_18 />_18 <Image_18 alt='Image alternate'_18 src='https://a.storyblok.com/f/185562/3840x2124/fbd9220094/backpacker.jpg'_18 />_18 <Image_18 alt='Image alternate'_18 src='https://a.storyblok.com/f/185562/3840x2124/d14f1944d6/mountains.jpg'_18 />_18 </GalleryGroup>_18 </GalleryGroupsContainer>_18</Gallery>
Gallery with Modal and Tag Label
This example demonstrates how to create a Gallery with multiple GalleryGroups, a GalleryModal, and a Link variant GalleryLabel. In this case, GalleryLabel does not have any children, so it will render just the image count.
_40<Gallery>_40 <GalleryGroupsContainer>_40 <GalleryGroup layout={'3/4 - 4/3 - 16/9'}>_40 <Image_40 alt='Image alternate'_40 src='https://a.storyblok.com/f/185562/1396x2368/5b940958e6/pisa.jpg'_40 data-slot={'Image'}_40 />_40 <Image_40 alt='Image alternate'_40 src='https://a.storyblok.com/f/185562/3840x2124/fbd9220094/backpacker.jpg'_40 data-slot={'Image'}_40 />_40 <Image_40 alt='Image alternate'_40 src='https://a.storyblok.com/f/185562/3840x2124/d14f1944d6/mountains.jpg'_40 data-slot={'Image'}_40 />_40 </GalleryGroup>_40 <GalleryGroup layout={'16/9 - 16/9'}>_40 <Video_40 url={'https://vimeo.com/357511081'}_40 light={true}_40 playing={true}_40 data-slot={'Video'}_40 />_40 <Image_40 alt='Image alternate'_40 src='https://a.storyblok.com/f/185562/2368x2376/00ee361383/photography.jpg'_40 data-slot={'Image'}_40 />_40 </GalleryGroup>_40 </GalleryGroupsContainer>_40_40 <GalleryModal>_40 <GalleryModalContent />_40 </GalleryModal>_40_40 <GalleryLabel variant={'tag'} />_40</Gallery>
Gallery with Modal and Link Label
_10<Gallery>_10 {/* Same as the example above */}_10 <GalleryLabel variant={'link'}>See all</GalleryLabel>>_10</Gallery>