Richtext Pencil
A small, decorative inline-SVG pencil mark for richtext emphasis. The stroke reads as a hand-drawn underline or marginal accent — a wobbly horizontal pencil line — and scales uniformly with the size prop.
Customize
Pencil
64px
1.5
accent
Installation
npx shadcn@latest add https://craftbits.dev/r/richtext-pencil.jsonUsage
import { RichtextPencil } from "@craft-bits/core";
<RichtextPencil size={64} />To theme via the surrounding text color, wrap in any text-cb-* utility.
Understanding the component
- Single hand-drawn path. The whole ornament is one cubic-Bezier stroke inside a 64x16 viewBox — soft lead-in, wobble across the midline, hooked finish. One
sizeprop scales it uniformly while preserving the aspect ratio. - Decorative, never announced. The root SVG carries
aria-hidden="true",focusable={false}, andpointer-events: noneso the ornament never enters the accessibility tree or steals focus. - Color flows from the parent.
accentColordefaults tocurrentColor, inheriting the wrapping text color — no theme prop drilling. Pass any CSS color to override. - Static — no motion. Richtext Pencil is fully static. Motion (for example a
pathLengthreveal) belongs to the parent — wrap in amotion.span. - Generalized from terminal-dreams. The source primitive was a span that tinted children with the accent color and widened letter-spacing. That coupled the mark to the inline text it adorned. This version splits the visual mark off into a composable SVG so it can stack under any inline element.
Variants
- Default —
<RichtextPencil /> - Explicit accent —
<RichtextPencil accentColor="#4A7BF7" /> - Larger size —
<RichtextPencil size={128} /> - Thinner stroke —
<RichtextPencil strokeWidth={1} />
Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | number | 64 | Width in px (height scales to preserve aspect). |
accentColor | string | 'currentColor' | CSS color for the pencil stroke. |
strokeWidth | number | 1.5 | Stroke width in viewBox units. |
className | string | — | Extra classes merged onto the root SVG. |
Accessibility
- The root SVG carries
aria-hidden="true"andfocusable={false}— Richtext Pencil is purely decorative and screen readers skip it. pointer-events: noneanduser-select: noneare applied so the ornament never blocks clicks or text selection on layered content.- No motion is rendered — there is nothing to gate behind
prefers-reduced-motion. - Color tinting flows from
currentColorby default, so the mark inherits whatever contrast the wrapping text already meets.
Credits
- Extracted from:
terminal-dreams(src/components/ui/richtext-pencil.tsx).