Composite

Compare

Before/after split with a draggable divider. Project anything (images, text, divs, components) via [wrCompareBefore] and [wrCompareAfter] attributes — the component stacks them and clips the after side.

Installation

import { WrCompare } from 'ngwr/compare';

@Component({ imports: [WrCompare] })
export class MyComponent {}

Image compare

Drag the divider — or use ←/→ on the focused slider.

<wr-compare [(position)]="pos">
  <img wrCompareBefore src="before.jpg" alt="" />
  <img wrCompareAfter src="after.jpg" alt="" />
</wr-compare>
Before
After

Vertical split

<wr-compare orientation="vertical">
  <img wrCompareBefore src="before.jpg" alt="" />
  <img wrCompareAfter src="after.jpg" alt="" />
</wr-compare>
Before
After

Arbitrary content

Works with any HTML. The before slot determines natural size; the after slot must occupy the same box.

<wr-compare>
  <div wrCompareBefore>…before content…</div>
  <div wrCompareAfter>…after content…</div>
</wr-compare>
Before
After

API

NameDescriptionTypeDefault
positionDivider position as a percentage (0–100). Two-way bindable.number50
ariaLabelAccessible name of the divider. Falls back to compare.label.string | nullnull
orientationDivider direction: - 'horizontal' — divider line is vertical, drags left/right. - 'vertical' — divider line is horizontal, drags up/down.'horizontal' | 'vertical''horizontal'
showHandleShow the round drag handle on the divider.booleantrue
disabledDisable interaction (divider stays put).booleanfalse
minPositionInitial position transform — accepts any number / numeric string.number0
maxPositionnumber100

Content slots

NameDescriptionTypeDefault
[wrCompareBefore] / [wrCompareAfter]Attributes marking the two pieces of projected content.attr