The Bento Inline Gallery component uses a Bento Carousel component to display slides, with optional pagination dots and thumbnails. Both components must be properly installed for the environment (Web Component vs Preact).
You must include each Bento component's required CSS library to guarantee proper loading and before adding custom styles. Or use the light-weight pre-upgrade styles available inline. See Layout and style.
The examples below demonstrate use of the <bento-inline-gallery>
web component.
[example preview="top-frame" playground="false"]
Install via npm:
npm install @ampproject/bento-inline-gallery
import '@ampproject/bento-inline-gallery';
[/example]
The example below contains a bento-inline-gallery
consisting of three slides with thumbnails and a pagination indicator.
[example preview="top-frame" playground="false"]
<head>
<script async src="https://cdn.ampproject.org/bento.js"></script>
<script async src="https://cdn.ampproject.org/v0/bento-inline-gallery-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/amp-inline-gallery-1.0.css">
</head>
<body>
<bento-inline-gallery id="inline-gallery">
<bento-inline-gallery-thumbnails aspect-ratio="1.5" loop></bento-inline-gallery-thumbnails>
<bento-base-carousel snap-align="center" visible-count="1.2" loop>
<img src="server.com/static/inline-examples/images/image1.jpg">
<img src="server.com/static/inline-examples/images/image2.jpg">
<img src="server.com/static/inline-examples/images/image3.jpg">
</bento-base-carousel>
<bento-inline-gallery-pagination inset></bento-inline-gallery-pagination>
</bento-inline-gallery>
</body>
[/example]
Each Bento component has a small CSS library you must include to guarantee proper loading without content shifts. Because of order-based specificity, you must manually ensure that stylesheets are included before any custom styles.
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/amp-inline-gallery-1.0.css">
Alternatively, you may also make the light-weight pre-upgrade styles available inline:
<style data-bento-boilerplate>
amp-inline-gallery,
amp-inline-gallery-pagination,
amp-inline-gallery-thumbnails {
display: block;
}
amp-inline-gallery {
contain: layout;
}
amp-inline-gallery-pagination,
amp-inline-gallery-thumbnails {
overflow: hidden;
position: relative;
}
</style>
Default: false
Boolean attribute indicating whether to display the pagination indicator as inset (overlaying the carousel itself)
Optional
Number: ratio of width to height that slides should be displayed in.
Default: false
Boolean attribute indicating whether thumbnails should loop.
You may use the bento-inline-gallery
, bento-inline-gallery-pagination
, bento-inline-gallery-thumbnails
, and bento-base-carousel
element selectors to style the pagination indicator, thumbnails, and carousel freely.
The examples below demonstrates use of the <BentoInlineGallery>
as a functional component usable with the Preact or React libraries.
[example preview="top-frame" playground="false"]
Install via npm:
npm install @ampproject/bento-inline-gallery
import React from 'react';
import { BentoInlineGallery } from '@ampproject/bento-inline-gallery/react';
import '@ampproject/bento-inline-gallery/styles.css';
function App() {
return (
<BentoInlineGallery id="inline-gallery">
<BentoInlineGalleryThumbnails aspect-ratio="1.5" loop></BentoInlineGalleryThumbnails>
<BentoBaseCarousel snap-align="center" visible-count="1.2" loop>
<img src="server.com/static/inline-examples/images/image1.jpg">
<img src="server.com/static/inline-examples/images/image2.jpg">
<img src="server.com/static/inline-examples/images/image3.jpg">
</BentoBaseCarousel>
<BentoInlineGallery-pagination inset></BentoInlineGallery-pagination>
</BentoInlineGallery>
}
[/example]
Container type
The BentoInlineGallery
component has a defined layout size type. To ensure the component renders correctly, be sure to apply a size to the component and its immediate children via a desired CSS layout (such as one defined with width
). These can be applied inline:
<BentoInlineGallery style={{width: '300px'}}>
...
</BentoInlineGallery>
Or via className
:
<BentoInlineGallery className='custom-styles'>
...
</BentoInlineGallery>
.custom-styles {
background-color: red;
}
In addition to the common props, BentoInlineGalleryPagination supports the props below:
Default: false
Boolean attribute indicating whether to display the pagination indicator as inset (overlaying the carousel itself)
In addition to the common props, BentoInlineGalleryThumbnails supports the props below:
Optional
Number: ratio of width to height that slides should be displayed in.
Default: false
Boolean attribute indicating whether thumbnails should loop.