Content changes
Changes what a box shows while the box keeps its size, so nothing around the change moves.
Four parts change what a box shows without changing the box. They share one contract: the box keeps its size while its content changes (D37), so the parent holds a fixed width, and a fixed height or a fixed shape, and nothing around the change moves. Pick by what changes.
| Part | What changes | What you see | Time and curve | Example |
|---|---|---|---|---|
| IconSwap | a glyph trades places in a fixed slot | both glyphs stacked; one fades and blurs out as the other fades in | --t-icon 250ms on --curve-in-out |
the eye and the crossed eye on an API key |
| TextSwap | a word or a short status, from a set known up front | every wording stacked in a slot as wide as the longest, or with fit as wide as the one on show, for a surface that eases with its words such as a tooltip; the old word gone before the new one can be read; opacity only |
out: 70 percent of --t-pop on --curve; in: --t-icon 250ms on --curve-in-out, so a glyph and its word land together |
Live and Paused on a live chart; Pause and Resume on its button |
| Crossfade | content replaced, many times a day, with no order worth showing | the old content gone at once, the new one fading in where it was; nothing moves | --t-crossfade 320ms on --curve-sheet |
the next paper in a screening queue |
| Swap | content leaving and arriving, with a direction | the old content leaving 8px one way, then, once it is nearly gone, the new arriving from 8px the other way | out: 70 percent of --t-pop on --curve; in: the settle spring, --t-settle 300ms, 42ms later |
the name of the next or previous day in a room booking, whose time slots crossfade below it |
- Is it a glyph? Use IconSwap.
- Is it one or two words, and do you know every wording now? Use TextSwap.
- Is it a step forward or back through an ordered sequence, a few times in a session? Use Swap.
- Anything else, especially content stepped through hundreds of times a day: use Crossfade.
A button that reports its own request is none of these: StateButton moves its label on the settle spring, vertically, inside the box its label sets, with Swap's handover.
Swap and TextSwap never show two legible copies at once, and StateButton hands its label over the same way; Crossfade removes the old content at once and IconSwap's glyphs blur as they cross. The leaving copy takes the quick exit a popup takes and is under 5 percent opacity 48ms after the change; the arriving copy starts late (Swap, 42ms) or slowly (TextSwap, on --curve-in-out). Recorded frame by frame at 16ms with a fake clock, the fainter of two overlapping copies never passed 3 percent, against 15 to 36 percent before (.design-system/evidence/swap/handover.json, .design-system/evidence/text-swap/handover.json).
Examples
Dense passage retrieval for open-domain question answering
Karpukhin et al., EMNLP 2020
Passages are retrieved with a dual encoder trained on question and passage pairs, replacing sparse term matching. On five open-domain benchmarks the learned index beats a strong term-based baseline by 9 to 19 points in top-20 accuracy.
tc_test_••••••••••••9Rw3Usage
Use it when
- You step through a sequence a few times in a session and the order matters, such as the days of a booking calendar, the weeks of a schedule or the steps of a setup, and seeing which way it went helps you keep your place: Swap.
- Content is stepped through hundreds of times a day, such as papers in a screening queue, rows in a review or search results, and the new item simply replaces the old: Crossfade.
- A glyph changes with a state, such as an eye becoming a crossed eye while a secret shows, a copy glyph becoming a check for a moment, or a bookmark filling when saved, inside a box that must not change: IconSwap.
- A slot is sometimes blank, such as the check on a pill that is off, and the blank must hold the slot's width: IconSwap with an empty glyph.
- A word or a short status changes in place beside things that must not move, such as Live and Paused, Pause and Resume, or Follow and Following, and every wording is known up front: TextSwap.
Use something else when
- A button reports its own request, such as Saving and Saved, or its glyph gives way to a turning ring while it waits. Use StateButton instead, which carries
aria-busy, the ring and the blocked repeat. - The content is loading, not changing. Use Skeleton instead for the wait, and let the content replace it.
- A surface opens or closes. Use Dialog, Sheet, Popover or Grow instead, which grow from their trigger.
Rules
General
Content
Avoid
Limits
Install
npx shadcn@latest add https://kaanarici.com/r/cobalt/swap.json https://kaanarici.com/r/cobalt/crossfade.json https://kaanarici.com/r/cobalt/icon-swap.json https://kaanarici.com/r/cobalt/text-swap.jsonimport { Swap } from "@/components/cobalt/ui/swap"import { Crossfade } from "@/components/cobalt/ui/crossfade"import { IconSwap } from "@/components/cobalt/ui/icon-swap"import { TextSwap } from "@/components/cobalt/ui/text-swap"