<content-carousel>
Slides that move sideways, built on Swiper, with labelled controls and a pause button when they move on their own.
import '@content-blocks/js/components/content-carousel';Examples
A photo carousel
Three photos of the realms, one at a time, with arrows and dots. Options are passed straight to Swiper.
<content-carousel label="The realms in peril" swiper-options='{"slidesPerView": 1, "loop": true, "pagination": {"clickable": true}}'>
<content-image
alt="A castle rising out of a sea of fog"
src="https://images.unsplash.com/photo-1515688272562-004db9d10783?w=900&h=600&fit=crop&auto=format&q=75"
aspect-ratio="3/2"
></content-image>
<content-image
alt="A pack of wolves running through a snowy forest"
src="https://images.unsplash.com/photo-1552249007-6759fe2742b6?w=900&h=600&fit=crop&auto=format&q=75"
aspect-ratio="3/2"
></content-image>
<content-image
alt="A lone figure on a rock at dusk"
src="https://images.unsplash.com/photo-1577814167854-c251f26c6cd9?w=900&h=600&fit=crop&auto=format&q=75"
aspect-ratio="3/2"
></content-image>
</content-carousel>// $ npm install @content-blocks/js
import '@content-blocks/js/components/content-carousel';
import '@content-blocks/js/components/content-image';<script type="module"
src="https://cdn.jsdelivr.net/npm/@content-blocks/js/dist/content-blocks/content-blocks.esm.js"></script>Anatomy
Content goes into the component's slots, chosen with the slot attribute on each child.
flowchart LR root["#lt;content-carousel#gt;"]:::component root --> s0["<b>no slot (default)</b><br/>Default slot, same as content slot."] root --> s1["<b>slot=#quot;content#quot;</b><br/>This slot will usually serve a content hero block or image."] classDef component fill:#141413,color:#faf9f5,stroke:#141413
| Slot | What goes in it |
|---|---|
(default) | Default slot, same as content slot. |
slot="content" | This slot will usually serve a content hero block or image. |
Properties
Set them as attributes. Those marked responsive take a value per breakpoint, separated by pipes and named or in order: 1|tablet=2 or 1|2. Seeresponsive values.
| Attribute | Type | Default | Description |
|---|---|---|---|
classesresponsive | String | – | Classes to add to the component. Use pipes for different classes per breakpoint, by name or in order: classes="stacked|laptop=side-by-side". |
init-method | Select | 'load' | Not documented yet |
label | String | 'Carousel' | The accessible name of the carousel, read by screen readers when they reach it. |
next-label | String | 'Next slide' | The accessible name of the next slide button. |
paddingresponsive | String | – | Padding around the component, written as CSS padding. Use pipes for different padding per breakpoint, by name or in order: padding="1rem|tablet=2rem 4rem" or padding="1rem|2rem 4rem|3rem 5rem 4rem". |
pause-label | String | 'Pause the slides' | The accessible name of the button that stops slides that move on their own. |
play-label | String | 'Play the slides' | The accessible name of the button that starts the slides moving again. |
prev-label | String | 'Previous slide' | The accessible name of the previous slide button. |
swiper-options | JSON | '{"slidesPerView": 1, "slidesPerGroup": 1, "autoplay": true, "loop": false}' | Not documented yet |
Events and methods
sequenceDiagram participant Page participant C as content-carousel Page->>C: focusin event Page->>C: setSwiperOptions event
