Self-drawing scene
A linear SVG scene — window, hills, laptop, steaming mug and plant — that inks itself layer by layer, in order, as you scroll inside the stage or press “draw”; the colours settle over the lines at the end, with erase, replay and a drawn-paths counter.
Real scenarios
The component as it is used in a product — not a specimen grid.
The scene that draws its own product
Svgator-style sequence drawing: scroll inside the frame and the workspace — window, hills, laptop, mug, steaming and the plant — inks itself path by path in layer order; at the end the colours settle over the lines. The draw button runs the whole sequence, erase resets, and the counter keeps score.
Scroll the frame itself (it is focusable — arrow keys scroll it too). Each stroke is a pathLength-normalised path; the counter rounds the scroll position onto the 17 paths.
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| paths | count | '17' | Seventeen paths in layer order: the desk line, the window frame and mullions, the hills, the laptop screen and base, the keyboard, the mug and its handle, two steam curls, the plant with three leaves. |
| progress | scroll | 'scrollTop / max' | The stage’s scroll position maps onto the path count; the scene stays sticky while a spacer below it buys the travel. The stage is focusable so arrow keys draw too. |
| colors | settle | 'p ≥ 0.97' | The colour layer sits behind the ink and settles over the scene with a 900ms fade once every path is in. |
| draw() | interval | '16ms · 7px' | The draw button advances that same scroll programmatically; the timer is cleared on destroy and on erase. |
| reduced-motion | media | 'instant' | Transitions drop out; each path shows complete the moment its turn arrives and the colours land without the fade. |
Snippet
<div class="imw" x-data="{
total: 17, drawn: 0, colored: false, t: null,
onScroll() {
const el = this.$refs.stage;
const max = el.scrollHeight - el.clientHeight;
const p = max > 0 ? el.scrollTop / max : 1;
this.drawn = Math.round(p * this.total);
this.colored = p >= 0.97;
},
erase() {
clearInterval(this.t);
this.$refs.stage.scrollTop = 0;
this.drawn = 0;
this.colored = false;
},
draw() {
this.erase();
this.t = setInterval(() => {
const el = this.$refs.stage;
const max = el.scrollHeight - el.clientHeight;
if (el.scrollTop >= max - 1) { clearInterval(this.t); this.onScroll(); }
else { el.scrollTop = Math.min(max, el.scrollTop + 7); this.onScroll(); }
}, 16);
},
}" x-init="$cleanup(() => clearInterval(t))">
<div class="imw-stage" x-ref="stage" x-on:scroll="onScroll()" tabindex="0" role="img"
aria-label="Line illustration of a workspace, drawn by scrolling">
<svg class="imw-scene" viewBox="0 0 320 200" aria-hidden="true">
{{-- the colour layer sits behind the ink and settles at the end --}}
<g class="imw-colors" x-bind:data-on="colored ? 'true' : 'false'">
<rect x="30" y="36" width="78" height="104" fill="#bfdbfe" opacity=".55" />
<rect x="152" y="84" width="92" height="58" fill="#c7d2fe" opacity=".45" />
</g>
@foreach ($paths as $i => $d)
<path class="imw-ink" pathLength="1" d="{{ $d }}" x-bind:data-drawn="drawn > {{ $i }}" />
@endforeach
</svg>
<div class="imw-spacer" aria-hidden="true"></div>
</div>
<div class="imw-toolbar">
<button type="button" class="imw-btn" x-on:click="draw()">
<svg viewBox="0 0 24 24"><path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 3v5h5"/></svg>
Draw
</button>
<button type="button" class="imw-btn" x-on:click="erase()">
<svg viewBox="0 0 24 24"><path d="M4 19h16"/><path d="m6 15 8-8 4 4-8 8H6z"/></svg>
Erase
</button>
<span class="imw-count" role="status" x-text="drawn + ' / ' + total + ' paths'"></span>
</div>
</div>
<style>
.imw-stage { block-size: 15.5rem; overflow-y: auto; border: 1px solid #e7e5e4;
border-radius: 1.1rem; background: #fff; }
.imw-scene { position: sticky; inset-block-start: 0; display: block; inline-size: 100%;
block-size: 15.5rem; background: #fff; }
.imw-spacer { block-size: 34rem; }
.imw-colors { opacity: 0; transition: opacity .9s ease; }
.imw-colors[data-on='true'] { opacity: 1; }
.imw-ink { fill: none; stroke: #1c1917; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .3s ease; }
.imw-ink[data-drawn='true'] { stroke-dashoffset: 0; }
@media (prefers-reduced-motion: reduce) {
.imw-ink, .imw-colors { transition: none; }
}
</style>
// app/Pages/IconMotion.jsx — Inertia (React) page; renders the React
// snippet below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import SelfDraw from '@/components/SelfDraw';
export default function IconMotion() {
return (
<NabuXUIProvider locale="en" linkComponent={Link}>
<main className="nx-page">
<SelfDraw />
</main>
</NabuXUIProvider>
);
}
// SelfDraw.jsx — a scene that inks itself layer by layer on scroll
import { useEffect, useRef, useState } from 'react';
import '@nabuxai/ui-core/css';
// Desk, window, hills, laptop, mug, steam, plant — in draw order.
const PATHS = [
'M14 170h292', 'M28 34h82v108H28z', 'M69 34v108', 'M28 88h82',
'M32 134q16-22 32 0', 'M62 134q12-16 24 0',
'M150 82h96v62h-96z', 'M138 144h136l10 16H128z', 'M156 156h92',
'M266 118h26v34a8 8 0 0 1-8 8h-10a8 8 0 0 1-8-8z', 'M292 126a9 9 0 0 1 0 18',
'M272 106q-4-6 0-12', 'M284 106q-4-6 0-12',
'M98 150h28l-4 20h-20z', 'M112 150c-2-14-12-24-24-26', 'M112 150c2-16 12-26 24-28', 'M112 150v-28',
];
export default function SelfDraw() {
const stageRef = useRef(null);
const timerRef = useRef(null);
const [drawn, setDrawn] = useState(0);
const [colored, setColored] = useState(false);
useEffect(() => () => clearInterval(timerRef.current), []);
// The scroll position maps onto the path count; colours settle at the end.
const onScroll = () => {
const el = stageRef.current;
const max = el.scrollHeight - el.clientHeight;
const p = max > 0 ? el.scrollTop / max : 1;
setDrawn(Math.round(p * PATHS.length));
setColored(p >= 0.97);
};
const erase = () => {
clearInterval(timerRef.current);
stageRef.current.scrollTop = 0;
setDrawn(0);
setColored(false);
};
const draw = () => {
erase();
timerRef.current = setInterval(() => {
const el = stageRef.current;
const max = el.scrollHeight - el.clientHeight;
if (el.scrollTop >= max - 1) { clearInterval(timerRef.current); onScroll(); }
else { el.scrollTop = Math.min(max, el.scrollTop + 7); onScroll(); }
}, 16);
};
return (
<>
<style>{`
.imw-stage { block-size: 15.5rem; overflow-y: auto; border: 1px solid #e7e5e4;
border-radius: 1.1rem; background: #fff; }
.imw-scene { position: sticky; inset-block-start: 0; display: block; inline-size: 100%;
block-size: 15.5rem; background: #fff; }
.imw-spacer { block-size: 34rem; }
.imw-colors { opacity: 0; transition: opacity .9s ease; }
.imw-colors[data-on='true'] { opacity: 1; }
.imw-ink { fill: none; stroke: #1c1917; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .3s ease; }
.imw-ink[data-drawn='true'] { stroke-dashoffset: 0; }
.imw-count { font: 700 .74rem/1.4 ui-monospace, monospace; color: #4f46e5; }
@media (prefers-reduced-motion: reduce) { .imw-ink, .imw-colors { transition: none; } }
`}</style>
<div className="imw-stage" ref={stageRef} onScroll={onScroll} tabIndex={0} role="img"
aria-label="Line illustration of a workspace, drawn by scrolling">
<svg className="imw-scene" viewBox="0 0 320 200" aria-hidden="true">
<g className="imw-colors" data-on={colored}>
<rect x="30" y="36" width="78" height="104" fill="#bfdbfe" opacity=".55" />
<rect x="152" y="84" width="92" height="58" fill="#c7d2fe" opacity=".45" />
</g>
{PATHS.map((d, i) => (
<path key={i} className="imw-ink" pathLength="1" d={d} data-drawn={drawn > i} />
))}
</svg>
<div className="imw-spacer" aria-hidden="true" />
</div>
<button type="button" onClick={draw}>Draw</button>
<button type="button" onClick={erase}>Erase</button>
<span className="imw-count" role="status">{drawn} / {PATHS.length} paths</span>
</>
);
}
<!-- SelfDraw.vue — a scene that inks itself layer by layer on scroll -->
<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue';
import '@nabuxai/ui-core/css';
// Desk, window, hills, laptop, mug, steam, plant — in draw order.
const paths = [
'M14 170h292', 'M28 34h82v108H28z', 'M69 34v108', 'M28 88h82',
'M32 134q16-22 32 0', 'M62 134q12-16 24 0',
'M150 82h96v62h-96z', 'M138 144h136l10 16H128z', 'M156 156h92',
'M266 118h26v34a8 8 0 0 1-8 8h-10a8 8 0 0 1-8-8z', 'M292 126a9 9 0 0 1 0 18',
'M272 106q-4-6 0-12', 'M284 106q-4-6 0-12',
'M98 150h28l-4 20h-20z', 'M112 150c-2-14-12-24-24-26', 'M112 150c2-16 12-26 24-28', 'M112 150v-28',
];
const stage = ref<HTMLElement | null>(null);
const drawn = ref(0);
const colored = ref(false);
let timer: number | undefined;
// The scroll position maps onto the path count; colours settle at the end.
const onScroll = () => {
const el = stage.value!;
const max = el.scrollHeight - el.clientHeight;
const p = max > 0 ? el.scrollTop / max : 1;
drawn.value = Math.round(p * paths.length);
colored.value = p >= 0.97;
};
const erase = () => {
clearInterval(timer);
stage.value!.scrollTop = 0;
drawn.value = 0;
colored.value = false;
};
const draw = () => {
erase();
timer = window.setInterval(() => {
const el = stage.value!;
const max = el.scrollHeight - el.clientHeight;
if (el.scrollTop >= max - 1) { clearInterval(timer); onScroll(); }
else { el.scrollTop = Math.min(max, el.scrollTop + 7); onScroll(); }
}, 16);
};
onBeforeUnmount(() => clearInterval(timer));
</script>
<template>
<div ref="stage" class="imw-stage" tabindex="0" role="img" @scroll="onScroll"
aria-label="Line illustration of a workspace, drawn by scrolling">
<svg class="imw-scene" viewBox="0 0 320 200" aria-hidden="true">
<g class="imw-colors" :data-on="colored">
<rect x="30" y="36" width="78" height="104" fill="#bfdbfe" opacity=".55" />
<rect x="152" y="84" width="92" height="58" fill="#c7d2fe" opacity=".45" />
</g>
<path v-for="(d, i) in paths" :key="i" class="imw-ink" pathLength="1" :d="d" :data-drawn="drawn > i" />
</svg>
<div class="imw-spacer" aria-hidden="true"></div>
</div>
<button type="button" @click="draw">Draw</button>
<button type="button" @click="erase">Erase</button>
<span class="imw-count" role="status">{{ drawn }} / {{ paths.length }} paths</span>
</template>
<style scoped>
.imw-stage { block-size: 15.5rem; overflow-y: auto; border: 1px solid #e7e5e4;
border-radius: 1.1rem; background: #fff; }
.imw-scene { position: sticky; inset-block-start: 0; display: block; inline-size: 100%;
block-size: 15.5rem; background: #fff; }
.imw-spacer { block-size: 34rem; }
.imw-colors { opacity: 0; transition: opacity .9s ease; }
.imw-colors[data-on='true'] { opacity: 1; }
.imw-ink { fill: none; stroke: #1c1917; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .3s ease; }
.imw-ink[data-drawn='true'] { stroke-dashoffset: 0; }
.imw-count { font: 700 .74rem/1.4 ui-monospace, monospace; color: #4f46e5; }
@media (prefers-reduced-motion: reduce) { .imw-ink, .imw-colors { transition: none; } }
</style>
<!-- SelfDraw.svelte — a scene that inks itself layer by layer on scroll -->
<script lang="ts">
import { onDestroy } from 'svelte';
import '@nabuxai/ui-core/css';
// Desk, window, hills, laptop, mug, steam, plant — in draw order.
const paths = [
'M14 170h292', 'M28 34h82v108H28z', 'M69 34v108', 'M28 88h82',
'M32 134q16-22 32 0', 'M62 134q12-16 24 0',
'M150 82h96v62h-96z', 'M138 144h136l10 16H128z', 'M156 156h92',
'M266 118h26v34a8 8 0 0 1-8 8h-10a8 8 0 0 1-8-8z', 'M292 126a9 9 0 0 1 0 18',
'M272 106q-4-6 0-12', 'M284 106q-4-6 0-12',
'M98 150h28l-4 20h-20z', 'M112 150c-2-14-12-24-24-26', 'M112 150c2-16 12-26 24-28', 'M112 150v-28',
];
let stage: HTMLElement;
let drawn = $state(0);
let colored = $state(false);
let timer: number | undefined;
// The scroll position maps onto the path count; colours settle at the end.
const onScroll = () => {
const max = stage.scrollHeight - stage.clientHeight;
const p = max > 0 ? stage.scrollTop / max : 1;
drawn = Math.round(p * paths.length);
colored = p >= 0.97;
};
const erase = () => {
clearInterval(timer);
stage.scrollTop = 0;
drawn = 0;
colored = false;
};
const draw = () => {
erase();
timer = window.setInterval(() => {
const max = stage.scrollHeight - stage.clientHeight;
if (stage.scrollTop >= max - 1) { clearInterval(timer); onScroll(); }
else { stage.scrollTop = Math.min(max, stage.scrollTop + 7); onScroll(); }
}, 16);
};
onDestroy(() => clearInterval(timer));
</script>
<div bind:this={stage} class="imw-stage" tabindex="0" role="img" onscroll={onScroll}
aria-label="Line illustration of a workspace, drawn by scrolling">
<svg class="imw-scene" viewBox="0 0 320 200" aria-hidden="true">
<g class="imw-colors" data-on={colored}>
<rect x="30" y="36" width="78" height="104" fill="#bfdbfe" opacity=".55" />
<rect x="152" y="84" width="92" height="58" fill="#c7d2fe" opacity=".45" />
</g>
{#each paths as d, i}
<path class="imw-ink" pathLength="1" {d} data-drawn={drawn > i} />
{/each}
</svg>
<div class="imw-spacer" aria-hidden="true"></div>
</div>
<button type="button" onclick={draw}>Draw</button>
<button type="button" onclick={erase}>Erase</button>
<span class="imw-count" role="status">{drawn} / {paths.length} paths</span>
<style>
.imw-stage { block-size: 15.5rem; overflow-y: auto; border: 1px solid #e7e5e4;
border-radius: 1.1rem; background: #fff; }
.imw-scene { position: sticky; inset-block-start: 0; display: block; inline-size: 100%;
block-size: 15.5rem; background: #fff; }
.imw-spacer { block-size: 34rem; }
.imw-colors { opacity: 0; transition: opacity .9s ease; }
.imw-colors[data-on='true'] { opacity: 1; }
.imw-ink { fill: none; stroke: #1c1917; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .3s ease; }
.imw-ink[data-drawn='true'] { stroke-dashoffset: 0; }
.imw-count { font: 700 .74rem/1.4 ui-monospace, monospace; color: #4f46e5; }
@media (prefers-reduced-motion: reduce) { .imw-ink, .imw-colors { transition: none; } }
</style>