Ward events

On Solid 2, a ward tells what happens to its element as events, where Solid 1 takes Motion's callback props (onTap, onDragEnd…). Hear them from any ward: one you made, or one a Wardic element hands to its wardRef callback.

import { domAnimation, drag } from "@wardic/solid"
import { elements, makeWard } from "@wardic/solid/hooks"

// This page drags: its own Wardic instance has `drag` beside `domAnimation`.
const { createWard } = makeWard({ features: [domAnimation, drag], elements })

const card = createWard({ drag: true, whileTap: { scale: 0.95 } })

// Once:
await card.next("tap")
// At each one, in an effect:
createEffect(card.when("tap"), (info) => {
  console.log(info.point)
})
// Every time:
for await (const info of card.each("drag")) console.log(info.offset)

<div {...card} />
Member
next(name)A promise of the next such event.
each(name)An async iterable of every one from now on.
when(name)A memo of the latest, for an effect: pending until the first, so the effect runs at each one and never before. Read it in an effect, not in JSX. Write the effect's apply as a block, (info) => { setPicked(info) }: Solid 2 keeps what an apply returns as its cleanup, and a setter returns the value it set.
settled()The latest landing, pending while an animation runs: isPending(() => card.settled()) is "animating".
tapped()The latest tap, pending while a press is held: isPending(() => card.tapped()) is "pressed".

The events

NameWhenMotion's
settledAn animation lands.onAnimationComplete
hoverStart, hover, hoverEndThe pointer comes over the element, moves on it, and leaves.onHoverStart, onHoverEnd
pressStart, tap, tapCancelA press begins, ends on the element, or ends elsewhere or is cancelled.onTapStart, onTap, onTapCancel
dragStart, drag, dragEndA drag starts, moves, and ends: let go, or taken away by the page.onDragStart, onDrag, onDragEnd
directionLockWith dragDirectionLock, the axis a drag locked to.onDirectionLock
dragTransitionEndThe element comes to rest after it's let go.onDragTransitionEnd
panSessionStart, panStart, pan, panEndA pan's pointer goes down, it starts, moves, and ends.onPan…
viewportEnter, viewportLeaveThe element comes into view, and leaves it.onViewportEnter, onViewportLeave
layoutStart, layoutCompleteA layout animation starts moving, and lands.onLayoutAnimationStart, onLayoutAnimationComplete

A gesture's events need its Feature, as its while* prop does.

Types

  • WardEvents: what each event resolves to, by name; WardEvent, a name.
  • WardSettled: a landing.
  • WardGestures: the gesture layers on during an animation: hover's, tap's and drag's.
  • WardElement: the element an event happened on.
  • WardPoint: a point in the viewport, as clientX and clientY measure it.
  • WardPointInfo, WardPressInfo, WardDragInfo: a hover's or a press's event, a press's (with how it was made: input is "pointer" or "keyboard"), and a drag's or a pan's (its point, delta, offset and velocity).
  • WardDragEndInfo: a drag's or a pan's end, dragEnd's and panEnd's: its WardDragInfo and how it ended, endedBy: "release", let go; "cancel", the page took the pointer away (a pointercancel, a touch it scrolled by), which doesn't fling; "lost", its release was never seen.