The carousel component is built using the Embla Carousel library.
Installation
Usage
Examples
Sizes
To set the size of the items, you can use the basis utility class on the <CarouselItem />.
1
2
3
4
5
Spacing
To set the spacing between the items, we use a pl-[VALUE] utility on the <CarouselItem /> and a negative -ml-[VALUE] on the <CarouselContent />.
Why: I tried to use the gap property or a grid layout on the <CarouselContent /> but it required a lot of math and mental effort to get the
spacing right. I found pl-[VALUE] and -ml-[VALUE] utilities much easier to
use.
You can always adjust this in your own project if you need to.
1
2
3
4
5
Orientation
Use the orientation prop to set the orientation of the carousel.
1
2
3
4
5
Dots
Enhance carousel navigation with the CarouselDots component, which presents interactive indicators for each slide.
Usage
Embed within the Carousel, connecting automatically to its context for slide information and active index.
dotsPosition: Dots placement - "top", "bottom", "left", or "right".
size: Size of Dot - "default", "sm", "md", "lg".
gap: Space between dots - "default", "sm", "md", "lg".
1
2
3
4
5
Options
You can pass options to the carousel using the opts prop. See the Embla Carousel docs for more information.
API
Use a state and the setApi props to get an instance of the carousel API.
1
2
3
4
5
Slide 0 of0
Events
You can listen to events using the api instance from setApi.