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 (
    <div className="mx-12 w-72">
      <Carousel orientation="horizontal">
        <CarouselContent>

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

CLI

$ 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

Manual

  1. Install the 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 the source into components/ui/carousel.tsx:

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.

Usage

import { Carousel, CarouselContent, CarouselItem, CarouselPrevious, CarouselNext, CarouselControls, CarouselDots, CarouselPlayButton } 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>

Carousel accepts opts (Embla options such as align, loop and dragFree), plugins, orientation (horizontal or vertical) and setApi, which receives the Embla API so you can read or drive the carousel from outside. The scroll direction follows the surrounding DirectionProvider.

Set the width of each slide with a basis-* class on CarouselItem, for example basis-1/2 to show two at a time. The track uses negative margin and slides use start padding for gutters; adjust both together, as in -ms-3 with ps-3.

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. CarouselPlayButton renders only when autoplay is enabled, and the active dot fills as a progress bar.

Use the useCarousel hook inside a Carousel to build custom controls.

Examples

Multiple items

Shows two slides at a time with basis-1/2.

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 (
    <div className="mx-12 w-72">
      <Carousel orientation="horizontal" opts={{ align: "start" }}>
        <CarouselContent>

Loop

Wraps from the last slide back to the first with opts={{ loop: true }}.

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 (
    <div className="mx-12 w-72">
      <Carousel orientation="horizontal" opts={{ loop: true }}>
        <CarouselContent>

Vertical

Scrolls vertically, with the buttons 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 (
    <div className="mx-12 w-72">
      <div className="my-12">
        <Carousel orientation="vertical" opts={{ align: "start" }}>

Featured

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

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

const picks = [
  {
    eyebrow: "Today's pick",
    title: "Weekend breakfast",
    tint: "from-orange-500 to-red-500",
  },
  {

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"

const features = [
  {
    eyebrow: "Point of sale",
    title: "Take orders at the table.",
    tint: "from-blue-500 to-indigo-500",

Shelf

A drag-free product shelf with no visible buttons.

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

const popular = [
  {
    name: "Breakfast platter",
    price: "₺620",
    tint: "from-orange-500 to-red-500",
  },
  {
    name: "Grilled meatballs",

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"

const quotes = [
  { quote: "The checkout line is half as long.", author: "Ayşe Y. · Kadıköy" },
  {
    quote: "The kitchen finally keeps up on Fridays.",
    author: "Mert K. · Beşiktaş",

Gallery

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

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

const features = [
  {
    eyebrow: "Point of sale",
    title: "Take orders at the table.",
    tint: "from-blue-500 to-indigo-500",
  },
  {

Featured autoplay

The featured layout advancing every four seconds.

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

const picks = [
  {
    eyebrow: "Today's pick",
    title: "Weekend breakfast",
    tint: "from-orange-500 to-red-500",
  },
  {

Spotlight autoplay

The spotlight layout with autoplay and a pause button in place of the next button.

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

const features = [
  {
    eyebrow: "Point of sale",
    title: "Take orders at the table.",
    tint: "from-blue-500 to-indigo-500",

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"

const popular = [
  {
    name: "Breakfast platter",
    price: "₺620",
    tint: "from-orange-500 to-red-500",
  },
  {
    name: "Grilled meatballs",

Testimonials autoplay

Testimonials advancing every six seconds.

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

const quotes = [
  { quote: "The checkout line is half as long.", author: "Ayşe Y. · Kadıköy" },
  {
    quote: "The kitchen finally keeps up on Fridays.",
    author: "Mert K. · Beşiktaş",

API Reference

Anatomy11 parts
<Carousel>
<CarouselContent>
<CarouselItem />
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
<CarouselControls>
<CarouselDots />
<CarouselPlayButton />
<CarouselNext />
<CarouselPrevious />
</CarouselControls>
<CarouselPlayButton />
</Carousel>
01

Carousel

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

PropTypeDefaultDescription
optsCarouselOptions-Options passed to Embla Carousel.
pluginsCarouselPlugin-Embla Carousel plugins.
orientation"horizontal" | "vertical""horizontal"The scroll direction.
setApi(api: CarouselApi) => void-Receives the Embla Carousel API once it is ready.
autoplayboolean | numberfalseAdvances the slides automatically; a number sets the delay in milliseconds.

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

02

CarouselContent

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

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

03

CarouselItem

A single slide.

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

04

CarouselPrevious

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

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

05

CarouselNext

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

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

06

CarouselControls

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

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

07

CarouselDots

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

PropTypeDefaultDescription
variant"default" | "plain""default"default places the dots on a blurred pill background; plain removes the background and padding.

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

08

CarouselPlayButton

Toggles autoplay between playing and paused.

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

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.

Notes

  • Styling hooks: data-slot values carousel, carousel-content, carousel-item, carousel-previous, carousel-next, carousel-controls, carousel-dots and carousel-play-button.
  • The root sets data-playing while autoplay is running. Dots expose data-active on the current dot, and the dots container sets data-variant and data-autoplay.
  • CarouselPrevious and CarouselNext default to the secondary variant and icon size; CarouselPlayButton defaults to secondary and icon-sm.
  • In vertical carousels, standalone previous and next buttons are rotated 90 degrees; inside CarouselControls they are not.
Web

Web preview

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>
import EsuissUI
import SwiftUI

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

struct CarouselPick {
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-rn/carousel

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

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

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

Manual

  1. Install the 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, and the primitives components/primitives/carousel.tsx, components/primitives/use-render.tsx, and the animated view components/ui/animated-view.tsx from the next step.

  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 source 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.
  1. Install the 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, and the primitives components/primitives/carousel.tsx, components/primitives/use-render.tsx, and the animated view components/ui/animated-view.tsx from the next step.

  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 source 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.
  1. Install the 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, and the primitives components/primitives/carousel.tsx, components/primitives/use-render.tsx, and the animated view components/ui/animated-view.tsx from the next step.

  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 source 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.
  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(0x2997FF))
  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(0xA1A1A6))
  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, 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
}
swift/Components/TextVariant.swift
import SwiftUI

public enum TextVariant: CaseIterable, Sendable {
  case `default`, h1, h2, h3, h4, p, blockquote, code, lead, large, small, muted

  var style: TextStyle {
    switch self {
    case .h1: .xl3
    case .h2: .xl2
    case .h3: .xl
    case .h4, .lead, .large: .lg
    case .code, .small, .muted: .sm
    default: .base
    }
  }
  1. Add the files to your app target.
  1. Set minSdk to 24 or higher and add the dependencies:
build.gradle.kts
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 { Carousel, CarouselContent, CarouselItem, CarouselPrevious, CarouselNext, CarouselControls, CarouselDots, CarouselPlayButton } from "@/components/ui/carousel"
<View className="mx-12">
  <Carousel>
    <NumberSlides />
    <CarouselPrevious />
    <CarouselNext />
  </Carousel>
</View>

Set each slide's width with basis on CarouselItem, as a fraction of the viewport (for example 0.5 for two per view). Use opts for loop, align (start or center) and dragFree scrolling without snapping.

Pass autoplay as true for the default 5-second delay, or as a number of milliseconds. Put CarouselDots, CarouselPlayButton and nav buttons inside CarouselControls to show them in a row below the slides; CarouselDots takes variant="plain" to drop its background.

Use setApi to get a CarouselApi for scrolling from outside, or call useCarousel() inside the carousel to read the selected index and scroll state.

Examples

Multiple items

Two slides per view with basis={0.5}.

Web

Web preview

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>
import EsuissUI
import SwiftUI

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

struct CarouselPick {
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 { 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>
import EsuissUI
import SwiftUI

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

struct CarouselPick {
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 { 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]

export function CarouselVerticalExample() {
  return (
    <View className="my-12">
      <Carousel orientation="vertical" opts={{ align: "start" }}>
        <CarouselContent className="h-64">
          {slides.map((slide) => (
            <CarouselItem key={slide} basis={0.5}>
              <Card size="sm" className="h-full justify-center">
                <CardContent className="items-center justify-center">
import EsuissUI
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.

Web

Web preview

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"

const picks = [
  {
    eyebrow: "Today's pick",
    title: "Weekend breakfast",
    tint: "bg-orange-500",
  },
  { eyebrow: "New", title: "Grilled meatballs", tint: "bg-red-500" },
  { eyebrow: "Chef's special", title: "Lentil soup", tint: "bg-teal-500" },
  { eyebrow: "Dessert", title: "Künefe", tint: "bg-purple-500" },
]
import EsuissUI
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),
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.

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"

const picks = [
  {
    eyebrow: "Today's pick",
    title: "Weekend breakfast",
    tint: "bg-orange-500",
  },
  { eyebrow: "New", title: "Grilled meatballs", tint: "bg-red-500" },
  { eyebrow: "Chef's special", title: "Lentil soup", tint: "bg-teal-500" },
  { eyebrow: "Dessert", title: "Künefe", tint: "bg-purple-500" },
]

export function CarouselFeaturedExample() {
import EsuissUI
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"

const features = [
  { title: "Take orders at the table." },
  { title: "Every ticket, right on time." },
  { title: "A full room, every night." },
]

export function CarouselSpotlightExample() {
  return (
    <Carousel opts={{ loop: true }}>
      <CarouselContent>
        {features.map((feature) => (
          <CarouselItem key={feature.title}>
import EsuissUI
import SwiftUI

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

struct CarouselPick {
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.

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"

const features = [
  { title: "Take orders at the table." },
  { title: "Every ticket, right on time." },
  { title: "A full room, every night." },
]

export function CarouselAutoplayExample() {
  return (
    <Carousel autoplay={4000} opts={{ loop: true }}>
      <CarouselContent>
        {features.map((feature) => (
          <CarouselItem key={feature.title}>
import EsuissUI
import SwiftUI

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

struct CarouselPick {
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.

Web

Web preview

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

const picks = [
  {
    eyebrow: "Today's pick",
    title: "Weekend breakfast",
    tint: "bg-orange-500",
  },
  { eyebrow: "New", title: "Grilled meatballs", tint: "bg-red-500" },
  { eyebrow: "Chef's special", title: "Lentil soup", tint: "bg-teal-500" },
  { eyebrow: "Dessert", title: "Künefe", tint: "bg-purple-500" },
]

export function CarouselShelfExample() {
import EsuissUI
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)
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

API Reference

01

Carousel

Root that holds the scroll state and options.

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

02

CarouselContent

Scrolling track for the slides.

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

03

CarouselItem

One slide.

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

04

CarouselPrevious

Button that scrolls to the previous slide.

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

05

CarouselNext

Button that scrolls to the next slide.

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

06

CarouselControls

Row that lays out dots and buttons below the slides.

Also accepts the props of ViewProps.

07

CarouselDots

One pressable dot per snap point.

PropTypeDefaultDescription
variant"default" | "plain""default"default (on a control background) or plain.

Also accepts the props of ViewProps.

08

CarouselPlayButton

Toggles autoplay.

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

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".

Notes

  • Arrow icons are mirrored in right-to-left layouts.
  • Dot and progress animations respect the system Reduce Motion setting.
  • Uses bg-secondary, bg-foreground and bg-muted-foreground tokens; light and dark follow the system appearance.
NextChartPreviousCard

On this page

  1. 01Installation
    • CLI
    • Manual
  2. 02Usage
  3. 03Examples
    • Multiple items
    • Loop
    • Vertical
    • Featured
    • Spotlight
    • Shelf
    • Testimonials
    • Gallery
    • Featured autoplay
    • Spotlight autoplay
    • Shelf autoplay
    • Testimonials autoplay
  4. 04API Reference
    • Carousel
    • CarouselContent
    • CarouselItem
    • CarouselPrevious
    • CarouselNext
    • CarouselControls
    • CarouselDots
    • CarouselPlayButton
  5. 05Accessibility
  6. 06Notes
  7. 07Installation
    • Manual
  8. 08Usage
  9. 09Examples
    • Multiple items
    • Loop
    • Vertical
    • With page indicator
    • Featured
    • Spotlight
    • Autoplay
    • Shelf
  10. 10API Reference
    • Carousel
    • CarouselContent
    • CarouselItem
    • CarouselPrevious
    • CarouselNext
    • CarouselControls
    • CarouselDots
    • CarouselPlayButton
  11. 11Accessibility
  12. 12Notes