Componentmedia0.79 KB gzipZero dependencies
ImageCompare
Before/after slider with clip-path inset controlled by draggable divider; BEFORE/AFTER labels.
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add image-compareOr install the full npm package:
npm install bigbulluiUsage
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 helperZero 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 />| Prop | Type | Description |
|---|---|---|
| before | string | URL or path to the before image. |
| after | string | URL or path to the after image. |
| alt | string | Optional alt text for images. |
| defaultPosition | number | Default divider position (0-100). |