Cómo funciona
The loop is one SVG path laid over the row. Its shape is built from the measured box of the current item's text: an ellipse 15px wider and 10px taller on each side that wobbles by a few percent, leans up to 4° and spirals slightly outward, so the pen ends outside where it started and runs 25–50° past it. Each selection gets a new random seed, so every loop is different; re-measuring (a resize, fonts loading) keeps the seed and only moves the loop. The path has pathLength="1": drawing animates stroke-dashoffset from 1 to 0, and erasing runs it on to −1 so the line is pulled away from its start. On narrow screens the row scrolls sideways and the loop scrolls with it.
Úsalo para
- The main navigation of a landing page, a portfolio or a small business site with a friendly, hand-made tone.
- Section switches inside a page (menu, timetable, prices) where the choice should feel personal.
- Pages that already use hand-drawn touches: underlines, notes, sketches.
Busca otra opción cuando
- Dense application navigation (dashboards, settings, admin areas): use sliding tabs or a side nav.
- Long lists of items, where a circle around each would be noise.
- Products with a strict, technical tone.
Uso
import { ScribbleNav } from './ScribbleNav.jsx'
export function SiteNav({ path }) {
return (
<ScribbleNav
label="Main"
value={path}
items={[
{ value: '/classes', label: 'Classes', href: '/classes' },
{ value: '/timetable', label: 'Timetable', href: '/timetable' },
{ value: '/prices', label: 'Prices', href: '/prices' },
{ value: '/visit', label: 'Visit', href: '/visit' },
]}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
items | { value: string, label: ReactNode, href?: string, onClick?: (event) => void }[] | — | The navigation items. An item with href renders as a link, the others as buttons. |
value | string | — | The current item (controlled), for example the current path. |
defaultValue | string | items[0].value | The first current item when uncontrolled. |
onChange | (value: string) => void | — | Called when another item is chosen. |
tone | 'accent' | 'tertiary' | 'accent' | Colour role of the pen line. |
drawOnMount | boolean | true | Draws the first loop when the row first comes into view; false shows it already drawn. |
label | string | 'Main' | Accessible name of the <nav> landmark. |
...rest | HTMLAttributes<HTMLElement> | — | Other attributes go to the root <nav>. |
Accesibilidad
- The row is a <nav> landmark named by label; the current item carries aria-current ("page" for links), so it is announced without relying on the loop.
- The current item's text also turns to the primary text colour, so the state is not carried by the loop alone.
- Every item is a native link or button: Tab reaches it, Enter or Space activates it, and the focus ring is visible.
- The loop is decorative and hidden from screen readers.
- Reduced motion shows the new loop at once and drops the old one, with no drawing or erasing.
Movimiento
Draw: 560ms cubic-bezier(0.5, 0.05, 0.25, 1), like a pen that speeds up and lands softly, starting 110ms after the old loop begins to lift. Erase: 260ms ease-in, the line pulled away from its start while fading to 30%. The first loop draws once the row is 30% in view.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
ScribbleNav.jsxscribble-nav.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

