Skip to content

Peeling and moving

How a sticker peels, comes off, is picked up and stuck down, and how to keep where it's been put.

@cesarvenzac/stickersv0.2.0

A sticker is peeled by an edge: pressed near one, the sheet rolls up round a cylinder from that point, its back showing, and the point you hold stays under the pointer. Pointed at, an edge offers a hand. Let go before half of it is lifted and it lies back down on a spring.

Coming off

Past half way (comesOff, a share from 0 to 1), it comes off. A sticker that can't be moved peels the rest of the way and goes: onPeel is called, and restore() puts it back, pressed down where it was.

<Sticker
  src={bolt}
  onPeel={() => setOff(true)}
  handle={(sticker) => (ref.current = sticker)}
/>;

ref.current?.restore();

peelOff() peels it away from a corner, as a hand would.

Picked up

With drag, a sticker that comes off is in your hand, and a press anywhere else on it picks it up. It lifts toward you, its shadow growing, and follows the point you hold it by, swinging round behind it as a card dragged across a table does, tilting as it goes. Let go and it's pressed down where it is, turned as it was.

<div className="relative h-96">
  <Sticker src={star} drag onDrop={(place) => save(place)} />
</div>

It moves with translate and rotate, so a transform of your own stays yours. Its middle stays inside its parent's box unless bounds names another element, or null lets it go anywhere. The one picked up comes to the top of its siblings.

Where it sits

onDrop is told where it now sits: moved x and y pixels from where the page laid it out, turned angle radians. Give it back as place to put it there again.

<Sticker src={star} drag place={{ x: 40, y: -12, angle: 0.2 }} />

Keys and less motion

  • A sticker that can be moved or peeled is focusable. The arrow keys move one with drag (Shift for further), lifting it as they do; Enter or Space peels off one that can't be moved.
  • Under reduced motion, or with reducedMotion, nothing swings, tilts or bounces: a peel lies straight back down, a held sticker follows without turning.
  • label is what assistive tech reads: a sticker is an image.