仕組み
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.
向いている場面
- 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.
向かない場面
- 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.
使い方
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' },
]}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
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>. |
アクセシビリティ
- 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.
モーション
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.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
ScribbleNav.jsxscribble-nav.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

