I built a ruler for signing contracts. Then I put it on my essays.
Morse is a table of contents (TOC) for React, drawn as a ruler on the left edge of the page. Each heading is a long tick placed where it really sits in the article, with short ticks between: a table of contents in dots and dashes.
A small dot rides down as you read, so the ruler doubles as a reading progress bar. It's open source under MIT, on npm as @hanifrestian/morse, with the code on GitHub.
Most React table of contents components are a sidebar of links, and a sidebar needs room. Morse fits in the margin, and that's the gap it's for.
On a wide screen, look left. The ruler on this page is the one Morse was cut from. Hover it to read a heading, and click a tick to jump there.
A table of contents that shows distance
My essays used to carry a small contents pill at the bottom of the screen. The pill told you where you were, never how far you had to go.
A contents list is a list, and a long read is a distance. So I drew the distance: every heading sits where it really falls in the article, and a dot shows how much is already behind you.
The ruler came from a line minimap in a contract-signing tool I built for myself. It turned out long essays wanted it more.
Getting started
pnpm add @hanifrestian/morseIt needs React 18 or 19 and Motion 11.11 to 13.
import { Morse } from '@hanifrestian/morse'
import '@hanifrestian/morse/style.css'
export default function Post() {
return (
<>
<article>{/* your h2 and h3 headings */}</article>
<Morse />
</>
)
}By default Morse maps the h2 and h3 headings inside your article. Import the stylesheet once, or the ruler has no layout. Every prop, heading attribute and CSS variable is in the README on GitHub.
Ruler ticks where the headings really are
My first ruler had 18 ticks, 18px apart. It felt too airy, and the short ticks were too short to swell, so hovering made no wave.
Now there are 28 ticks, 11px from one centre to the next, 36px long for a heading and 20px between. At that spacing, 28 keeps the ruler under 300px tall. The cost: 28 is also the most headings it can show, and any past that are dropped. Mark a heading with data-toc-ignore to leave it off.
A heading you've read is full ink, headings ahead are at 55%, and plain ticks sit at 20%. The ink shows how far you've read.
Move the pointer near the ruler and the ticks swell on a cosine curve, 2.2 times at the pointer and back to normal 64px away. Scrolling swells them too, around the dot, so the ruler shows where you are with the pointer away.
The dot is 6px, half the size of my cursor dot, so it never reads as a second cursor.
One label at a time, slow then quick
Hovering shows the full text of the nearest heading, wrapped rather than cut. My first label sat in a chip, and the chip jumped to a new size every time the text changed.
Now it's plain text that follows the pointer on a spring, and each new heading rolls in from the side you're moving toward.
The timing works like a row of tooltips. The first label arrives slowly, over 480ms with a little blur and slide. Moving to the next heading is quick, and coming back within 400ms skips the slow start.
My first curve was a strong ease-out, and even at 480ms it felt rushed, so the arrival uses a gentler one. Clicking a tick jumps to its heading and leaves 80px above it; with a taller sticky header, raise jumpOffset.
The bug the package found
Writing tests for the package turned up something I'd missed on my own site for three days. Hover just after a scroll, and the ticks wouldn't swell.
The dot was still easing into place, and every frame of that easing reset the tick sizes for the scroll swell, flattening the swell under the pointer. Now the pointer wins: while it's near the ruler, scrolling leaves the ticks alone.
Limitations
It doesn't do phones. Below 1280px the ruler hides, since most layouts have no free left margin there. If your layout does have the room, one media query brings it back.
It also needs Motion for the springs. If your app doesn't use it already, that's an extra dependency for one ruler.
Long ticks for headings, short ticks between, and one dot for you. That's Morse.