Carousel Primitive
Carousel is a Starwind Runtime primitive in the viewport-measurement contract family.
Anatomy
Use the Astro primitive adapter to render Carousel anatomy with the Runtime wiring included.
---import { Carousel } from "@starwind-ui/astro/carousel";---
<Carousel.Root> <Carousel.Viewport> <Carousel.Container> <Carousel.Item>Slide 1</Carousel.Item> </Carousel.Container> </Carousel.Viewport> <Carousel.Previous>Previous</Carousel.Previous> <Carousel.Next>Next</Carousel.Next></Carousel.Root>Use the React primitive adapter when Carousel state participates in React rendering.
import { Carousel } from "@starwind-ui/react/carousel";
export function Example() { return ( <Carousel.Root> <Carousel.Viewport> <Carousel.Container> <Carousel.Item>Slide 1</Carousel.Item> </Carousel.Container> </Carousel.Viewport> <Carousel.Previous>Previous</Carousel.Previous> <Carousel.Next>Next</Carousel.Next> </Carousel.Root> );}Render the Carousel data-sw-* contract yourself, then initialize createCarousel.
<div data-sw-carousel role="region" aria-roledescription="carousel"> <div data-sw-carousel-viewport> <div data-sw-carousel-container> <div data-sw-carousel-item role="group" aria-roledescription="slide">Slide 1</div> </div> </div> <button data-sw-carousel-previous type="button">Previous</button> <button data-sw-carousel-next type="button">Next</button></div>
<script type="module"> import { createCarousel } from "@starwind-ui/runtime/carousel";
const root = document.querySelector("[data-sw-carousel]"); if (root) { createCarousel(root); }</script>API Reference
Root
The main element that owns the Carousel Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-carousel
- Role
- region
Props
Prop Type Default Toggle
orientation "horizontal" | "vertical" "horizontal"
- Description
- Sets the Carousel orientation.
- Kind
- option
- Targets
- root
- Full type
- "horizontal" | "vertical"
opts CarouselOptions["opts"] {}
- Description
- Passes options to the underlying carousel engine.
- Kind
- option
- Targets
- root
- Full type
- CarouselOptions["opts"]
plugins CarouselOptions["plugins"] -
- Description
- Passes plugins to the underlying carousel engine.
- Kind
- option
- Targets
- root
- Full type
- CarouselOptions["plugins"]
setApi (api: CarouselInstance["api"]) => void -
- Description
- Receives the carousel API instance when it is ready.
- Kind
- callback
- Targets
- root
- Full type
- (api: CarouselInstance["api"]) => void
autoInit boolean true
- Description
- Initializes the carousel automatically when the page loads.
- Kind
- option
- Targets
- root
- Full type
- boolean
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-carousel - Marks the Root part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-axis - Reflects the axis prop on the Root part.
data-opts - Reflects the opts prop on the Root part.
data-auto-init - Reflects the auto init prop on the Root part.
Viewport
The visible viewport for Carousel content.
- Default element
- div
- Discovery hook
- data-sw-carousel-viewport
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-carousel-viewport - Marks the Viewport part so Starwind Runtime can find it.
Container
Groups the scrolling or moving content for Carousel.
- Default element
- div
- Discovery hook
- data-sw-carousel-container
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-carousel-container - Marks the Container part so Starwind Runtime can find it.
Item
An interactive item inside the Carousel collection.
- Default element
- div
- Discovery hook
- data-sw-carousel-item
- Role
- group
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-carousel-item - Marks the Item part so Starwind Runtime can find it.
Previous
Moves Carousel to the previous item or slide.
- Default element
- button
- Discovery hook
- data-sw-carousel-previous
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-carousel-previous - Marks the Previous part so Starwind Runtime can find it.
State
Attribute Value Description
data-disabled - Reflects the disabled state on the Previous part.
Next
Moves Carousel to the next item or slide.
- Default element
- button
- Discovery hook
- data-sw-carousel-next
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-carousel-next - Marks the Next part so Starwind Runtime can find it.
State
Attribute Value Description
data-disabled - Reflects the disabled state on the Next part.
Runtime API
- Factory
createCarousel- Import
@starwind-ui/runtime/carousel- Root hook
- root
data-sw-carousel - Option props
- orientation, opts, plugins, setApi
Option Lifecycles
| Option | Lifecycle |
|---|---|
| orientation | refresh-required |
| opts | refresh-required |
| plugins | refresh-required |
| setApi | constructor-only |
Related Styled Components
Component Relationship
Carousel Direct primitive