Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
Data display

ImageComparison

Compares aligned before and after media with an accessible reveal control.

FrameworksAstro · React · Elements

Registry commandlumen add ImageComparison

InteractionEnhanced runtime

01

See it and copy it

Framework example

Choose Astro, React, or Elements to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.

AstroCode target · live preview uses Astro
A muted landscape illustration with mountains and a lake
The same landscape illustration with warmer light and deeper color

Illustrative color treatment. Move the control to compare the same framing.

View ImageComparison code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.
astro
---
import { Image, ImageComparison } from '@santi020k/lumen-astro'
---

<ImageComparison afterLabel="Color adjusted" beforeLabel="Original" label="Compare the landscape treatment" ratio={1.6} value={50}>
  <Image slot="before" alt="A muted landscape illustration with mountains and a lake" height={600} radius="none" src="/comparison-before.svg" width={960} />
  <Image slot="after" alt="The same landscape illustration with warmer light and deeper color" height={600} radius="none" src="/comparison-after.svg" width={960} />
  <p>Illustrative color treatment. Move the control to compare the same framing.</p>
</ImageComparison>
Edit ImageComparison in browser
02

Choose your target

Add this component

Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add ImageComparison
lumen add ImageComparison

API reference

Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.

AttributeValuesDefaultDescription
labelstringrequiredProvides the visible label for the native comparison range control.
before / afternamed Astro slots | ReactNode props | slotted child nodesrequiredSupplies media with matching framing and meaningful alternative text. Media is clipped, never resized as the range moves.
beforeLabel / afterLabelstring"Before" / "After"Labels each side. Elements uses before-label and after-label attributes.
value / defaultValuenumber50Percentage of the after image revealed (0–100). React value is controlled; defaultValue initializes local state. Astro value is the initial position; Elements value is reflected.
onValueChange(value: number) => void-React callback for user changes. Astro and Elements emit ui:image-comparison-change with { value }.
rationumber16 / 9Sets a shared positive finite aspect ratio. Invalid values fall back to 16 / 9.
fit"cover" | "contain""cover"Applies the same media fit to both layers.
disabledbooleanfalseDisables the native range without hiding either image. Astro keeps the range disabled until UIPrimitives enhances the static comparison.
localestringenvironment localeFormats the accessible percentage. Localize label, beforeLabel, and afterLabel separately.
mode"reveal" | "side-by-side" | "before" | "after""reveal"Changes the view without replacing media or resetting the reveal. Alternate views hide and disable the range. Change data-mode in enhanced Astro, mode in Elements, or the React prop.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML attributes-Forwards standard attributes to the root element unless the component consumes them.

Keyboard interactions

Keyboard behavior provided by the Astro UIPrimitives runtime for this component.

KeyAction
Arrow keysAdjust the reveal using the native range control; horizontal direction follows writing direction.
Home / EndReveal the full before / after image.

Runtime events

CustomEvents dispatched by the Astro UIPrimitives runtime for this component.

EventTargetDetailWhen
ui:image-comparison-changeImageComparison root{ value: number }Fires as the native range changes the percentage of the after image revealed.

Web docsFull catalog