Carousel

Carousel

A slideshow component for cycling through content with auto-play, swipe gestures, and navigation controls.


Import

tsx
import { Carousel } from "asheeui";

Usage

tsx
import { Carousel } from "asheeui";
const slides = [
{
id: "1",
content: (
<div className="flex h-40 items-center justify-center bg-primary/10">
Slide 1
</div>
),
},
{
id: "2",
content: (
<div className="flex h-40 items-center justify-center bg-secondary/10">
Slide 2
</div>
),
},
{
id: "3",
content: (
<div className="flex h-40 items-center justify-center bg-success/10">
Slide 3
</div>
),
},
];
export default function Basic() {
return (
<div className="w-full max-w-2xl">
<Carousel items={slides} />
</div>
);
}

Examples

Variant

Bordered
Bordered
Bordered
Ghost
Ghost
Ghost

Size

Small
Small
Small
Medium
Medium
Medium
Large
Large
Large

Radius

None
None
None
Extra Small
Extra Small
Extra Small
Small
Small
Small
Medium
Medium
Medium
Large
Large
Large
Extra Large
Extra Large
Extra Large
Full
Full
Full

Auto-play

Slide 1
Slide 2
Slide 3

Loop

Slide 1
Slide 2
Slide 3
Slide 1
Slide 2
Slide 3

With controls

Slide 1
Slide 2
Slide 3
Slide 1
Slide 2
Slide 3

With indicators

Slide 1
Slide 2
Slide 3

Pause on hover

Slide 1
Slide 2
Slide 3

Without animation

Slide 1
Slide 2
Slide 3

Controlled

Slide 1
Slide 2
Slide 3

Current slide: 1

Custom controls

Slide 1
Slide 2
Slide 3

Props

PropTypeDefaultDescription
itemsCarouselItem[]NoneArray of slides to render
childrenReactNodeNoneAlternative to items prop for simple usage
variant"bordered" | "ghost""bordered"*Visual style of the carousel
size"sm" | "md" | "lg""md"Size scale for height and padding
radius"none" | "xs" | "sm" | "md" | "lg" | "xl" | "full""lg"*Corner rounding
autoPlaybooleanfalse*Automatically advance slides
autoPlayIntervalnumber5000*Delay in ms between auto-play transitions
loopbooleantrue*Enable infinite looping
showControlsbooleantrue*Show navigation arrows
showIndicatorsbooleantrue*Show dot indicators
pauseOnHoverbooleantrue*Pause auto-play when hovered
disableAnimationbooleanfalseDisable slide transition animations
defaultIndexnumber0Initial slide index for uncontrolled usage
indexnumberNoneControlled slide index
onIndexChange(index: number) => voidNoneCallback when slide changes
renderPrevControl(props: { onClick: () => void; disabled: boolean }) => ReactNodeNoneCustom previous control renderer
renderNextControl(props: { onClick: () => void; disabled: boolean }) => ReactNodeNoneCustom next control renderer
itemClassNamestringNoneExtra classes applied to each slide
controlClassNamestringNoneExtra classes for control buttons
indicatorClassNamestringNoneExtra classes for indicator dots
classNamestringNoneExtra classes, merged with internal styles

* Falls back through Global Configuration if not set. See below.

CarouselItem

PropTypeDescription
idstringUnique identifier for the slide
contentReactNodeSlide content

Global Configuration

Carousel reads defaults from four places, in this order of precedence:

  1. Instance prop: set directly on <Carousel />
  2. Component config: components.carousel in your ashee.config
  3. Theme default: defaultVariant / defaultRadius in your ashee.config
  4. Built-in fallback: component's internal default values

Component config

ts
// ashee.config.ts
import type { ExternalConfig } from "asheeui";
export const config: ExternalConfig = {
components: {
carousel: {
variant: "bordered",
size: "md",
radius: "lg",
autoPlay: true,
autoPlayInterval: 3000,
loop: true,
showControls: true,
showIndicators: true,
pauseOnHover: true,
},
},
};

Built-in fallbacks

ts
{
size: "md",
variant: "bordered",
radius: "lg",
autoPlay: false,
autoPlayInterval: 5000,
loop: true,
showControls: true,
showIndicators: true,
pauseOnHover: true,
}

Accessibility

  • Uses native button elements for controls with proper aria-label attributes
  • Supports keyboard navigation via focus management
  • Dot indicators include aria-label with slide number
  • Touch gestures support pointer events
  • Disabled controls prevent interaction in non-looping carousels
  • Implements focus-visible rings for keyboard navigation

Notes

  • Items vs Children: Use items for structured data or children for simple content. If both are provided, items takes precedence.
  • Controlled vs Uncontrolled: Use index/onIndexChange for controlled usage, or defaultIndex for uncontrolled.
  • Swipe Support: The carousel supports touch and mouse drag gestures with a 50px threshold for swipe detection.
  • Auto-play: Auto-play pauses when the carousel is hovered (if pauseOnHover is enabled) or when dragging.
  • Looping: When loop is false, navigation controls are disabled at the first and last slides.
  • Performance: For large carousels with many slides, consider using disableAnimation to reduce layout shifts.
Previous

← Card

Next

Chip →