DocsBlog
  • 1.1.2

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Data Grid
Signals
Styling
Theming

Concepts

OverviewCompositionCerberus ContextTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridGroupLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPaginationPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Carousel

Used to cycle through a series of visual content within a container.

  • npm
  • source
  • recipe
  • Ark
import { Carousel } from '@cerberus/react'

Usage

With Indicators

Use the showIndicators prop to display indicators for each slide.

Primitives

You can utilize the primitive components or the css prop to customize the button.

ComponentDescription
CarouselRootThe context provider for the Carousel parts
CarouselControlThe container of the Next and Prev triggers
CarouselPrevTriggerThe button to navigate to the previous slide
CarouselNextTriggerThe button to navigate to the next slide
CarouselItemGroupThe container for the Carousel items
CarouselItemThe individual item within the Carousel
CarouselIndicatorGroupThe container for the indicators
CarouselIndicatorThe individual indicator representing each slide

Data Attributes

The primitives additionally use the following data attributes for custom styling:

AttributeValue
[data-scope]carousel
[data-part]root
[data-orientation]The orientation of the carousel

Root CSS Variables

The Root primitive sets the following CSS variables for customization:

VariableDescription
--slides-per-pageThe number of slides visible per page
--slide-spacingThe spacing between slides
--slide-item-sizeThe calculated size of each slide item

API

Props

The Carousel component is an abstraction of the primitives and accepts the following props:

NameDefaultDescription
showIndicatorsfalseWhether to show indicators for each slide.

The Carousel also accepts all the props of the Root component.

Parts

The CarouselParts API is an Object containing the full family of components.

Note

It is best to only use the CarouselParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

NameDescription
RootThe Carousel component which is the Provider for the family.
ControlThe container of the Next and Prev triggers.
PrevTriggerThe button to navigate to the previous slide.
NextTriggerThe button to navigate to the next slide.
ItemGroupThe container for the Carousel items.
ItemThe CarouselItem component which represents an individual item within the carousel.
IndicatorGroupThe container for the indicators.
IndicatorThe individual indicator representing each slide.

On this page

  • Edit this page on Github
Slide 0
Slide 1
Slide 2
Slide 3
Slide 4
Slide 6
Slide 7
Slide 8
Slide 9
Copy
Slide 0
Slide 1
Slide 2
Slide 3
Slide 4
Slide 5
Slide 7
Slide 8
Slide 9
Copy
import { Center } from '@/styled-system/jsx'
import { Button, Carousel, For } from '@cerberus/react'
import { ITEMS } from './items'

export function BasicDemo() {
  return (
    <Carousel.Root
      defaultPage={0}
      padding="1rem"
      slideCount={ITEMS.length}
      slidesPerPage={2.5}
      spacing="1rem"
    >
      <Carousel.ItemGroup>
        <For each={ITEMS}>
          {(item, idx) => (
            <Carousel.Item key={item.id} index={idx} asChild>
              <Center
                bgColor="page.bg.100"
                border="1px solid"
                borderColor="page.border.200"
                color="page.text.100"
                h="21rem"
                rounded="md"
                transitionProperty="all"
                transitionDuration="normal"
                transitionTimingFunction="cubic-bezier(0.075, 0.82, 0.165, 1)"
                willChange="z-index, transform, box-shadow"
                _hover={{
                  shadow: 'lg',
                  transform: 'scale(1.2)',
                  zIndex: 'decorator',
                }}
              >
                {item.content}
              </Center>
            </Carousel.Item>
          )}
        </For>
      </Carousel.ItemGroup>

      <Carousel.Control>
        <Carousel.PrevTrigger asChild>
          <Button shape="rounded" size="sm" usage="outlined">
            Prev
          </Button>
        </Carousel.PrevTrigger>
        <Carousel.NextTrigger asChild>
          <Button shape="rounded" size="sm" usage="outlined">
            Next
          </Button>
        </Carousel.NextTrigger>
      </Carousel.Control>
    </Carousel.Root>
  )
}
import { Center } from '@/styled-system/jsx'
import { Carousel, For } from '@cerberus/react'
import { ITEMS } from './items'

export function IndicatorDemo() {
  return (
    <Carousel.Root
      defaultPage={0}
      padding="1rem"
      slideCount={ITEMS.length}
      slidesPerPage={1}
      spacing="1rem"
      showIndicators
    >
      <Carousel.ItemGroup>
        <For each={ITEMS}>
          {(item, idx) => (
            <Carousel.Item key={item.id} index={idx} asChild>
              <Center
                bgColor="page.bg.100"
                border="1px solid"
                borderColor="page.border.200"
                color="page.text.100"
                h="16rem"
                rounded="md"
                transitionProperty="all"
                transitionDuration="normal"
                transitionTimingFunction="cubic-bezier(0.075, 0.82, 0.165, 1)"
                willChange="z-index, transform, box-shadow"
              >
                {item.content}
              </Center>
            </Carousel.Item>
          )}
        </For>
      </Carousel.ItemGroup>
    </Carousel.Root>
  )
}