Toggle and toast
A small state change in the product: a switch flips, a confirmation appears.
Rendered video, with motion blur.
Auto-save
Saved
0.00 / 3.20 s
Live preview, driven by the code below. No motion blur.
What it does
A switch slides to on as its track changes colour, then a short confirmation rises in, is read and leaves.
Curve
Ease in-out cubic
Values
S is the frame's short side, 1080 px at 1080p. Unmeasured inputs in the preview are illustrations, not rules.
| Fact | Value |
|---|---|
Purpose | Emphasis |
Acts on | Card |
Typical length | 0.2 to 0.25 s (6 to 8 frames at 30 fps), then the toast holds to be read |
Caution | Keep the product’s real UI colours, and one toast at a time. |
| Property | Value |
|---|---|
Toggle thumb | Travels in 0.2 s, ease-in-out cubic |
Track colour | Crossfades over the same 0.2 s, with no overshoot on colour |
Toast enters | 0.25 s, ease-out cubic: fade plus 1.5% S (16 px) rise |
Toast holds | Hold formula: 0.75 s + words / 2.5 + 0.5 s, minimum 1.2 s |
Toast exits | 0.2 s, ease-in cubic (about 50 ms shorter than the entry, as in Atlassian's flags) |
Pairing | Pair with Cursor click when a pointer flips the switch |
Export samples | 12; 1 when still |
Starting values from research. Measure against a reference before relying on them.
Code
ts
export const seg = (t: number, a: number, b: number) => Math.max(0, Math.min(1, (t - a) / (b - a)));
export const lerp = (a: number, b: number, k: number) => a + (b - a) * k;
export const out = (k: number) => (k >= 1 ? 1 : 1 - Math.pow(2, -10 * k));
export const io = (k: number) => (k < 0.5 ? 16 * k ** 5 : 1 - Math.pow(-2 * k + 2, 5) / 2);
export const inn = (k: number) => k * k * k;
export const cubicOut = (k: number) => 1 - Math.pow(1 - k, 3);
export const h = (i: number, j: number) => { const x = Math.sin(i * 127.1 + j * 311.7) * 43758.5453; return x - Math.floor(x); };
export const phase = (t: number, start = 0, duration = 0.6) => seg(t, start, start + duration);
export const easeInOut = (p: number) => p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2;
export const holdTime = (words: number) => Math.max(1.2, 0.75 + words / 2.5 + 0.5);
export function toggleSwitch(t: number, start: number, travel: number) {
const k = easeInOut(phase(t, start, 0.2));
return { x: travel * k, colourMix: k };
}
export function toast(t: number, start: number, hold: number) {
const a = cubicOut(phase(t, start, 0.25));
const b = inn(phase(t, start + 0.25 + hold, 0.2));
return { y: 16 * (1 - a) + 16 * b, opacity: a * (1 - b) };
}Best practices
| Use it for | Avoid |
|---|---|
Settings saved, a feature switched on | Changing the product's real UI colours |
Confirming an action the viewer just saw | More than one toast at a time |
Reduced motion: a simple opacity fade over 0.2 s.