Carousel

Swipeable, keyboard-accessible slides for testimonials, media and onboarding.

Status: beta. Category: Data display.

import { Carousel, CarouselContent, CarouselItem, CarouselPrevious, CarouselNext, CarouselDots } from '@glyphui/ui'

Exports: Carousel, CarouselContent, CarouselItem, CarouselPrevious, CarouselNext, CarouselDots, carouselStyles.

Notes

  • Built on Embla. Swipe on touch, drag with a mouse, or use the arrow keys while focus is inside.
  • Uses the WAI-ARIA carousel pattern: the region is labelled and each slide announces “n of total”.
  • Pass setApi to build custom controls on the Embla API.

Carousel props

PropTypeDefaultDescription
aria-label (required)stringRequired: describes the content, e.g. "Customer stories".
loopbooleanShortcut for opts.loop.
optsPartial<OptionsType>Embla options, e.g. { align: 'start', loop: true }.
orientation"horizontal" | "vertical"
pluginsCreatePluginType<LoosePluginType, {}>[]
setApi((api: EmblaCarouselType) => void)Receives the Embla API for custom controls.

Example: Testimonials

One slide at a time, with dots.

import {
  Avatar,
  Card,
  Carousel,
  CarouselContent,
  CarouselDots,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
  Text,
} from '@glyphui/ui'

const quotes = [
  {
    name: 'Ada Lovelace',
    role: 'Staff engineer, Acme',
    quote: 'We swapped our whole design language by editing one theme file. Nothing else changed.',
  },
  {
    name: 'Grace Hopper',
    role: 'Founder, Compile',
    quote: 'Forms with server errors used to take a day. Now it is ten lines.',
  },
  {
    name: 'Alan Kay',
    role: 'Design lead, Smalltalk Labs',
    quote: 'The defaults are already good. We mostly delete code now.',
  },
]

export default function Example() {
  return (
    <Carousel aria-label="Customer stories" loop className="w-full max-w-md">
      <CarouselContent>
        {quotes.map((q) => (
          <CarouselItem key={q.name}>
            <Card className="h-full px-14">
              <Text size="lead">“{q.quote}”</Text>
              <div className="flex items-center gap-3">
                <Avatar name={q.name} size="sm" />
                <div>
                  <Text size="small" weight="medium">
                    {q.name}
                  </Text>
                  <Text size="caption" tone="muted">
                    {q.role}
                  </Text>
                </div>
              </div>
            </Card>
          </CarouselItem>
        ))}
      </CarouselContent>
      <CarouselPrevious />
      <CarouselNext />
      <CarouselDots />
    </Carousel>
  )
}

Example: Several per view

Size items with basis classes; align and loop through opts.

import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from '@glyphui/ui'

const covers = ['Theming', 'Forms', 'Data tables', 'Layouts', 'Charts', 'Blocks']

export default function Example() {
  return (
    <Carousel aria-label="Guides" opts={{ align: 'start' }} className="w-full max-w-lg">
      <CarouselContent>
        {covers.map((title, i) => (
          <CarouselItem key={title} className="basis-1/2 sm:basis-1/3">
            <div className="flex aspect-[4/5] flex-col justify-end rounded-md border border-border bg-subtle p-4">
              <span className="font-mono text-caption text-faint-foreground">Guide {i + 1}</span>
              <span className="font-display text-h4">{title}</span>
            </div>
          </CarouselItem>
        ))}
      </CarouselContent>
      <CarouselPrevious />
      <CarouselNext />
    </Carousel>
  )
}

Live page: https://glyphui.xyz/components/carousel