Carousel

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

Examples

Weekly planning12 tasks
Launch checklist8 tasks
Design review5 tasks
Quarterly report1 task

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

Mon123 meetings
Tue131 meeting
Wed144 meetings
Thu152 meetings
Fri161 meeting
Sat17Free
Sun18Free

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

Mon123 meetings
Tue131 meeting
Wed144 meetings
Thu152 meetings
Fri161 meeting
Sat17Free
Sun18Free

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

Step 1 of 4Connect your calendarTwo minutes
Step 2 of 4Invite your teamUp to 10 members on the free plan
Step 3 of 4Create a first boardStart from a template
Step 4 of 4Share the weekly viewRead only for guests

Installation

npx shadcn@latest add https://ui.ndekocode.dev/r/motion-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.