Image Compare
A before/after slider: two layers on top of each other, the after layer cut at a divider the reader drags.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
position | number | 50 | The share of the before layer shown, from 0 to 100. |
orientation | ImageCompareOrientation | horizontal | horizontal puts the before layer on the left; vertical puts it on top. |
hover | boolean | false | The divider follows the pointer without a press. |
before-label | string | — | Text of the chip in the before layer's corner. |
after-label | string | — | Text of the chip in the after layer's corner. |
label | string | — | The handle's accessible name. Without it the name is built from the layers' alternative text. |
Slots
| Name | Description |
|---|---|
before | The layer shown before the divider: on the left, or on top when vertical. It sets the component's size. |
after | The layer shown past the divider, laid over the before layer. |
handle | Replaces the grip drawn in the handle. |
Events
| Name | Type | Description |
|---|---|---|
change | Event | When the divider settles: on release, or after a key. |
input | Event | While the divider moves, by pointer or key. Read position. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
frame | The box holding both layers. |
divider | The line between the layers. |
handle | The grip on the divider, the slider the keyboard moves. |
label | Each corner chip. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-image-compare--border-radius | length | 8px | Corner radius of the frame. |
--c2-image-compare--aspect-ratio | string | auto | The frame's aspect ratio; auto lets the before layer set it. |
--c2-image-compare--background | color | #f4f4f5 | Behind the layers, while they load. |
--c2-image-compare__divider--width | pixel | 2px | Thickness of the divider line. |
--c2-image-compare__divider--color | color | #ffffff | Colour of the divider line. |
--c2-image-compare__divider--box-shadow | shadow | 0 0 0 1px rgba(0, 0, 0, 0.25) | Edge of the divider line, so it reads on light images. |
--c2-image-compare__handle--size | pixel | 40px | Diameter of the handle. |
--c2-image-compare__handle--background | color | #ffffff | Fill of the handle. |
--c2-image-compare__handle--color | color | #18181b | The grip arrows. |
--c2-image-compare__handle--border | border | 0 solid transparent | Border of the handle. |
--c2-image-compare__handle--box-shadow | shadow | 0 2px 8px rgba(0, 0, 0, 0.25) | Shadow of the handle. |
--c2-image-compare__handle__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | Focus ring of the handle. |
--c2-image-compare__handle__focus--outline-offset | pixel | 2px | Gap between the handle and its focus ring. |
--c2-image-compare__label--background | color | rgba(24, 24, 27, 0.6) | Fill of the corner chips. |
--c2-image-compare__label--color | color | #ffffff | Text of the corner chips. |
--c2-image-compare__label--font-size | length | 12px | Text size of the corner chips. |
--c2-image-compare__label--font-weight | number | 600 | Text weight of the corner chips. |
--c2-image-compare__label--padding | length | 4px 10px | Inner spacing of the corner chips. |
--c2-image-compare__label--border-radius | length | 999px | Corner radius of the chips. |
--c2-image-compare__label--offset | pixel | 12px | Distance of the chips from the frame's edges. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under image-compare, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
compare | Compare images | — |
compareNamed | Compare: {0} / {1} | {0} before {1} after |
value | {0} before, {1} after | {0} before {1} after |