Carousel
DraftA carousel allows users to browse through a series of content items one at a time with navigation controls and optional autoplay. Requires Carousel Item components as children to define individual slides.
Preview
Code
Install
npm install @fbin-web/neighborhood-core
Import
import { NbhdCarousel } from '@fbin-web/neighborhood-core';
Usage
<nbhd-carousel
slides-per-view="2"
space-between="16">
<nbhd-carousel-item>
<nbhd-flex surface="secondary">
<nbhd-text
tag="h2"
variant="title"
>Slide 1</nbhd-text
>
<nbhd-text tag="p">This is the first slide.</nbhd-text>
<nbhd-link
href="go-to-this-link-1"
aria-label="Learn more about Slide 1"
>Learn More</nbhd-link
>
</nbhd-flex>
</nbhd-carousel-item>
<nbhd-carousel-item>
<nbhd-flex surface="secondary">
<nbhd-text
tag="h2"
variant="title"
>Slide 2</nbhd-text
>
<nbhd-text tag="p">This is the second slide.</nbhd-text>
<nbhd-link
href="go-to-this-link-2"
aria-label="Learn more about Slide 2"
>Learn More</nbhd-link
>
</nbhd-flex>
</nbhd-carousel-item>
<nbhd-carousel-item>
<nbhd-flex surface="secondary">
<nbhd-text
tag="h2"
variant="title"
>Slide 3</nbhd-text
>
<nbhd-text tag="p">This is the third slide.</nbhd-text>
<nbhd-link
href="go-to-this-link-3"
aria-label="Learn more about Slide 3"
>Learn More</nbhd-link
>
</nbhd-flex>
</nbhd-carousel-item>
<nbhd-carousel-item>
<nbhd-flex surface="secondary">
<nbhd-text
tag="h2"
variant="title"
>Slide 4</nbhd-text
>
<nbhd-text tag="p">This is the fourth slide.</nbhd-text>
<nbhd-link
href="go-to-this-link-4"
aria-label="Learn more about Slide 4"
>Learn More</nbhd-link
>
</nbhd-flex>
</nbhd-carousel-item>
<nbhd-carousel-item>
<nbhd-flex surface="secondary">
<nbhd-text
tag="h2"
variant="title"
>Slide 5</nbhd-text
>
<nbhd-text tag="p">This is the fifth slide.</nbhd-text>
<nbhd-link
href="go-to-this-link-5"
aria-label="Learn more about Slide 5"
>Learn More</nbhd-link
>
</nbhd-flex>
</nbhd-carousel-item>
<nbhd-carousel-item>
<nbhd-flex surface="secondary">
<nbhd-text
tag="h2"
variant="title"
>Slide 6</nbhd-text
>
<nbhd-text tag="p">This is the sixth slide.</nbhd-text>
<nbhd-link
href="go-to-this-link-6"
aria-label="Learn more about Slide 6"
>Learn More</nbhd-link
>
</nbhd-flex>
</nbhd-carousel-item>
</nbhd-carousel>
Install
npm install @fbin-web/neighborhood-react
Import
import { NbhdCarousel } from '@fbin-web/neighborhood-react';
Usage
import {
NbhdCarousel,
NbhdText,
NbhdLink,
NbhdCarouselItem,
NbhdFlex,
} from '@fbin-web/neighborhood-react';
const App = () => (
<>
<NbhdCarousel
slidesPerView={2}
spaceBetween={16}>
<NbhdCarouselItem>
<NbhdFlex surface="secondary">
<NbhdText
tag="h2"
variant="title">
Slide 1
</NbhdText>
<NbhdText tag="p">This is the first slide.</NbhdText>
<NbhdLink
href="go-to-this-link-1"
ariaLabel="Learn more about Slide 1">
Learn More
</NbhdLink>
</NbhdFlex>
</NbhdCarouselItem>
<NbhdCarouselItem>
<NbhdFlex surface="secondary">
<NbhdText
tag="h2"
variant="title">
Slide 2
</NbhdText>
<NbhdText tag="p">This is the second slide.</NbhdText>
<NbhdLink
href="go-to-this-link-2"
aria-label="Learn more about Slide 2">
Learn More
</NbhdLink>
</NbhdFlex>
</NbhdCarouselItem>
<NbhdCarouselItem>
<NbhdFlex surface="secondary">
<NbhdText
tag="h2"
variant="title">
Slide 3
</NbhdText>
<NbhdText tag="p">This is the third slide.</NbhdText>
<nbhd-link
href="go-to-this-link-3"
ariaLabel="Learn more about Slide 3">
Learn More
</nbhd-link>
</NbhdFlex>
</NbhdCarouselItem>
<NbhdCarouselItem>
<NbhdFlex surface="secondary">
<NbhdText
tag="h2"
variant="title">
Slide 4
</NbhdText>
<NbhdText tag="p">This is the fourth slide.</NbhdText>
<NbhdLink
href="go-to-this-link-4"
ariaLabel="Learn more about Slide 4">
Learn More
</NbhdLink>
</NbhdFlex>
</NbhdCarouselItem>
<NbhdCarouselItem>
<NbhdFlex surface="secondary">
<NbhdText
tag="h2"
variant="title">
Slide 5
</NbhdText>
<NbhdText tag="p">This is the fifth slide.</NbhdText>
<NbhdLink
href="go-to-this-link-5"
ariaLabel="Learn more about Slide 5">
Learn More
</NbhdLink>
</NbhdFlex>
</NbhdCarouselItem>
<NbhdCarouselItem>
<NbhdFlex surface="secondary">
<NbhdText
tag="h2"
variant="title">
Slide 6
</NbhdText>
<NbhdText tag="p">This is the sixth slide.</NbhdText>
<NbhdLink
href="go-to-this-link-6"
ariaLabel="Learn more about Slide 6">
Learn More
</NbhdLink>
</NbhdFlex>
</NbhdCarouselItem>
</NbhdCarousel>
</>
);
Usage
- Without
loop, the previous and next buttons are disabled at the first and last slide. - When every slide fits in view, the navigation, pagination and play/pause button are hidden.
- With
autoplayset, a play/pause button shows next to the pagination. Rotation pauses while the pointer is over the slides, stops when keyboard focus enters the carousel, and starts paused for visitors who prefer reduced motion.play()andpause()control it from script.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
variant | variant | cardproduct-cardminitronjumbotronhumongotroncustom | custom | Carousel content variant. |
slidesPerView | slides-per-view | number | 1 | Number of slides shown at once when using slide transition. |
spaceBetween | space-between | number | 16 | Space between slides in pixels. |
hideNavigation | hide-navigation | boolean | false | Hide previous/next navigation controls when set to true. |
hidePagination | hide-pagination | boolean | false | Hide pagination bullets when set to true. With autoplay set, the play/pause button stays visible. |
loop | loop | boolean | false | Enable continuous loop mode. Without it, the previous/next buttons are disabled at the first/last slide. |
fade | fade | boolean | false | Use fade transition instead of slide transition. |
speed | speed | 500100020003000 | 1000 | Transition duration in milliseconds. |
autoplay | autoplay | 020003000400050006000 | 0 | Autoplay delay in milliseconds; 0 disables autoplay. When set, a play/pause button shows next to the pagination. |
paginationVariant | pagination-variant | circleline | circle | Pagination style variant. |
navigationVariant | navigation-variant | primarysecondaryghost | primary | Navigation button style variant. |
navigationPosition | navigation-position | sidebottom | side | Navigation control placement. |
fullwidth | fullwidth | boolean | false | Enable full-width carousel presentation. |
keyboard | keyboard | boolean | true | Enable keyboard navigation for carousel controls. |
breakpoints | breakpoints | string | — | JSON string map of viewport widths to slidesPerView values. |
surface | surface | noneprimarysecondaryinverseinverse-secondary | primary | Surface theme for the carousel section. |
marginTop | margin-top | nonesmallmediumlarge | none | Adjust margin above the component. |
marginBottom | margin-bottom | nonesmallmediumlarge | none | Adjust margin below the component. |
paddingTop | padding-top | defaultnonesmallmediumlarge | default | Adjust padding above the component. |
paddingBottom | padding-bottom | defaultnonesmallmediumlarge | default | Adjust padding below the component. |
previousLabel | previous-label | string | Previous slide | Accessible name of the previous-slide button. |
nextLabel | next-label | string | Next slide | Accessible name of the next-slide button. |
paginationLabel | pagination-label | string | Choose slide | Accessible name of the group of pagination buttons. |
slideButtonLabel | slide-button-label | string | Go to slide {index} | Accessible name of each pagination button; `{index}` is replaced with the slide number. |
playLabel | play-label | string | Start slide rotation | Accessible name of the autoplay toggle while rotation is paused. |
pauseLabel | pause-label | string | Pause slide rotation | Accessible name of the autoplay toggle while slides are rotating. |
No properties match.
Events
| Name | Description | Event Detail |
|---|---|---|
nbhd-slide-change | Fired when the carousel changes to a new slide. | { activeIndex: number, previousIndex: number } |
nbhd-autoplay-change | Fired when automatic slide rotation is started or stopped by the viewer - through the play/pause toggle, play()/pause(), or keyboard focus entering the carousel. | { running: boolean, reason: 'user' | 'focus' } |
CSS Parts
| Name | Description |
|---|---|
base | The component's base section wrapper. |
container | The container element wrapping all carousel content. |
carousel | The Swiper container element. |
wrapper | The slides wrapper container. |
navigation | The navigation controls container. |
navigation-prev | The previous slide navigation button. |
navigation-next | The next slide navigation button. |
carousel-navigation-icon | The navigation button SVG icons. |
pagination | The pagination controls container. |
pagination-row | The row holding the pagination and the autoplay toggle. |
autoplay-control | The autoplay play/pause toggle button. Rendered when autoplay is set. |
autoplay-control-icon | The autoplay toggle's play/pause SVG icon. |
carousel-controls | The container for carousel navigation, pagination, and autoplay controls. |
No css parts match.
nbhd-carousel::part(base) {
/* your styles */
}
CSS Properties
Set these on nbhd-carousel or an ancestor to override the defaults. Token is the design token a default comes from and Value is what it resolves to in core Neighborhood; brands may override them. Properties that adapt to surface follow the light or inverse surface they sit on until you set them.
Carousel
| Property | Token | Value | Description | Copy |
|---|---|---|---|---|
--nbhd-carousel-controls-size | --nbhd-size-control-lg | 40px | — | |
--nbhd-carousel-navigation-blockSize | — | auto | — | |
--nbhd-carousel-navigation-button-insetBlockStart | — | 50% | — | |
--nbhd-carousel-navigation-button-insetInlineEnd | — | auto | — | |
--nbhd-carousel-navigation-button-insetInlineStart | — | auto | — | |
--nbhd-carousel-navigation-button-position | — | absolute | — | |
--nbhd-carousel-navigation-button-transform | — | translateY(-50%) | — | |
--nbhd-carousel-navigation-button-zIndex | --nbhd-z-1 | 1 | — | |
--nbhd-carousel-navigation-display | — | block | — | |
--nbhd-carousel-navigation-ghost-icon-maxBlockSize | --nbhd-size-icon-sm | 16px | — | |
--nbhd-carousel-navigation-icon-inlineSize | — | 100% | — | |
--nbhd-carousel-navigation-icon-maxBlockSize | --nbhd-size-icon-xs | 10px | — | |
--nbhd-carousel-navigation-icon-transform | — | none | — | |
--nbhd-carousel-navigation-inlineSize | — | 100% | — | |
--nbhd-carousel-navigation-insetBlockEnd | — | auto | — | |
--nbhd-carousel-navigation-insetBlockStart | — | auto | — | |
--nbhd-carousel-navigation-insetInlineStart | — | auto | — | |
--nbhd-carousel-navigation-marginBlock | — | 0 | — | |
--nbhd-carousel-navigation-marginInline | — | 0 | — | |
--nbhd-carousel-navigation-maxInlineSize | — | none | — | |
--nbhd-carousel-navigation-position | — | static | — | |
--nbhd-carousel-navigation-transform | — | none | — | |
--nbhd-carousel-pagination-alignItems | — | center | — | |
--nbhd-carousel-pagination-blockSize | --nbhd-carousel-controls-size | 40px | — | |
--nbhd-carousel-pagination-display | — | flex | — | |
--nbhd-carousel-pagination-insetBlockEnd | — | auto | — | |
--nbhd-carousel-pagination-insetInlineStart | — | 50% | — | |
--nbhd-carousel-pagination-item-active-background-opacity | — | 1 | — | |
--nbhd-carousel-pagination-item-background-opacity | — | 0.3 | — | |
--nbhd-carousel-pagination-item-blockSize | --nbhd-size-dot | 8px | — | |
--nbhd-carousel-pagination-item-border | --nbhd-border-width-none | 0 | — | |
--nbhd-carousel-pagination-item-borderRadius | --nbhd-border-radius-full | 9999px | — | |
--nbhd-carousel-pagination-item-cursor | — | pointer | — | |
--nbhd-carousel-pagination-item-hitArea-size | --nbhd-size-target-min | 24px | — | |
--nbhd-carousel-pagination-item-hover-background-opacity | — | 0.75 | — | |
--nbhd-carousel-pagination-item-inlineSize | --nbhd-size-dot | 8px | — | |
--nbhd-carousel-pagination-item-line-blockSize | — | 3px | — | |
--nbhd-carousel-pagination-item-line-borderRadius | --nbhd-border-radius-none | 0 | — | |
--nbhd-carousel-pagination-item-line-inlineSize | — | 50px | — | |
--nbhd-carousel-pagination-item-line-marginInline | --nbhd-space-05 | 2px | — | |
--nbhd-carousel-pagination-item-marginInline | --nbhd-space-2 | 8px | 8px dots at a 24px pitch, so each dot's 24px hit area doesn't overlap its neighbors (WCAG 2.5.8). | |
--nbhd-carousel-pagination-item-paddingBlock | --nbhd-space-0 | 0px | — | |
--nbhd-carousel-pagination-item-paddingInline | --nbhd-space-0 | 0px | — | |
--nbhd-carousel-pagination-item-position | — | relative | — | |
--nbhd-carousel-pagination-item-transitionDuration | --nbhd-motion-duration-normal | 0.2s | — | |
--nbhd-carousel-pagination-item-transitionProperty | — | background-color | — | |
--nbhd-carousel-pagination-item-transitionTimingFunction | --nbhd-motion-easing-inOut | ease-in-out | — | |
--nbhd-carousel-pagination-justifyContent | — | center | — | |
--nbhd-carousel-pagination-maxInlineSize | — | none | — | |
--nbhd-carousel-pagination-position | — | relative | — | |
--nbhd-carousel-pagination-textAlign | — | center | — | |
--nbhd-carousel-pagination-transform | — | translateX(-50%) | — | |
--nbhd-carousel-pagination-zIndex | --nbhd-z-1 | 1 | — | |
--nbhd-carousel-shell-boxShadow | --nbhd-shadow-none | none | — | |
--nbhd-carousel-shell-transitionDuration | --nbhd-motion-duration-normal | 0.2s | — | |
--nbhd-carousel-shell-transitionProperty | — | box-shadow | — | |
--nbhd-carousel-shell-transitionTimingFunction | --nbhd-motion-easing-inOut | ease-in-out | — |
No carousel match.
Minitron
| Property | Token | Value | Copy |
|---|---|---|---|
--nbhd-minitron-reverse-shadow | --nbhd-shadow-lg-reverse | 20px 10px 20px rgb(from #000000 r g b / 0.15) |
|
--nbhd-minitron-shadow | --nbhd-shadow-lg | -20px 10px 20px rgb(from #000000 r g b / 0.15) |
Dependencies
Child components <nbhd-carousel> renders internally. Import them too when you tree-shake.