Carousel

Shows a set of slides one at a time, with buttons, dots, or swipes to move between them.

Usage

Code
import { Carousel } from '@leverui/components';
Code
<Carousel.Root>
  <Carousel.ItemGroup>
    <Carousel.Item />
  </Carousel.ItemGroup>
  <Carousel.Control>
    <Carousel.AutoplayTrigger>
      <Carousel.AutoplayIndicator />
    </Carousel.AutoplayTrigger>
    <Carousel.PrevTrigger />
    <Carousel.Indicators />
    <Carousel.NextTrigger />
    <Carousel.ProgressText />
  </Carousel.Control>
</Carousel.Root>

Shortcuts

Renders one indicator per slide. Replaces:

Code
<Carousel.IndicatorGroup>
  <For each={items} keyed={false}>
    {(_, index) => <Carousel.Indicator index={index} />}
  </For>
</Carousel.IndicatorGroup>

With:

Code
<Carousel.Indicators />

Examples

Controlled

Use the page and onPageChange props to programatically control the active carousel page.

Store

Alternatively, use the useCarousel hook to create a carousel store and pass it to the Carousel.RootProvider component for full programmatic control.

Arrows

Use the Carousel.PrevTrigger and Carousel.NextTrigger components to create arrows that navigate between slides.

Indicators

Use the Carousel.Indicators component to render visual indicators that help users track the progress of the carousel and jump to specific slides.

Thumbnail Indicators

Here's an example that uses an image thumbnail as a custom indicator.

Spacing

Use the spacing prop to control the spacing between slides.

Variable Size

Use the autoSize prop to allow variable width/height slide items.

Vertical

Use the orientation prop to vertical to transform your carousel into a vertical slider.

Mouse Drag

Use the allowMouseDrag prop to enable mouse dragging on the carousel.

Autoplay

Pass the autoPlay prop to the Carousel.Root component to make the carousel automatically move between slides.

Lightbox

Compose the Carousel component with the Dialog component to create a lightbox.

Image Carousel

Here's an example that shows how to create an image carousel for a product showcase.

Property Card

Here's an example that shows how to compose the Carousel component with other components to create a property card carousel.

Props

Root

PropDefaultTypeDescription
countrequirednumberTotal number of slides.
inViewThreshold0.6number | number[]Visible share of a slide that counts as in view.
orientationhorizontal'horizontal' | 'vertical'Scroll direction.
slidesPerMoveautonumber | 'auto'Slides to scroll at a time.
slidesPerPage1numberSlides shown at a time.
snapTypemandatory'proximity' | 'mandatory'How strictly scrolling snaps to a slide.
spacing1remstringSpace between slides.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the part's props.
unstyledfalsebooleanTurn off the Lever UI styles.
allowMouseDragfalsebooleanScroll by dragging with a mouse.
autoPlayfalseboolean | { delay: number }Advance on its own. Default delay: 4000ms.
autoSizefalsebooleanLet slides have different widths.
defaultPage0numberStarting page.
ids—Element ID mapYour own ids, in place of the generated ones.
loopfalsebooleanWrap from the last slide to the first, and back.
onAutoplayStatusChange—(details) => voidCalled when the autoplay status changes.
onDragStatusChange—(details) => voidCalled when the drag status changes.
onPageChange—(details) => voidCalled when the page changes.
padding—stringSpace that keeps neighboring slides partly in view.
page—numberCurrent page, when you control it.
translations—IntlTranslationsTranslated text for the built-in labels.

ItemGroup

PropDefaultTypeDescription
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the part's props.

Item

PropDefaultTypeDescription
indexrequirednumberPosition in the list of slides.
snapAlignstart'center' | 'start' | 'end'Where the item lines up when it snaps.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the part's props.

Control

PropDefaultTypeDescription
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the part's props.

Give the root an accessible name, such as aria-label. Label each icon-only trigger too.

Explorer

Click a part name to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts