Introducing Motion-Primitives Pro - Advanced components and templates to help you build a website that stands out.

Carousel

A flexible and easy-to-use carousel with customizable navigation and indicators.

Examples

1
2
3
4

We use basis-1/3 to set the width of each carousel item to one-third of the container.

1
2
3
4
5
6
7

We use -ml-4 on CarouselContent and pl-4 on CarouselItem to add spacing between carousel items.

1
2
3
4
5
6
7

We can use index and onIndexChange to create custom indicators for the carousel.

1
2
3
4

Installation

npx shadcn add "https://motion-primitives.com/c/carousel.json"

Component API

PropTypeDefaultDescription
childrenReactNodeThe content elements of the carousel.
classNamestringOptional CSS class for styling the carousel container.
initialIndexnumber0Initial index of the active carousel item.
indexnumberControlled index of the active carousel item.
onIndexChange(newIndex: number) => voidCallback function when the active index changes.
disableDragbooleanfalseWhether dragging is disabled.

CarouselNavigation

PropTypeDefaultDescription
classNamestringOptional CSS class for styling the navigation container.
classNameButtonstringOptional CSS class for styling the navigation buttons.
alwaysShowbooleanfalseWhether navigation buttons are always visible.

CarouselIndicator

PropTypeDefaultDescription
classNamestringOptional CSS class for styling the indicator container.
classNameButtonstringOptional CSS class for styling the indicator buttons.

CarouselContent

PropTypeDefaultDescription
childrenReactNodeThe sliding elements or items of the carousel.
classNamestringOptional CSS class for additional styling.
transitionTransitionOptional motion transition for animating slides.

CarouselItem

PropTypeDefaultDescription
childrenReactNodeThe individual content item within the carousel.
classNamestringOptional CSS class for styling the carousel item.

useCarousel

ReturnTypeDescription
indexnumberThe current index of the active carousel item.
setIndex(newIndex: number) => voidFunction to update the index to show a different carousel item.
itemsCountnumberTotal number of items in the carousel.
setItemsCount(newItemsCount: number) => voidFunction to set the number of items in the carousel.

This hook provides context values related to the carousel's state, allowing components within the carousel to adjust based on the active item and total items.