Skip to main content

Starwind UI v3.0 is now available! Migration guide

1
2
3
4
5

Installation

Usage

---
import { Card, CardContent } from "@/components/starwind/card";
import {
Carousel,
CarouselContent,
CarouselItem,
CarouselNext,
CarouselPrevious,
} from "@/components/starwind/carousel";
---
<Carousel opts={{ align: "start" }} class="mx-auto w-full max-w-xs">
<CarouselContent>
{
Array.from({ length: 5 }).map((_, index) => (
<CarouselItem>
<div class="p-1">
<Card>
<CardContent class="flex aspect-square items-center justify-center p-6">
<span class="text-4xl font-semibold">{index + 1}</span>
</CardContent>
</Card>
</div>
</CarouselItem>
))
}
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
</Carousel>

Composition

Place each slide inside CarouselContent, then add the controls beside it:

Carousel
├── CarouselContent
│ ├── CarouselItem
│ └── CarouselItem
├── CarouselPrevious
└── CarouselNext

Behavior

Carousel uses Embla Carousel for touch gestures, orientation, looping, and plugin support.

Multiple Items

Show multiple items at once by using responsive basis classes on carousel items.

1
2
3
4
5

Carousels can be oriented vertically by setting the orientation prop.

1
2
3
4
5

Enable infinite looping with the loop option.

Loop

Plugins

Extend carousel functionality with Embla Carousel plugins. First install the plugin package, then manually initialize the Runtime primitive with createCarousel.

Info

You need to set autoInit={false} on the Carousel component, so that you can manually initialize it with your plugins and any additional options.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
autoInit boolean
Description
Controls whether Runtime behavior initializes automatically.
Classification
Primitive override
Primitive prop
carousel.Root.autoInit
opts CarouselOptions["opts"]
Description
Provides options to the underlying carousel engine.
Classification
Primitive override
Type imports
Astro import type { CarouselOptions } from "@starwind-ui/astro";
React import type { CarouselOptions } from "@starwind-ui/react";
Primitive prop
carousel.Root.opts

Inherits button attributes.

Contains the following additional props:

Prop Type Default Toggle details
size "sm" | "md" | "lg" | "icon-sm" | "icon" | "icon-lg" "icon"
Description
Selects the component's visual size.
Classification
Styled variant
variant "default" | "primary" | "secondary" | "outline" | "ghost" | "info" | "success" | "warning" | "error" "outline"
Description
Selects the component's visual variant.
Classification
Styled variant

Inherits button attributes.

Contains the following additional props:

Prop Type Default Toggle details
size "sm" | "md" | "lg" | "icon-sm" | "icon" | "icon-lg" "icon"
Description
Selects the component's visual size.
Classification
Styled variant
variant "default" | "primary" | "secondary" | "outline" | "ghost" | "info" | "success" | "warning" | "error" "outline"
Description
Selects the component's visual variant.
Classification
Styled variant

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Carousel.

Primitive API

Runtime API

Carousel primitive
createCarousel from @starwind-ui/runtime/carousel

Changelog

View version history v2.0.1 2 releases

v2.0.1

  • Named the generated aggregate default export so React and Astro tooling can identify the installed component cleanly.

v2.0.0

  • Rebuilt Carousel on Starwind Runtime for navigation, orientation, looping, and plugin lifecycle.
  • See the Carousel Primitive for the underlying unstyled anatomy and behavior API.