suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Code Block
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Trace
  • Wheel Picker
  • Widget

suiss/ui · Component

Carousel

A swipeable track of slides with buttons, dots and optional autoplay, built on Embla Carousel.

Carousel is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"

const slides = [1, 2, 3, 4, 5]

export default function CarouselDemo() {
  return (
    <Carousel className="mx-12 w-72 min-w-0" orientation="horizontal">
      <CarouselContent>
        {slides.map((slide) => (

Carousel is built on embla-carousel-react. A Carousel root holds a CarouselContent track whose children are CarouselItem slides. Add CarouselPrevious and CarouselNext to page through slides; on their own they float outside the track's edges. To lay controls out in a row below the track instead, place them in a CarouselControls container, along with CarouselDots for per-slide indicators and CarouselPlayButton for autoplay.

Use a carousel for featured content, product shelves, testimonials and galleries where people browse a set of peers one at a time. For content everyone must see, prefer a static layout.

Installation

$ pnpm dlx shadcn@latest add @esuiss/carousel

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add carousel
  1. Install the following dependencies and add the cn helper:
$ pnpm add @phosphor-icons/react embla-carousel-react
  1. Add the pieces it builds on: Button, Direction.

  2. Copy and paste the following code into your project.

components/ui/carousel.tsx
"use client"

import {
  CaretLeftIcon,
  CaretRightIcon,
  PauseIcon,
  PlayIcon,
} from "@phosphor-icons/react"
import useEmblaCarousel, {
  type UseEmblaCarouselType,
} from "embla-carousel-react"
import * as React from "react"
import { Button } from "@/components/ui/button"
import { useDirection } from "@/components/ui/direction"
import { cn } from "@/lib/utils"
  1. Update the import paths to match your project setup.

Usage

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselNext,
  CarouselPlayButton,
  CarouselPrevious,
} from "@/components/ui/carousel"
<Carousel orientation="horizontal">
  <CarouselContent>
    {slides.map((slide) => (
      <CarouselItem key={slide}>
        <Card>
          <CardContent className="flex aspect-square items-center justify-center">
            <span className="text-4xl font-semibold">{slide}</span>
          </CardContent>
        </Card>
      </CarouselItem>
    ))}
  </CarouselContent>
  <CarouselPrevious />
  <CarouselNext />
</Carousel>

Composition

Use the following composition to build a Carousel:

Carousel
├── CarouselContent
│   └── CarouselItem
├── CarouselPrevious
├── CarouselNext
├── CarouselControls
│   ├── CarouselDots
│   ├── CarouselPlayButton
│   ├── CarouselNext
│   └── CarouselPrevious
└── CarouselPlayButton

Examples

Multiple items

Set the width of each slide with a basis-* class on CarouselItem. basis-1/2 shows two slides at a time.

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"

const slides = [1, 2, 3, 4, 5]

export default function CarouselMultipleItems() {
  return (
    <Carousel
      className="mx-12 w-72 min-w-0"
      orientation="horizontal"

Loop

Pass opts={{ loop: true }} to wrap from the last slide back to the first.

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"

const slides = [1, 2, 3, 4, 5]

export default function CarouselLoop() {
  return (
    <Carousel
      className="mx-12 w-72 min-w-0"
      orientation="horizontal"

Vertical

Set orientation="vertical" to scroll vertically. Standalone previous and next buttons are rotated 90 degrees and sit above and below the track.

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"

const slides = [1, 2, 3, 4, 5]

export default function CarouselVertical() {
  return (
    <Carousel
      className="m-12 w-72 min-w-0"
      orientation="vertical"

Featured

Large cards that peek at the next slide, with plain dots below.

import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"

export default function CarouselFeatured() {
  return (
    <Carousel
      className="w-[min(56rem,calc(100vw-2rem))] max-w-sm"
      orientation="horizontal"
      opts={{ align: "start" }}
    >

Spotlight

A looping hero with dots and a next button in a centered control bar.

import { Button } from "@/components/ui/button"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselNext,
  CarouselPlayButton,
} from "@/components/ui/carousel"

export default function CarouselSpotlight() {
  return (
    <Carousel
      className="w-[min(56rem,calc(100vw-2rem))] max-w-md"
      orientation="horizontal"

Shelf

A product shelf with opts={{ dragFree: true }} and no visible buttons.

import { CaretRightIcon } from "@phosphor-icons/react"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"

export default function CarouselShelf() {
  return (
    <Carousel
      className="w-[min(56rem,calc(100vw-2rem))] max-w-md"
      orientation="horizontal"
      opts={{ align: "start", dragFree: true }}
    >
      <div className="mb-3 flex items-center justify-between">

Testimonials

Quotes with dots and large previous and next buttons in a control row.

import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselNext,
  CarouselPlayButton,
  CarouselPrevious,
} from "@/components/ui/carousel"

export default function CarouselTestimonials() {
  return (
    <div className="w-[min(56rem,calc(100vw-2rem))] max-w-md rounded-3xl bg-muted p-8">
      <Carousel orientation="horizontal">
        <CarouselContent>

Gallery

Tall cards with controls aligned to the end below the track.

import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"

export default function CarouselGallery() {
  return (
    <Carousel
      className="w-[min(56rem,calc(100vw-2rem))]"
      orientation="horizontal"
      opts={{ align: "start" }}
    >

Featured autoplay

Set autoplay to a number of milliseconds, here 4000, to advance the slides automatically. The active dot fills as a progress bar.

import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"

export default function CarouselFeaturedAutoplay() {
  return (
    <Carousel
      className="w-[min(56rem,calc(100vw-2rem))] max-w-sm"
      orientation="horizontal"
      opts={{ align: "start", loop: true }}
      autoplay={4000}

Spotlight autoplay

The spotlight layout with autoplay. A CarouselPlayButton takes the place of the next button; it renders only when autoplay is enabled.

import { Button } from "@/components/ui/button"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"

export default function CarouselSpotlightAutoplay() {
  return (
    <Carousel
      className="w-[min(56rem,calc(100vw-2rem))] max-w-md"
      orientation="horizontal"
      opts={{ loop: true }}

Shelf autoplay

The shelf advancing every three seconds and looping.

import { CaretRightIcon } from "@phosphor-icons/react"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"

export default function CarouselShelfAutoplay() {
  return (
    <Carousel
      className="w-[min(56rem,calc(100vw-2rem))] max-w-md"
      orientation="horizontal"
      autoplay={3000}
      opts={{ align: "start", loop: true }}
    >

Testimonials autoplay

Testimonials advancing every six seconds.

import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselNext,
  CarouselPlayButton,
  CarouselPrevious,
} from "@/components/ui/carousel"

export default function CarouselTestimonialsAutoplay() {
  return (
    <div className="w-[min(56rem,calc(100vw-2rem))] max-w-md rounded-3xl bg-muted p-8">
      <Carousel orientation="horizontal" autoplay={6000} opts={{ loop: true }}>
        <CarouselContent>

Accessibility

  • The root renders with role="region" and aria-roledescription="carousel"; each CarouselItem has role="group" and aria-roledescription="slide". Add an aria-label to the root to name it.
  • Arrow keys move between slides while focus is inside the carousel: left and right for horizontal (reversed in right-to-left layouts), up and down for vertical.
  • CarouselPrevious and CarouselNext include visually hidden labels, Previous slide and Next slide. When one becomes disabled while focused, focus moves to the other.
  • Each dot is labelled Go to slide N, and the current dot has aria-current="true".
  • CarouselPlayButton is labelled Pause slideshow or Play slideshow to match its state.

API Reference

Carousel

The root region that owns the Embla instance, keyboard handling and autoplay state.

PropTypeDefault
optsEmblaOptionsType-
pluginsEmblaPluginType[]-
orientation"horizontal" | "vertical""horizontal"
setApi(api: CarouselApi) => void-
autoplayboolean | numberfalse

Also accepts the props of React.ComponentProps<"div">.

opts are passed to Embla Carousel, for example align, loop and dragFree, and plugins are Embla plugins. setApi receives the Embla API once it is ready, so you can read or drive the carousel from outside. The scroll direction follows the surrounding DirectionProvider.

Set autoplay to true for a 5-second interval, or to a number of milliseconds. Autoplay pauses while the pointer hovers the carousel, while it has keyboard focus, and while the page is hidden, and starts paused when the user prefers reduced motion. The root sets data-playing while autoplay is running. Use the useCarousel hook inside a Carousel to build custom controls.

CarouselContent

The clipping viewport and the flex track that holds the slides.

Also accepts the props of React.ComponentProps<"div">.

CarouselItem

A single slide.

Also accepts the props of React.ComponentProps<"div">.

The track uses negative margin and slides use start padding for gutters; adjust both together, as in -ms-3 with ps-3.

CarouselPrevious

A button that scrolls to the previous slide, disabled at the start.

PropTypeDefault
variant"default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link""secondary"
size"default" | "xs" | "sm" | "lg" | "xl" | "form" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-xl""icon"

Also accepts the props of Button.

CarouselNext

A button that scrolls to the next slide, disabled at the end.

PropTypeDefault
variant"default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link""secondary"
size"default" | "xs" | "sm" | "lg" | "xl" | "form" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-xl""icon"

Also accepts the props of Button.

variant and size are passed to the Button, as on CarouselPrevious. On their own, the previous and next buttons float outside the track's edges; inside CarouselControls they sit in the row and are not rotated in vertical carousels.

CarouselControls

A row that lays out buttons, dots and the play button below the track.

Also accepts the props of React.ComponentProps<"div">.

CarouselDots

One button per snap point that jumps to that slide and marks the current one.

PropTypeDefault
variant"default" | "plain""default"

Also accepts the props of React.ComponentProps<"div">.

default places the dots on a blurred pill background; plain removes the background and padding. The current dot sets data-active, and the container sets data-variant and data-autoplay.

CarouselPlayButton

Toggles autoplay between playing and paused.

PropTypeDefault
variant"default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link""secondary"
size"default" | "xs" | "sm" | "lg" | "xl" | "form" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-xl""icon-sm"

Also accepts the props of Button.

It renders only when autoplay is enabled. variant and size are passed to the Button.

Each part sets a data-slot, such as carousel-item or carousel-play-button, for styling.

Web

Web preview

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselDemo() {
  return (
    <Carousel className="mx-12">
      <CarouselContent>
        {[1, 2, 3, 4, 5].map((slide) => (
          <CarouselItem key={slide}>
import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselDemo() {
  return (
    <Carousel style={{ marginHorizontal: 48 }}>
      <CarouselContent>
        {[1, 2, 3, 4, 5].map((slide) => (
          <CarouselItem key={slide}>
import SwiftUI

struct CarouselExample: View {
  var body: some View {
    Carousel {
      HStack(spacing: 12) {
        CarouselPrevious()
        CarouselNumberSlides(basis: nil)
        CarouselNext()
      }
    }
  }
}

struct CarouselPick {
  let eyebrow: String
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent

Carousel wraps a scroll view that snaps to each CarouselItem. It scrolls horizontally by default or vertically with orientation="vertical". CarouselPrevious and CarouselNext are round Buttons that sit outside the slides, or inline when placed in CarouselControls.

CarouselDots shows one dot per snap point, with the active dot stretched into a pill; with autoplay on, the active dot fills up as a timer. CarouselPlayButton pauses and resumes autoplay.

Installation

$ pnpm dlx shadcn@latest add @esuiss/carousel

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add carousel
$ pnpm dlx shadcn@latest add @esuiss/carousel

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add carousel --platform swift
$ pnpm dlx shadcn@latest add @esuiss/carousel

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add carousel --platform kotlin

The CLI also adds what it builds on: Button, Icon. It also adds the animated view components/ui/animated-view.tsx.

  1. Install the following dependencies:
npx expo install cn phosphor-react-native react-native-reanimated react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon.

  2. Copy the animated view into components/ui/animated-view.tsx:

uniwind/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
uniwind/components/primitives/carousel.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  AppState,
  type LayoutChangeEvent,
  type NativeScrollEvent,
  type NativeSyntheticEvent,
  Pressable,
  ScrollView,
  View,
} from "react-native"
import { useEffectEvent } from "./hooks"
import type { BaseUIComponentProps, Orientation } from "./types"
import { useRender } from "./use-render"

type CarouselEvent = "select" | "reInit"
uniwind/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
uniwind/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
uniwind/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
uniwind/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/carousel.tsx:
uniwind/components/ui/carousel.tsx
import { cn } from "cn"
import {
  CaretLeftIcon,
  CaretRightIcon,
  PauseIcon,
  PlayIcon,
} from "phosphor-react-native"
import * as React from "react"
import { I18nManager, View, type ViewProps } from "react-native"
import {
  cancelAnimation,
  Easing,
  ReduceMotion,
  useAnimatedStyle,
  useSharedValue,
  withTiming,
  1. Update the import paths to match your project setup.
  1. Install the following dependencies:
npx expo install cn phosphor-react-native react-native-reanimated react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon.

  2. Copy the animated view into components/ui/animated-view.tsx:

nativewind/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
nativewind/components/primitives/carousel.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  AppState,
  type LayoutChangeEvent,
  type NativeScrollEvent,
  type NativeSyntheticEvent,
  Pressable,
  ScrollView,
  View,
} from "react-native"
import { useEffectEvent } from "./hooks"
import type { BaseUIComponentProps, Orientation } from "./types"
import { useRender } from "./use-render"

type CarouselEvent = "select" | "reInit"
nativewind/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
nativewind/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
nativewind/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
nativewind/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/carousel.tsx:
nativewind/components/ui/carousel.tsx
import { cn } from "cn"
import {
  CaretLeftIcon,
  CaretRightIcon,
  PauseIcon,
  PlayIcon,
} from "phosphor-react-native"
import * as React from "react"
import { I18nManager, View, type ViewProps } from "react-native"
import {
  cancelAnimation,
  Easing,
  ReduceMotion,
  useAnimatedStyle,
  useSharedValue,
  withTiming,
  1. Update the import paths to match your project setup.
  1. Install the following dependencies:
npx expo install phosphor-react-native react-native-reanimated react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon.

  2. Copy the animated view into components/ui/animated-view.tsx:

stylesheet/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
stylesheet/components/primitives/carousel.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  AppState,
  type LayoutChangeEvent,
  type NativeScrollEvent,
  type NativeSyntheticEvent,
  Pressable,
  ScrollView,
  View,
} from "react-native"
import { useEffectEvent } from "./hooks"
import type { BaseUIComponentProps, Orientation } from "./types"
import { useRender } from "./use-render"

type CarouselEvent = "select" | "reInit"
stylesheet/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
stylesheet/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
stylesheet/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
stylesheet/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/carousel.tsx:
stylesheet/components/ui/carousel.tsx
import {
  CaretLeftIcon,
  CaretRightIcon,
  PauseIcon,
  PlayIcon,
} from "phosphor-react-native"
import * as React from "react"
import { I18nManager, StyleSheet, View, type ViewProps } from "react-native"
import {
  cancelAnimation,
  Easing,
  ReduceMotion,
  useAnimatedStyle,
  useSharedValue,
  withTiming,
} from "react-native-reanimated"
  1. Update the import paths to match your project setup.
  1. Target iOS 17 or later.

  2. Add the Swift package to your app:

Package.swift
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")
  1. Copy the theme files every view uses:
swift/Theme/Theme.swift
import CoreText
import SwiftUI
import UIKit

struct RGBA: Sendable {
  let red: CGFloat
  let green: CGFloat
  let blue: CGFloat
  let alpha: CGFloat

  init(_ hex: UInt32, _ alpha: CGFloat = 1) {
    red = CGFloat((hex >> 16) & 0xFF) / 255
    green = CGFloat((hex >> 8) & 0xFF) / 255
    blue = CGFloat(hex & 0xFF) / 255
    self.alpha = alpha
  }
swift/Theme/Tokens.swift
import SwiftUI

public enum EsuissColor {
  public static let background = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))
  public static let foreground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let card = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let cardForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let popover = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let popoverForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let primary = Color.adaptive(light: .init(0x0071E3), dark: .init(0x0A84FF))
  public static let primaryForeground = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0xFFFFFF))
  public static let secondary = Color.adaptive(light: .init(0x000000, 0.04), dark: .init(0xFFFFFF, 0.1))
  public static let secondaryForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let muted = Color.adaptive(light: .init(0xF5F5F7), dark: .init(0x161617))
  public static let mutedForeground = Color.adaptive(light: .init(0x6E6E73), dark: .init(0x86868B))
  public static let accent = Color.adaptive(light: .init(0x000000, 0.06), dark: .init(0xFFFFFF, 0.1))
  1. Copy the source and every file it uses:
swift/Components/Carousel.swift
import PhosphorSwift
import SwiftUI

public enum CarouselOrientation: CaseIterable, Sendable {
  case horizontal, vertical
}

public enum CarouselDotsVariant: CaseIterable, Sendable {
  case `default`, plain
}

let carouselAnimation = Animation.timingCurve(0.32, 0.72, 0, 1, duration: 0.5)

enum CarouselMath {
  static func clamp(_ index: Int, count: Int) -> Int {
    count == 0 ? 0 : min(max(index, 0), count - 1)
swift/Components/Button.swift
import SwiftUI

public struct VariantButtonStyle: ButtonStyle {
  public enum Variant: CaseIterable, Sendable {
    case `default`, outline, secondary, tinted, ghost, plain, destructive, link
  }

  public enum Size: CaseIterable, Sendable {
    case `default`, xs, sm, lg, xl, form, icon, iconXs, iconSm, iconLg, iconXl

    var height: CGFloat {
      switch self {
      case .xs, .iconXs: Metrics.Height.buttonXs
      case .sm, .iconSm: Metrics.Height.buttonSm
      case .default, .icon: Metrics.Height.button
      case .lg, .iconLg: Metrics.Height.buttonLg
swift/Components/ButtonGroup.swift
import SwiftUI

extension EnvironmentValues {
  @Entry var buttonGroup: Axis? = nil
  @Entry var buttonGroupSize: CGSize = .zero
}

enum ButtonGroupSpace: Hashable {
  case group
}

struct ButtonGroupFrame {
  let bounds: Anchor<CGRect>
  let outlined: Bool
}
  1. Add the files to your app target.
  1. Apply the Compose compiler plugin, enable Compose, set compileSdk to 37 or higher and minSdk to 24 or higher, and add the dependencies:
build.gradle.kts
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
    implementation("com.adamglin:phosphor-icon-android:1.0.0")
}
  1. Copy the theme files every view uses:
kotlin/theme/Theme.kt
package com.esuiss.ui.theme

import android.content.res.AssetManager
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.dropShadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.shadow.Shadow as DropShadow
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
kotlin/theme/Tokens.kt
package com.esuiss.ui.theme

import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

@Immutable
data class Colors(
    val background: Color,
    val foreground: Color,
    val card: Color,
    val cardForeground: Color,
    val popover: Color,
    val popoverForeground: Color,
    val primary: Color,
  1. Copy the source and every file it uses:
kotlin/components/Carousel.kt
package com.esuiss.ui.components

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsDraggedAsState
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
kotlin/components/Button.kt
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
kotlin/components/ButtonGroup.kt
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.Immutable
kotlin/components/Content.kt
package com.esuiss.ui.components

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

val LocalContentStyle = compositionLocalOf { TextStyle.Default }

val LocalContentColor = compositionLocalOf { Color.Unspecified }

val LocalIconSize = compositionLocalOf { 20.dp }
kotlin/components/Icon.kt
package com.esuiss.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import com.esuiss.ui.theme.EsuissTheme

@Composable
fun Icon(
    imageVector: ImageVector,
  1. Update the com.esuiss.ui package names to match your project.

Usage

import { View } from "react-native"
import { Card, CardContent } from "@/components/ui/card"
import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

const slides = [1, 2, 3, 4, 5]

function NumberSlides({ basis }: { basis?: number }) {
  return (
    <CarouselContent>
      {slides.map((slide) => (
        <CarouselItem key={slide} basis={basis}>
          <Card size={basis ? "sm" : "default"}>
            <CardContent className="aspect-square items-center justify-center">
              <Text className="text-4xl font-semibold">{slide}</Text>
            </CardContent>
          </Card>
        </CarouselItem>
      ))}
    </CarouselContent>
  )
}

export function CarouselExample() {
  return (
    <View className="mx-12">
      <Carousel>
        <NumberSlides />
        <CarouselPrevious />
        <CarouselNext />
      </Carousel>
    </View>
  )
}
import { View } from "react-native"
import { Card, CardContent } from "@/components/ui/card"
import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

const slides = [1, 2, 3, 4, 5]

function NumberSlides({ basis }: { basis?: number }) {
  return (
    <CarouselContent>
      {slides.map((slide) => (
        <CarouselItem key={slide} basis={basis}>
          <Card size={basis ? "sm" : "default"}>
            <CardContent style={{ aspectRatio: 1, alignItems: "center", justifyContent: "center" }}>
              <Text style={{ fontSize: 36, lineHeight: 40, fontWeight: "600" }}>{slide}</Text>
            </CardContent>
          </Card>
        </CarouselItem>
      ))}
    </CarouselContent>
  )
}

export function CarouselExample() {
  return (
    <View style={{ marginHorizontal: 48 }}>
      <Carousel>
        <NumberSlides />
        <CarouselPrevious />
        <CarouselNext />
      </Carousel>
    </View>
  )
}
import SwiftUI

struct CarouselExample: View {
  var body: some View {
    Carousel {
      HStack(spacing: 12) {
        CarouselPrevious()
        CarouselNumberSlides(basis: nil)
        CarouselNext()
      }
    }
  }
}

struct CarouselPick {
  let eyebrow: String
  let title: String
  let tint: Color
}

enum CarouselData {
  static let slides = [1, 2, 3, 4, 5]

  static let picks = [
    CarouselPick(eyebrow: "Today's pick", title: "Weekend breakfast", tint: Palette.amber500),
    CarouselPick(eyebrow: "New", title: "Grilled meatballs", tint: EsuissColor.destructive),
    CarouselPick(eyebrow: "Chef's special", title: "Lentil soup", tint: Palette.green500),
    CarouselPick(eyebrow: "Dessert", title: "Künefe", tint: EsuissColor.primary),
  ]

  static let features = [
    "Take orders at the table.",
    "Every ticket, right on time.",
    "A full room, every night.",
  ]
}

struct CarouselNumberSlides: View {
  let basis: CGFloat?

  var body: some View {
    CarouselContent {
      ForEach(CarouselData.slides, id: \.self) { slide in
        CarouselItem(basis: basis ?? 1) {
          Card(size: basis == nil ? .default : .sm) {
            CardContent {
              Text(verbatim: "\(slide)")
                .textStyle(.xl3, weight: .semibold)
                .frame(maxWidth: .infinity, maxHeight: .infinity)
                .aspectRatio(1, contentMode: .fit)
            }
          }
        }
      }
    }
  }
}
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.Carousel
import com.esuiss.ui.components.CarouselContent
import com.esuiss.ui.components.CarouselItem
import com.esuiss.ui.components.CarouselNext
import com.esuiss.ui.components.CarouselPrevious
import com.esuiss.ui.components.Text
import com.esuiss.ui.components.rememberCarouselState
import com.esuiss.ui.theme.Typography

@Composable
fun CarouselExample() {
    CarouselNumbers(basis = null, loop = false)
}

val carouselSlides = listOf(1, 2, 3, 4, 5)

val carouselSpacing = 16.dp

fun carouselPeek(width: Dp, basis: Float?, spacing: Dp = carouselSpacing): PaddingValues {
    if (basis == null) return PaddingValues(0.dp)
    val page = (width + spacing) * basis - spacing
    return PaddingValues(end = width - page)
}

@Composable
fun CarouselNumbers(basis: Float?, loop: Boolean) {
    val state = rememberCarouselState(pageCount = carouselSlides.size, loop = loop)
    BoxWithConstraints(Modifier.fillMaxWidth()) {
        val width = maxWidth
        Carousel(state = state, modifier = Modifier.fillMaxWidth()) {
            CarouselContent(contentPadding = carouselPeek(width, basis)) { page ->
                CarouselItem {
                    Card(size = if (basis != null) CardSize.Sm else CardSize.Default) {
                        CardContent {
                            Box(Modifier.fillMaxWidth().aspectRatio(1f), contentAlignment = Alignment.Center) {
                                Text(
                                    carouselSlides[page].toString(),
                                    style = Typography.xl3.copy(fontWeight = FontWeight.SemiBold),
                                )
                            }
                        }
                    }
                }
            }
            Row(
                Modifier.fillMaxWidth().padding(top = 12.dp),
                horizontalArrangement = Arrangement.SpaceBetween,
                verticalAlignment = Alignment.CenterVertically,
            ) {
                CarouselPrevious()
                CarouselNext()
            }
        }
    }
}

Examples

Multiple items

Set each slide's width with basis on CarouselItem, as a fraction of the viewport. basis={0.5} shows two slides per view.

Web

Web preview

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselMultipleItems() {
  return (
    <Carousel opts={{ align: "start" }} className="mx-12">
      <CarouselContent>
        {[1, 2, 3, 4, 5].map((slide) => (
          <CarouselItem key={slide} basis={0.5}>
import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselMultipleItems() {
  return (
    <Carousel opts={{ align: "start" }} style={{ marginHorizontal: 48 }}>
      <CarouselContent>
        {[1, 2, 3, 4, 5].map((slide) => (
          <CarouselItem key={slide} basis={0.5}>
import SwiftUI

struct CarouselMultipleItemsExample: View {
  var body: some View {
    Carousel {
      HStack(spacing: 12) {
        CarouselPrevious()
        CarouselNumberSlides(basis: 0.5)
        CarouselNext()
      }
    }
  }
}

struct CarouselPick {
  let eyebrow: String
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent

Loop

Wraps around from the last slide to the first.

Web

Web preview

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselLoop() {
  return (
    <Carousel opts={{ loop: true }} className="mx-12">
      <CarouselContent>
        {[1, 2, 3, 4, 5].map((slide) => (
          <CarouselItem key={slide}>
import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselLoop() {
  return (
    <Carousel opts={{ loop: true }} style={{ marginHorizontal: 48 }}>
      <CarouselContent>
        {[1, 2, 3, 4, 5].map((slide) => (
          <CarouselItem key={slide}>
import SwiftUI

struct CarouselLoopExample: View {
  var body: some View {
    Carousel(loop: true) {
      HStack(spacing: 12) {
        CarouselPrevious()
        CarouselNumberSlides(basis: nil)
        CarouselNext()
      }
    }
  }
}

struct CarouselPick {
  let eyebrow: String
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardContent

Vertical

A vertical carousel with arrows above and below.

Web

Web preview

import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselVertical() {
  return (
    <Carousel
      orientation="vertical"
      opts={{ align: "start" }}
      className="my-12"
import { Card, CardContent } from "@/components/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"
import { fontSize } from "@/components/ui/theme"

export default function CarouselVertical() {
  return (
    <Carousel
      orientation="vertical"
      opts={{ align: "start" }}
import SwiftUI

struct CarouselVerticalExample: View {
  var body: some View {
    Carousel(orientation: .vertical) {
      VStack(spacing: 12) {
        CarouselPrevious()
        CarouselContent {
          ForEach(CarouselData.slides, id: \.self) { slide in
            CarouselItem(basis: 0.5) {
              Card(size: .sm) {
                CardContent {
                  Text(verbatim: "\(slide)")
                    .textStyle(.xl2, weight: .semibold)
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
                }
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Card
import com.esuiss.ui.components.CardSize
import com.esuiss.ui.components.Carousel

With page indicator

Full-width cards with a page indicator below.

React Native
import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  useCarousel,
} from "@/components/ui/carousel"
import { PageIndicator } from "@/components/ui/page-indicator"
import { Text } from "@/components/ui/text"

function CarouselPageIndicator() {
  const { scrollSnaps, selectedIndex, scrollTo } = useCarousel()
  return (
    <PageIndicator
      className="mt-4"
      count={scrollSnaps.length}
import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  useCarousel,
} from "@/components/ui/carousel"
import { PageIndicator } from "@/components/ui/page-indicator"
import { Text } from "@/components/ui/text"
import { fontSize, palette, radius, useTheme } from "@/components/ui/theme"

function CarouselPageIndicator() {
  const { scrollSnaps, selectedIndex, scrollTo } = useCarousel()
  return (
    <PageIndicator
      style={{ marginTop: 16 }}
import SwiftUI

struct CarouselPick {
  let eyebrow: String
  let title: String
  let tint: Color
}

enum CarouselData {
  static let slides = [1, 2, 3, 4, 5]

  static let picks = [
    CarouselPick(eyebrow: "Today's pick", title: "Weekend breakfast", tint: Palette.amber500),
    CarouselPick(eyebrow: "New", title: "Grilled meatballs", tint: EsuissColor.destructive),
    CarouselPick(eyebrow: "Chef's special", title: "Lentil soup", tint: Palette.green500),
    CarouselPick(eyebrow: "Dessert", title: "Künefe", tint: EsuissColor.primary),
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Carousel
import com.esuiss.ui.components.CarouselContent

Featured

Peeking cards with plain dots and a play button.

CarouselDots takes variant="plain" to drop its background.

Web

Web preview

import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselFeatured() {
  return (
    <Carousel opts={{ align: "start" }}>
      <CarouselContent>
        <CarouselItem basis={0.88}>
import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"
import { fontSize, palette, radius, useTheme } from "@/components/ui/theme"

export default function CarouselFeatured() {
  const { colors } = useTheme()
  return (
    <Carousel opts={{ align: "start" }}>
import SwiftUI

struct CarouselFeaturedExample: View {
  var body: some View {
    Carousel {
      CarouselContent {
        ForEach(CarouselData.picks, id: \.title) { pick in
          CarouselItem(basis: 0.88) {
            CarouselPickCard(pick: pick)
          }
        }
      }
      CarouselControls {
        CarouselDots(variant: .plain)
        CarouselPlayButton(variant: .ghost)
      }
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp

Spotlight

A looping showcase with dots and an inline next button.

Web

Web preview

import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselNext,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselSpotlight() {
  return (
    <Carousel opts={{ loop: true }}>
      <CarouselContent>
        <CarouselItem>
import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselNext,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"
import { fontSize, radius, useTheme } from "@/components/ui/theme"

export default function CarouselSpotlight() {
  const { colors } = useTheme()
  return (
    <Carousel opts={{ loop: true }}>
import SwiftUI

struct CarouselSpotlightExample: View {
  var body: some View {
    Carousel(loop: true) {
      CarouselFeatureSlides()
      CarouselControls {
        CarouselDots()
        CarouselNext(size: .iconSm)
      }
    }
  }
}

struct CarouselPick {
  let eyebrow: String
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.ButtonSize
import com.esuiss.ui.components.Carousel

Autoplay

Advances every four seconds, with progress dots and a play button.

Pass autoplay as true for the default 5-second delay, or as a number of milliseconds.

React Native
import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselAutoplay() {
  return (
    <Carousel autoplay={4000} opts={{ loop: true }}>
      <CarouselContent>
        <CarouselItem>
import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselControls,
  CarouselDots,
  CarouselItem,
  CarouselPlayButton,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"
import { fontSize, radius, useTheme } from "@/components/ui/theme"

export default function CarouselAutoplay() {
  const { colors } = useTheme()
  return (
    <Carousel autoplay={4000} opts={{ loop: true }}>
import SwiftUI

struct CarouselAutoplayExample: View {
  var body: some View {
    Carousel(loop: true, autoplay: .seconds(4)) {
      CarouselFeatureSlides()
      CarouselControls {
        CarouselDots()
        CarouselPlayButton()
      }
    }
  }
}

struct CarouselPick {
  let eyebrow: String
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Carousel
import com.esuiss.ui.components.CarouselContent

Shelf

A free-scrolling shelf of small cards with dragFree in opts, so it scrolls without snapping.

Web

Web preview

import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"

export default function CarouselShelf() {
  return (
    <Carousel opts={{ align: "start", dragFree: true }}>
      <Text className="mb-3 text-xl font-bold">Popular</Text>
      <CarouselContent className="-ms-3">
        <CarouselItem basis={0.4} className="ps-3">
          <View className="aspect-square rounded-2xl bg-orange-500" />
          <Text className="mt-2 text-sm font-semibold" numberOfLines={1}>
import { View } from "react-native"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
} from "@/components/ui/carousel"
import { Text } from "@/components/ui/text"
import { fontSize, palette, radius } from "@/components/ui/theme"

export default function CarouselShelf() {
  return (
    <Carousel opts={{ align: "start", dragFree: true }}>
      <Text style={{ marginBottom: 12, ...fontSize.xl, fontWeight: "700" }}>Popular</Text>
      <CarouselContent style={{ marginStart: -12 }}>
        <CarouselItem basis={0.4} style={{ paddingStart: 12 }}>
          <View style={{ aspectRatio: 1, borderRadius: radius["2xl"], backgroundColor: palette.orange500 }} />
import SwiftUI

struct CarouselShelfExample: View {
  var body: some View {
    Carousel {
      Text("Popular")
        .textStyle(.xl, weight: .bold)
        .foregroundStyle(EsuissColor.foreground)
        .frame(maxWidth: .infinity, alignment: .leading)
        .padding(.bottom, 12)
      CarouselContent(spacing: 12) {
        ForEach(CarouselData.picks, id: \.title) { pick in
          CarouselItem(basis: 0.4) {
            VStack(alignment: .leading, spacing: 8) {
              RoundedRectangle(cornerRadius: Radius.xl2, style: .continuous)
                .fill(pick.tint)
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp

Accessibility

  • Previous and next buttons have the button role and are labelled "Previous slide" and "Next slide", with a disabled state at the ends.
  • Each dot is labelled "Go to slide N" and marks the current slide as selected.
  • The play button is labelled "Pause slideshow" or "Play slideshow".

API Reference

Carousel

Root that holds the scroll state and options.

Also accepts the props of React.ComponentProps<typeof CarouselPrimitive.Root>.

Use opts for loop, align (start or center) and dragFree. Pass autoplay as true for the default 5-second delay, or as a number of milliseconds. Use setApi to get a CarouselApi for scrolling from outside, or call useCarousel() inside the carousel to read the selected index and scroll state.

CarouselContent

Scrolling track for the slides.

Also accepts the props of React.ComponentProps<typeof CarouselPrimitive.Content>.

CarouselItem

One slide.

Also accepts the props of React.ComponentProps<typeof CarouselPrimitive.Item>.

CarouselPrevious

Button that scrolls to the previous slide.

Also accepts the props of React.ComponentProps<typeof Button>.

CarouselNext

Button that scrolls to the next slide.

Also accepts the props of React.ComponentProps<typeof Button>.

Arrow icons are mirrored in right-to-left layouts.

CarouselControls

Row that lays out dots and buttons below the slides.

Also accepts the props of ViewProps.

Put CarouselDots, CarouselPlayButton and the previous and next buttons inside it to show them in a row below the slides.

CarouselDots

One pressable dot per snap point.

PropTypeDefault
variant"default" | "plain""default"

Also accepts the props of ViewProps.

default sets the dots on a control background, and plain drops it. Dot and progress animations respect the system Reduce Motion setting.

CarouselPlayButton

Toggles autoplay.

Also accepts the props of React.ComponentProps<typeof Button>.

CarouselOrientation

Values: .horizontal, .vertical.

CarouselDotsVariant

Values: .default, .plain.

CarouselController

Takes no parameters.

PropertyType
selectedIndexInt
countInt
canScrollPrevBool
canScrollNextBool

CarouselController.scrollTo

ParameterTypeDefault
_ indexInt-
animatedBooltrue

CarouselController.scrollPrev

Takes no parameters.

CarouselController.scrollNext

Takes no parameters.

CarouselController.setPlaying

ParameterTypeDefault
_ playingBool-

Carousel

Root that holds the scroll state and options.

ParameterTypeDefault
orientationCarouselOrientation: .horizontal | .vertical.horizontal
loopBoolfalse
autoplayDuration?nil
controllerCarouselController?nil
onSelect((Int) -> Void)?nil
content() -> Content-

CarouselContent

Scrolling track for the slides.

ParameterTypeDefault
spacingCGFloat16
content() -> Content-

CarouselItem

One slide.

ParameterTypeDefault
basisCGFloat1
content() -> Content-

CarouselPrevious

Button that scrolls to the previous slide.

ParameterTypeDefault
variantVariantButtonStyle.Variant.secondary
sizeVariantButtonStyle.Size.icon

CarouselNext

Button that scrolls to the next slide.

ParameterTypeDefault
variantVariantButtonStyle.Variant.secondary
sizeVariantButtonStyle.Size.icon

CarouselControls

Row that lays out dots and buttons below the slides.

ParameterTypeDefault
content() -> Content-

CarouselDots

One pressable dot per snap point.

ParameterTypeDefault
variantCarouselDotsVariant: .default | .plain.default

CarouselPlayButton

Toggles autoplay.

ParameterTypeDefault
variantVariantButtonStyle.Variant.secondary
sizeVariantButtonStyle.Size.iconSm

CarouselOrientation

Values: Horizontal, Vertical.

CarouselDotsVariant

Values: Default, Plain.

CarouselState

PropertyType
pageCountInt get()
selectedIndexInt get()
canScrollPrevBoolean get()
canScrollNextBoolean get()
isPlayingBoolean get()

CarouselState.scrollTo

ParameterTypeDefault
indexInt-
animateBooleantrue

CarouselState.scrollPrev

Takes no parameters.

CarouselState.scrollNext

Takes no parameters.

CarouselState.setPlaying

ParameterTypeDefault
playingBoolean-

rememberCarouselState

ParameterTypeDefault
pageCountInt-
initialPageInt0
loopBooleanfalse

Returns CarouselState.

Carousel

Root that holds the scroll state and options.

ParameterTypeDefault
stateCarouselState-
modifierModifierModifier
orientationCarouselOrientation: Horizontal | VerticalCarouselOrientation.Horizontal
autoplayBooleanfalse
autoplayDelayMillisLong5000L
onSelect((Int) -> Unit)?null
content@Composable ColumnScope.() -> Unit-

CarouselContent

Scrolling track for the slides.

ParameterTypeDefault
modifierModifierModifier
contentPaddingPaddingValuesPaddingValues(0.dp)
pageSpacingDp16.dp
key((Int) -> Any)?null
content@Composable (page: Int) -> Unit-

CarouselItem

One slide.

ParameterTypeDefault
modifierModifierModifier
content@Composable BoxScope.() -> Unit-

CarouselPrevious

Button that scrolls to the previous slide.

ParameterTypeDefault
modifierModifierModifier
variantButtonVariantButtonVariant.Secondary
sizeButtonSizeButtonSize.Icon
contentDescriptionString"Previous slide"

CarouselNext

Button that scrolls to the next slide.

ParameterTypeDefault
modifierModifierModifier
variantButtonVariantButtonVariant.Secondary
sizeButtonSizeButtonSize.Icon
contentDescriptionString"Next slide"

CarouselControls

Row that lays out dots and buttons below the slides.

ParameterTypeDefault
modifierModifierModifier
content@Composable RowScope.() -> Unit-

CarouselDots

One pressable dot per snap point.

ParameterTypeDefault
modifierModifierModifier
variantCarouselDotsVariant: Default | PlainCarouselDotsVariant.Default

CarouselPlayButton

Toggles autoplay.

ParameterTypeDefault
modifierModifierModifier
variantButtonVariantButtonVariant.Secondary
sizeButtonSizeButtonSize.IconSm
NextChartPreviousCard

On this page

  1. 01Installation
  2. 02Usage
  3. 03Composition
  4. 04Examples
    • Multiple items
    • Loop
    • Vertical
    • Featured
    • Spotlight
    • Shelf
    • Testimonials
    • Gallery
    • Featured autoplay
    • Spotlight autoplay
    • Shelf autoplay
    • Testimonials autoplay
  5. 05Accessibility
  6. 06API Reference
    • Carousel
    • CarouselContent
    • CarouselItem
    • CarouselPrevious
    • CarouselNext
    • CarouselControls
    • CarouselDots
    • CarouselPlayButton
  7. 07Installation
  8. 08Usage
  9. 09Examples
    • Multiple items
    • Loop
    • Vertical
    • With page indicator
    • Featured
    • Spotlight
    • Autoplay
    • Shelf
  10. 10Accessibility
  11. 11API Reference
    • Carousel
    • CarouselContent
    • CarouselItem
    • CarouselPrevious
    • CarouselNext
    • CarouselControls
    • CarouselDots
    • CarouselPlayButton
    • CarouselOrientation
    • CarouselDotsVariant
    • CarouselController
    • CarouselController.scrollTo
    • CarouselController.scrollPrev
    • CarouselController.scrollNext
    • CarouselController.setPlaying
    • Carousel
    • CarouselContent
    • CarouselItem
    • CarouselPrevious
    • CarouselNext
    • CarouselControls
    • CarouselDots
    • CarouselPlayButton
    • CarouselOrientation
    • CarouselDotsVariant
    • CarouselState
    • CarouselState.scrollTo
    • CarouselState.scrollPrev
    • CarouselState.scrollNext
    • CarouselState.setPlaying
    • rememberCarouselState
    • Carousel
    • CarouselContent
    • CarouselItem
    • CarouselPrevious
    • CarouselNext
    • CarouselControls
    • CarouselDots
    • CarouselPlayButton