Thinking UI

Before / AfterPRO

A draggable divider compares the original with the upscaled or enhanced result.

Code

1 file · 254 lines of TypeScriptPRO

Before / After is part of Pro

Get its source, the one-paste agent prompt and all 113 components, for a one-time $99.

Motion notes

  • The handle glides to clicks and keyboard steps on a layout spring, then sticks to the pointer once it has caught up, so dragging never feels laggy.
  • While nobody touches it, the handle sways a few percent on its own. The sway is a visual offset on top of the real value, so it never changes what's reported.
  • With no separate original, the same image is pixelated, softened and desaturated by an inline SVG filter, so one asset is enough for a demo.
  • Labels fade as their half gets too thin to hold them. With reduced motion the handle jumps and the idle sway is off.

Usage

Example
<ImageCompare
    src={upscaled.url}
    beforeSrc={original.url}
    beforeLabel="Original"
    afterLabel="4× upscale"
  />

Props

PropTypeDefaultDescription
srcstring—The enhanced image, shown right of the handle.
beforeSrcstring—A separate original. Leave it out to show `src` degraded.
beforeFilterstring—CSS filter for the original, replacing the built-in pixelate.
altstring—Describes the image for screen readers.
beforeLabelstring"Original"Label on the left half.
afterLabelstring"Enhanced"Label on the right half.
positionnumber—Controlled handle position, 0–100 from the left.
defaultPositionnumber50Starting position when uncontrolled.
onPositionChange(position: number) => void—Called while dragging and on arrow keys.
hintbooleantrueSways the handle while idle, until the first interaction.
classNamestring—Size it here; the default is w-64 at 3:4.