Animated icons
JS behaviour
Icon browser
An icon library inside the demo itself: 28 Lucide-style line icons with live Persian/English search over names, click-to-copy the exact SVG with a confirming toast, size and stroke sliders, colour swatches, a result counter and an honest empty state.
Real scenarios
The component as it is used in a product — not a specimen grid.
The icon library, browsable
28 Lucide-style icons with live Persian/English search over their names. Click any tile to copy its exact SVG — the toast confirms with the icon’s name — while the sliders resize and restroke the whole grid and the swatches recolour it. The result count keeps score and the empty state stays honest.
· «»
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| icons | count | '28' | Twenty-eight hand-drawn 24×24 icons — every shape a plain path so the copy and the preview come from one source. |
| search | filter | 'fa ∪ en' | The search matches the English name (case-insensitive) and the Persian one — “heart” and «قلب» land on the same tile. |
| copy | clipboard | 'svg' | The SVG string is built with the current size/stroke/colour and copied; the toast names the icon and fades in 1.8s (with a fallback for stubborn browsers). |
| size · stroke · color | controls | '24px · 2 · #4f46e5' | The sliders apply to the whole grid — every tile takes the live value and the copied output carries exactly these settings. |
| empty | state | 'honest' | With no hits, a plain message suggesting real names plus a clear-search button — no blank cells, no endless scroll. |
Snippet
<div class="imb" x-data="{
all: @js($icons), q: '', size: 24, sw: 2, color: '#4f46e5', toast: null, t: null,
get hits() {
const n = this.q.trim().toLowerCase();
return n ? this.all.filter((i) => i.en.includes(n) || i.fa.includes(this.q.trim())) : this.all;
},
svgOf(icon) {
const body = icon.paths.map((d) => ' <path d=\"' + d + '\"/>').join('\n');
return '<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"' + this.size
+ '\" height=\"' + this.size + '\" fill=\"none\" stroke=\"' + this.color
+ '\" stroke-width=\"' + this.sw + '\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n'
+ body + '\n</svg>';
},
async copy(icon) {
try { await navigator.clipboard.writeText(this.svgOf(icon)); } catch (e) {}
this.toast = 'Copied the ' + icon.en + ' SVG';
clearTimeout(this.t);
this.t = setTimeout(() => (this.toast = null), 1800);
},
}" x-init="$cleanup(() => clearTimeout(t))">
{{-- live search --}}
<label class="imb-search">
<svg viewBox="0 0 24 24"><path d="M18 11a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z"/><path d="m16.65 16.65 4.35 4.35"/></svg>
<input type="search" x-model="q" placeholder="Search icon names — English or Persian…">
</label>
{{-- size / stroke / colour controls --}}
<input type="range" min="16" max="44" step="2" x-model.number="size">
<input type="range" min="1" max="3" step="0.25" x-model.number="sw">
<button type="button" class="imb-swatch" style="background: #4f46e5" x-on:click="color = '#4f46e5'"></button>
{{-- the grid + copy --}}
<div class="imb-grid">
<template x-for="icon in hits" :key="icon.en">
<button type="button" class="imb-tile" x-on:click="copy(icon)" :aria-label="'Copy the ' + icon.en + ' SVG'">
<svg viewBox="0 0 24 24" :stroke="color" :stroke-width="sw"
:style="`inline-size: ${size}px; block-size: ${size}px`">
<template x-for="d in icon.paths" :key="d"><path :d="d"></path></template>
</svg>
<span class="imb-name" x-text="icon.en"></span>
</button>
</template>
</div>
{{-- counter and empty state --}}
<p class="imb-count" x-text="hits.length + ' of ' + all.length + ' icons'"></p>
<div class="imb-empty" x-show="hits.length === 0" x-cloak>
<p x-text="'Nothing matched ' + q + ' — try heart or قلب.'"></p>
<button type="button" class="imb-clear" x-on:click="q = ''">Clear the search</button>
</div>
<div class="imb-toast" x-show="toast" x-cloak role="status" x-text="toast"></div>
</div>
<style>
.imb-search { display: flex; align-items: center; gap: .6rem; padding: .65rem .9rem;
border: 1px solid #e7e5e4; border-radius: .85rem; }
.imb-search svg { inline-size: 1.05rem; fill: none; stroke: #78716c; stroke-width: 2; }
.imb-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr)); }
.imb-tile { display: grid; gap: .6rem; justify-items: center; padding: .9rem .4rem .75rem;
border: 1px solid #e7e5e4; border-radius: .8rem; background: #fff; cursor: copy; }
.imb-tile:hover { border-color: #4f46e5; }
.imb-tile path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.imb-swatch { inline-size: 1.35rem; aspect-ratio: 1; border-radius: 50%; border: none; cursor: pointer; }
.imb-toast { position: absolute; inset-block-end: 1rem; padding: .55rem 1.1rem; border-radius: 999px;
background: #1c1917; color: #fff; animation: imb-rise .25s ease-out; }
@keyframes imb-rise { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
@media (prefers-reduced-motion: reduce) { .imb-toast { animation: 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 IconBrowser from '@/components/IconBrowser';
export default function IconMotion() {
return (
<NabuXUIProvider locale="en" linkComponent={Link}>
<main className="nx-page">
<IconBrowser />
</main>
</NabuXUIProvider>
);
}
// IconBrowser.jsx — a searchable, copyable Lucide-style icon library
import { useEffect, useMemo, useRef, useState } from 'react';
import '@nabuxai/ui-core/css';
const ICONS = [
{ en: 'heart', fa: 'قلب', paths: ['M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3.5c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z'] },
{ en: 'moon', fa: 'ماه', paths: ['M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z'] },
{ en: 'search', fa: 'جستوجو', paths: ['M18 11a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z', 'm16.65 16.65 4.35 4.35'] },
{ en: 'globe', fa: 'کره', paths: ['M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z', 'M3 12h18', 'M12 3a13.5 13.5 0 0 1 3.5 9A13.5 13.5 0 0 1 12 21a13.5 13.5 0 0 1-3.5-9A13.5 13.5 0 0 1 12 3Z'] },
{ en: 'lock', fa: 'قفل', paths: ['M5 11a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2Z', 'M8 11V7a4 4 0 0 1 8 0v4'] },
{ en: 'command', fa: 'فرمان', paths: ['M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3'] },
// …22 more in the same shape.
];
export default function IconBrowser() {
const [q, setQ] = useState('');
const [size, setSize] = useState(24);
const [sw, setSw] = useState(2);
const [color, setColor] = useState('#4f46e5');
const [toast, setToast] = useState(null);
const timer = useRef(null);
useEffect(() => () => clearTimeout(timer.current), []);
// Search matches the English name and the Persian one.
const hits = useMemo(() => {
const n = q.trim().toLowerCase();
return n ? ICONS.filter((i) => i.en.includes(n) || i.fa.includes(q.trim())) : ICONS;
}, [q]);
// The copied string carries the live size/stroke/colour.
const svgOf = (icon) =>
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="${color}" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round">\n`
+ icon.paths.map((d) => ` <path d="${d}"/>`).join('\n') + '\n</svg>';
const copy = async (icon) => {
try { await navigator.clipboard.writeText(svgOf(icon)); } catch { /* older browsers */ }
setToast(`Copied the ${icon.en} SVG`);
clearTimeout(timer.current);
timer.current = setTimeout(() => setToast(null), 1800);
};
return (
<>
<style>{`
.imb-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr)); }
.imb-tile { display: grid; gap: .6rem; justify-items: center; padding: .9rem .4rem .75rem;
border: 1px solid #e7e5e4; border-radius: .8rem; background: #fff; cursor: copy; }
.imb-tile:hover { border-color: #4f46e5; }
.imb-tile path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.imb-toast { position: absolute; inset-block-end: 1rem; padding: .55rem 1.1rem; border-radius: 999px;
background: #1c1917; color: #fff; animation: imb-rise .25s ease-out; }
@keyframes imb-rise { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
@media (prefers-reduced-motion: reduce) { .imb-toast { animation: none; } }
`}</style>
<input type="search" value={q} onChange={(e) => setQ(e.target.value)}
placeholder="Search icon names — English or Persian…" aria-label="Search icons" />
<input type="range" min="16" max="44" step="2" value={size} onChange={(e) => setSize(+e.target.value)} aria-label="Icon size" />
<input type="range" min="1" max="3" step="0.25" value={sw} onChange={(e) => setSw(+e.target.value)} aria-label="Stroke width" />
{['#4f46e5', '#0ea5e9', '#ec4899'].map((c) => (
<button key={c} type="button" aria-label={c} aria-pressed={color === c}
onClick={() => setColor(c)} style={{ background: c, inlineSize: '1.35rem', blockSize: '1.35rem', borderRadius: '50%' }} />
))}
<p role="status">{hits.length} of {ICONS.length} icons</p>
<div className="imb-grid">
{hits.map((icon) => (
<button key={icon.en} type="button" className="imb-tile" onClick={() => copy(icon)}
aria-label={`Copy the ${icon.en} SVG`}>
<svg viewBox="0 0 24 24" aria-hidden="true" stroke={color} strokeWidth={sw}
style={{ inlineSize: size, blockSize: size }}>
{icon.paths.map((d, i) => <path key={i} d={d} />)}
</svg>
<span>{icon.en}</span>
</button>
))}
</div>
{hits.length === 0 && <p>Nothing matched — try heart or قلب.</p>}
{toast && <div className="imb-toast" role="status">{toast}</div>}
</>
);
}
<!-- IconBrowser.vue — a searchable, copyable Lucide-style icon library -->
<script setup lang="ts">
import { computed, onBeforeUnmount, ref } from 'vue';
import '@nabuxai/ui-core/css';
const icons = [
{ en: 'heart', fa: 'قلب', paths: ['M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3.5c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z'] },
{ en: 'moon', fa: 'ماه', paths: ['M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z'] },
{ en: 'search', fa: 'جستوجو', paths: ['M18 11a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z', 'm16.65 16.65 4.35 4.35'] },
{ en: 'globe', fa: 'کره', paths: ['M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z', 'M3 12h18', 'M12 3a13.5 13.5 0 0 1 3.5 9A13.5 13.5 0 0 1 12 21a13.5 13.5 0 0 1-3.5-9A13.5 13.5 0 0 1 12 3Z'] },
{ en: 'lock', fa: 'قفل', paths: ['M5 11a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2Z', 'M8 11V7a4 4 0 0 1 8 0v4'] },
{ en: 'command', fa: 'فرمان', paths: ['M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3'] },
// …22 more in the same shape.
];
const q = ref('');
const size = ref(24);
const sw = ref(2);
const color = ref('#4f46e5');
const toast = ref<string | null>(null);
let timer: number | undefined;
// Search matches the English name and the Persian one.
const hits = computed(() => {
const n = q.value.trim().toLowerCase();
return n ? icons.filter((i) => i.en.includes(n) || i.fa.includes(q.value.trim())) : icons;
});
// The copied string carries the live size/stroke/colour.
const svgOf = (icon: typeof icons[number]) =>
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="${size.value}" height="${size.value}" fill="none" stroke="${color.value}" stroke-width="${sw.value}" stroke-linecap="round" stroke-linejoin="round">\n`
+ icon.paths.map((d) => ` <path d="${d}"/>`).join('\n') + '\n</svg>';
const copy = async (icon: typeof icons[number]) => {
try { await navigator.clipboard.writeText(svgOf(icon)); } catch { /* older browsers */ }
toast.value = `Copied the ${icon.en} SVG`;
clearTimeout(timer);
timer = window.setTimeout(() => (toast.value = null), 1800);
};
onBeforeUnmount(() => clearTimeout(timer));
</script>
<template>
<input type="search" v-model="q" placeholder="Search icon names — English or Persian…" aria-label="Search icons" />
<input type="range" min="16" max="44" step="2" v-model.number="size" aria-label="Icon size" />
<input type="range" min="1" max="3" step="0.25" v-model.number="sw" aria-label="Stroke width" />
<p role="status">{{ hits.length }} of {{ icons.length }} icons</p>
<div class="imb-grid">
<button v-for="icon in hits" :key="icon.en" type="button" class="imb-tile" @click="copy(icon)"
:aria-label="`Copy the ${icon.en} SVG`">
<svg viewBox="0 0 24 24" aria-hidden="true" :stroke="color" :stroke-width="sw"
:style="{ inlineSize: size + 'px', blockSize: size + 'px' }">
<path v-for="d in icon.paths" :key="d" :d="d" />
</svg>
<span>{{ icon.en }}</span>
</button>
</div>
<p v-if="hits.length === 0">Nothing matched — try heart or قلب.</p>
<div v-if="toast" class="imb-toast" role="status">{{ toast }}</div>
</template>
<style scoped>
.imb-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr)); }
.imb-tile { display: grid; gap: .6rem; justify-items: center; padding: .9rem .4rem .75rem;
border: 1px solid #e7e5e4; border-radius: .8rem; background: #fff; cursor: copy; }
.imb-tile:hover { border-color: #4f46e5; }
.imb-tile path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.imb-toast { position: absolute; inset-block-end: 1rem; padding: .55rem 1.1rem; border-radius: 999px;
background: #1c1917; color: #fff; animation: imb-rise .25s ease-out; }
@keyframes imb-rise { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
@media (prefers-reduced-motion: reduce) { .imb-toast { animation: none; } }
</style>
<!-- IconBrowser.svelte — a searchable, copyable Lucide-style icon library -->
<script lang="ts">
import { onDestroy } from 'svelte';
import '@nabuxai/ui-core/css';
const icons = [
{ en: 'heart', fa: 'قلب', paths: ['M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3.5c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z'] },
{ en: 'moon', fa: 'ماه', paths: ['M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z'] },
{ en: 'search', fa: 'جستوجو', paths: ['M18 11a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z', 'm16.65 16.65 4.35 4.35'] },
{ en: 'globe', fa: 'کره', paths: ['M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z', 'M3 12h18', 'M12 3a13.5 13.5 0 0 1 3.5 9A13.5 13.5 0 0 1 12 21a13.5 13.5 0 0 1-3.5-9A13.5 13.5 0 0 1 12 3Z'] },
{ en: 'lock', fa: 'قفل', paths: ['M5 11a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2Z', 'M8 11V7a4 4 0 0 1 8 0v4'] },
{ en: 'command', fa: 'فرمان', paths: ['M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3'] },
// …22 more in the same shape.
];
let q = $state('');
let size = $state(24);
let sw = $state(2);
let color = $state('#4f46e5');
let toast = $state<string | null>(null);
let timer: number | undefined;
onDestroy(() => clearTimeout(timer));
// Search matches the English name and the Persian one.
const hits = $derived.by(() => {
const n = q.trim().toLowerCase();
return n ? icons.filter((i) => i.en.includes(n) || i.fa.includes(q.trim())) : icons;
});
// The copied string carries the live size/stroke/colour.
const svgOf = (icon: typeof icons[number]) =>
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="${color}" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round">\n`
+ icon.paths.map((d) => ` <path d="${d}"/>`).join('\n') + '\n</svg>';
const copy = async (icon: typeof icons[number]) => {
try { await navigator.clipboard.writeText(svgOf(icon)); } catch { /* older browsers */ }
toast = `Copied the ${icon.en} SVG`;
clearTimeout(timer);
timer = window.setTimeout(() => (toast = null), 1800);
};
</script>
<input type="search" bind:value={q} placeholder="Search icon names — English or Persian…" aria-label="Search icons" />
<input type="range" min="16" max="44" step="2" bind:value={size} aria-label="Icon size" />
<input type="range" min="1" max="3" step="0.25" bind:value={sw} aria-label="Stroke width" />
<p role="status">{hits.length} of {icons.length} icons</p>
<div class="imb-grid">
{#each hits as icon (icon.en)}
<button type="button" class="imb-tile" onclick={() => copy(icon)} aria-label="Copy the {icon.en} SVG">
<svg viewBox="0 0 24 24" aria-hidden="true" stroke={color} stroke-width={sw}
style="inline-size: {size}px; block-size: {size}px">
{#each icon.paths as d (d)}
<path {d} />
{/each}
</svg>
<span>{icon.en}</span>
</button>
{/each}
</div>
{#if hits.length === 0}
<p>Nothing matched — try heart or قلب.</p>
{/if}
{#if toast}
<div class="imb-toast" role="status">{toast}</div>
{/if}
<style>
.imb-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr)); }
.imb-tile { display: grid; gap: .6rem; justify-items: center; padding: .9rem .4rem .75rem;
border: 1px solid #e7e5e4; border-radius: .8rem; background: #fff; cursor: copy; }
.imb-tile:hover { border-color: #4f46e5; }
.imb-tile path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.imb-toast { position: absolute; inset-block-end: 1rem; padding: .55rem 1.1rem; border-radius: 999px;
background: #1c1917; color: #fff; animation: imb-rise .25s ease-out; }
@keyframes imb-rise { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
@media (prefers-reduced-motion: reduce) { .imb-toast { animation: none; } }
</style>