Start

These are the docs of @wardic/solid@next, a prerelease built from the solid-next branch so you can try Wardic's hooks. Its API may still change. The stable 2.x, with Motion's components, has its own docs. Tell us how it goes in the hooks' discussion.

Wardic's binding for Solid 2 is @wardic/solid, and its hooks are at @wardic/solid/hooks. createWard makes one element's motion out of runes, and you spread it on the element: nothing to set up, no provider. Its Effect-typed parts move to a new Effect major only in a Wardic major. It works in a Solid 2 app rendered on the server or not.

On Solid 1, see Start on Solid 1: its binding is @wardic/solid/v1, deprecated, unchanged in this prerelease. On Foldkit, see Start on Foldkit: its binding is @wardic/foldkit.

Install

npm install @wardic/solid@next @wardic/dom@next effect solid-js @solidjs/web
pnpm add @wardic/solid@next @wardic/dom@next effect solid-js @solidjs/web
yarn add @wardic/solid@next @wardic/dom@next effect solid-js @solidjs/web
bun add @wardic/solid@next @wardic/dom@next effect solid-js @solidjs/web

effect, solid-js and @solidjs/web are peers: Wardic uses the copies your app has. @wardic/dom at @next too, so it's the one @wardic/solid@next was built with.

Your first ward

A ward takes Motion's animation keys: it animates from initial to animate, and to its whileHover target while the pointer is over its Subject, the element it's spread on.

import { createWard } from "@wardic/solid/hooks"

export function Card() {
  const card = createWard({ initial: { opacity: 0, y: 24 }, animate: { opacity: 1, y: 0 }, whileHover: { y: -4, scale: 1.02 } })
  return (
    <div class="card" {...card}>
      Hello, Wardic
    </div>
  )
}
Live demo
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>
  )
}

Nothing is set up: a ward brings the Features its own config uses, here hover, each a module of its own that the page fetches the first time a ward asks for it. Until it arrives, its keys do nothing, and values animate at once. A ward's when("ready") says when they're all there.

Runes

A ward is made of runes: createWard(...runes), each a config, or a rune made once with createRune and shared by every ward that takes it. A rune that listens is a function rune, createRune((ward) => …): it's handed its ward, whose when and next hear the ward's events.

import { createRune, createWard } from "@wardic/solid/hooks"

const fadesIn = createRune({ initial: { opacity: 0 }, animate: { opacity: 1 } })
const lifts = createRune({ whileHover: { y: -4 } })

export function Card() {
  const card = createWard(fadesIn, lifts)
  return <div class="card" {...card} />
}

See createWard and Runes.

Features at once

Wards that shouldn't wait for theirs come from a makeWard, in a module of its own, given the Features at once, and with the page's settings:

// src/lib/wardic.ts
import { domAnimation } from "@wardic/solid"
import { makeWard } from "@wardic/solid/hooks"

export const wardic = makeWard({ features: domAnimation, strict: true })

Its createWard brings those Features, and wardic.with(...) the same with more, a lazy load among them. See makeWard.

Lists, leaving and the rest

From 2.x

<AnimatePresence> is <Presence>. createWardic is makeWard, which also takes a lazy load of Features in place of <LazyWardic>. usePresence, useIsPresent and usePresenceData are a ward's own exiting() and hold(). PresenceContext and usePresenceContext are gone. wardic.* still works, deprecated. <WardicProvider>, <WardicConfig>, <LayoutGroup>, <Reorder.Group>, <Reorder.Item> and w.<tag> stay, built on the hooks. Many of the guides' samples still show 2.x's w.* elements: they run here, and the hooks' form is in the reference.

Rendered on the server

On a server-rendered page, an element arrives in the HTML already at initial, so it never flashes at its target first. Its entrance plays from the first paint, before the JavaScript has loaded, and the client takes it over mid-flight when it hydrates. See Server rendering.

Next