Lab // Index
Total: 07Component // Text
03 of 07Dia TextNew
Text written in by a band of colour sweeping across it, then left in its base colour. A web port of the Dia-style text reveal, with no dependencies
Demo // Live
InteractiveDesign engineering
Install // Steps
Total: 01Step 01
Copy and paste the following code into your project.
One file, React only. The sweep runs on the Web Animations API, so there is nothing to install.
import { DiaText } from "@/components/craft/dia-text";
export default function MyPage() {
return (
<div className="flex min-h-screen flex-col items-center justify-center gap-10 p-8">
{/* One line, revealed once. Change `text` and it sweeps again. */}
<DiaText text="Hello, world" className="text-5xl font-semibold" />
{/* Several lines, cycling */}
<DiaText
text={["Design engineering", "Details, on purpose", "Built end to end"]}
loop
className="text-5xl font-semibold"
/>
{/* Your own colours and pace */}
<DiaText
text="Monochrome works too"
sweepColors={["#ffffff", "#8a8a8a"]}
baseColor="#111111"
duration={900}
bandRatio={0.5}
className="text-3xl"
/>
</div>
);
}Spec // Features
Total: 06- 01
Works on real text
The text is the mask, so it stays selectable, readable by screen readers and free to wrap
- 02
Sweeps again when the text changes
- 03
Cycles through several lines
Pass an array with loop; each line slides out and the next is swept in
- 04
Custom colours, band width and pace
- 05
Respects reduced motion
The text simply appears
- 06
No dependencies
Spec // Props
Total: 10| Prop | Type | Default | Description |
|---|---|---|---|
| text | string | string[] | - | The line to reveal, or several to cycle through |
| sweepColors | string[] | 5 colours | Colours inside the moving band |
| baseColor | string | currentColor | What the text settles into |
| duration | number | 1500 | Length of one sweep, in ms |
| delay | number | 0 | Wait before the sweep starts, in ms |
| loop | boolean | false | Replay, moving to the next text if there are several |
| loopDelay | number | 500 | Pause between sweeps, in ms |
| bandRatio | number | 0.34 | Band width as a fraction of the text width |
| autoPlay | boolean | true | Set false to hold the text hidden |
| onSweepEnd | (index) => void | - | Called when a sweep finishes |