BeforeAfter compares two images of the same frame: a 3 px ink divider with a 44 px handle splits them, and "Before" and "After" print on flat white plates in the top corners. The control is a native range laid over the whole frame, so a drag anywhere, the arrow keys and Home and End all move it, and vertical scrolling still works on phones.
Example#
Usage#
Use before and after for two images of the same frame where the difference is the story: a redesign, a speed fix, a cleaned-up layout. A divider splits the images; dragging anywhere, the arrow keys, Page Up and Down, Home and End all move it.
- Inputs.
beforeandafterare image elements with their own alt text;labelnames the comparison ("Fernlight homepage, before and after"). - The control is a native range over the frame, with a value text such as "40 % before", so keyboards and screen readers get the full control.
- Phones keep vertical scrolling: only sideways drags move the divider.
Anatomy#
- Frame
data-mk-part="frame" - Before
data-mk-part="before" - After
data-mk-part="after" - Divider
data-mk-part="divider" - Handle
data-mk-part="handle" - Caption
data-mk-part="caption"
Volume#
Reading layer: identical at every volume.
Quiet
Fernlight's homepage before and after the booking flow rebuild. Studio
Fernlight's homepage before and after the booking flow rebuild. Press
Fernlight's homepage before and after the booking flow rebuild. Rave
Fernlight's homepage before and after the booking flow rebuild.
Content#
beforeLabelandafterLabelstay "Before" and "After" unless dates say more: "March", "June".- The caption says what changed and by how much, with the number.
Do and don't#
Do
Don't
Before and after images with different crops, so the divider compares two different pages.
Accessibility#
- The range is named by
labeland says "40 % before" as its value. - Both images keep their own alt text.
- The frame shows the focus ring while the range has focus; the handle turns to the selected face.
| Keys | What happens |
|---|---|
| Tab | Focuses the divider (the frame shows the ring) |
| Arrow LeftorArrow Right | Moves the divider by 1 % |
| Page UporPage Down | Moves the divider by 10 % |
| HomeorEnd | Shows only the after or only the before image |
The colour pairs it prints, with their contrast on both papers:
| Text | Surface | Role | Bone | Night |
|---|---|---|---|---|
--mk-ink | --mk-paper-plate | body | 18.42:1 · Lc 105.1, passes | 15.02:1 · Lc 95.4, passes |
--mk-text-2 | --mk-surface | ui | not in this look | not in this look |
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
before required | ReactElement<unknown, string | React.JSXElementConstructor<any>> | none | The earlier image (an element with its own alt text). |
after required | ReactElement<unknown, string | React.JSXElementConstructor<any>> | none | The later image. |
label required | string | none | Names the range ("Fernlight homepage, before and after"). |
beforeLabel | string | none | |
afterLabel | string | none | |
caption | ReactNode | none | A visible caption under the frame. |
defaultValue | number | 50 | The share of the frame showing the before image, 0 to 100 (default 50). |
value | number | none | |
onValueChange | ((value: number) => void) | none | |
aspectRatio | string | "16 / 10" | Width / height of the frame (default "16 / 10"). |
Tokens#
System tokens (19)
--mk-border--mk-border-thick--mk-focus--mk-font-text--mk-on-selected--mk-radius-control--mk-radius-plate--mk-selected--mk-space-1--mk-space-2--mk-space-3--mk-surface--mk-surface-raised--mk-surface-sunken--mk-text--mk-text-2--mk-type-label-leading--mk-type-label-size--mk-type-label-weight
Its own properties (3)
--mk-before-after--mk-before-after-divider--mk-before-after-ratio
Changelog#
Arrived in 0.9.0.
CharacterCount,TableSortButton(in./table) andBeforeAfter. Read the whole entry