Carousel
Carousel is a responsive, accessible slider. It supports keyboard arrows, touch/swipe, autoplay (pausing on hover/focus), and configurable transitions. It has two modes, so you can either let it manage a list of items or drive the current slide yourself.
Two modes
| Mode | Use when | Key props |
|---|---|---|
| Items-driven | You have an array and want the carousel to render + track it. | items, renderItem |
| Controlled | You already track the index and just want navigation. | itemCount, children (render function) |
Import
import { Carousel } from '@spartanfx/react';
Items-driven mode
Pass items and a renderItem function. The carousel owns the current index.
<Carousel
items={[
{ id: 1, data: { title: 'Slide 1', image: '/img1.jpg' } },
{ id: 2, data: { title: 'Slide 2', image: '/img2.jpg' } },
]}
renderItem={(item) => (
<figure>
<img src={item.data.image} alt={item.data.title} />
<figcaption>{item.data.title}</figcaption>
</figure>
)}
autoPlay={{ enabled: true, interval: 4000 }}
/>
Controlled mode
Pass itemCount and a render function as children. You receive the current index.
<Carousel itemCount={3}>
{(currentIndex) => <div>Current slide: {currentIndex + 1}</div>}
</Carousel>
Common options
These live on the shared base (available in both modes):
autoPlay—truefor defaults or an object ({ enabled, interval }).transition— animation config (slide, fade, none).navigation— show/customize arrows and indicators.keyboardNavigation(defaulttrue),touchEnabled(defaulttrue),swipeThreshold(default50).initialIndex(default0) orcurrentIndexfor controlled index.maxWidth— cap and center the carousel.
See also
- Full generated reference: Carousel API ↗
- Prop shapes:
ICarouselItemsProps,ICarouselControlledProps - Components overview