Componentmedia0.79 KB gzipZero dependencies

ImageCompare

Before/after slider with clip-path inset controlled by draggable divider; BEFORE/AFTER labels.

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add image-compare

Or install the full npm package:

npm install bigbullui

Usage

tsx3 lines
import { ImageCompare } from "@/components/ui/image-compare" <ImageCompare before="/placeholder.svg?before" after="/placeholder.svg?after" alt="Comparison" />

Source code

image-compare.tsx + 1 helper

Zero third-party dependencies (2 local files shown in tabs below).

tsximage-compare.tsx91 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; export type ImageCompareProps = {  before: string;  after: string;  alt?: string;  defaultPosition?: number;} & React.HTMLAttributes<HTMLElement>; export function ImageCompare({ before, after, alt = "Comparison", defaultPosition = 50, ...props }: ImageCompareProps) {  const [position, setPosition] = React.useState(defaultPosition);  const [dragging, setDragging] = React.useState(false);   const handleMouseMove = (e: React.MouseEvent) => {    const container = e.currentTarget as HTMLElement;

Props

Interactive Prop Playground

Tweak parsed AST props below to generate ready-to-paste JSX.

tsx3 lines
import { ImageCompare } from "@/components/ui/image-compare"; <ImageCompare />
PropTypeDescription
beforestringURL or path to the before image.
afterstringURL or path to the after image.
altstringOptional alt text for images.
defaultPositionnumberDefault divider position (0-100).