• Docs
  • Blog
    • 0.25.1

    • light

      dark

      system

      Switch mode
    • Cerberus

      Acheron

      Elysium

    Get Started
    Components
    Styling
    Theming

    Concepts

    OverviewCompositionTesting

    Layout

    Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

    Components

    AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

    Utilities

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

    Carousel

    A component for displaying a series of items in a sliding format.

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

    Usage

    Slide 1
    Slide 2
    Slide 3
    Slide 4
    Slide 5
    Slide 6
    Slide 7
    Slide 8
    Slide 9
    Slide 10
    Copy
    Basic Demo
    import { Button, Carousel, For } from '@cerberus/react'
    import { Center } from 'styled-system/jsx'
    import items from './items.json'
    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>
    )
    }

    With Indicators

    Use the showIndicators prop to display indicators for each slide.

    Slide 1
    Slide 2
    Slide 3
    Slide 4
    Slide 5
    Slide 6
    Slide 7
    Slide 8
    Slide 9
    Slide 10
    Copy
    With Indicators
    import { Button, Carousel, For } from '@cerberus/react'
    import { Center } from 'styled-system/jsx'
    import items from './items.json'
    function WithIndicatorsDemo() {
    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>
    )
    }

    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

    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
    Cerberus Design System | Docs