GitHub

ImageSlider

An image carousel component with two modes: carousel navigation and comparison slider.

Loading...

Basic Usage

import { ImageSlider } from "@corew500/ui"

const images = [
  { src: "/image1.jpg", alt: "Image 1" },
  { src: "/image2.jpg", alt: "Image 2" },
  { src: "/image3.jpg", alt: "Image 3" },
]

<ImageSlider images={images} />

Carousel Mode (Default)

Standard carousel with navigation arrows and indicators:

<ImageSlider
  images={images}
  mode="carousel"
  showControls
  showIndicators
/>

Comparison Mode

Draggable divider to compare two images:

<ImageSlider
  images={[
    { src: "/before.jpg", alt: "Before" },
    { src: "/after.jpg", alt: "After" },
  ]}
  mode="comparison"
/>

Auto Play

<ImageSlider
  images={images}
  autoPlay
  interval={5000} // 5 seconds
/>

Without Controls

<ImageSlider
  images={images}
  showControls={false}
  showIndicators={false}
/>

Custom Overlay Content

<ImageSlider
  images={images}
  overlay={(image, index) => (
    <div className="absolute bottom-4 left-4">
      <h3 className="text-white font-bold">{image.alt}</h3>
    </div>
  )}
/>

Props

PropTypeDefaultDescription
images*SliderImage[]Array of images to display
modeenumcarouselSlider mode: carousel or comparison
autoPlayenumfalseEnable auto-play in carousel mode
intervalnumber5000Auto-play interval in milliseconds
showControlsenumtrueShow navigation controls
showIndicatorsenumtrueShow indicator dots
onSlideChange(index: number) => voidCallback when slide changes
defaultIndexnumber0Initial slide index
variantenumdefault
aspectRatioenum16/9

Design Tokens

| Token | Description | |-------|-------------| | --image-slider-overlay-bg | Overlay background color | | --image-slider-handle-size | Comparison handle size | | --image-slider-indicator-size | Dot indicator size |

Accessibility

  • Arrow buttons have aria-label for screen readers
  • Images require alt text
  • Keyboard navigation with arrow keys
  • Touch/swipe support on mobile