Text reveal
Reveals text by line, word or character as it enters the viewport.
The text is revealed as it scrolls into view, once unless replay is set. With reduced motion it is plain text, in place from the start.
By lines
Every task in the March release has an owner, a due date and a reviewer. The notes go out on Wednesday morning.
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { TextReveal } from "@/components/ui/text-reveal"
export default function TextRevealByLines() {
const [run, setRun] = useState(0)
return (
<div className="flex w-full max-w-md flex-col items-start gap-4">
<TextReveal key={run} as="p" by="lines" className="w-full text-lg">
Every task in the March release has an owner, a due date and a reviewer. The notes go out on Wednesday morning.
</TextReveal>
<Button variant="outline" onClick={() => setRun(run + 1)}>
Play again
</Button>
</div>
)
}
By words
Twelve tasks shipped this month and three are still in review.
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { TextReveal } from "@/components/ui/text-reveal"
export default function TextRevealByWords() {
const [run, setRun] = useState(0)
return (
<div className="flex w-full max-w-md flex-col items-start gap-4">
<TextReveal key={run} as="p" by="words" className="w-full text-lg">
Twelve tasks shipped this month and three are still in review.
</TextReveal>
<Button variant="outline" onClick={() => setRun(run + 1)}>
Play again
</Button>
</div>
)
}
By characters
Released on Thursday
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { TextReveal } from "@/components/ui/text-reveal"
export default function TextRevealByCharacters() {
const [run, setRun] = useState(0)
return (
<div className="flex w-full max-w-md flex-col items-start gap-4">
<TextReveal key={run} as="p" by="chars" className="w-full text-lg">
Released on Thursday
</TextReveal>
<Button variant="outline" onClick={() => setRun(run + 1)}>
Play again
</Button>
</div>
)
}
Replaying on scroll
The review is on Tuesday, the notes go out on Wednesday and the invoice follows on Friday.
import { TextReveal } from "@/components/ui/text-reveal"
export default function TextRevealReplayingOnScroll() {
return (
<TextReveal as="p" replay className="w-full max-w-md text-lg">
The review is on Tuesday, the notes go out on Wednesday and the invoice follows on Friday.
</TextReveal>
)
}
Installation
npx shadcn@latest add @khaeli/text-revealbunx --bun shadcn@latest add @khaeli/text-revealInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- motion ^12.23.12
Accessible name
- The whole text is in the page once, in a visually hidden
span, and that is what a screen reader reads. The lines, words and characters that move arearia-hidden. - It renders a
div. Passasfor the element the text should be, such asas="h2"for a heading oras="p"for a paragraph.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/text-reveal.json