Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(quill): add highlight primitive with marker animation (#108289)

Adam Leith9c52fabbc15f
diff --git a/packages/quill/packages/primitives/AGENTS.md b/packages/quill/packages/primitives/AGENTS.md
index 05ad8911eba2..b2d1e075f918 100644
--- a/packages/quill/packages/primitives/AGENTS.md
+++ b/packages/quill/packages/primitives/AGENTS.md
@@ -121,6 +121,7 @@ For a run of questions asked one at a time — an agent needing a few decisions
| Heading | Section/page titles — sizes 2xl/xl/lg/base/sm, semantic level via `render={<h1 />}` decoupled from size |
| Text | Body copy — sizes lg/base/sm/xs/xxs, variants default/muted/destructive, weights normal/medium/semibold |
| Label | `<label>` bound to a control; inside forms prefer FieldLabel |
+| Highlight | A marker-pen tint on a few words of a heading or sentence, for emphasis; `animate` draws it in |
Don't hand-roll `<p className="text-xs text-muted-foreground">` when `<Text size="xs" variant="muted">` exists.
@@ -948,6 +949,26 @@ Skipped items don't appear at all.
- **Tabs across the top are the same controlled navigation**, for a short run the user should see whole before committing: hold the active question's name in state, pass it as both the root's `item` and the `Tabs` `value`, and take `onItemChange` and `onValueChange` back into it. Read each item's `onStatusChange` to show a check in its tab — keep the icon mounted and `invisible` until the answer lands, tinted `text-success-foreground`, so the label doesn't shift. Keep the tabs outside the form — inside it they are one more stop between a question and its answers, and their buttons take part in the form. In a `Card` that means the card wraps the questionnaire: tabs in `CardHeader`, then the root with `className="contents"` around `CardContent` and `CardFooter`.
- Inside a `Dialog`, put `className="contents"` on the root so the header, body, and footer stay in the dialog's own grid (and keep their padding and dividers) while the form still wraps the submit button. Cancel and dismiss remain the dialog's. Drop `QuestionnaireActions` there and put the navigation buttons straight into `DialogFooter` next to the `DialogClose`, the way every other dialog does — the footer is already the button row, and nesting the actions grid inside it doubles the gap.
+### Highlight
+
+A marker-pen tint over inline text — a pale background with the text in the same hue.
+The colors (`orange` default, `red`, `yellow`, `green`, `blue`, `purple`) are decorative, with no meaning; use `Badge` for status.
+It renders a `<mark>` and never changes layout: the tint bleeds a little past the text through padding that a matching negative margin cancels, so wrapping lines break exactly where they would without it.
+
+`animate` draws it like a marker stroke the first time it scrolls into view.
+The stroke covers one line before it starts the next, and the text takes the highlight color as the stroke passes it.
+The stroke length scales with the text length; override it with `duration`, and stagger several with `delay` (both in ms).
+Reduced motion shows the finished highlight at once.
+
+```tsx
+<Heading size="2xl">
+ Make your product{' '}
+ <Highlight color="blue" animate>
+ self-driving
+ </Highlight>
+</Heading>
+```
+
### Keyboard Shortcuts
```tsx
diff --git a/packages/quill/packages/primitives/src/highlight.css b/packages/quill/packages/primitives/src/highlight.css
new file mode 100644
index 000000000000..3b52624867f0
--- /dev/null
+++ b/packages/quill/packages/primitives/src/highlight.css
@@ -0,0 +1,124 @@
+@layer components {
+ .quill-highlight {
+ --quill-highlight-bleed: 0.15em;
+
+ /* The negative margin cancels the padding, so the highlight bleeds past the text without moving it. */
+ padding-inline: var(--quill-highlight-bleed);
+ margin-inline: calc(var(--quill-highlight-bleed) * -1);
+ color: var(--quill-highlight-foreground);
+ background-color: transparent;
+ background-image: linear-gradient(var(--quill-highlight-background), var(--quill-highlight-background));
+ background-repeat: no-repeat;
+ background-position: left center;
+ background-size: 100% 100%;
+ border-radius: 0.2em;
+
+ /* Keep the default `box-decoration-break: slice`: one background strip spans all line fragments, so the stroke finishes one line before it starts the next. */
+ }
+
+ /*
+ * The ink follows the stroke: two text-clipped layers paint the glyphs (highlight color over the inherited color),
+ * and the top one grows in step with the marker layer underneath.
+ */
+ .quill-highlight:is([data-phase='waiting'], [data-phase='drawing']) {
+ --quill-highlight-progress: 0%;
+
+ color: inherit;
+ background-image:
+ linear-gradient(var(--quill-highlight-foreground), var(--quill-highlight-foreground)),
+ linear-gradient(currentColor, currentColor),
+ linear-gradient(var(--quill-highlight-background), var(--quill-highlight-background));
+ background-clip: text, text, padding-box;
+ background-size:
+ var(--quill-highlight-progress) 100%,
+ 100% 100%,
+ var(--quill-highlight-progress) 100%;
+ -webkit-text-fill-color: transparent;
+ }
+
+ .quill-highlight[data-phase='drawing'] {
+ --quill-highlight-progress: 100%;
+
+ transition: background-size var(--quill-highlight-duration) cubic-bezier(0.45, 0.1, 0.35, 1)
+ var(--quill-highlight-delay);
+ }
+
+ /* Colors — decorative only, no semantic meaning. Background is a pale tint, text the same hue at full strength. */
+ .quill-highlight--color-orange {
+ --quill-highlight-background: oklch(0.92 0.05 45deg);
+ --quill-highlight-foreground: oklch(0.56 0.17 42deg);
+ }
+
+ .quill-highlight--color-red {
+ --quill-highlight-background: oklch(0.92 0.045 20deg);
+ --quill-highlight-foreground: oklch(0.53 0.19 25deg);
+ }
+
+ .quill-highlight--color-yellow {
+ --quill-highlight-background: oklch(0.94 0.08 95deg);
+ --quill-highlight-foreground: oklch(0.52 0.11 75deg);
+ }
+
+ .quill-highlight--color-green {
+ --quill-highlight-background: oklch(0.93 0.06 150deg);
+ --quill-highlight-foreground: oklch(0.5 0.13 150deg);
+ }
+
+ .quill-highlight--color-blue {
+ --quill-highlight-background: oklch(0.92 0.04 260deg);
+ --quill-highlight-foreground: oklch(0.55 0.19 262deg);
+ }
+
+ .quill-highlight--color-purple {
+ --quill-highlight-background: oklch(0.88 0.07 305deg);
+ --quill-highlight-foreground: oklch(0.47 0.2 305deg);
+ }
+
+ :is(.dark, [theme='dark']) .quill-highlight--color-orange {
+ --quill-highlight-background: oklch(0.38 0.09 45deg / 70%);
+ --quill-highlight-foreground: oklch(0.85 0.1 50deg);
+ }
+
+ :is(.dark, [theme='dark']) .quill-highlight--color-red {
+ --quill-highlight-background: oklch(0.36 0.1 20deg / 70%);
+ --quill-highlight-foreground: oklch(0.84 0.09 20deg);
+ }
+
+ :is(.dark, [theme='dark']) .quill-highlight--color-yellow {
+ --quill-highlight-background: oklch(0.4 0.08 90deg / 70%);
+ --quill-highlight-foreground: oklch(0.9 0.12 95deg);
+ }
+
+ :is(.dark, [theme='dark']) .quill-highlight--color-green {
+ --quill-highlight-background: oklch(0.36 0.08 150deg / 70%);
+ --quill-highlight-foreground: oklch(0.87 0.1 150deg);
+ }
+
+ :is(.dark, [theme='dark']) .quill-highlight--color-blue {
+ --quill-highlight-background: oklch(0.36 0.1 262deg / 70%);
+ --quill-highlight-foreground: oklch(0.84 0.09 262deg);
+ }
+
+ :is(.dark, [theme='dark']) .quill-highlight--color-purple {
+ --quill-highlight-background: oklch(0.36 0.12 305deg / 70%);
+ --quill-highlight-foreground: oklch(0.85 0.09 305deg);
+ }
+
+ /* The reduced-motion hook only answers after hydration, so server-rendered markup needs this to show the finished highlight on first paint. */
+ @media (prefers-reduced-motion: reduce) {
+ .quill-highlight[data-phase='waiting'] {
+ --quill-highlight-progress: 100%;
+ }
+ }
+
+ /* Forced colors drop gradient backgrounds, so paint the system mark colors and undo the text clip of the stroke. */
+ @media (forced-colors: active) {
+ .quill-highlight,
+ .quill-highlight[data-phase] {
+ color: MarkText;
+ background-color: Mark;
+ background-clip: padding-box;
+ -webkit-text-fill-color: currentColor;
+ }
+ }
+}
diff --git a/packages/quill/packages/primitives/src/highlight.stories.tsx b/packages/quill/packages/primitives/src/highlight.stories.tsx
new file mode 100644
index 000000000000..251caabee60d
--- /dev/null
+++ b/packages/quill/packages/primitives/src/highlight.stories.tsx
@@ -0,0 +1,118 @@
+import type { Meta, StoryObj } from '@storybook/react'
+import * as React from 'react'
+
+import { Button } from './button'
+import { Heading } from './heading'
+import { Highlight, type HighlightColor } from './highlight'
+import { Text } from './text'
+
+const COLORS: HighlightColor[] = ['orange', 'red', 'yellow', 'green', 'blue', 'purple']
+
+const meta: Meta<typeof Highlight> = {
+ title: 'Typography/Highlight',
+ component: Highlight,
+ tags: ['autodocs'],
+ args: {
+ children: 'self-driving',
+ color: 'orange',
+ animate: true,
+ },
+ argTypes: {
+ color: {
+ control: 'select',
+ options: COLORS,
+ },
+ animate: { control: 'boolean' },
+ duration: { control: { type: 'number', min: 100, step: 100 } },
+ delay: { control: { type: 'number', min: 0, step: 100 } },
+ },
+}
+
+export default meta
+type Story = StoryObj<typeof meta>
+
+export const Playground = {
+ render: (args) => (
+ <Heading size="2xl">
+ Make your product <Highlight {...args} />
+ </Heading>
+ ),
+} satisfies Story
+
+export const Colors = {
+ render: () => (
+ <div className="flex flex-col gap-3">
+ {COLORS.map((color) => (
+ <Heading key={color} size="xl">
+ A simpler <Highlight color={color}>{color} sidebar</Highlight>
+ </Heading>
+ ))}
+ </div>
+ ),
+} satisfies Story
+
+function Replayable({ children }: { children: React.ReactNode }): React.ReactElement {
+ const [run, setRun] = React.useState(0)
+ return (
+ <div className="flex flex-col items-start gap-4">
+ <div key={run}>{children}</div>
+ <Button variant="outline" onClick={() => setRun((value) => value + 1)}>
+ Replay
+ </Button>
+ </div>
+ )
+}
+
+export const Animated = {
+ render: () => (
+ <Replayable>
+ <div className="flex flex-col gap-3">
+ <Heading size="2xl">
+ Are software factories{' '}
+ <Highlight color="purple" animate>
+ BS?
+ </Highlight>
+ </Heading>
+ <Heading size="xl">
+ Make your product{' '}
+ <Highlight color="blue" animate delay={300}>
+ self-driving
+ </Highlight>
+ </Heading>
+ <Heading size="lg">
+ <Highlight color="orange" animate delay={600}>
+ A simpler sidebar
+ </Highlight>
+ </Heading>
+ </div>
+ </Replayable>
+ ),
+} satisfies Story
+
+export const Wrapping = {
+ render: () => (
+ <Replayable>
+ <Text className="max-w-80">
+ Many of you told us things were hard to find.{' '}
+ <Highlight color="yellow" animate>
+ So we rebuilt the sidebar around the products you use, and moved everything else one click away
+ </Highlight>
+ . Let us know what you think.
+ </Text>
+ </Replayable>
+ ),
+} satisfies Story
+
+const LAYOUT_COPY = 'The highlight paints behind the text. It never adds space, so line breaks stay where they were.'
+
+export const LayoutUnchanged = {
+ render: () => (
+ <div className="flex max-w-72 flex-col gap-4">
+ <Text>{LAYOUT_COPY}</Text>
+ <Text>
+ The highlight paints behind the text.{' '}
+ <Highlight color="green">It never adds space, so line breaks stay where they were.</Highlight>
+ </Text>
+ </div>
+ ),
+} satisfies Story
diff --git a/packages/quill/packages/primitives/src/highlight.tsx b/packages/quill/packages/primitives/src/highlight.tsx
new file mode 100644
index 000000000000..132c18ce8dd7
--- /dev/null
+++ b/packages/quill/packages/primitives/src/highlight.tsx
@@ -0,0 +1,123 @@
+import './highlight.css'
+
+import { mergeProps } from '@base-ui/react/merge-props'
+import { useRender } from '@base-ui/react/use-render'
+import { cva, type VariantProps } from 'class-variance-authority'
+import * as React from 'react'
+
+import { useReducedMotion } from './lib/use-reduced-motion'
+import { cn } from './lib/utils'
+
+const highlightVariants = cva('quill-highlight', {
+ variants: {
+ color: {
+ orange: 'quill-highlight--color-orange',
+ red: 'quill-highlight--color-red',
+ yellow: 'quill-highlight--color-yellow',
+ green: 'quill-highlight--color-green',
+ blue: 'quill-highlight--color-blue',
+ purple: 'quill-highlight--color-purple',
+ },
+ },
+ defaultVariants: {
+ color: 'orange',
+ },
+})
+
+type HighlightColor = NonNullable<VariantProps<typeof highlightVariants>['color']>
+
+// `done` is the static highlight, so the text-clipped glyphs of the stroke never outlive it.
+type Stroke = { phase: 'waiting' } | { phase: 'drawing'; durationMs: number } | { phase: 'done' }
+
+const WAITING: Stroke = { phase: 'waiting' }
+const DONE: Stroke = { phase: 'done' }
+
+const MS_PER_CHARACTER = 30
+const MIN_DURATION_MS = 350
+const MAX_DURATION_MS = 1600
+
+// A marker moves at a steady hand speed, so a long phrase takes longer to cover than a short one.
+function strokeDuration(text: string): number {
+ return Math.min(MAX_DURATION_MS, Math.max(MIN_DURATION_MS, text.length * MS_PER_CHARACTER))
+}
+
+interface HighlightProps extends Omit<useRender.ComponentProps<'mark'>, 'color'> {
+ color?: HighlightColor
+ /** Draw the highlight like a marker stroke the first time it scrolls into view. */
+ animate?: boolean
+ /** Stroke length in ms. Defaults to a value based on the text length. */
+ duration?: number
+ /** Wait this many ms after the text enters the view before the stroke starts. */
+ delay?: number
+}
+
+function Highlight({
+ className,
+ color = 'orange',
+ animate = false,
+ duration,
+ delay = 0,
+ render,
+ ...props
+}: HighlightProps): React.ReactElement {
+ const elementRef = React.useRef<HTMLElement>(null)
+ const reducedMotion = useReducedMotion()
+ const strokes = animate && !reducedMotion
+ const [strokeState, setStroke] = React.useState<Stroke>(WAITING)
+ const stroke = strokes ? strokeState : DONE
+
+ React.useEffect(() => {
+ const element = elementRef.current
+ if (!strokes || !element) {
+ return
+ }
+ // Re-arm when `animate` turns back on after an earlier stroke.
+ setStroke(WAITING)
+ const draw = (): void => setStroke({ phase: 'drawing', durationMs: strokeDuration(element.textContent ?? '') })
+ if (typeof IntersectionObserver === 'undefined') {
+ draw()
+ return
+ }
+ const observer = new IntersectionObserver((entries) => {
+ if (entries.some((entry) => entry.isIntersecting)) {
+ observer.disconnect()
+ draw()
+ }
+ })
+ observer.observe(element)
+ return () => observer.disconnect()
+ }, [strokes])
+
+ return useRender({
+ defaultTagName: 'mark',
+ ref: elementRef,
+ props: mergeProps<'mark'>(
+ {
+ 'data-quill': '',
+ className: cn(highlightVariants({ color }), className),
+ style:
+ stroke.phase === 'drawing'
+ ? ({
+ '--quill-highlight-duration': `${duration ?? stroke.durationMs}ms`,
+ '--quill-highlight-delay': `${delay}ms`,
+ } as React.CSSProperties)
+ : undefined,
+ onTransitionEnd: (event: React.TransitionEvent<HTMLElement>) => {
+ if (event.target === event.currentTarget && event.propertyName === 'background-size') {
+ setStroke(DONE)
+ }
+ },
+ } as Omit<React.ComponentProps<'mark'>, 'ref'>,
+ props
+ ),
+ render,
+ state: {
+ slot: 'highlight',
+ color,
+ phase: stroke.phase,
+ },
+ })
+}
+
+export { Highlight, highlightVariants }
+export type { HighlightColor, HighlightProps }
diff --git a/packages/quill/packages/primitives/src/index.ts b/packages/quill/packages/primitives/src/index.ts
index e52ed6d25627..5848cafa6fda 100644
--- a/packages/quill/packages/primitives/src/index.ts
+++ b/packages/quill/packages/primitives/src/index.ts
@@ -239,6 +239,7 @@ export {
ItemHeader,
ItemFooter,
} from './item'
+export { Highlight, highlightVariants, type HighlightColor, type HighlightProps } from './highlight'
export { Kbd, KbdGroup, KbdText } from './kbd'
export { Label } from './label'
export {