Expiry

A time limit on an element — an "undo" button, an offer, a one-time link — with the element burning away as the time runs out. The element stays native; the time limit and what expiry means are yours.

Live: burn timer playground.

Usage

<button id="undo">Undo send · <span id="left">7</span>s</button>
import { createRenderer, createExpiryFx } from 'webgl-ui'

const renderer = createRenderer()
const undo = document.querySelector<HTMLButtonElement>('#undo')!
const expiry = createExpiryFx(undo, {
  renderer,
  seconds: 7,
  onTick: s => { left.textContent = String(s) },
  onExpire: () => { undo.hidden = true }   // same task as the last frame: nothing flashes
})
expiry.start()
undo.addEventListener('click', () => { expiry.cancel(); undoSend() })

Options

OptionTypeDefaultDescription
rendererRenderer | () => RendererrequiredThe shared renderer.
secondsnumberrequiredHow long the element lives.
effectEffectDefburnEffectReceives uBox (the element in canvas pixels) and uDrift (the flames' clock).
bleednumber56How far flames and smoke may reach outside the element, in CSS pixels. The element must not clip its overflow.
onTick(secondsLeft) => voidnoneEach time the whole seconds left change: update your text.
onExpire() => voidnoneWhen the time is up, in the same task as the last frame: hide, remove or replace the element.
pauseOnInteractionbooleantruePause while hovered or focused.

Returns

MemberDescription
start()Starts the clock (and the burn).
pause(), resume()Stops and restarts the clock; while paused the burned state stays on screen, flames still.
extend(seconds)Adds time.
cancel()Stops for good without expiring (the action was taken); the element is shown intact.
secondsLeft()Whole seconds left.
destroy()Stops and removes the listeners.

CSS hooks

HookMeaning
[data-animating], --pWhile the burn runs; --p is the share burned.
[data-paused]While the clock is stopped (hover, focus or pause()).
--fx-coverThe page colour behind the element, which the burned part is painted with. Default: the parent's background.

Behavior and accessibility