āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/ibelick/motion-primitives/carousel/page ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
export const metadata = { title: 'Carousel - Motion-Primitives', description: 'A flexible and easy-to-use carousel with customizable navigation and indicators. Built for React, Next.js, and Tailwind CSS.', };
import { CarouselBasic } from './carousel-basic'; import { CarouselCustomSizes } from './carousel-custom-sizes'; import { CarouselSpacing } from './carousel-spacing'; import { CarouselCustomIndicator } from './carousel-custom-indicator'; import ComponentCodePreview from '@/components/website/component-code-preview';
A flexible and easy-to-use carousel with customizable navigation and indicators.
<ComponentCodePreview component={<CarouselBasic />} filePath='app/docs/carousel/carousel-basic.tsx' />
We use basis-1/3 to set the width of each carousel item to one-third of the container.
<ComponentCodePreview component={<CarouselCustomSizes />} filePath='app/docs/carousel/carousel-custom-sizes.tsx' />
We use -ml-4 on CarouselContent and pl-4 on CarouselItem to add spacing between carousel items.
<ComponentCodePreview component={<CarouselSpacing />} filePath='app/docs/carousel/carousel-spacing.tsx' />
We can use index and onIndexChange to create custom indicators for the carousel.
<ComponentCodePreview component={<CarouselCustomIndicator />} filePath='app/docs/carousel/carousel-custom-indicator.tsx' />
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath='components/core/carousel.tsx' /><Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </Tabs>| Prop | Type | Default | Description |
| :-------------- | :--------------------------- | :------ | :----------------------------------------------------- |
| children | ReactNode | | The content elements of the carousel. |
| className | string | | Optional CSS class for styling the carousel container. |
| initialIndex | number | 0 | Initial index of the active carousel item. |
| index | number | | Controlled index of the active carousel item. |
| onIndexChange | (newIndex: number) => void | | Callback function when the active index changes. |
| disableDrag | boolean | false | Whether dragging is disabled. |
| Prop | Type | Default | Description |
| :---------------- | :-------- | :------ | :------------------------------------------------------- |
| className | string | | Optional CSS class for styling the navigation container. |
| classNameButton | string | | Optional CSS class for styling the navigation buttons. |
| alwaysShow | boolean | false | Whether navigation buttons are always visible. |
| Prop | Type | Default | Description |
| :---------------- | :------- | :------ | :------------------------------------------------------ |
| className | string | | Optional CSS class for styling the indicator container. |
| classNameButton | string | | Optional CSS class for styling the indicator buttons. |
| Prop | Type | Default | Description |
| :----------- | :----------- | :------ | :----------------------------------------------- |
| children | ReactNode | | The sliding elements or items of the carousel. |
| className | string | | Optional CSS class for additional styling. |
| transition | Transition | | Optional motion transition for animating slides. |
| Prop | Type | Default | Description |
| :---------- | :---------- | :------ | :------------------------------------------------ |
| children | ReactNode | | The individual content item within the carousel. |
| className | string | | Optional CSS class for styling the carousel item. |
| Return | Type | Description |
| :-------------- | :-------------------------------- | :-------------------------------------------------------------- |
| index | number | The current index of the active carousel item. |
| setIndex | (newIndex: number) => void | Function to update the index to show a different carousel item. |
| itemsCount | number | Total number of items in the carousel. |
| setItemsCount | (newItemsCount: number) => void | Function 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.
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā