组件

Highlight

A highlighter swipe behind real words. The phrase stays text you can select and copy; the swipe follows it line by line when it wraps, in yellow or any stationery color, and can draw itself on as it scrolls into view.

安装

terminal
npx shadcn@latest add @wobko/highlight

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Default

A swipe behind a phrase. Select the text, copy it: it is still just words.

Tones and weights

Yellow is the highlighter. Pink, green, blue, orange, lilac and teal are the stationery accents held as translucent markers.

Wraps, and draws on

A phrase that runs onto three lines gets three swipes, one per line, that start and stop where the words do. Press replay to watch it being drawn.

Reading notes

Highlights inside a card: the swipe sits on the paper, behind the words, and the card's tilt never touches the text.

API 参考

Highlight

A <mark> (or your own element with asChild) that hosts the drawing. One aria-hidden swipe per line of the phrase, measured from the browser's own line boxes, so it starts and ends where the words do.

属性类型默认值说明
tone"yellow" | "pink" | "green" | "blue" | "orange" | "lilac" | "teal""yellow"The marker. Yellow is the highlighter; the rest are the stationery accents as translucent markers.
weight"light" | "regular" | "heavy""regular"How fat the marker is held.
cover"full" | "under""full"full covers the letters; under runs along the lower half of the line so the words stay clear above it.
animatebooleanfalseHold the swipe back and draw it on, left to right, the first time the phrase scrolls into view. Reduced motion just shows it.
showbooleantrueShow or hide the swipe. With animate, turning it on plays the draw-on.
delaynumber-Milliseconds to wait before the first line draws on; each further line follows a beat later.
seedstring | number-Pins the hand. Default: derived from useId(), so server and client draw the same swipe.
asChildbooleanfalseRender the swipe on your own child element (a link, a strong).

无障碍

  • The words are ordinary text: selectable, copyable, found by search, read in order. The swipe is aria-hidden and pointer-events-none, so it never takes a click or a selection.
  • It is a <mark>, so assistive technology that announces highlighted text still does. Text on the swipe stays ink on a translucent tint (about 12:1 on the yellow).
  • Before the first measure, without JavaScript and in Windows high contrast you get the browser's own <mark> background (system Mark colors in high contrast). With animate the swipe is only drawn once scripts run.
  • Reduced motion (or data-motion="reduced") zeroes the draw-on: the swipe simply appears.

源码

CLI 会复制进你项目的文件。

正在加载源码