Compare Slider
NewInstallation
npx shadcn@latest add https://uibrik.com/r/compare-slider.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/compare-slider/compare-slider.tsx"use client"; // Two layers stacked in one frame; the top one is cut at the handle, so // dragging it wipes between them. Press anywhere to glide there, drag to // scrub, or focus the handle and use the arrow keys. On first view it sweeps // in from one side to show what it does. Each label fades as the handle covers // its side, so it never sits on top of the wrong layer. // // Everything moves with transforms only (no clip-path, no left/top), and the // position never goes through React state, so dragging stays on the compositor. import { animate, motion, useInView, useMotionValue, useMotionValueEvent, useReducedMotion, useSpring, useTransform, type AnimationPlaybackControls, type MotionValue, } from "motion/react"; import { useEffect, useRef, useState, type KeyboardEvent, type PointerEvent, type ReactNode } from "react";
Adds the files to
components/uibrik/compare-slider and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/compare-slider.Props
CompareSlider- beforeLabel
- Type string
- "Raw"
- Label on the start side. Empty hides it.
- afterLabel
- Type string
- "Graded"
- Label on the end side. Empty hides it.
- defaultPosition
- Type number
- 50
- Where the handle starts.
- orientation
- Type "horizontal" | "vertical"
- "horizontal"
- Wipe left to right, or top to bottom.
- intro
- Type boolean
- true
- Sweep the handle in from the far edge the first time it scrolls into view.
- hover
- Type boolean
- false
- Move the handle with the mouse, without pressing.
- radius
- Type number
- 20
- Corner radius.
- beforerequired
- Type ReactNode
- –
- The start layer, usually an <img>. Images fill and cover the frame.
- afterrequired
- Type ReactNode
- –
- The end layer, laid exactly over the start one.
- onChange
- Type (position: number) => void
- –
- Called with the handle position, 0–100.
- className
- Type string
- –
- Classes for the frame. Give it a size or aspect ratio.