Introducing Nuvyx UI v1.0.0

Docs
Image Comparison

Image Comparison

An interactive image comparison slider that allows users to drag or hover to reveal two different images.

Installation

Usage

import {
  ImageSlider,
  ImageLayer,
  Divider,
} from "@/components/ui/image-comparison";
<ImageSlider className="h-96 w-full overflow-hidden rounded-xl">
  <ImageLayer
    src="/path/to/before-image.jpg"
    alt="Before Image"
    layer="first"
  />
  <ImageLayer src="/path/to/after-image.jpg" alt="After Image" layer="second" />
  <Divider />
</ImageSlider>;
 
{
  /* Vertical orientation with custom handle icon */
}
<ImageSlider
  className="h-96 w-full overflow-hidden"
  orientation="vertical"
  defaultPosition={40}
>
  <ImageLayer src="/path/to/original.jpg" alt="Original" layer="first" />
  <ImageLayer src="/path/to/edited.jpg" alt="Edited" layer="second" />
  <Divider handleIcon={<ArrowUpDown size={16} />} />
</ImageSlider>;
 
{
  /* Hover-controlled comparison */
}
<ImageSlider
  className="h-96 w-full overflow-hidden rounded-xl"
  hoverControl={true}
  defaultPosition={20}
>
  <ImageLayer src="/path/to/before.jpg" alt="Before" layer="first" />
  <ImageLayer src="/path/to/after.jpg" alt="After" layer="second" />
  <Divider width={4} handleSize={32} />
</ImageSlider>;

Props

ImageSlider

PropTypeDefaultDescription
childrenReact.ReactNodeundefinedContent of the slider, typically ImageLayer components and a Divider
classNamestring""Additional CSS classes to apply to the container
hoverControlbooleanfalseWhether to control the slider by hovering instead of dragging
orientationstring"horizontal"The orientation of the slider: "horizontal" or "vertical"
defaultPositionnumber50The initial position of the divider as a percentage (0-100)
animationConfigPartial<AnimationOptions>{ damping: 15, stiffness: 400, mass: 0.4 }Framer Motion spring animation options for the slider movement
dividerColorstring"#ffffff"Color of the divider line

ImageLayer

PropTypeDefaultDescription
classNamestring""Additional CSS classes to apply to the image
altstringundefinedAlt text for the image (required for accessibility)
srcstringundefinedSource URL of the image
layerstringundefinedWhich side of the divider this image appears on: "first" or "second"
loadingstring"eager"Image loading behavior: "lazy" or "eager"
prioritybooleanfalseWhether the image should be considered high priority for loading

Divider

PropTypeDefaultDescription
classNamestring""Additional CSS classes to apply to the divider
childrenReact.ReactNodeundefinedCustom content to display in the handle
widthnumber2Width of the divider line in pixels
showHandlebooleantrueWhether to show the handle on the divider
handleSizenumber24Size of the handle in pixels
handleColorstringundefinedColor of the handle (defaults to divider color if not specified)
handleIconReact.ReactNodeundefinedCustom icon to display in the handle
hitAreaSizenumber20Size of the invisible hit area around the divider