Shimmer
A style map that sweeps a highlight across text while it streams.
Drafting a reply…
Installation
Needs the arene setup first.
Install the packages it imports:
Set up the StyleX compiler, if you have not already. See Installation.
Paste this source into the file named in its title.
Change the @/ imports if your project uses different aliases.
Usage
Merge shimmerStyles.base into the stylex.props() call of a text element.
On a arene component, pass it through xstyle, which the component merges
last.
Trace merges base into the title of a running line
itself, so a trace needs nothing from this page unless you tune the sweep.
| Key | What it does |
|---|---|
base | Paints the text with a moving gradient and loops the sweep |
once | Plays a single sweep instead of looping |
reverse | Sweeps from right to left instead of left to right |
none | Turns the effect off and renders the text in its own colour |
The gradient is built from currentColor, so the shimmer takes the element's
text colour, from mutedForeground to a status colour, with nothing to set.
The highlight is a light-dark() pair: a faded copy of the text colour in the
light scheme, and a brighter one in the dark scheme, so it stays visible on a
dark background. The gradient fills the glyphs through background-clip: text,
and an animation on background-position moves the highlight across them.
once, reverse and none change base, so merge them after it.
With Marker
The shimmer works on any element that renders text. A common use is a Marker that shows a live status while an assistant works.
Tuning
Four custom properties tune the sweep: colour, duration, spread and angle. They inherit, so set them on the shimmering element or on any element above it, such as the list around a set of lines.
On an element you style yourself, put them in an entry merged into the same
stylex.props() call as base:
On a arene component, set them with style, cast to CSSProperties. xstyle
rejects a StyleX entry that sets only custom properties, because StyleX types
it as having nothing in common with CSS properties.
Color
Set --arene-shimmer-color to pick the highlight colour. The default is
derived from the text colour.
Drafting a reply…
Drafting a reply…
Duration
Set --arene-shimmer-duration to the length of one sweep. The default is
2s.
Drafting a reply…
2s
Drafting a reply…
1s
Spread
Set --arene-shimmer-spread to the width of the highlight band. The default
is calc(3ch + 40px). The 40px part is fixed, and the 3ch part scales with
the font size.
Drafting a reply…
1rem
Drafting a reply…
6rem
Angle
Set --arene-shimmer-angle to tilt the band. The default is 20deg.
Drafting a reply…
20deg
Drafting a reply…
45deg
Reverse
The highlight sweeps from left to right. Merge shimmerStyles.reverse to sweep
from right to left. arene assumes a left-to-right layout, so in a
right-to-left one, merge reverse to make the sweep follow the text.
Drafting a reply…
forward
Drafting a reply…
reverse
Play once
Merge shimmerStyles.once to play a single sweep, as a reveal when streaming
finishes. Set --arene-shimmer-duration to control how long it takes. The
demo remounts the text to replay it.
Turning it off
Merge shimmerStyles.none conditionally to stop the effect, for example when a
response finishes streaming.
Drafting a reply…
Reduced motion
When the user prefers reduced motion, base drops the gradient and the
animation, and the text renders in its own colour. This needs no setup.
API reference
shimmerStyles
| Key | Description |
|---|---|
base | The gradient, background-clip: text, the transparent fill and the looping sweep |
once | animation-iteration-count: 1 |
reverse | animation-direction: reverse |
none | Removes the gradient and the animation and restores the text fill |
CSS variables
They inherit. See Tuning for where to set them.
| Variable | Default | Effect |
|---|---|---|
--arene-shimmer-duration | 2s | The length of one sweep |
--arene-shimmer-spread | calc(3ch + 40px) | The width of the highlight |
--arene-shimmer-angle | 20deg | The tilt of the band |
--arene-shimmer-color | A light-dark() tint of currentColor | The highlight colour |