import { useState } from 'react' import { Stage, States, type Act } from '../kit' import './text-settle.css' type State = { added: boolean } const labels = { empty: 'Add a note', added: 'Note added' } export const textLessons = [{ id: 'text-settle', title: 'Text shifts as the transition finishes', note: 'Watch the label and “Optional” as the old words finish fading. Hidden text can still move the line’s baseline.', bad: 'A hidden label changes the baseline', good: 'Travel stays separate from layout', }] as const async function sequence(a: Act) { await a.wait(1300) await a.set({ added: true }) await a.wait(2000) await a.set({ added: false }) await a.wait(1400) } // A real failure mode: margin travel on an overlapping inline-grid item // contributes to the shared baseline even after that item becomes invisible. // Keep this reproduction local; corrected scenes use the shared States part. function UnstableLabel({ added }: State) { return {Object.entries(labels).map(([key, text]) => {text} )} } export function TextComparison() { const [revision, replay] = useState(0) const lesson = textLessons[0] return

{lesson.title}

{lesson.note}

key={revision} width={704} height={150} compact={{ below: 704, width: 340, height: 316 }} initial={{ added: false }} poster={{ added: true }} script={sequence} play="once" className="tc-stage"> {state =>
{[false, true].map(good =>
{good ? : } Optional
{good ? lesson.good : lesson.bad}
)}
}
}