Files
hyperframes/docs/catalog/components/toggle-flip.mdx
Miguel Ángel f24ff83834 feat(catalog): add the seven 3D-motion pieces as installable registry blocks (#4056)
* feat(catalog): add the seven 3D-motion pieces as installable registry blocks

Each piece ships as a registry block with a CDN poster and preview, a live
catalog detail page and its source. Scripts travel inside the catalog payload
(shared vendor libraries fetched once, item scripts inline, the one HDR as a
data URI) because the docs host only serves fonts, images and JSON.

NO_ESSAY_COMMENTS_OK: the long comment blocks are in vendored libraries and
the ported frost source under registry/blocks, not hand-written here.
HF_MAX_NONLFS_KB=6000: four hosted texture PNGs under docs/public/catalog/items
are runtime assets the docs host must serve as files.
fallow skipped locally: it audits against origin/main and this branch is
stacked on an older main.

* chore(catalog): regenerate gallery data and nav after rebasing onto main

* fix(catalog): read the install manifest through the bounded project reader

* fix(catalog): a script the inliner missed fails the payload instead of shipping a dead URL

* refactor(catalog): the leftover-script check reuses the reference finder

* fix(catalog): frost and glass textures load from the CDN and the iteration presets are gone

* chore(catalog): regenerate the frost and glass payloads and nav

* fix(catalog): frost and glass textures are hosted through the registry url field, not hardcoded

* chore(catalog): regenerate the frost and glass payloads against the hosted texture URLs

* fix(catalog): the hosted-reference rewrite refuses a bare name it cannot safely replace

* ci(catalog): verify changed catalog payloads in headless Chrome and check the docs catalog

* feat(catalog): every item page follows the shared layout with a Tune panel and tabs

* fix(catalog): let the texture-mask item host its masks so its tile plays live

* chore(catalog): regenerate item pages, gallery data and the texture-mask payload

* chore(catalog): regenerate item pages after merging main

* fix(catalog): declared-only variables get the Tune panel, Code and Docs tabs capped

* feat(catalog): give the blend-difference caption a demo scene so its tile plays live

* chore(catalog): live payload for the blend-difference caption

* perf(catalog): heavy 3d pieces compile and draw before ready, not on the first visible frame

* feat(catalog): the avatar promo card hosts its videos, audio and fonts on the CDN

* feat(catalog): the avatar promo card tile plays live from its CDN-hosted media

* chore(catalog): the avatar promo card plays live, no allowlist left

* chore(catalog): shorten two comment blocks

* chore(catalog): trim first-party comment blocks to the comment-check limits

* chore(catalog): shorten two frost source comments

* fix(catalog): the Docs tab renders as prose again, and the detail page honours reduced motion

Frame-mode pages carry no prose wrapper, and the detail component sat inside
not-prose, so the Docs slot's headings, paragraphs, links and lists had no
styling at all. The slots now carry their own prose classes and the chrome
around them keeps not-prose.

The recorded clip also gets the reduced-motion guard the docs-snippet check
requires, and the generator reads stability from the source metadata type so
the scripts typecheck passes.

* fix(catalog): docs-tab paragraphs render as blocks

Mintlify emits paragraphs as inline spans, so two paragraphs in the Docs slot ran together.

* fix(ci): drop the duplicate docs_catalog job output

git's line-based auto-merge silently duplicated the outputs key when
main and this branch each added it on non-adjacent lines during the
rebase; oxfmt's yaml parser rejects the repeated map key.

* fix(catalog): close four CodeQL alerts in the frost source

* chore(catalog): allowlist the avatar-promo-card CDN asset deletions, format sync-docs-catalog

check-no-main-deletions.mjs was rejecting 11 local mp4/font files this branch
already deleted in favor of CDN hosting; scripts/sync-docs-catalog.mjs had one
line over the 100-col print width from an earlier edit in this branch.

* fix(catalog): detail tabs use docs prose spacing, Install first; previews skip no-WebGPU runners

* fix(catalog): the docs tab scrolls with the page instead of a capped inner box

* refactor(catalog): split the payload asset and verify scripts into single-purpose helpers

* refactor(catalog): split the preview generator into single-purpose helpers

* ci(catalog): fail when the committed catalog differs from generator output

The docs host serves the committed catalog and nothing regenerates it, so a stale
copy shipped silently. The catalog payloads job now generates into a temp dir and
compares it with the committed tree.

* chore(catalog): regenerate docs/public/catalog with the refactored scripts

One full regeneration from an empty output tree with the current scripts. The tree grows
from 58.4 MB to 65.1 MB. Two hosted assets are about 2 MB each (an avatar png and a wav);
the same bytes are already committed under assets/, so HF_MAX_NONLFS_KB is raised for
this commit only.

* fix(catalog): run the catalog script tests under the runner they are written for

The rebase put three node:test files in the vitest half of test:scripts, where they report
"No test suite found". They now sit in the node --test list.

* fix(catalog): a WebGPU item without an adapter shows its recorded clip and says why

* ci(catalog): the drift check runs from a committed fetch mirror with no network

Generation now serves every font and CDN script fetch from scripts/catalog-fetch-mirror and fails
when a fetch is not in it, even if the caller swallowed the error. CATALOG_FETCH_MIRROR=record
refreshes the mirror from the live network. The docs_catalog filter also watches packages/core,
packages/producer and the mirror, and the 13 re-hashed font files are listed in ALLOWED_DELETIONS.

* chore(catalog): clean up the temp font cache and sort the mirror index without a locale

* fix(catalog): hide Tune when the clip stands in, time out the adapter request, share one check

* fix(catalog): the adapter probe survives a sync throw and a hang; test the clip guard

* fix(catalog): keep the adapter probe inside the component, Mintlify evaluates only exports

* fix(catalog): run the detail and page generator tests in CI; no Tune flash while probing WebGPU

* docs(catalog): credit vendored libraries and make each SKILL.md list what the block installs

CREDITS.md names every vendored dependency with its upstream and licence, and flags the two leaf
textures whose origin is still to be confirmed. Each SKILL.md Files table now comes from the block
manifest and its install and render paths point at compositions/<name>/. A test checks that every
path a SKILL.md names is a manifest file that exists.

* fix(catalog): a declared WebGPU item passes verify by its manifest tag, not by console wording

verify-catalog-payloads forgave a missing adapter only by matching the markup and the message, which
library-reported errors and widgets never satisfy. The webgpu tag in the item manifest is now the
owner: a tagged item ignores its page and console errors, an untagged one gets no forgiveness, and a
marker payload with no html is listed instead of crashing the run.

* docs(catalog): correct the credits per block and guard the mount and render paths

CREDITS.md states the three.js version and vendored-or-CDN status per block, adds d3-delaunay,
Clipper on the CDN and the Google Fonts loads, and lists every texture with no known origin.
The SKILL.md test now also checks the mount and render paths against the manifest composition.

* test(catalog): read each block manifest once in the SKILL.md file test

The two checks shared a copied manifest read, which fallow flagged as a clone with a high score.

* fix(catalog): commit the hosted item files a gitignore rule kept out, and check git not the disk

The compositions/ and *-ad/ ignore rules matched folder names under docs/public/catalog/items,
so 33 hosted fonts, textures and marks were generated but never committed and would 404 on
the docs host. The rules now have a negation for that tree and the files are added.

The drift check read the checkout, where git-ignored files still exist, so it passed locally
and failed only in CI. It now unpacks HEAD with git archive and compares that.

* fix(catalog): a tile keeps its poster until the composition has painted

* fix(catalog): a tagged WebGPU item forgives only the adapter-absent error, and test the wiring

The manifest webgpu tag now decides whether an item may lack an adapter, and the error wording
decides which lines are that absence. Any other page or console error on the item, and every
failed request, still fails. The per-item decision is one exported function the tests drive,
marker payloads are parsed by a tested helper, and the SKILL.md variable counts are checked
against their tables (cuboid-carousel said forty-nine for forty).

* fix(catalog): the pinned group's posters load eagerly at high priority

* fix(catalog): type the tile reveal test so the scripts typecheck passes

* fix(catalog): stop the adapter signature matching an unrelated failed adapter request

failed to request .*adapter also matched errors about other adapters. It now matches only a
request for the WebGPU adapter, so a tagged item cannot hide an unrelated failure behind it.

* test(catalog): a tagged item still fails on an error about some other adapter

* feat(catalog): the install command sits above the preview, as on the live catalog

* fix(catalog): find the install slot through Mintlify's child wrapper

* fix(docs): catalog copy buttons keep their size when the label swaps to Copied

* refactor(docs): name the shown copy label once in the catalog copy button

* fix(docs): primary catalog button keeps a readable label on hover and after copy

* fix(docs): inset the catalog tab strip and tab content to match the boxed panels
2026-09-19 16:53:29 -04:00

506 lines
21 KiB
Plaintext

---
title: "Toggle Flip"
description: "An oversized UI toggle switch that flips with real physicality: thumb overshoot, track color crossfade, and a soft press-compress before release. The reference prop of the ui-props family."
mode: "frame"
---
import { CatalogDetail, CatalogSlot } from "/snippets/catalog-detail.jsx";
import { InstallCommand } from "/snippets/install-command.jsx";
<CatalogDetail
previewSrc="/public/catalog/components/toggle-flip.json"
compositionId="toggle-flip"
compositionSrc="compositions/components/toggle-flip.html"
title="Toggle Flip"
description="An oversized UI toggle switch that flips with real physicality: thumb overshoot, track color crossfade, and a soft press-compress before release. The reference prop of the ui-props family."
variables={[{"id":"direction","type":"enum","role":"content","label":"Flip direction","description":"Target end state the flip lands on.","default":"on","options":[{"value":"on","label":"Off → On"},{"value":"off","label":"On → Off"}]},{"id":"label","type":"string","role":"content","label":"Caption","description":"Optional caption under the toggle. Blank hides the line.","default":"Auto-save"},{"id":"size","type":"number","role":"layout","label":"Size","description":"Toggle width as a percent of the host box width.","default":40,"min":20,"max":70,"step":1,"unit":"%"}]}
meta={{"category":"Product Demo","badge":"Stable","codeLines":424}}
attribution={{"path":"registry/components/toggle-flip","tags":["prop","ui-props","toggle","interaction","reference-prop","demonstrate"]}}
hasCode
rawUrl="https://raw.githubusercontent.com/heygen-com/hyperframes/main/registry/components/toggle-flip/toggle-flip.html"
>
<CatalogSlot slot="code">
```html toggle-flip.html
<!doctype html>
<!--
toggle-flip -- HyperFrames video primitive (ui-props / interaction / demonstrate)
Concept: an oversized UI toggle switch that flips with real physicality --
thumb travel with a slight overshoot, a track color crossfade from
var(--surface) to var(--brand), and a soft press-compress right before the
knob releases into its new state. One mechanic, one job: demonstrating a
state change. This is the reference prop of the ui-props family -- the
thing a cursor or touch actor "operates" in a composed scene, and it also
has to read alone.
Compiled-from evidence: fixture; the reference prop (video-primitives
catalog, ui-props / interaction / demonstrate shelf).
Use when: showing a feature, setting, or permission turning on/off, or any
binary state change a pointer actor (oversized-cursor, touch-indicator)
operates on. Composes with those pointer primitives, which anchor to this
file's [data-anchor="toggle-flip"] button.
Variables (declared in data-composition-variables below):
- direction ("on" | "off", default "on"): the flip's TARGET state.
"on" -> starts OFF (surface track), flips TO on (brand track).
"off" -> starts ON (brand track), flips TO off (surface track).
- label (string, default "Auto-save"): optional caption under the
toggle. Empty string hides the caption line entirely.
- size (number, percent of container width, default 40): toggle width
as a percentage of the host box's own width (cqw-driven, so it stays
proportional no matter what box a host composition gives it).
Envelope (fixed IN/OUT, elastic HOLD only -- never gsap.timeScale()):
IN_BASE = 0.90s stage settles in, anticipation press, then the flip
HOLD = elastic = max(0, D - (IN_BASE + OUT_BASE)); ambient glow
breathes gently to prove the frame is alive, or sits calm at
HOLD = 0 for short durations
OUT_BASE = 0.50s release fade
If D < IN_BASE + OUT_BASE, IN and OUT scale down together (never
time-scaled) so IN + OUT == D and HOLD == 0.
Sync point (fixed offset into IN, never inside the elastic HOLD): the flip
lands at FLIP_AT = 0.5s into an unscaled IN (scales proportionally with IN
when the envelope is compressed -- see RETIME RANGE below).
Sound cue: a soft click/tock foley fires at the flip sync point. The
primitive never plays audio -- it dispatches a `hf:sfx` CustomEvent
({ id: "click-soft", t: FLIP_AT }) that a scene's mix stage can catch and
route to the catalog SFX id of its choice.
Mount contract: this file is a MOUNTABLE SUB-COMPOSITION, not a standalone
composition. A host loads it via data-composition-src; the runtime only
clones <template> contents (everything outside <template>, including the
entire <head>, is discarded on mount) -- see
skills/hyperframes-core/references/sub-compositions.md. The root carries
no data-width/data-height: it is elastic, sized off whatever box the host
clip gives it (position:absolute; inset:0; container-type:size), so the
toggle reads correctly whether the host mounts it into a 960x540 slot or a
full 1920x1080 frame. The root is styled by #root, never a class --
composited renders scope this file's CSS to
[data-composition-id="toggle-flip"], and a rule keyed on the root's own
class would stop matching the root itself (sub-compositions.md, Pitfall
3). Variables are read via window.__hyperframes.getVariables() (not by
parsing this file's own <html> tag at runtime): once mounted,
document.documentElement is the HOST's <html>, not this one, so the
loader's declared-defaults-plus-per-instance-overrides table is the only
reliable source once the primitive is running inside a host page.
-->
<html
lang="en"
data-composition-variables='[
{ "id": "direction", "type": "enum", "role": "content", "label": "Flip direction", "description": "Target end state the flip lands on.", "default": "on", "options": [{ "value": "on", "label": "Off → On" }, { "value": "off", "label": "On → Off" }] },
{ "id": "label", "type": "string", "role": "content", "label": "Caption", "description": "Optional caption under the toggle. Blank hides the line.", "default": "Auto-save" },
{ "id": "size", "type": "number", "role": "layout", "label": "Size", "description": "Toggle width as a percent of the host box width.", "default": 40, "min": 20, "max": 70, "step": 1, "unit": "%" }
]'
>
<head>
<meta charset="UTF-8" />
<title>Toggle Flip</title>
<!-- Metadata only for whoever opens this file directly -- the runtime
discards everything outside <template> on mount. The
data-composition-variables attribute above stays on <html> (not
inside <template>): the loader reads declared variable defaults
directly off the fetched document's root element, whether or not
the body is template-wrapped. -->
</head>
<body>
<template>
<div id="root" data-composition-id="toggle-flip" data-duration="4" data-fps="30">
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
/* Root: sized off the HOST box, never a fixed stage. inset:0 fills
whatever box the host clip gives it -- a 960x540 mounted slot,
a full 1920x1080 frame, anything in between. container-type
establishes the cqw/cqh basis every internal measurement below
is expressed in. Styled by #root, never a class -- see the
mount-contract note in the header comment. */
#root {
position: absolute;
inset: 0;
container-type: size;
isolation: isolate;
overflow: hidden;
background: var(--bg, #0b1120);
color: var(--fg, #f8fafc);
font-family: var(--font-body, Inter, system-ui, sans-serif);
}
.tf-clip {
width: 100%;
height: 100%;
display: grid;
place-items: center;
}
.tf-stage {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--space-3, 3cqh);
opacity: 0;
}
.tf-label {
color: var(--muted, #94a3b8);
font-family: var(--font-display, Inter, system-ui, sans-serif);
font-weight: 650;
font-size: clamp(12px, 2.4cqw, 28px);
letter-spacing: 0.01em;
text-align: center;
}
.tf-label:empty {
display: none;
}
/* EDIT ZONE: geometry ratios. Track is a fixed 2.2:1 pill; the knob is
80% of the track's own height, inset 10% top/bottom. All of it is
expressed in cqw off --tf-size so it holds proportion at any size. */
.tf-toggle {
--tf-track-w: calc(var(--tf-size, 40) * 1cqw);
width: var(--tf-track-w);
aspect-ratio: 2.2 / 1;
position: relative;
display: block;
border: 0;
padding: 0;
background: transparent;
cursor: default;
/* transform is GSAP-owned below (press squeeze); no CSS transform here */
}
.tf-track {
position: absolute;
inset: 0;
border-radius: 999px;
--tf-mix: 0; /* 0..100, GSAP-tweened: 0 = surface/off, 100 = brand/on */
border: 0.15cqw solid
color-mix(
in srgb,
var(--border, #334155) calc(100% - var(--tf-mix, 0) * 0.4%),
var(--brand, #22c55e) calc(var(--tf-mix, 0) * 0.4%)
);
background: color-mix(
in srgb,
var(--surface, #1e293b) calc((100 - var(--tf-mix, 0)) * 1%),
var(--brand, #22c55e) calc(var(--tf-mix, 0) * 1%)
);
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--border, #334155) 45%, transparent);
}
.tf-glow {
position: absolute;
inset: -14%;
border-radius: 999px;
background: radial-gradient(
closest-side,
color-mix(in srgb, var(--accent, #38bdf8) 55%, transparent),
transparent 72%
);
opacity: 0;
pointer-events: none;
}
.tf-knob {
position: absolute;
top: calc(var(--tf-size, 40) * 0.0455cqw);
left: calc(var(--tf-size, 40) * 0.0455cqw);
width: calc(var(--tf-size, 40) * 0.3636cqw);
aspect-ratio: 1;
border-radius: 50%;
background: var(--surface, #f8fafc);
box-shadow: 0 0.35cqw 0.7cqw rgba(2, 6, 23, 0.4);
/* RETIME RANGE ends here for geometry; 150% is the exact travel a
2.2:1 track / 80%-of-height knob pair produces -- see header. GSAP
tweens x/scale directly below; no CSS transform authored here. */
}
</style>
<div
id="toggle-flip-clip"
class="tf-clip clip"
data-start="0"
data-duration="4"
data-track-index="0"
>
<div class="tf-stage">
<div class="tf-label"></div>
<button
class="tf-toggle"
type="button"
data-anchor="toggle-flip"
aria-pressed="false"
tabindex="-1"
>
<span class="tf-glow"></span>
<span class="tf-track"></span>
<span class="tf-knob"></span>
</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script>
(function () {
"use strict";
var root = document.getElementById("root");
// Literal, not read off the DOM: once mounted, the framework's
// flattening step strips data-composition-id from the mounted
// root (see FLATTENED_INNER_ROOT_STRIP_ATTRS in
// packages/core/src/runtime/flattenedRoot.ts), so
// root.getAttribute("data-composition-id") would read null post-
// mount and silently register the timeline under the key
// "null" instead of "toggle-flip" -- the render then waits the
// full 45s sub-composition poll and gives up. Matches the
// convention in sub-compositions.md's own example and
// empty.html: hardcode the id this file is always mounted
// under.
var compositionId = "toggle-flip";
var stage = root.querySelector(".tf-stage");
var labelEl = root.querySelector(".tf-label");
var toggleEl = root.querySelector(".tf-toggle");
var trackEl = root.querySelector(".tf-track");
var knobEl = root.querySelector(".tf-knob");
var glowEl = root.querySelector(".tf-glow");
// EDIT ZONE: variable defaults come from data-composition-variables
// above (declared on <html>). window.__hyperframes.getVariables()
// returns those defaults already merged with any per-instance
// data-variable-values a host sets on the mounting clip -- see
// sub-compositions.md's "Per-Instance Variables" section. Add a
// variable in both places together (declaration above + fallback
// below).
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
// INVARIANT: only "on" | "off" ever reaches the renderer, whatever a
// bad override sends.
var direction = vars.direction === "off" ? "off" : "on";
var toOn = direction === "on";
var labelText = vars.label == null ? "" : String(vars.label);
// INVARIANT: size always clamps into the declared 20-70% range so an
// out-of-range override can't blow the toggle past its container.
var sizePct = Math.max(20, Math.min(70, Number(vars.size) || 40));
labelEl.textContent = labelText;
toggleEl.style.setProperty("--tf-size", String(sizePct));
// A project's own --dur-beat sets this primitive's ambient pace, so
// the HOLD breathing feels native to whatever theme is compiled in.
var beat = parseFloat(getComputedStyle(root).getPropertyValue("--dur-beat")) || 0.5;
var SHEEN_HALF = beat * 1.5;
// RETIME RANGE: these are the only numbers to touch for a global
// pacing retune. Do not reach for gsap.timeScale() -- HOLD below is
// the only elastic phase; IN and OUT are always this long (scaled
// down together only when D itself is shorter than IN_BASE+OUT_BASE).
var IN_BASE = 0.9;
var OUT_BASE = 0.5;
var STAGE_IN_BASE = 0.4;
var PRESS_LEAD_BASE = 0.2;
var FLIP_AT_BASE = 0.5; // sync point: fixed offset into IN, never into HOLD
var FLIP_DURATION_BASE = 0.25;
var GLOW_DURATION_BASE = 0.15;
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "4"));
var totalBase = IN_BASE + OUT_BASE;
var scale = duration < totalBase ? duration / totalBase : 1;
var IN = IN_BASE * scale;
var OUT = OUT_BASE * scale;
var STAGE_IN = STAGE_IN_BASE * scale;
var PRESS_LEAD = PRESS_LEAD_BASE * scale;
var FLIP_AT = FLIP_AT_BASE * scale;
var FLIP_DURATION = FLIP_DURATION_BASE * scale;
var GLOW_DURATION = GLOW_DURATION_BASE * scale;
var HOLD = Math.max(0, duration - (IN + OUT));
var HOLD_START = IN;
var OUT_START = IN + HOLD;
function fireSfx(id, t) {
root.dispatchEvent(
new CustomEvent("hf:sfx", { detail: { id: id, t: t }, bubbles: true }),
);
}
// Explicit both-endpoints state (gsap.set, never gsap.from()) so a
// seek to t=0 is always correct without playing the timeline.
var mixFrom = toOn ? 0 : 100;
var mixTo = toOn ? 100 : 0;
var xFrom = toOn ? "0%" : "150%";
var xTo = toOn ? "150%" : "0%";
gsap.set(stage, { opacity: 0 });
gsap.set(toggleEl, { scaleX: 1, scaleY: 1 });
gsap.set(knobEl, { x: xFrom, scale: 1 });
gsap.set(trackEl, { "--tf-mix": mixFrom });
gsap.set(glowEl, { opacity: 0 });
toggleEl.setAttribute("aria-pressed", toOn ? "false" : "true");
var tl = gsap.timeline({ paused: true });
// IN: stage settle
tl.to(stage, { opacity: 1, duration: STAGE_IN, ease: "power2.out" }, 0);
// anticipation press, resolves exactly as the flip begins
if (PRESS_LEAD > 0) {
var pressStart = Math.max(0, FLIP_AT - PRESS_LEAD);
var pressHalf = PRESS_LEAD / 2;
tl.to(
toggleEl,
{ scaleX: 0.94, scaleY: 1.06, duration: pressHalf, ease: "power1.inOut" },
pressStart,
);
tl.to(
toggleEl,
{ scaleX: 1, scaleY: 1, duration: pressHalf, ease: "power1.inOut" },
pressStart + pressHalf,
);
}
// the flip: knob travel with overshoot + track color crossfade, one
// shared sync point (FLIP_AT) so they always land together
tl.to(knobEl, { x: xTo, duration: FLIP_DURATION, ease: "back.out(1.9)" }, FLIP_AT);
tl.to(
trackEl,
{ "--tf-mix": mixTo, duration: FLIP_DURATION, ease: "back.out(1.9)" },
FLIP_AT,
);
tl.fromTo(
knobEl,
{ scale: 1 },
{
scale: 1.08,
duration: FLIP_DURATION * 0.45,
ease: "power1.out",
yoyo: true,
repeat: 1,
},
FLIP_AT,
);
tl.set(
toggleEl,
{ attr: { "aria-pressed": toOn ? "true" : "false" } },
FLIP_AT + FLIP_DURATION,
);
tl.call(
function () {
fireSfx("click-soft", FLIP_AT);
},
[],
FLIP_AT,
);
// soft glow pulse right as the flip settles
tl.fromTo(
glowEl,
{ opacity: 0 },
{
opacity: 1,
duration: GLOW_DURATION * 0.5,
ease: "power1.out",
yoyo: true,
repeat: 1,
},
FLIP_AT + FLIP_DURATION,
);
// HOLD: gentle ambient breathing so an elastic frame still reads
// alive; naturally absent when HOLD == 0. Finite repeat count per
// the determinism rule -- floor, never ceil, so it can't overshoot D.
if (HOLD > SHEEN_HALF) {
var breathRepeat = Math.max(0, Math.floor(HOLD / SHEEN_HALF) - 1);
tl.fromTo(
glowEl,
{ opacity: 0 },
{
opacity: 0.32,
duration: SHEEN_HALF,
ease: "sine.inOut",
yoyo: true,
repeat: breathRepeat,
},
HOLD_START + GLOW_DURATION,
);
}
// OUT: release fade
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.out" }, OUT_START);
tl.seek(0);
window.__timelines = window.__timelines || {};
window.__timelines[compositionId] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</CatalogSlot>
<CatalogSlot slot="install">
<InstallCommand command="npx hyperframes add toggle-flip" item="toggle-flip" />
That writes one file: `compositions/components/toggle-flip.html`.
</CatalogSlot>
<CatalogSlot slot="docs">
## Paste it into your composition
Open `compositions/components/toggle-flip.html` and copy what is inside into your own composition.
A component has no size or duration of its own. It takes both from the composition
you paste it into.
## Variables
Every one of these has a default, so the piece works untouched. Set the ones you
want to change on the element:
| Variable | Default | Accepts | What it does |
| --- | --- | --- | --- |
| `direction` | `on` | `on`, `off` | Target end state the flip lands on. |
| `label` | `Auto-save` | string | Optional caption under the toggle. Blank hides the line. |
| `size` | `40` | 20% to 70%, step 1% | Toggle width as a percent of the host box width. |
Set them with `data-variable-values` on the element that mounts it. These are the
defaults, so this behaves exactly like the preview above until you change one:
```html wrap
<div
data-composition-id="toggle-flip"
data-composition-src="compositions/components/toggle-flip.html"
data-variable-values='{"direction":"on","label":"Auto-save","size":40}'
></div>
```
{/* hf:generated-footer */}
Tagged `prop` `ui-props` `toggle` `interaction` `reference-prop` `demonstrate`.
## Related topics
- [Browse the complete Catalog](/catalog)
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
- [Build a richer composition](/go-further)
</CatalogSlot>
</CatalogDetail>