- Docs
- Components
- Carousel
Carousel
A carousel with motion and swipe built using Embla.
About
The carousel component is built using the Embla Carousel library.
Installation
Anatomy
Examples
Sizes
To set the size of the items, you can use the basis utility class on the <Carousel.Item>.
Spacing
To set the spacing between the items, we use a pl-[VALUE] utility on the <Carousel.Item> and a negative -ml-[VALUE] on the <Carousel.Content>.
Why: I tried to use the gap property or a grid layout on the <Carousel.Content> 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.
Orientation
Use the orientation prop to set the orientation of the carousel.
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 prop to get an instance of the carousel API.
Events
You can listen to events using the api instance from setApi.
See the Embla Carousel docs for more information on using events.
Plugins
You can use the plugins prop to add plugins to the carousel.
See the Embla Carousel docs for more information on using plugins.
API Reference
Carousel.Root
| Prop | Type | Default |
|---|---|---|
orientation | enum | "horizontal" |
opts | CarouselOptions | |
plugins | CarouselPlugin[] | |
setApi | function | |
className | string |
Carousel.Content
| Prop | Type | Default |
|---|---|---|
children | ReactNode | |
className | string |
Carousel.Item
| Prop | Type | Default |
|---|---|---|
children | ReactNode | |
className | string |
Carousel.Previous
| Prop | Type | Default |
|---|---|---|
variant | enum | "outline" |
size | enum | "icon" |
className | string |
Carousel.Next
| Prop | Type | Default |
|---|---|---|
variant | enum | "outline" |
size | enum | "icon" |
className | string |