본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

캐러셀(Carousel)

원문 보기 위키 갱신

요소들을 순환해 보여주는 대화형 슬라이드쇼 컴포넌트예요.

출처: 문서

본문

구조(Anatomy)

<Carousel.Root>
  <Carousel.Control>
    <Carousel.PrevTrigger />
    <Carousel.NextTrigger />
  </Carousel.Control>
  <Carousel.ItemGroup>
    <Carousel.Item />
  </Carousel.ItemGroup>
  <Carousel.IndicatorGroup>
    <Carousel.Indicator />
  </Carousel.IndicatorGroup>
</Carousel.Root>

예제(Examples)

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react'
import styles from 'styles/carousel.module.css'

const images = [
  { src: 'https://picsum.photos/seed/1/500/300', alt: 'Nature landscape' },
  { src: 'https://picsum.photos/seed/2/500/300', alt: 'City skyline' },
  { src: 'https://picsum.photos/seed/3/500/300', alt: 'Mountain view' },
  { src: 'https://picsum.photos/seed/4/500/300', alt: 'Ocean sunset' },
  { src: 'https://picsum.photos/seed/5/500/300', alt: 'Forest path' },
]

export const Basic = () => {
  return (
    <Carousel.Root className={styles.Root} slideCount={images.length}>
      <Carousel.Control className={styles.Control}>
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ArrowLeftIcon />
        </Carousel.PrevTrigger>
        <Carousel.ItemGroup className={styles.ItemGroup}>
          {images.map((image, index) => (
            <Carousel.Item className={styles.Item} key={index} index={index}>
              <img src={image.src} alt={image.alt} width="500" height="300" />
            </Carousel.Item>
          ))}
        </Carousel.ItemGroup>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ArrowRightIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
      <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
        {images.map((_, index) => (
          <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
        ))}
      </Carousel.IndicatorGroup>
    </Carousel.Root>
  )
}

제어(Controlled)

제어(controlled) 캐러셀 컴포넌트를 만들려면 page prop으로 캐러셀 상태를 관리하고, onPageChange 이벤트 핸들러가 호출될 때 이를 갱신하면 돼요:

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/carousel.module.css'

const images = [
  { src: 'https://picsum.photos/seed/1/500/300', alt: 'Nature landscape' },
  { src: 'https://picsum.photos/seed/2/500/300', alt: 'City skyline' },
  { src: 'https://picsum.photos/seed/3/500/300', alt: 'Mountain view' },
  { src: 'https://picsum.photos/seed/4/500/300', alt: 'Ocean sunset' },
  { src: 'https://picsum.photos/seed/5/500/300', alt: 'Forest path' },
]

export const Controlled = () => {
  const [page, setPage] = useState(0)

  return (
    <Carousel.Root className={styles.Root} slideCount={images.length} page={page} onPageChange={(e) => setPage(e.page)}>
      <Carousel.Control className={styles.Control}>
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ArrowLeftIcon />
        </Carousel.PrevTrigger>
        <Carousel.ItemGroup className={styles.ItemGroup}>
          {images.map((image, index) => (
            <Carousel.Item className={styles.Item} key={index} index={index}>
              <img src={image.src} alt={image.alt} width="500" height="300" />
            </Carousel.Item>
          ))}
        </Carousel.ItemGroup>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ArrowRightIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
      <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
        {images.map((_, index) => (
          <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
        ))}
      </Carousel.IndicatorGroup>
    </Carousel.Root>
  )
}

Root Provider

캐러셀을 제어하는 또 다른 방법으로 RootProvider 컴포넌트와 useCarousel 훅을 사용하는 방법이 있어요. 이렇게 하면 컴포넌트 외부에서 상태와 메서드에 접근할 수 있어요.

import { Carousel, useCarousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react'
import styles from 'styles/carousel.module.css'

const images = [
  { src: 'https://picsum.photos/seed/1/500/300', alt: 'Nature landscape' },
  { src: 'https://picsum.photos/seed/2/500/300', alt: 'City skyline' },
  { src: 'https://picsum.photos/seed/3/500/300', alt: 'Mountain view' },
  { src: 'https://picsum.photos/seed/4/500/300', alt: 'Ocean sunset' },
  { src: 'https://picsum.photos/seed/5/500/300', alt: 'Forest path' },
]

export const RootProvider = () => {
  const carousel = useCarousel({ slideCount: images.length })

  return (
    <div className="vstack">
      <output>Page: {carousel.page}</output>
      <Carousel.RootProvider className={styles.Root} value={carousel}>
        <Carousel.Control className={styles.Control}>
          <Carousel.PrevTrigger className={styles.Trigger}>
            <ArrowLeftIcon />
          </Carousel.PrevTrigger>
          <Carousel.ItemGroup className={styles.ItemGroup}>
            {images.map((image, index) => (
              <Carousel.Item className={styles.Item} key={index} index={index}>
                <img src={image.src} alt={image.alt} width="500" height="300" />
              </Carousel.Item>
            ))}
          </Carousel.ItemGroup>
          <Carousel.NextTrigger className={styles.Trigger}>
            <ArrowRightIcon />
          </Carousel.NextTrigger>
        </Carousel.Control>
        <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
          {images.map((_, index) => (
            <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
          ))}
        </Carousel.IndicatorGroup>
      </Carousel.RootProvider>
    </div>
  )
}

자동 재생(Autoplay)

Carousel.Root에 autoplay와 loop props를 전달해 캐러셀이 자동으로 재생되게 해요.

import { Carousel } from '@ark-ui/react/carousel'
import { ChevronLeftIcon, ChevronRightIcon, PauseIcon, PlayIcon } from 'lucide-react'
import styles from 'styles/carousel.module.css'

const images = [
  { src: 'https://picsum.photos/seed/1/500/300', alt: 'Nature landscape' },
  { src: 'https://picsum.photos/seed/2/500/300', alt: 'City skyline' },
  { src: 'https://picsum.photos/seed/3/500/300', alt: 'Mountain view' },
  { src: 'https://picsum.photos/seed/4/500/300', alt: 'Ocean sunset' },
  { src: 'https://picsum.photos/seed/5/500/300', alt: 'Forest path' },
]

export const Autoplay = () => {
  return (
    <Carousel.Root className={styles.Root} slideCount={images.length} autoplay loop>
      <Carousel.ItemGroup className={styles.ItemGroup}>
        {images.map((image, index) => (
          <Carousel.Item className={styles.Item} key={index} index={index}>
            <img src={image.src} alt={image.alt} width="500" height="300" />
          </Carousel.Item>
        ))}
      </Carousel.ItemGroup>
      <Carousel.Control className={styles.Control} data-justify="center">
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ChevronLeftIcon />
        </Carousel.PrevTrigger>
        <Carousel.AutoplayTrigger className={styles.AutoplayTrigger}>
          <Carousel.AutoplayIndicator fallback={<PlayIcon />}>
            <PauseIcon />
          </Carousel.AutoplayIndicator>
        </Carousel.AutoplayTrigger>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ChevronRightIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
    </Carousel.Root>
  )
}

호버 시 일시 정지(Pause on Hover)

이 기능은 내장돼 있지 않아요. Carousel.Context의 play()와 pause() 메서드로 호버 시 일시 정지를 구현할 수 있어요.

import { Carousel } from '@ark-ui/react/carousel'
import styles from 'styles/carousel.module.css'

const images = [
  { src: 'https://picsum.photos/seed/1/500/300', alt: 'Nature landscape' },
  { src: 'https://picsum.photos/seed/2/500/300', alt: 'City skyline' },
  { src: 'https://picsum.photos/seed/3/500/300', alt: 'Mountain view' },
  { src: 'https://picsum.photos/seed/4/500/300', alt: 'Ocean sunset' },
  { src: 'https://picsum.photos/seed/5/500/300', alt: 'Forest path' },
]

export const PauseOnHover = () => {
  return (
    <Carousel.Root className={styles.Root} slideCount={images.length} autoplay loop>
      <Carousel.Control className={styles.Control}>
        <Carousel.Context>
          {({ isPlaying }) => (
            <span className={styles.StatusText}>Autoplay is: {isPlaying ? 'playing' : 'paused'}</span>
          )}
        </Carousel.Context>
      </Carousel.Control>
      <Carousel.Context>
        {(api) => (
          <Carousel.ItemGroup
            className={styles.ItemGroup}
            onPointerOver={() => api.pause()}
            onPointerLeave={() => api.play()}
          >
            {images.map((image, index) => (
              <Carousel.Item className={styles.Item} key={index} index={index}>
                <img src={image.src} alt={image.alt} width="500" height="300" />
              </Carousel.Item>
            ))}
          </Carousel.ItemGroup>
        )}
      </Carousel.Context>
      <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
        {images.map((_, index) => (
          <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
        ))}
      </Carousel.IndicatorGroup>
    </Carousel.Root>
  )
}

썸네일 인디케이터(Thumbnail Indicators)

기본 인디케이터 점을 이미지 썸네일로 교체해요. 각 썸네일을 Carousel.Indicator 안에 렌더링해 각 슬라이드의 시각적 미리보기를 만들 수 있어요:

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react'
import styles from 'styles/carousel.module.css'

const images = [
  { src: 'https://picsum.photos/seed/1/500/300', alt: 'Nature landscape' },
  { src: 'https://picsum.photos/seed/2/500/300', alt: 'City skyline' },
  { src: 'https://picsum.photos/seed/3/500/300', alt: 'Mountain view' },
  { src: 'https://picsum.photos/seed/4/500/300', alt: 'Ocean sunset' },
  { src: 'https://picsum.photos/seed/5/500/300', alt: 'Forest path' },
]

export const ThumbnailIndicator = () => {
  return (
    <Carousel.Root className={styles.Root} defaultPage={0} slideCount={images.length}>
      <Carousel.Control className={styles.Control}>
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ArrowLeftIcon />
        </Carousel.PrevTrigger>
        <Carousel.ItemGroup className={styles.ItemGroup}>
          {images.map((image, index) => (
            <Carousel.Item className={styles.Item} key={index} index={index}>
              <img src={image.src} alt={image.alt} width="500" height="300" />
            </Carousel.Item>
          ))}
        </Carousel.ItemGroup>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ArrowRightIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
      <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
        {images.map((image, index) => (
          <Carousel.Indicator className={styles.ThumbnailIndicator} key={index} index={index}>
            <img src={image.src} alt={image.alt} width="500" height="300" />
          </Carousel.Indicator>
        ))}
      </Carousel.IndicatorGroup>
    </Carousel.Root>
  )
}

세로(Vertical)

Carousel.Root에 orientation="vertical" prop을 추가하면 캐러셀이 세로 스크롤로 전환돼요. 세로 갤러리나 콘텐츠 피드를 표시하는 데 유용해요.

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowDownIcon, ArrowUpIcon } from 'lucide-react'
import styles from 'styles/carousel.module.css'

const images = [
  { src: 'https://picsum.photos/seed/1/500/300', alt: 'Nature landscape' },
  { src: 'https://picsum.photos/seed/2/500/300', alt: 'City skyline' },
  { src: 'https://picsum.photos/seed/3/500/300', alt: 'Mountain view' },
  { src: 'https://picsum.photos/seed/4/500/300', alt: 'Ocean sunset' },
  { src: 'https://picsum.photos/seed/5/500/300', alt: 'Forest path' },
]

export const Vertical = () => {
  return (
    <Carousel.Root className={styles.Root} defaultPage={0} orientation="vertical" slideCount={images.length}>
      <Carousel.ItemGroup className={styles.ItemGroup}>
        {images.map((image, index) => (
          <Carousel.Item className={styles.Item} key={index} index={index}>
            <img src={image.src} alt={image.alt} width="500" height="300" />
          </Carousel.Item>
        ))}
      </Carousel.ItemGroup>
      <Carousel.Control className={styles.Control}>
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ArrowUpIcon />
        </Carousel.PrevTrigger>
        <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
          {images.map((_, index) => (
            <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
          ))}
        </Carousel.IndicatorGroup>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ArrowDownIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
    </Carousel.Root>
  )
}

동적(Dynamic)

슬라이드를 state에 저장하고 캐러셀 페이지를 동기화해 슬라이드를 동적으로 관리해요. Carousel.Root에 page prop과 onPageChange 핸들러를 전달하고, 슬라이드가 추가되거나 제거될 때 slideCount를 갱신해요. 이는 컴포넌트 상태와 캐러셀 사이의 양방향 상태 동기화를 보여줘요.

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon, PlusIcon } from 'lucide-react'
import { useState } from 'react'
import button from 'styles/button.module.css'
import styles from 'styles/carousel.module.css'

export const DynamicSlides = () => {
  const [slides, setSlides] = useState([0, 1, 2, 3, 4])
  const [page, setPage] = useState(0)

  const addSlide = () => {
    setSlides((prevSlides) => {
      const max = Math.max(...prevSlides)
      return [...prevSlides, max + 1]
    })
  }

  return (
    <div className="stack">
      <Carousel.Root
        className={styles.Root}
        slideCount={slides.length}
        page={page}
        onPageChange={(details) => setPage(details.page)}
      >
        <Carousel.ItemGroup className={styles.ItemGroup}>
          {slides.map((slide, index) => (
            <Carousel.Item className={styles.Item} key={index} index={index}>
              <div className={styles.Slide}>Slide {slide + 1}</div>
            </Carousel.Item>
          ))}
        </Carousel.ItemGroup>
        <Carousel.Control className={styles.Control}>
          <Carousel.PrevTrigger className={styles.Trigger}>
            <ArrowLeftIcon />
          </Carousel.PrevTrigger>
          <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
            {slides.map((_, index) => (
              <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
            ))}
          </Carousel.IndicatorGroup>
          <Carousel.NextTrigger className={styles.Trigger}>
            <ArrowRightIcon />
          </Carousel.NextTrigger>
        </Carousel.Control>
      </Carousel.Root>
      <button className={button.Root} onClick={addSlide}>
        <PlusIcon />
        Add Slide
      </button>
    </div>
  )
}

슬라이드로 스크롤(Scroll to Slide)

Carousel.Context로 캐러셀 API에 접근해 api.scrollToIndex(index)를 호출해 특정 슬라이드로 프로그래밍 방식으로 이동해요. 커스텀 내비게이션이나 슬라이드로 이동 기능을 만들 때 유용해요.

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react'
import button from 'styles/button.module.css'
import styles from 'styles/carousel.module.css'

export const ScrollTo = () => {
  return (
    <Carousel.Root className={styles.Root} slideCount={5}>
      <Carousel.Context>
        {(api) => (
          <button className={button.Root} onClick={() => api.scrollToIndex(3)}>
            Go to slide 4
          </button>
        )}
      </Carousel.Context>
      <Carousel.ItemGroup className={styles.ItemGroup}>
        {Array.from({ length: 5 }, (_, index) => (
          <Carousel.Item className={styles.Item} key={index} index={index}>
            <div className={styles.Slide}>Slide {index + 1}</div>
          </Carousel.Item>
        ))}
      </Carousel.ItemGroup>
      <Carousel.Control className={styles.Control}>
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ArrowLeftIcon />
        </Carousel.PrevTrigger>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ArrowRightIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
      <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
        {Array.from({ length: 5 }, (_, index) => (
          <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
        ))}
      </Carousel.IndicatorGroup>
    </Carousel.Root>
  )
}

페이지당 슬라이드(Slides Per Page)

Carousel.Root에 slidesPerPage prop을 설정해 여러 슬라이드를 동시에 표시해요. Carousel.Context의 api.pageSnapPoints를 사용해 개별 슬라이드가 아닌 페이지 기준으로 올바른 수의 인디케이터를 렌더링해요. spacing prop을 추가해 슬라이드 사이 간격을 제어해요.

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react'
import styles from 'styles/carousel.module.css'

export const SlidesPerPage = () => {
  const slides = Array.from({ length: 6 })

  return (
    <Carousel.Root className={styles.Root} slideCount={slides.length} slidesPerPage={2} spacing="20px">
      <Carousel.Control className={styles.Control}>
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ArrowLeftIcon />
        </Carousel.PrevTrigger>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ArrowRightIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
      <Carousel.ItemGroup className={styles.ItemGroup}>
        {slides.map((_, index) => (
          <Carousel.Item className={styles.Item} key={index} index={index}>
            <div className={styles.Slide}>Slide {index + 1}</div>
          </Carousel.Item>
        ))}
      </Carousel.ItemGroup>
      <Carousel.Context>
        {(api) => (
          <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
            {api.pageSnapPoints.map((_, index) => (
              <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
            ))}
          </Carousel.IndicatorGroup>
        )}
      </Carousel.Context>
    </Carousel.Root>
  )
}

간격(Spacing)

Carousel.Root의 spacing prop으로 슬라이드 사이 간격을 제어해요. slidesPerPage와 함께 사용하면 인접한 슬라이드의 일부 미리보기를 보여주는 레이아웃을 만들 수 있어요.

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react'
import styles from 'styles/carousel.module.css'

const slides = Array.from({ length: 6 })

export const Spacing = () => {
  return (
    <Carousel.Root className={styles.Root} slideCount={slides.length} slidesPerPage={1.5} spacing="48px">
      <span className={styles.StatusText}>spacing='48px'</span>
      <Carousel.ItemGroup className={styles.ItemGroup}>
        {slides.map((_, index) => (
          <Carousel.Item className={styles.Item} key={index} index={index}>
            <div className={styles.Slide}>{index + 1}</div>
          </Carousel.Item>
        ))}
      </Carousel.ItemGroup>
      <Carousel.Control className={styles.Control}>
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ArrowLeftIcon />
        </Carousel.PrevTrigger>
        <Carousel.Context>
          {(api) => (
            <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
              {api.pageSnapPoints.map((_, index) => (
                <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
              ))}
            </Carousel.IndicatorGroup>
          )}
        </Carousel.Context>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ArrowRightIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
    </Carousel.Root>
  )
}

가변 크기(Variable Sizes)

다른 너비의 슬라이드를 허용하려면 Carousel.Root에 autoSize prop을 설정해요. 이러면 각 Carousel.Item이 자신의 너비를 정의하고, 캐러셀이 자동으로 조정돼요. 개별 항목에 snapAlign prop을 사용해 각 항목이 어디에 스냅되는지 제어할 수도 있어요.

import { Carousel } from '@ark-ui/react/carousel'
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react'
import styles from 'styles/carousel.module.css'

const items = [
  { id: '1', width: '120px', label: 'Small' },
  { id: '2', width: '200px', label: 'Medium Size' },
  { id: '3', width: '80px', label: 'XS' },
  { id: '4', width: '250px', label: 'Large Content Here' },
  { id: '5', width: '150px', label: 'Regular' },
]

export const VariableSize = () => {
  return (
    <Carousel.Root className={styles.Root} slideCount={items.length} autoSize spacing="8px">
      <Carousel.Control className={styles.Control}>
        <Carousel.PrevTrigger className={styles.Trigger}>
          <ArrowLeftIcon />
        </Carousel.PrevTrigger>
        <Carousel.NextTrigger className={styles.Trigger}>
          <ArrowRightIcon />
        </Carousel.NextTrigger>
      </Carousel.Control>
      <Carousel.ItemGroup className={styles.ItemGroup}>
        {items.map((item, index) => (
          <Carousel.Item key={item.id} index={index} snapAlign="center">
            <div className={styles.Slide} style={{ width: item.width, height: '6rem' }}>
              {item.label}
            </div>
          </Carousel.Item>
        ))}
      </Carousel.ItemGroup>
      <Carousel.Context>
        {(api) => (
          <Carousel.IndicatorGroup className={styles.IndicatorGroup}>
            {api.pageSnapPoints.map((_, index) => (
              <Carousel.Indicator className={styles.Indicator} key={index} index={index} />
            ))}
          </Carousel.IndicatorGroup>
        )}
      </Carousel.Context>
    </Carousel.Root>
  )
}

API 레퍼런스(API Reference)

Props

Root

Props

slideCount Type: number Required: true Default Value: undefined Description: 슬라이드의 총 개수예요. SSR에서 초기 스냅 포인트를 렌더링하는 데 유용해요.

allowMouseDrag Type: boolean Required: false Default Value: false Description: 마우스 드래그로 스크롤하는 것을 허용할지 여부예요.

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

autoplay Type: boolean | { delay: number } Required: false Default Value: false Description: 자동으로 스크롤할지 여부예요. 기본 지연 시간은 4000ms예요.

autoSize Type: boolean Required: false Default Value: false Description: 가변 너비 슬라이드를 활성화할지 여부예요.

defaultPage Type: number Required: false Default Value: 0 Description: 렌더링될 때 스크롤할 초기 페이지예요. 캐러셀의 페이지를 제어할 필요가 없을 때 사용해요.

ids Type: Partial<{ root: string item: (index: number) => string itemGroup: string nextTrigger: string prevTrigger: string indicatorGroup: string indicator: (index: number) => string }> Required: false Default Value: undefined Description: 캐러셀 내 요소들의 id예요. 구성(composition)에 유용해요.

inViewThreshold Type: number | number[] Required: false Default Value: 0.6 Description: 항목이 화면 안에 있는지 판단하는 임계값이에요.

loop Type: boolean Required: false Default Value: false Description: 캐러셀이 순환(loop)할지 여부예요.

onAutoplayStatusChange Type: (details: AutoplayStatusDetails) => void Required: false Default Value: undefined Description: 자동 재생 상태가 변경될 때 호출되는 함수예요.

onDragStatusChange Type: (details: DragStatusDetails) => void Required: false Default Value: undefined Description: 드래그 상태가 변경될 때 호출되는 함수예요.

onPageChange Type: (details: PageChangeDetails) => void Required: false Default Value: undefined Description: 페이지가 변경될 때 호출되는 함수예요.

orientation Type: 'horizontal' | 'vertical' Required: false Default Value: "horizontal" Description: 요소의 방향이에요.

padding Type: string Required: false Default Value: undefined Description: 스크롤 가능한 영역 주위에 추가되는 여유 공간을 정의해서, 인접한 항목이 일부 화면에 남아 있도록 해요.

page Type: number Required: false Default Value: undefined Description: 캐러셀의 제어(controlled) 페이지예요.

slidesPerMove Type: number | 'auto' Required: false Default Value: "auto" Description: 한 번에 스크롤할 슬라이드 수예요.

auto로 설정하면 스크롤할 슬라이드 수는 slidesPerPage 속성에 의해 결정돼요.

slidesPerPage Type: number Required: false Default Value: 1 Description: 한 번에 표시할 슬라이드 수예요.

snapType Type: 'proximity' | 'mandatory' Required: false Default Value: "mandatory" Description: 항목의 스냅 타입이에요.

spacing Type: string Required: false Default Value: "0px" Description: 항목 사이의 간격이에요.

translations Type: IntlTranslations Required: false Default Value: undefined Description: 사용할 지역화된 메시지예요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: root data-orientation: The orientation of the carousel

AutoplayIndicator

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

fallback Type: string | number | bigint | boolean | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<...> Required: false Default Value: undefined Description: 자동 재생이 일시 중지됐을 때 렌더링할 fallback 콘텐츠예요.

AutoplayTrigger

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: autoplay-trigger data-orientation: The orientation of the autoplaytrigger data-pressed: Present when pressed

Control

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: control data-orientation: The orientation of the control

IndicatorGroup

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: indicator-group data-orientation: The orientation of the indicatorgroup

Indicator

Props

index Type: number Required: true Default Value: undefined Description: 인디케이터의 인덱스예요.

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

readOnly Type: boolean Required: false Default Value: false Description: 인디케이터가 읽기 전용인지 여부예요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: indicator data-orientation: The orientation of the indicator data-index: The index of the item data-readonly: Present when read-only data-current: Present when current

ItemGroup

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: item-group data-orientation: The orientation of the item data-dragging: Present when in the dragging state

Item

Props

index Type: number Required: true Default Value: undefined Description: 항목의 인덱스예요.

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

snapAlign Type: 'center' | 'start' | 'end' Required: false Default Value: "start" Description: 항목의 스냅 정렬이에요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: item data-index: The index of the item data-inview: Present when in viewport data-orientation: The orientation of the item

NextTrigger

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: next-trigger data-orientation: The orientation of the nexttrigger

PrevTrigger

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

데이터 속성(Data Attributes)

data-scope: carousel data-part: prev-trigger data-orientation: The orientation of the prevtrigger

ProgressText

Props

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

RootProvider

Props

value Type: UseCarouselReturn Required: true Default Value: undefined Description: undefined

asChild Type: boolean Required: false Default Value: undefined Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하며, 해당 요소의 props와 동작을 결합해요.

Context

API:

Property Type Description
page number The current index of the carousel
pageSnapPoints number[] The current snap points of the carousel
isPlaying boolean Whether the carousel is auto playing
isDragging boolean Whether the carousel is being dragged. This only works when draggable is true.
canScrollNext boolean Whether the carousel is can scroll to the next view
canScrollPrev boolean Whether the carousel is can scroll to the previous view
scrollToIndex (index: number, instant?: boolean) => void Function to scroll to a specific item index
scrollTo (page: number, instant?: boolean) => void Function to scroll to a specific page
scrollNext (instant?: boolean) => void Function to scroll to the next page
scrollPrev (instant?: boolean) => void Function to scroll to the previous page
getProgress () => number Returns the current scroll progress as a percentage
getProgressText () => string Returns the progress text
play VoidFunction Function to start/resume autoplay
pause VoidFunction Function to pause autoplay
isInView (index: number) => boolean Whether the item is in view
refresh VoidFunction Function to re-compute the snap points
and clamp the page

접근성(Accessibility)

Carousel WAI-ARIA design pattern을 준수해요.

더 알아보기 (Learn more)