Shimmer
Text with a light sweeping across it.
Demo
Usage
import { Shimmer } from '@tuttn/slant'
<Shimmer>Thinking…</Shimmer>
// Stop the sweep when the work is done: the children become plain text, in
// the colour around them.
<p role="status">
<Shimmer active={thinking}>{thinking ? 'Thinking…' : 'Thought for 4 seconds'}</Shimmer>
</p>
// A faster or slower sweep, in milliseconds.
<Shimmer duration={1200}>Generating a summary</Shimmer>Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The text. It stays real text: selectable, read by screen readers, found by search. |
active | boolean | true | While true, the text is muted and a light band sweeps across it. False renders the children as plain text, in the colour around them. |
duration | number | 2000 | Milliseconds per sweep. |
…rest | HTMLAttributes<HTMLSpanElement> | — | className, style and other attributes go on the span, which also takes the ref. |
Accessibility
The text stays real text: a screen reader reads it, it can be selected and copied, and find-in-page finds it. While active it is drawn in --sl-muted, which holds 4.5:1 against the backgrounds in every theme, and the sweeping band only brightens it towards --sl-text, so the contrast never drops below the muted colour's. Shimmer announces nothing itself; if the words change as the work moves on, put them in a role="status" element, as the demo does.
Keyboard
None: Shimmer is a span of text and takes no focus.
Motion and colour
The band is painted with background-clip: text, one sweep per duration, with a pause while it is off the text. Under prefers-reduced-motion it rests off the text, so the line reads as plain muted text, and in forced-colours mode the effect is dropped for the system text colour. active={false} removes every style, leaving the text in the colour around it.
Direction
The sweep runs from the inline start: left to right, and right to left under dir="rtl".