Coming from Motion

Wardic is Motion for React's API on Solid. The props and the components keep Motion's names, and a w.div takes what a motion.div takes, with the Features its Wardic instance gives. What changes comes from Solid:

  • A component runs once. Nothing re-renders: Wardic reads its props as they change. A value you move by hand is a signal given in style, not a motion value.
  • Hooks are create* primitives, as Solid names them: useScroll is createScroll.
  • On Solid 2, events come from the element's ward, next(name) and when(name), not from callback props.

The same card, in all three:

enter/solid2.tsx
import { createWard } from "@wardic/solid/hooks"

/** A card that rises into place as it mounts, and lifts under the pointer. */
export default function Enter() {
  const card = createWard({
    initial: { opacity: 0, y: 24 },
    animate: { opacity: 1, y: 0 },
    whileHover: { y: -4, scale: 1.02 },
    transition: { type: "spring", stiffness: 260, damping: 22 },
  })
  return (
    <div class="sample-card" {...card}>
      Hello, Wardic
    </div>
  )
}
enter/solid1.tsx
import { w } from "~/lib/wardic.ts"

/** A card that rises into place as it mounts, and lifts under the pointer. */
export default function Enter() {
  return (
    <w.div
      class="sample-card"
      initial={{ opacity: 0, y: 24 }}
      animate={{ opacity: 1, y: 0 }}
      whileHover={{ y: -4, scale: 1.02 }}
      transition={{ type: "spring", stiffness: 260, damping: 22 }}
    >
      Hello, Wardic
    </w.div>
  )
}
enter/foldkit.ts
import type { Html, HtmlBuilder } from "foldkit/html"
import { wardic } from "~/lib/wardic.ts"

/** A card that rises into place as it mounts, and lifts under the pointer. */
export const view = <Message,>(h: HtmlBuilder<Message>): Html => {
  const w = wardic.html(h)
  return w.div(
    [
      h.Class("sample-card"),
      w.Initial({ opacity: 0, y: 24 }),
      w.Animate({ opacity: 1, y: 0 }),
      w.WhileHover({ y: -4, scale: 1.02 }),
      w.Transition({ type: "spring", stiffness: 260, damping: 22 }),
    ],
    ["Hello, Wardic"],
  )
}
enter/motion.tsx
import * as m from "motion/react-m"

/** A card that rises into place as it mounts, and lifts under the pointer. */
export default function Enter() {
  return (
    <m.div
      className="sample-card"
      initial={{ opacity: 0, y: 24 }}
      animate={{ opacity: 1, y: 0 }}
      whileHover={{ y: -4, scale: 1.02 }}
      transition={{ type: "spring", stiffness: 260, damping: 22 }}
    >
      Hello, Wardic
    </m.div>
  )
}

Elements and Features

MotionWardic
motion.divw.div, from a Wardic instance, makeWard({ features, elements }) (on Solid 1, createWardic(features)), with the Features it was given. wardic.div has every Feature.
m.div under <LazyMotion features={domAnimation}>w.div from makeWard({ features: domAnimation, elements }), typed to those Features; or the binding's w.div under a <WardicProvider features={[domAnimation]}>, or on Solid 1 a <LazyWardic>
<LazyMotion features={() => import(…)}>A load in a Wardic instance's list, makeWard({ features: [domAnimation, () => import("./features.ts").then((m) => m.drag)], elements }), or a provider's features={…} for a section (on Solid 1, a <LazyWardic>'s too): its elements animate at once, and each Feature takes effect as it arrives.
<LazyMotion strict>strict on WardicProvider, or on Solid 1 LazyWardic: a wardic.* element below it throws in development.
domAnimation, domMaxThe same: domAnimation is hover, press, focus and in-view, domMax every Feature.
(none)A Feature per gesture, hover, press, focus, inView, pan and drag, and layout and colors (every CSS colour space beyond hex, rgb(), hsl() and the colour names).
motion.create(Component), with forwardMotionProps or type: "svg"w.create(Component), with the same options.
isMotionComponent, unwrapMotionComponent, isValidMotionPropisWardicComponent, unwrapWardicComponent, isValidWardicProp
(none)A ward on your own element: on Solid 2, w.ward(config), spread or given to a w.* element as wardRef; on Solid 1, w.createWard(config) spread onto it, or the use:w directive.

Motion's Features load for the whole page. Wardic's are a Wardic instance's, chosen in the module that makes it, or a section's, so a page ships only the Features its own elements use.

Components

MotionWardic
<AnimatePresence>: mode, custom, propagate, initial, onExitComplete, anchorX, anchorY, presenceAffectsLayoutOn Solid 2, <Presence>, from @wardic/solid/hooks: wait or pop for mode, a corner of pop's (pop="bottom-right") for anchorX and anchorY, enter={false} for initial={false}, affectsLayout for presenceAffectsLayout, custom and propagate the same, and for onExitComplete, presence.next("exitComplete"), from a createPresence given as its ref. On Solid 1, <AnimatePresence>, the same. Around many children, each DOM node is one: a <For>'s items, a <Show>'s child. A key on the element lets one that comes back mid-exit start where its leaver is.
usePresence, useIsPresent, usePresenceDataThe same names on Solid 1. On Solid 2, a ward under a presence: ward.exiting() for useIsPresent, ward.hold() for safeToRemove, and a function variant's custom for the presence's data.
<LayoutGroup id inherit>The same.
<Reorder.Group>, <Reorder.Item>The same, with a keyboard reorder built in. onReorderEnd is told once a reorder ends with a changed order, the moment to save it.
<MotionConfig>: transition, reducedMotion, skipAnimations, transformPagePoint, isValidProp<WardicConfig>, with the same props.

Hooks

MotionWardic
useMotionValue(0)A signal, given in style.
useTransform(value, input, output, options)createTransform(value, input, output, options)
useSpring(value, options), .jump(v)createSpring(value, options), the same jump(v)
useFollowValue(value, transition)createFollowValue(value, transition)
useScroll({ container, target, offset })createScroll({ container, target, offset })
useVelocity, useTime, useAnimationFramecreateVelocity, createTime, createAnimationFrame
useCycle(…)createCycle(…), its value an accessor
useInView, usePageInViewcreateInView, createPageInView
useReducedMotion, useReducedMotionConfigcreateReducedMotion, createReducedMotionConfig
useWillChange()createWillChange(), given as style={{ "will-change": willChange }}
useAnimate()createAnimate(), its scope given as ref={scope}. Sequences, stagger, and the controls (pause, play, time, speed…) are Motion's.
useAnimationControls()createAnimationControls()
useDragControls()createDragControls()
useInstantTransition, useInstantLayoutTransition, useResetProjectioncreateInstantTransition, createInstantLayoutTransition, createResetProjection
addScaleCorrector(…)<WardicProvider scaleCorrectors={…}>, the same entries
stagger, arc, cubicBezier, easeOut, …The same exports.

Props

The props keep Motion's names and meanings: initial, animate, exit, variants, custom, transition and its per-value entries (default, layout), the while* props, viewport, layout, layoutId, layoutScroll, layoutRoot, layoutDependency, layoutCrossfade, drag and its options, propagate, transformTemplate and onUpdate. Keyframes, times, ease, transitionEnd, delayChildren: stagger(…), path: arc(…) and type: "inertia" work as Motion's do.

Callbacks. On Solid 2, the element's ward gives each of Motion's callbacks as an event: await card.next("tap"), or an effect over card.when("hover"). On Solid 1, an element takes the callbacks (onHoverStart, onTap, onDrag, onViewportEnter, …), each called at its event with (event, info), and info.point in the viewport's coordinates.

Where Wardic differs

  • The controls say when an animation ends however it ends. Beside Motion's finished, which resolves only when it lands, controls.ended resolves at a stop, a cancel or a takeover too, with { landed }, so code after await controls.ended always runs.
  • A spring field makes a spring. With no type, a spring's field (stiffness, damping, mass, bounce, visualDuration, …) makes a spring, where Motion quietly tweens { stiffness: 300 }. repeat with no type makes a tween, since Wardic's springs don't repeat.
  • visualDuration alone is honoured, with no bounce, where Motion ignores it, and a visualDuration spring keeps the velocity it's handed.
  • An animation lands once every key it set has landed, the ones it left running included. So a hover that starts mid-entrance is told it landed once the entrance has landed too.
  • A long stall advances 0.5 s. After a main-thread stall longer than 0.5 s (a hidden tab, a debugger), an animation moves on 0.5 s and plays out the rest, where Motion's jumps to where the elapsed time puts it.
  • Layout animations account for scroll on their own: the scroll of every scrolling element around them, with no layoutScroll, the page's inside a position: fixed element, with no layoutRoot, and a position: sticky element's offset as it sticks.
  • A value you move is never written to. It's an input the element follows; what Wardic draws comes out of the element's ward, ward.read(key) on Solid 2 and ward.value(key) on Solid 1.
  • reducedMotion is followed as it changes, where Motion reads it once, as each element mounts.
  • An interrupted path lands back on its line. An axis the target leaves out, y under animate={{ x }}, ends where the path in flight was taking it, where Motion's ends where the Retarget caught it, a little further off each time.
  • A drag the page takes away doesn't fling. When the browser takes the pointer (a pointercancel: the page scrolling under a touch), the drag ends where it is with no throw, and onDragEnd's info says how it ended, endedBy: "cancel", where Motion's flings as if it were let go.
  • A locked drag starts at its lock. With dragDirectionLock, the drag starts once its axis is decided and claims only that axis, so a card that drags sideways inside a sheet that drags down doesn't start on a vertical swipe.
  • Space presses too, as a button takes it, beside Motion's Enter.
  • skipAnimations lands everything, layout animations and springs included, which Motion's leaves animating.
  • Mount animations play before hydration. On a server-rendered page, an element's entrance plays from the first paint, from CSS Wardic writes into the page, and the client takes it over mid-flight. appear={false} turns it off.
  • A target's own transition counts in animate. animate(el, { x: 100, transition: { duration: 1 } }, { delay: 0.2 }) runs a 1 s tween after 0.2 s: the options' fields are laid over the target's. Motion's animate runs on the options alone. Its transitionEnd is set before the animation is told it landed, and a cancel() puts it back.
  • An animation that loses a key to a later one mid-flight ends. As in Motion, it never resolves and its onComplete never comes. Once the keys it still draws have landed, its state reads "idle", as after a stop(), so a scope's settled() and a Foldkit Command stop waiting on it. Motion's reads its first value's state, and ends nothing.
  • Many like elements run as one. Motion's animate(elements, …) runs each element on its own. createBatch animates hundreds or thousands of them as one Batch, a change to all their targets costing about a twentieth of what it does one at a time: see Many elements at once.