start here
Get started- 1from
- 2bend · 0.3
- width · 160
- height · 96
Schedule of props
| Mark | Prop | Type | Default | Description |
|---|---|---|---|---|
| P1 | variant | InkArrowVariant | 'curved' | — |
| P2 | width | number | 160 | The box the arrow is drawn in, in px. |
| P3 | height | number | 96 | — |
| P4 | from | [number, number] | [0.06, 0.3] | Where the arrow starts, as a share of the box (0 to 1 across, 0 to 1 down). |
| P5 | to | [number, number] | [0.92, 0.74] | Where its head is, likewise. |
| P6 | bend | number | 0.3 | How far a curved or looped arrow bends to one side, as a share of its length; negative bends it the other way. |
| P7 | head | number | 12 | The length of the head's barbs, in px. |
| P8 | accent | string | '#e0482a' | The pen's colour: the accent, unless you pass `currentColor` for ink. |
| P9 | strokeWidth | number | 1.6 | — |
| P10 | seed | number | 1 | — |
| P11 | trigger | InkTrigger | 'scroll' | `scroll`: drawn as it rises, done at mid-screen. `view`: played once as it comes into view. |
| P12 | duration | number | 1100 | With `view`, how long the arrow takes, in ms. |
| P13 | className | string | '' | — |
Notes
- 1.A hand-drawn arrow pointing at something: nearly straight, curved, or looped, with a head made in one stroke.
- 2.The words and content it marks stay in the server HTML. The marks are measured to them in the browser, and made again when the layout changes.
- 3.Tied to the scroll by default: the last stroke lands as the drawing reaches the middle of the screen. With
trigger="view"it plays once as it comes into view instead. Reduced motion shows it drawn.
- 4.Detail A, Curved. A curve bending to one side, from a note to what it is about.
- 5.Usage, as drawn:
import { InkArrow } from '@/components/scrollfx/ink-arrow'; const Note = ({ children }: { children: React.ReactNode }) => <span className="font-serif text-xl italic tracking-[-0.01em] text-muted-foreground">{children}</span>; const Button = ({ children }: { children: React.ReactNode }) => ( <span className="inline-flex h-11 items-center rounded-full bg-foreground px-6 text-[15px] font-medium text-background">{children}</span> ); export function CurvedExample() { return ( <div className="flex items-end gap-2"> <div className="pb-20"><Note>start here</Note></div> <InkArrow className="mb-2" /> <Button>Get started</Button> </div> ); }
- 4.Detail B, Straight. Nearly straight, as a hand draws one without a ruler.
- 5.Usage, as drawn:
import { InkArrow } from '@/components/scrollfx/ink-arrow'; const Note = ({ children }: { children: React.ReactNode }) => <span className="font-serif text-xl italic tracking-[-0.01em] text-muted-foreground">{children}</span>; export function StraightExample() { return ( <div className="flex items-center gap-3"> <Note>the price drops here</Note> <InkArrow variant="straight" width={140} height={30} from={[0.04, 0.5]} to={[0.94, 0.5]} seed={2} /> <span className="font-serif text-4xl tracking-[-0.03em]">$18</span> </div> ); }
- 4.Detail C, Looped. A loop thrown half way, for a note that wants to be noticed.
- 5.Usage, as drawn:
import { InkArrow } from '@/components/scrollfx/ink-arrow'; const Note = ({ children }: { children: React.ReactNode }) => <span className="font-serif text-xl italic tracking-[-0.01em] text-muted-foreground">{children}</span>; const Button = ({ children }: { children: React.ReactNode }) => ( <span className="inline-flex h-11 items-center rounded-full bg-foreground px-6 text-[15px] font-medium text-background">{children}</span> ); export function LoopedExample() { return ( <div className="flex items-start gap-1"> <div className="pt-1"><Note>new this week</Note></div> <InkArrow variant="looped" width={200} height={120} from={[0.04, 0.12]} to={[0.94, 0.86]} bend={-0.25} seed={5} /> <div className="self-end"><Button>Plotted charts</Button></div> </div> ); }
View source · components/scrollfx/ink-arrow.tsx
'use client';
/**
* ink-arrow — an arrow drawn by hand to point at something: nearly straight,
* curved to one side, or with a loop thrown half way, ending in a head made
* in one stroke. The pen goes at one speed, shaft first, then the head.
*
* Built on svg-scroll-draw (MIT): https://github.com/DhruvilChauahan0210/scrollfx
* Needs: react, svg-scroll-draw, lib/plotter and lib/ink (installed with it).
* Styling: Tailwind CSS. Place it with `className` (absolute, in a flex row,
* beside a note); `from` and `to` set where it starts and ends in its box.
*
* The arrow is made in the browser and hidden from assistive tech: say in
* text what it points at. Reduced motion shows it drawn.
*/
import { useEffect, useRef, useState } from 'react';
import 'svg-scroll-draw/no-flash.css';
import { inkArrow, type ArrowKind, type Stroke } from '@/lib/plotter';
import { useInk, type InkTrigger } from '@/lib/ink';
export type InkArrowVariant = ArrowKind;
export interface InkArrowProps {
variant?: InkArrowVariant;
/** The box the arrow is drawn in, in px. */
width?: number;
height?: number;
/** Where the arrow starts, as a share of the box (0 to 1 across, 0 to 1 down). */
from?: [number, number];
/** Where its head is, likewise. */
to?: [number, number];
/** How far a curved or looped arrow bends to one side, as a share of its length; negative bends it the other way. */
bend?: number;
/** The length of the head's barbs, in px. */
head?: number;
/** The pen's colour: the accent, unless you pass `currentColor` for ink. */
accent?: string;
strokeWidth?: number;
seed?: number;
/** `scroll`: drawn as it rises, done at mid-screen. `view`: played once as it comes into view. */
trigger?: InkTrigger;
/** With `view`, how long the arrow takes, in ms. */
duration?: number;
className?: string;
}
export function InkArrow({
variant = 'curved',
width = 160,
height = 96,
from = [0.06, 0.3],
to = [0.92, 0.74],
bend = 0.3,
head = 12,
accent = '#e0482a',
strokeWidth = 1.6,
seed = 1,
trigger = 'scroll',
duration = 1100,
className = '',
}: InkArrowProps) {
const ref = useRef<SVGSVGElement>(null);
const [strokes, setStrokes] = useState<Stroke[] | null>(null);
const [fx, fy] = from, [tx, ty] = to;
useEffect(() => {
setStrokes(inkArrow({ w: width, h: height, kind: variant, from: [fx, fy], to: [tx, ty], bend, seed, head }));
}, [variant, width, height, fx, fy, tx, ty, bend, seed, head]);
const n = strokes?.length ?? 0;
// One piece after another: the pen keeps one speed down the shaft and round the head.
useInk(ref, { paths: n, spread: Math.max(0, n - 1), trigger, duration, version: strokes });
return (
<svg
ref={ref}
key={strokes ? strokes.length + strokes[0]?.d : 'empty'}
data-scroll-draw-pending=""
data-ink={trigger}
aria-hidden
width={width}
height={height}
viewBox={`0 0 ${width} ${height}`}
className={`pointer-events-none shrink-0 overflow-visible ${className}`}
fill="none"
stroke={accent}
strokeWidth={strokeWidth}
strokeLinecap="round"
strokeLinejoin="round"
>
{strokes?.map((s, i) => <path key={i} d={s.d} />)}
</svg>
);
}
Parts list
| Item | Part, as installed |
|---|---|
| 1 | components/scrollfx/ink-arrow.tsxThe component |
| 2 | lib/ink.tsThe pen hook the ink pieces share, and Hershey’s script |
| 3 | lib/plotter.tsStroke geometry: hatching, sketched lines, scroll windows |
| 4 | svg-scroll-draw ^2.29.0Dependency, from npm |
ViewCurved
Pens1ink2vermilion
Install
npx shadcn@latest add
https://scrollfx-ui.vercel.app/r/ink-arrow.jsonTitle
Ink arrow
scrollfx · Ink- Dwg no.
- ink-arrow
- Sheet
- 14/14
- Scale
- 1:1
- Rev
- 2.29.0
- Drawn by
- svg-scroll-draw
- Licence
- MIT