Skip to content

slide enter and exit

Read as Markdown

Show and hide a captured Pibbl subtree with the slide transition.

Plain source. Run as a browser module after the document body exists. TSX uses jsx: "react-jsx" and jsxImportSource: "@pibbl/core".

import {
pibbl,
Group,
Rectangle,
Text,
useVisibilityTransition,
slide,
type PibblSlideOptions,
type PibblTransitionEffect,
type PibblVisibilityTransition,
type PibblVisibilityTransitionOptions,
type PibblVisibilityTransitionResult,
type PibblVisibilityTransitionStatus,
type PibblTransitionBinding,
} from "@pibbl/core";
const options: PibblSlideOptions = { x: -80 };
const effect: PibblTransitionEffect = slide(options);
const visibility: PibblVisibilityTransitionOptions = {
initial: true,
enter: effect,
duration: 1200,
};
const canvas = document.createElement("canvas");
canvas.width = 360;
canvas.height = 220;
const output = document.createElement("output");
document.body.append(canvas, output);
let handle: PibblVisibilityTransition | undefined;
function Scene() {
const transition = useVisibilityTransition(visibility);
handle = transition;
const binding: PibblTransitionBinding = transition.binding;
const status: PibblVisibilityTransitionStatus = transition.status.get();
return (
<>
<Group style={{ transition: binding }}>
<Rectangle
style={{
left: 30,
top: 30,
width: 260,
height: 100,
fill: "#087e8b",
}}
/>
<Text
style={{ left: 60, top: 90, font: "24px sans-serif", fill: "#fff" }}
>
slide
</Text>
</Group>
<Text
style={{ left: 30, top: 195, fill: "#222", font: "14px sans-serif" }}
>
{status}
</Text>
</>
);
}
const controller = pibbl(canvas, <Scene />);
for (const action of ["show", "hide"] as const) {
const button = document.createElement("button");
button.textContent = action;
button.onclick = async () => {
const result: PibblVisibilityTransitionResult | undefined =
await handle?.[action]();
if (result) output.textContent = result.phase + ": " + result.status;
};
document.body.append(button);
}
window.addEventListener("pagehide", () => controller.dispose(), { once: true });
  • Transitions affect pixels, not hit testing or native HTML. Keep the subject mounted until hide() resolves with status finished before removing it.
  • Mount-time transition options are stable. The Pibbl mount owns playback and effect cleanup.

Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.