makeWard
The hooks' API, from
@wardic/solid/hooks: a prerelease, on npm'snexttag, built from thesolid-nextbranch. It may still change.
The hooks need nothing set up. createWard, createWards and createPresence are imported and called: the page's Environment is the DOM's, and each ward brings the Features its own config uses, loaded the first time one is asked for. No provider, no list of Features.
makeWard(options) is for a page that gives its Features at once, in its own bundle, with nothing loaded later, and with them its own Environment or the page's settings. setupWard gives the settings alone.
// src/lib/wardic.ts
import { domAnimation } from "@wardic/solid"
import { makeWard } from "@wardic/solid/hooks"
export const wardic = makeWard({ features: domAnimation, strict: true })
export const { createWard, createWards } = wardicCall it once, in a module of its own: make* is called once, in a module, and create* in a component, where Solid's own primitives are. It took the place of createWardic, deleted from Solid 2.
What it returns
| Member | |
|---|---|
createWard | One Subject's motion, made of runes: createWard, its wards bringing the Features given. |
createWards | A ward for each item of a list, kept until its exit has landed: createWards, its rows bringing them too. |
useAnimateLayout, createInstantLayoutTransition, createResetProjection | The layout hooks, in its type only when its Features have layout. |
w | Only when it's given elements. |
with(features) | The same again, with more Features. |
createPresence isn't among them: it brings no Features of its own, so it's imported by name from @wardic/solid/hooks, as on a page with nothing set up.
with(features) makes the same hooks with features beside its own, on the same page: for a module only the pages that lay out or drag import, so the rest ship neither.
// src/lib/wardic-layout.ts
import { layout } from "@wardic/solid"
import { wardic } from "./wardic.ts"
export const { createWard, createWards, useAnimateLayout } = wardic.with(layout)Options
| Option | |
|---|---|
features | The Features every ward, row and element it makes brings, wherever it's made: one, or a list, a load among them (() => import("./drag.ts").then((m) => m.drag)). Given at once, they're in the module's own bundle. |
elements | elements, for a w whose elements bring the same Features. |
And the page's settings, below. Its Features are asked for, not left out for the hooks' own: a makeWard that could be given none would hand back the hooks that load a Feature at its first use, and every app that called one would ship that loading. A page that gives settings and no Features calls setupWard.
The page's settings
makeWard and setupWard take the same settings: a <WardicProvider>'s, and a WardicConfig's transition, skipAnimations and transformPagePoint, for the page.
| Setting | |
|---|---|
env | The Environment Wardic runs in: the DOM's, DomLive, unless given. |
strict | In development, a wardic.* element throws, so every element ships only its Features. |
reducedMotion | "user" (the default) follows the visitor's setting, "always" reduces motion, "never" doesn't. A getter given for it is followed, as a provider's prop is. |
appear | false: on a server-rendered page, entrances wait for the JavaScript. "explain" plays them, and logs on the server why each one that can't play waits. |
nonce | The nonce your page's Content Security Policy gives inline styles: the <style> a server render writes for its entrances carries it. |
scaleCorrectors | Your own corrections of values a layout animation's scale would distort, by key: Motion's addScaleCorrector, given here. |
transition | The Config transition of every ward on the page that gives none of its own. A value or an accessor, read at each animation's start. |
skipAnimations | Every animation on the page lands at its end on the next frame: for end-to-end and visual tests. A value or an accessor, read at each animation's start. |
transformPagePoint | Where the points a drag or a pan on the page uses are: handed each in the viewport's coordinates. The function itself, called at each drag or pan start, so it follows whatever it reads. |
Every hook, w.* element and presence with no provider above it runs on the page's one runtime, built the first time one of them asks, and kept for the page's life. A provider above still wins, so a test or a second Environment keeps its own.
transition, skipAnimations and transformPagePoint are read where a WardicConfig's are, as the outermost config: a config scope or a WardicConfig an app nests lays over them. A Wardic scope is a page of its own, and none of the page's settings reach its wards.
On a server, each render gets its own context, so two requests never share their Appear animations' rules; a render with no hydration plays no Appear animation.
setupWard
// src/lib/wardic.ts
import { setupWard } from "@wardic/solid/hooks"
setupWard({ strict: true, reducedMotion: "user" })Gives the page its own Environment or settings, where its wards still bring the Features their own configs use: the hooks imported by name, nothing listed. Call it once, in a module that loads before anything renders, as a makeWard is. A page that sets nothing calls nothing; one that gives its Features at once gives them to makeWard with its settings instead.
elements
// src/lib/wardic.ts
import { domAnimation } from "@wardic/solid"
import { elements, makeWard } from "@wardic/solid/hooks"
export const { createWard, w } = makeWard({ features: domAnimation, elements })
<w.li whileHover={{ scale: 1.05 }} />Today's elements, for a makeWard that returns w as well. A value to import, not a flag, so a page that renders no w.* element ships none of their code. Its w.<tag> is the hooks' utility, each element's ward made by the makeWard's own createWard; its w.create and w.ward are today's, of the makeWard's Features. See w and Wardic instances.
Types
MakeWardOptions<F>: whatmakeWardtakes: the page's settings, itsfeaturesandelements.MakeWardSettings: the page's settings asmakeWardandsetupWardtake them:PageOptions, itsenvthe DOM's unless given, withtransition,skipAnimationsandtransformPagePoint.PageOptions: a page's settings:<WardicProvider>'s props, without its children and itsfeatures, which amakeWard's wards bring themselves.MadeWard<F>: whatmakeWardreturns for FeaturesF: its hooks, the layout hooks whenFhaslayout,wwhen it was givenelements, andwith.Elements: what gives amakeWarditsw:elements, and nothing else.