Exit animations
An element that Solid removes is gone at once. Inside a <Presence>, from @wardic/solid/hooks (on Solid 1, <AnimatePresence>), one with an exit stays on the page until that animation has played, then goes.
import { domAnimation, layout } from "@wardic/solid"
import { elements, makeWard, Presence } from "@wardic/solid/hooks"
import { createSignal, For } from "solid-js"
// This page lays out: its own Wardic instance brings `layout`, so pages that don't never load it.
const { w } = makeWard({ features: [domAnimation, layout], elements })
/** Chips that pop in and out: each plays its `exit` before it goes, and the rest close the gap. */
export default function Chips() {
const [chips, setChips] = createSignal([1, 2, 3])
let next = 4
const add = () => setChips((all) => [...all, next++])
const remove = (chip: number) => setChips((all) => all.filter((one) => one !== chip))
return (
<div class="sample-stack">
<button class="sample-button" onClick={add}>
Add
</button>
<ul class="sample-chips">
{/* pop takes a leaving chip out of the row at once, so the rest move up as it goes. */}
<Presence pop>
<For each={chips()}>
{(chip) => (
<w.li class="sample-chip" layout initial={{ opacity: 0, scale: 0.6 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }}>
<button aria-label={`Remove ${chip}`} onClick={() => remove(chip)}>
{chip} ×
</button>
</w.li>
)}
</For>
</Presence>
</ul>
</div>
)
}import { AnimatePresence, createWardic, domAnimation, layout } from "@wardic/solid/v1"
import { createSignal, For } from "solid-js"
// This page lays out: its own Wardic instance brings `layout`, so pages that don't never load it.
const { w } = createWardic([domAnimation, layout])
/** Chips that pop in and out: each plays its `exit` before it goes, and the rest close the gap. */
export default function Chips() {
const [chips, setChips] = createSignal([1, 2, 3])
let next = 4
const add = () => setChips((all) => [...all, next++])
const remove = (chip: number) => setChips((all) => all.filter((one) => one !== chip))
return (
<div class="sample-stack">
<button class="sample-button" onClick={add}>
Add
</button>
<ul class="sample-chips">
{/* popLayout takes a leaving chip out of the row at once, so the rest move up as it goes. */}
<AnimatePresence mode="popLayout">
<For each={chips()}>
{(chip) => (
<w.li class="sample-chip" layout initial={{ opacity: 0, scale: 0.6 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }}>
<button aria-label={`Remove ${chip}`} onClick={() => remove(chip)}>
{chip} ×
</button>
</w.li>
)}
</For>
</AnimatePresence>
</ul>
</div>
)
}import { DomLive } from "@wardic/dom"
import * as Schema from "effect/Schema"
import type { Html, HtmlBuilder } from "foldkit/html"
import { defineMessageUnion } from "foldkit/message"
import { Features, Wardic } from "@wardic/foldkit"
// This app lays out and plays exits: its Handle names `layout` and `presence` among its Features.
const wardic = Wardic.make({ env: DomLive, features: [Features.domAnimation, Features.layout, Features.presence] })
const Model = Schema.Struct({ chips: Schema.Array(Schema.Number), next: Schema.Number })
type Model = typeof Model.Type
const Message = defineMessageUnion({ Add: {}, Remove: { chip: Schema.Number } })
type Message = typeof Message.Type
export const init = (): Model => ({ chips: [1, 2, 3], next: 4 })
export const update = (model: Model, message: Message) =>
Message.match(message, {
Add: () => ({ model: { chips: [...model.chips, model.next], next: model.next + 1 } }),
Remove: ({ chip }) => ({ model: { ...model, chips: model.chips.filter((one) => one !== chip) } }),
})
/** Chips that pop in and out: each plays its `Exit` before it goes, and the rest close the gap. */
export const view = (model: Model, h: HtmlBuilder<Message>): Html => {
const w = wardic.html(h)
return h.div([h.Class("sample-stack")], [
h.button([h.Class("sample-button"), h.OnClick(Message.Add())], ["Add"]),
// popLayout takes a leaving chip out of the row at once, so the rest move up as it goes. Each
// chip is keyed, so Foldkit's patch keeps it the same element while it leaves.
w.ul(
[h.Class("sample-chips"), w.Presence({ mode: "popLayout" })],
model.chips.map((chip) =>
w.keyed("li")(String(chip), [h.Class("sample-chip"), w.Layout(true), w.Initial({ opacity: 0, scale: 0.6 }), w.Animate({ opacity: 1, scale: 1 }), w.Exit({ opacity: 0, scale: 0.6 })], [
h.button([h.AriaLabel(`Remove ${chip}`), h.OnClick(Message.Remove({ chip }))], [`${chip} ×`]),
]),
),
),
])
}import { AnimatePresence, domMax, LazyMotion } from "motion/react"
import * as m from "motion/react-m"
import { useRef, useState } from "react"
/** Chips that pop in and out: each plays its `exit` before it goes, and the rest close the gap. */
export default function Chips() {
const [chips, setChips] = useState([1, 2, 3])
const next = useRef(4)
const add = () => setChips((all) => [...all, next.current++])
const remove = (chip: number) => setChips((all) => all.filter((one) => one !== chip))
return (
// The chips close the gap with `layout`, so this page brings `domMax`, Motion's layout and drag, itself.
<LazyMotion features={domMax}>
<div className="sample-stack">
<button className="sample-button" onClick={add}>
Add
</button>
<ul className="sample-chips">
{/* popLayout takes a leaving chip out of the row at once, so the rest move up as it goes. */}
<AnimatePresence mode="popLayout">
{chips.map((chip) => (
<m.li key={chip} className="sample-chip" layout initial={{ opacity: 0, scale: 0.6 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }}>
<button aria-label={`Remove ${chip}`} onClick={() => remove(chip)}>
{chip} ×
</button>
</m.li>
))}
</AnimatePresence>
</ul>
</div>
</LazyMotion>
)
}What counts as a child
Each element directly inside is a child of its own: a <Show>'s element, or each of a <For>'s, an SVG one as much as an HTML one. For one element that swaps for another, a <Show keyed> makes each value a new child, so the last one leaves as the next one enters:
// Solid 1: <AnimatePresence mode="wait">, its own entry's.
import { Presence } from "@wardic/solid/hooks"
<Presence wait>
<Show when={tab()} keyed>
{(name) => <w.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}>{name}</w.div>}
</Show>
</Presence>A key on the element, as in Motion, lets one that comes back while it's still leaving pick up from where its leaver is, rather than enter again.
Inside an <svg>
A <Presence> can sit inside an <svg>, with SVG elements for children: each point here grows in on its radius, and shrinks out before it goes.
import { Presence } from "@wardic/solid/hooks"
import { w } from "~/lib/wardic.ts"
import { createSignal, For } from "solid-js"
/** Where point `id` sits on the 320 × 160 plot, spread evenly from its number, and which of four colours it takes. */
const pointAt = (id: number) => ({ cx: 20 + ((0.5 + id * 0.7549) % 1) * 280, cy: 20 + ((0.5 + id * 0.5698) % 1) * 120, tone: id % 4 })
/** Points on a plot that grow in and shrink out: a `<Presence>` inside an `<svg>`, its children SVG circles. */
export default function Plot() {
const [points, setPoints] = createSignal([1, 2, 3, 4, 5, 6, 7, 8])
let next = 9
const add = () => setPoints((all) => [...all, next++])
const remove = (point: number) => setPoints((all) => all.filter((one) => one !== point))
return (
<div class="sample-stack">
<div class="sample-actions">
<button class="sample-button" onClick={add}>
Add
</button>
<button class="sample-button" disabled={points().length === 0} onClick={() => remove(points()[0])}>
Remove
</button>
</div>
<svg class="sample-plot" viewBox="0 0 320 160" role="img" aria-label={`A plot of ${points().length} points`}>
<line x1="0" y1="53" x2="320" y2="53" />
<line x1="0" y1="107" x2="320" y2="107" />
{/* Each circle stays until its exit has shrunk it away. */}
<Presence>
<For each={points()}>
{(point) => (
<w.circle
class="sample-point"
data-tone={pointAt(point).tone}
cx={pointAt(point).cx}
cy={pointAt(point).cy}
initial={{ r: 0, opacity: 0 }}
animate={{ r: 9, opacity: 1 }}
whileHover={{ r: 12 }}
exit={{ r: 0, opacity: 0, transition: { duration: 0.25 } }}
transition={{ type: "spring", visualDuration: 0.4, bounce: 0.4 }}
onClick={() => remove(point)}
/>
)}
</For>
</Presence>
</svg>
<p class="sample-note">Click a point to remove it.</p>
</div>
)
}import { AnimatePresence } from "@wardic/solid/v1"
import { w } from "~/lib/wardic.ts"
import { createSignal, For } from "solid-js"
/** Where point `id` sits on the 320 × 160 plot, spread evenly from its number, and which of four colours it takes. */
const pointAt = (id: number) => ({ cx: 20 + ((0.5 + id * 0.7549) % 1) * 280, cy: 20 + ((0.5 + id * 0.5698) % 1) * 120, tone: id % 4 })
/** Points on a plot that grow in and shrink out: an `<AnimatePresence>` inside an `<svg>`, its children SVG circles. */
export default function Plot() {
const [points, setPoints] = createSignal([1, 2, 3, 4, 5, 6, 7, 8])
let next = 9
const add = () => setPoints((all) => [...all, next++])
const remove = (point: number) => setPoints((all) => all.filter((one) => one !== point))
return (
<div class="sample-stack">
<div class="sample-actions">
<button class="sample-button" onClick={add}>
Add
</button>
<button class="sample-button" disabled={points().length === 0} onClick={() => remove(points()[0])}>
Remove
</button>
</div>
<svg class="sample-plot" viewBox="0 0 320 160" role="img" aria-label={`A plot of ${points().length} points`}>
<line x1="0" y1="53" x2="320" y2="53" />
<line x1="0" y1="107" x2="320" y2="107" />
{/* Each circle stays until its exit has shrunk it away. */}
<AnimatePresence>
<For each={points()}>
{(point) => (
<w.circle
class="sample-point"
data-tone={pointAt(point).tone}
cx={pointAt(point).cx}
cy={pointAt(point).cy}
initial={{ r: 0, opacity: 0 }}
animate={{ r: 9, opacity: 1 }}
whileHover={{ r: 12 }}
exit={{ r: 0, opacity: 0, transition: { duration: 0.25 } }}
transition={{ type: "spring", visualDuration: 0.4, bounce: 0.4 }}
onClick={() => remove(point)}
/>
)}
</For>
</AnimatePresence>
</svg>
<p class="sample-note">Click a point to remove it.</p>
</div>
)
}import { DomLive } from "@wardic/dom"
import * as Schema from "effect/Schema"
import type { Html, HtmlBuilder } from "foldkit/html"
import { defineMessageUnion } from "foldkit/message"
import { Features, Wardic } from "@wardic/foldkit"
// This app plays exits: its Handle names `presence` among its Features.
const wardic = Wardic.make({ env: DomLive, features: [Features.domAnimation, Features.presence] })
/** Where point `id` sits on the 320 × 160 plot, spread evenly from its number, and which of four colours it takes. */
const pointAt = (id: number) => ({ cx: 20 + ((0.5 + id * 0.7549) % 1) * 280, cy: 20 + ((0.5 + id * 0.5698) % 1) * 120, tone: id % 4 })
const Model = Schema.Struct({ points: Schema.Array(Schema.Number), next: Schema.Number })
type Model = typeof Model.Type
const Message = defineMessageUnion({ Add: {}, Remove: { point: Schema.Number } })
type Message = typeof Message.Type
export const init = (): Model => ({ points: [1, 2, 3, 4, 5, 6, 7, 8], next: 9 })
export const update = (model: Model, message: Message) =>
Message.match(message, {
Add: () => ({ model: { points: [...model.points, model.next], next: model.next + 1 } }),
Remove: ({ point }) => ({ model: { ...model, points: model.points.filter((one) => one !== point) } }),
})
/** Points on a plot that grow in and shrink out: a `Presence` on an `<svg>`, its children SVG circles. */
export const view = (model: Model, h: HtmlBuilder<Message>): Html => {
const w = wardic.html(h)
return h.div([h.Class("sample-stack")], [
h.div([h.Class("sample-actions")], [
h.button([h.Class("sample-button"), h.OnClick(Message.Add())], ["Add"]),
h.button([h.Class("sample-button"), h.Disabled(model.points.length === 0), h.OnClick(Message.Remove({ point: model.points[0] ?? 0 }))], ["Remove"]),
]),
// Each circle stays until its exit has shrunk it away.
w.svg(
[h.Class("sample-plot"), h.ViewBox("0 0 320 160"), h.Role("img"), h.AriaLabel(`A plot of ${model.points.length} points`), w.Presence({})],
[
h.line([h.X1("0"), h.Y1("53"), h.X2("320"), h.Y2("53")]),
h.line([h.X1("0"), h.Y1("107"), h.X2("320"), h.Y2("107")]),
...model.points.map((point) =>
w.keyed("circle")(String(point), [
h.Class("sample-point"),
h.DataAttribute("tone", String(pointAt(point).tone)),
h.Cx(String(pointAt(point).cx)),
h.Cy(String(pointAt(point).cy)),
w.Initial({ r: 0, opacity: 0 }),
w.Animate({ r: 9, opacity: 1 }),
w.WhileHover({ r: 12 }),
w.Exit({ r: 0, opacity: 0, transition: { duration: 0.25 } }),
w.Transition({ type: "spring", visualDuration: 0.4, bounce: 0.4 }),
h.OnClick(Message.Remove({ point })),
]),
),
],
),
h.p([h.Class("sample-note")], ["Click a point to remove it."]),
])
}import { AnimatePresence, domAnimation, LazyMotion } from "motion/react"
import * as m from "motion/react-m"
import { useRef, useState } from "react"
/** Where point `id` sits on the 320 × 160 plot, spread evenly from its number, and which of four colours it takes. */
const pointAt = (id: number) => ({ cx: 20 + ((0.5 + id * 0.7549) % 1) * 280, cy: 20 + ((0.5 + id * 0.5698) % 1) * 120, tone: id % 4 })
/** Points on a plot that grow in and shrink out: an `<AnimatePresence>` inside an `<svg>`, its children SVG circles. */
export default function Plot() {
const [points, setPoints] = useState([1, 2, 3, 4, 5, 6, 7, 8])
const next = useRef(9)
const add = () => setPoints((all) => [...all, next.current++])
const remove = (point: number) => setPoints((all) => all.filter((one) => one !== point))
return (
<LazyMotion features={domAnimation}>
<div className="sample-stack">
<div className="sample-actions">
<button className="sample-button" onClick={add}>
Add
</button>
<button className="sample-button" disabled={points.length === 0} onClick={() => remove(points[0])}>
Remove
</button>
</div>
<svg className="sample-plot" viewBox="0 0 320 160" role="img" aria-label={`A plot of ${points.length} points`}>
<line x1="0" y1="53" x2="320" y2="53" />
<line x1="0" y1="107" x2="320" y2="107" />
{/* Each circle stays until its exit has shrunk it away. */}
<AnimatePresence>
{points.map((point) => (
<m.circle
key={point}
className="sample-point"
data-tone={pointAt(point).tone}
cx={pointAt(point).cx}
cy={pointAt(point).cy}
initial={{ r: 0, opacity: 0 }}
animate={{ r: 9, opacity: 1 }}
whileHover={{ r: 12 }}
exit={{ r: 0, opacity: 0, transition: { duration: 0.25 } }}
transition={{ type: "spring", visualDuration: 0.4, bounce: 0.4 }}
onClick={() => remove(point)}
/>
))}
</AnimatePresence>
</svg>
<p className="sample-note">Click a point to remove it.</p>
</div>
</LazyMotion>
)
}Modes
How a child enters while another leaves, by <Presence>'s props (on Solid 1, <AnimatePresence>'s mode, in brackets):
- Neither, the default (
"sync"): the leaving and the entering children animate at once. wait("wait"): the entering child waits until the leaving one has gone.pop("popLayout"): a leaving child is taken out of the layout as it starts to leave, so the others move into its place as it goes, withlayouton them. It keeps its top left corner while it's popped, or the one it's given,pop="bottom-right"(on Solid 1,anchorXandanchorYsay which edges). An icon's<svg>is popped too, where Motion pops only an HTML element; the SVG elements inside an<svg>leave where they are.
Here a play button's icon swaps for a pause one. The leaving <svg> is popped, so it turns out over the new icon rather than beside it, and the button keeps its size. Motion's tab wraps each icon in an m.span to pop it.
import { Presence } from "@wardic/solid/hooks"
import { w } from "~/lib/wardic.ts"
import { createSignal, Show } from "solid-js"
/** Each icon turns in a quarter turn from half its size, and turns out the same way on. */
const TURN = {
initial: { opacity: 0, scale: 0.5, rotate: -90 },
animate: { opacity: 1, scale: 1, rotate: 0 },
exit: { opacity: 0, scale: 0.5, rotate: 90 },
transition: { type: "spring", visualDuration: 0.3, bounce: 0.3 },
} as const
/** A play button whose icon swaps for a pause one: each icon an `<svg>`, the leaving one popped out of the flow. */
export default function PlayButton() {
const [playing, setPlaying] = createSignal(false)
return (
<div class="sample-stack">
<button class="sample-button sample-icon-button" aria-label={playing() ? "Pause" : "Play"} onClick={() => setPlaying((on) => !on)}>
{/* The leaving icon is popped: it turns out over the new one, not beside it, and the button keeps its size. */}
<Presence pop enter={false}>
<Show
when={playing()}
fallback={
<w.svg viewBox="0 0 24 24" width="22" height="22" initial={TURN.initial} animate={TURN.animate} exit={TURN.exit} transition={TURN.transition}>
<path d="M7 5 L19 12 L7 19 Z" />
</w.svg>
}
>
<w.svg viewBox="0 0 24 24" width="22" height="22" initial={TURN.initial} animate={TURN.animate} exit={TURN.exit} transition={TURN.transition}>
<rect x="6" y="5" width="4" height="14" rx="1" />
<rect x="14" y="5" width="4" height="14" rx="1" />
</w.svg>
</Show>
</Presence>
</button>
<p class="sample-note">{playing() ? "Playing" : "Paused"}</p>
</div>
)
}import { AnimatePresence } from "@wardic/solid/v1"
import { w } from "~/lib/wardic.ts"
import { createSignal, Show } from "solid-js"
/** Each icon turns in a quarter turn from half its size, and turns out the same way on. */
const TURN = {
initial: { opacity: 0, scale: 0.5, rotate: -90 },
animate: { opacity: 1, scale: 1, rotate: 0 },
exit: { opacity: 0, scale: 0.5, rotate: 90 },
transition: { type: "spring", visualDuration: 0.3, bounce: 0.3 },
} as const
/** A play button whose icon swaps for a pause one: each icon an `<svg>`, the leaving one popped out of the flow. */
export default function PlayButton() {
const [playing, setPlaying] = createSignal(false)
return (
<div class="sample-stack">
<button class="sample-button sample-icon-button" aria-label={playing() ? "Pause" : "Play"} onClick={() => setPlaying((on) => !on)}>
{/* The leaving icon is popped: it turns out over the new one, not beside it, and the button keeps its size. */}
<AnimatePresence mode="popLayout" initial={false}>
<Show
when={playing()}
fallback={
<w.svg viewBox="0 0 24 24" width="22" height="22" initial={TURN.initial} animate={TURN.animate} exit={TURN.exit} transition={TURN.transition}>
<path d="M7 5 L19 12 L7 19 Z" />
</w.svg>
}
>
<w.svg viewBox="0 0 24 24" width="22" height="22" initial={TURN.initial} animate={TURN.animate} exit={TURN.exit} transition={TURN.transition}>
<rect x="6" y="5" width="4" height="14" rx="1" />
<rect x="14" y="5" width="4" height="14" rx="1" />
</w.svg>
</Show>
</AnimatePresence>
</button>
<p class="sample-note">{playing() ? "Playing" : "Paused"}</p>
</div>
)
}import { DomLive } from "@wardic/dom"
import * as Schema from "effect/Schema"
import type { Html, HtmlBuilder } from "foldkit/html"
import { defineMessageUnion } from "foldkit/message"
import { Features, Wardic } from "@wardic/foldkit"
// This app plays exits: its Handle names `presence` among its Features.
const wardic = Wardic.make({ env: DomLive, features: [Features.domAnimation, Features.presence] })
const Model = Schema.Struct({ playing: Schema.Boolean })
type Model = typeof Model.Type
const Message = defineMessageUnion({ Toggle: {} })
type Message = typeof Message.Type
export const init = (): Model => ({ playing: false })
export const update = (model: Model, message: Message) => Message.match(message, { Toggle: () => ({ model: { playing: !model.playing } }) })
/** Each icon turns in a quarter turn from half its size, and turns out the same way on. */
const TURN = {
initial: { opacity: 0, scale: 0.5, rotate: -90 },
animate: { opacity: 1, scale: 1, rotate: 0 },
exit: { opacity: 0, scale: 0.5, rotate: 90 },
transition: { type: "spring", visualDuration: 0.3, bounce: 0.3 },
} as const
/** A play button whose icon swaps for a pause one: each icon an `<svg>`, keyed, the leaving one popped out of the flow. */
export const view = (model: Model, h: HtmlBuilder<Message>): Html => {
const w = wardic.html(h)
const icon = (key: string, shapes: ReadonlyArray<Html>): Html =>
w.keyed("svg")(key, [h.ViewBox("0 0 24 24"), h.Width("22"), h.Height("22"), w.Initial(TURN.initial), w.Animate(TURN.animate), w.Exit(TURN.exit), w.Transition(TURN.transition)], shapes)
return h.div([h.Class("sample-stack")], [
h.button([h.Class("sample-button sample-icon-button"), h.AriaLabel(model.playing ? "Pause" : "Play"), h.OnClick(Message.Toggle())], [
// The leaving icon is popped: it turns out over the new one, not beside it, and the button keeps its size.
w.span([w.Presence({ mode: "popLayout", initial: false })], [
model.playing
? icon("pause", [h.rect([h.X("6"), h.Y("5"), h.Width("4"), h.Height("14"), h.Rx("1")]), h.rect([h.X("14"), h.Y("5"), h.Width("4"), h.Height("14"), h.Rx("1")])])
: icon("play", [h.path([h.D("M7 5 L19 12 L7 19 Z")])]),
]),
]),
h.p([h.Class("sample-note")], [model.playing ? "Playing" : "Paused"]),
])
}import { AnimatePresence, domAnimation, LazyMotion } from "motion/react"
import * as m from "motion/react-m"
import { useState } from "react"
/** Each icon turns in a quarter turn from half its size, and turns out the same way on. */
const TURN = {
initial: { opacity: 0, scale: 0.5, rotate: -90 },
animate: { opacity: 1, scale: 1, rotate: 0 },
exit: { opacity: 0, scale: 0.5, rotate: 90 },
transition: { type: "spring", visualDuration: 0.3, bounce: 0.3 },
} as const
/** A play button whose icon swaps for a pause one, the leaving one popped out of the flow. */
export default function PlayButton() {
const [playing, setPlaying] = useState(false)
return (
<LazyMotion features={domAnimation}>
<div className="sample-stack">
<button className="sample-button sample-icon-button" aria-label={playing ? "Pause" : "Play"} onClick={() => setPlaying((on) => !on)}>
{/* Motion pops only an HTML element, so each icon turns in an `m.span` around its `<svg>`. */}
<AnimatePresence mode="popLayout" initial={false}>
{playing ? (
<m.span key="pause" className="sample-icon" initial={TURN.initial} animate={TURN.animate} exit={TURN.exit} transition={TURN.transition}>
<svg viewBox="0 0 24 24" width="22" height="22">
<rect x="6" y="5" width="4" height="14" rx="1" />
<rect x="14" y="5" width="4" height="14" rx="1" />
</svg>
</m.span>
) : (
<m.span key="play" className="sample-icon" initial={TURN.initial} animate={TURN.animate} exit={TURN.exit} transition={TURN.transition}>
<svg viewBox="0 0 24 24" width="22" height="22">
<path d="M7 5 L19 12 L7 19 Z" />
</svg>
</m.span>
)}
</AnimatePresence>
</button>
<p className="sample-note">{playing ? "Playing" : "Paused"}</p>
</div>
</LazyMotion>
)
}Its other props
enter={false}(on Solid 1,initial={false}) skips the children's entrance at the first render.customis handed to each leaving child'sexitvariants, for an exit that depends on something only known as it leaves, such as the direction a slider went.- Once every leaving child has gone: on Solid 2,
presence.next("exitComplete")resolves, from acreatePresence()given as<Presence ref={presence}>; on Solid 1,onExitCompleteis called. propagateplays the exits of nested presences when their parent leaves.
Your own exit
A child's exit can be taken over from the code: it stays on the page until you say it can go.
- On Solid 2, a ward does it, one with no motion if it needs none: under a presence it hears its own leave,
ward.exiting()istruefrom it, andconst release = ward.hold()keeps it on the page untilrelease(). - On Solid 1,
usePresence(element, (safeToRemove, custom) => { … })calls you when it leaves, anduseIsPresentis whether the child is still present,falsefrom the moment it starts to leave.
In the storefront
The storefront's examples that show it, live and with their code:
- "Added to cart", in toasts that make room: Each piece you add says so in a toast; when one goes, the others close the gap. (on Foldkit)
- A photo gallery that slides the way you go: Swipe or step through the collection's photos: each comes in from the side you're heading to, and the last one leaves by the other. (on Foldkit)
- A quick view whose list leaves before it: Open a piece in a quick view and dismiss the suggestions you don't want. Close it, and what's left of the list goes first. (on Foldkit)
- A gift note you can fold away: Hide the gift note and it fades while its card closes up around it; show it and the card opens for it. The note is the page's own element, moved by a component that only takes it as a child.
- A delivery estimate that changes with the method: Pick another delivery method: its mark glides across, and the old estimate slides out the way you came as the new one slides in from where you went. The page writes each estimate, and the slot it sits in moves them.
- Waiting for a piece's details: A piece's page whose details come from the store, on Solid 2: show a skeleton and the photo flies at once, or keep the catalogue until the details land, then fly.
- A size guide in Kobalte's dialog: Open the size guide: the shop dims and the guide rises in. Escape, a click outside or ✕ takes it away as smoothly. (on Foldkit)