BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/jolyui/ui/image-comparison

image-comparison

jolyui-ui/image-comparison
FreeComponent

jolyui/ui publishes no description for this item.

Live preview

live · rendered by the registry
Rendered by jolyui/ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://jolyui.dev/r/image-comparison.json

Source

ui/image-comparison.tsxjolyui.dev/r/image-comparison.json · first 6 KB
1import { GripHorizontal, GripVertical } from "lucide-react";
2import { motion, useMotionValue, useTransform } from "motion/react";
3import type React from "react";
4import { useCallback, useEffect, useRef, useState } from "react";
5import { cn } from "@/lib/utils";
6
7// Basic Comparison Slider
8interface ImageComparisonProps {
9 beforeImage: string;
10 afterImage: string;
11 beforeLabel?: string;
12 afterLabel?: string;
13 className?: string;
14 initialPosition?: number;
15 orientation?: "horizontal" | "vertical";
16 showLabels?: boolean;
17 sliderColor?: string;
18}
19
20export function ImageComparison({
21 beforeImage,
22 afterImage,
23 beforeLabel = "Before",
24 afterLabel = "After",
25 className,
26 initialPosition = 50,
27 orientation = "horizontal",
28 showLabels = true,
29 sliderColor = "hsl(var(--background))",
30}: ImageComparisonProps) {
31 const containerRef = useRef<HTMLDivElement>(null);
32 const [position, setPosition] = useState(initialPosition);
33 const [isDragging, setIsDragging] = useState(false);
34
35 const handleMove = useCallback(
36 (clientX: number, clientY: number) => {
37 if (!containerRef.current) return;
38
39 const rect = containerRef.current.getBoundingClientRect();
40 let newPosition: number;
41
42 if (orientation === "horizontal") {
43 newPosition = ((clientX - rect.left) / rect.width) * 100;
44 } else {
45 newPosition = ((clientY - rect.top) / rect.height) * 100;
46 }
47
48 setPosition(Math.max(0, Math.min(100, newPosition)));
49 },
50 [orientation],
51 );
52
53 const handleMouseDown = (e: React.MouseEvent) => {
54 e.preventDefault();
55 setIsDragging(true);
56 };
57
58 const handleTouchStart = () => {
59 setIsDragging(true);
60 };
61
62 useEffect(() => {
63 const handleMouseMove = (e: MouseEvent) => {
64 if (isDragging) {
65 handleMove(e.clientX, e.clientY);
66 }
67 };
68
69 const handleTouchMove = (e: TouchEvent) => {
70 if (isDragging && e.touches[0]) {
71 handleMove(e.touches[0].clientX, e.touches[0].clientY);
72 }
73 };
74
75 const handleEnd = () => {
76 setIsDragging(false);
77 };
78
79 if (isDragging) {
80 window.addEventListener("mousemove", handleMouseMove);
81 window.addEventListener("mouseup", handleEnd);
82 window.addEventListener("touchmove", handleTouchMove);
83 window.addEventListener("touchend", handleEnd);
84 }
85
86 return () => {
87 window.removeEventListener("mousemove", handleMouseMove);
88 window.removeEventListener("mouseup", handleEnd);
89// … truncated

What it pulls in

npm packages

  • motion

Files it writes

  • ui/image-comparison.tsx

Facts

Registry
jolyui/ui
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-02
Last confirmed
yesterday

Go to the source

Docs on jolyui/ui jolyui.dev Johuniq/jolyui on GitHub Raw registry item This item as JSON

More from jolyui/ui

All 199 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
ai-prompt-boxai-prompt-boxjolyui/uiComponentsFree4 deps
animated-beamanimated-beamjolyui/uiComponentsFree1 dep
animated-tableanimated-tablejolyui/uiComponentsFree2 deps
animated-theme-toggleanimated-theme-togglejolyui/uiComponentsFree2 deps
animated-toastanimated-toastjolyui/uiComponentsFree2 deps
animated-tooltipanimated-tooltipjolyui/uiComponentsFree1 dep
bento-gridbento-gridjolyui/uiComponentsFreeno deps
buttonbuttonjolyui/uiComponentsFree3 deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex