Carousel

Steps through slides with buttons and indicators.

Carousel rendered by Tarve Carousel rendered by Tarve
Native render. The live version loads when this comes into view.

Import

import { Carousel } from "@tarve/core";

Usage

Carousel.tsx
import { Carousel, Column, Text } from "@tarve/core";

let index = 0;

const slide = (title: string, background: string) => (
  <Column align="center" justify="center" style={{ width: 280, height: 160, radius: 12, background }}>
    <Text size={28} weight={700}>{title}</Text>
  </Column>
);

<Carousel
  index={index}
  loop
  items={[
    { value: "one", content: slide("One", "#4c1d95") },
    { value: "two", content: slide("Two", "#155e75") },
    { value: "three", content: slide("Three", "#9a3412") },
  ]}
  onIndexChange={(next) => {
    index = next;
  }}
/>

Props

PropTypeDefault
index required number—
items required readonly CarouselItem[]—
loop booleanfalse
nextLabel string"Next slide"
onIndexChange (index: number) => void—
previousLabel string"Previous slide"
showIndicators booleantrue

Common props

Shared by every component. See descriptions →

childrenclassclassNamehighlightidkeymotionFromonHighlightonPasteonPointerLeaveonPointerMoveonSizeonTransitionEndrovingGroupstyle

Types

CarouselItem
interface CarouselItem {
  value: string;
  content: Child;
  label?: string;
}