Highlight Text
Sequential hand-drawn SVG marker, underline, and circle strokes over ordered keywords or composable inline HighlightMark spans.
Purposeful motion clarifies state, guides attention, and rewards every action.
Customize
Installation
npx shadcn@latest add @kinetic/highlight-textUsage
Pass the full copy to text and an array of target phrases to highlights. HighlightText finds matches in reading order and draws each SVG stroke sequentially using the shared drawStroke WAAPI helper. By default, strokes animate when the block enters the viewport (trigger="inView").
import { HighlightText } from "@/components/kinetic/ui/highlight-text";
interface CalloutSentenceProps {
readonly text: string;
readonly highlights: readonly string[];
}
export function CalloutSentence({ text, highlights }: CalloutSentenceProps) {
return (
<HighlightText
text={text}
highlights={highlights}
variant="marker"
tone="amber"
className="text-xl leading-relaxed"
/>
);
}Variants, tones, and composable marks
Choose between three hand-styled SVG strokes via variant: "marker" (default translucent brush pass behind text), "underline", or "circle". Pick a semantic tone: "primary", "amber" (default), "emerald", or "rose".
When you want to mix variants or tones inside the same sentence, compose <HighlightMark> directly around inline text and coordinate sequence timing with active and delayMs.
import { HighlightMark } from "@/components/kinetic/ui/highlight-text";
interface ComposedNoteProps {
readonly active: boolean;
}
export function ComposedNote({ active }: ComposedNoteProps) {
return (
<p className="text-lg leading-relaxed">
Draw attention to{" "}
<HighlightMark variant="marker" tone="amber" active={active} delayMs={0}>
key metrics
</HighlightMark>
, call out{" "}
<HighlightMark variant="underline" tone="emerald" active={active} delayMs={180}>
fast wins
</HighlightMark>
, and frame{" "}
<HighlightMark variant="circle" tone="rose" active={active} delayMs={360}>
critical deadlines
</HighlightMark>
.
</p>
);
}Imperative control
Attach a HighlightTextHandle ref to HighlightText to call play() or reset() on demand. Adjust per-stroke timing with durationMs (default 420, clamped 80 to 3000), sequence gap with staggerMs (default 140, clamped 0 to 1200), and stroke thickness with strokeWidth (default 2.5, clamped 1 to 8).
import { useRef } from "react";
import { HighlightText, type HighlightTextHandle } from "@/components/kinetic/ui/highlight-text";
interface ControlledHighlightProps {
readonly text: string;
}
export function ControlledHighlight({ text }: ControlledHighlightProps) {
const ref = useRef<HighlightTextHandle>(null);
return (
<div className="space-y-3">
<HighlightText
ref={ref}
text={text}
highlights={["precision", "clarity"]}
variant="underline"
tone="primary"
trigger="manual"
className="text-xl font-medium"
/>
<div className="flex gap-2">
<button type="button" onClick={() => ref.current?.play()}>
Play
</button>
<button type="button" onClick={() => ref.current?.reset()}>
Reset
</button>
</div>
</div>
);
}Accessibility and reduced motion
Both HighlightText and HighlightMark keep the text as plain selectable inline DOM content while marking every decorative <svg> stroke with aria-hidden="true" and focusable="false". Screen readers read the sentence normally with no duplicate announcements.
Stroke colors mix semantic CSS variables (--primary, --swatch-amber, --swatch-emerald, --swatch-rose) with color-mix so markers stay legible across light and dark themes. durationMs, staggerMs, delayMs, and speed scale with the global Kinetic tempo. Under reduced motion, strokes render immediately in their completed state and invoke onComplete.
API Reference
HighlightText
Paragraph and headline annotator that matches ordered keywords and draws hand-crafted SVG strokes sequentially.
| Prop | Type | Default | Description |
|---|---|---|---|
text | string | - | Full sentence or headline text. |
highlights | readonly string[] | - | Ordered phrases to annotate in sequence. |
variant | "marker" | "underline" | "circle" | "marker" | Hand-drawn annotation shape. |
tone | "primary" | "amber" | "emerald" | "rose" | "amber" | Semantic token palette for the stroke. |
trigger | "inView" | "mount" | "manual" | "inView" | When drawing begins. |
durationMs | number | 420 | Base draw duration per keyword stroke. |
staggerMs | number | 140 | Additional beat between consecutive keywords. |
HighlightMark
Composable inline wrapper for drawing a hand-crafted SVG stroke around arbitrary JSX.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Inline content to highlight. |
variant | "marker" | "underline" | "circle" | "marker" | Stroke style around children. |
tone | "primary" | "amber" | "emerald" | "rose" | "amber" | Semantic color token. |
active | boolean | true | Controls whether the stroke draws in. |
delayMs | number | 0 | Start delay in milliseconds for manual sequencing. |