Image compare
Drag a divider across two images to see what changed.
npx shadcn@latest add @silicon-ui/image-compareInstallation
With the shadcn CLI
npx shadcn@latest add @silicon-ui/image-compareManually
Install the dependencies
npm install lucide-react motionCopy these files into your project
- components/silicon-ui/image-compare/image-compare.tsx
- components/silicon-ui/image-compare/image-compare.module.css
Add the foundation, once per app, for the design and motion tokens
npx shadcn@latest add @silicon-ui/silicon-foundation
Usage
API reference
| Prop | Type | Default |
|---|---|---|
before*The original, shown on the left (or top). Pass an image with its own alt text; it is sized to cover the frame. | ReactNode | — |
after*The result, shown on the right (or bottom). | ReactNode | — |
positionWhere the divider sits, in percent from the left (or top). | number | — |
defaultPosition | number | 50 |
onPositionChange | (position: number) => void | — |
orientationVertical stacks the images top and bottom. Changing it swings the divider a quarter turn instead of swapping layouts. | "horizontal" | "vertical" | "horizontal" |
labelsCaptions over each side. They fade as the divider reaches them. Pass false to hide them. | [string, string] | false | ["Before", "After"] |
labelAccessible name of the divider. | string | "Before and after" |
aspectRatioFrame proportions, as a CSS aspect-ratio. | string | "3 / 2" |
className | string | — |
Dependencies
- npm
- lucide-reactmotion
- Registry
- silicon-motion-tokens