Render the SVG paths from a Lucide icon definition. Import the individual icons the component uses.
Icon example
Example.jsx
import { Icon } from "./ui/icon";
import { BookOpen, Printer, Check } from "@lucide/icons";
import "./example.css";
export default function Example() {
return (
<section class="sample">
<h2>Production stages</h2>
{[
[BookOpen, "Manuscript assembled"],
[Printer, "Press proof printed"],
[Check, "Binding approved"],
].map(([icon, label]) => (
<div key={label} class="identity">
<span class="glyph">
<Icon icon={icon} size={18} />
</span>
<span>{label}</span>
</div>
))}
</section>
);
}
example.css
@media screen and (prefers-reduced-motion: no-preference) {
#example button:is(.v-primary, .v-secondary):enabled {
transition: transform 120ms ease-out;
}
#example button:is(.v-primary, .v-secondary):enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button:is(.v-primary, .v-secondary):enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
--example-seed: var(--aster-primary);
--example-secondary-text: var(--aster-on-surface-subtle);
}
body {
--aster-primary: color-mix(in srgb, var(--example-seed) 84%, var(--aster-on-surface));
--aster-on-surface-subtle: color-mix(in srgb, var(--example-secondary-text) 84%, var(--aster-on-surface));
--aster-input-border: color-mix(in srgb, var(--aster-on-surface) 55%, var(--aster-surface));
margin: 0;
padding: clamp(0.8rem, 4vw, 1.5rem);
color: var(--aster-on-surface);
background: var(--aster-surface-muted);
font: 1rem/1.5 var(--aster-font-sans);
}
#example {
display: grid;
gap: 0.8rem;
min-width: 0;
align-content: start;
}
#example > button,
.sample > button {
justify-self: start;
}
.sample,
.tile {
background: var(--aster-surface);
border: 1px solid var(--aster-border);
border-radius: var(--aster-radius-lg);
}
.sample {
display: grid;
gap: 0.8rem;
padding: clamp(0.85rem, 3vw, 1.35rem);
box-shadow: var(--aster-shadow-xs);
min-width: 0;
}
.tile {
padding: 1rem;
min-width: 0;
}
h2,
h3,
p,
dl,
ul {
margin-block: 0;
}
h2,
h3 {
letter-spacing: -0.025em;
line-height: 1.2;
}
h2 {
font-size: 1.25rem;
}
h3 {
font-size: 1rem;
}
.sample > header,
.identity > div,
.receipt {
display: grid;
gap: 0.25rem;
}
.sample > header p,
.tile p,
small {
color: var(--aster-on-surface-muted);
}
small {
font-size: 0.82rem;
}
.split,
.actions,
.identity {
display: flex;
align-items: center;
gap: 0.65rem;
flex-wrap: wrap;
}
.split {
justify-content: space-between;
padding-block: 0.4rem;
border-bottom: 1px solid var(--aster-border);
}
.split:last-child {
border-bottom: 0;
}
.metric {
font-size: 2rem;
letter-spacing: -0.06em;
}
.facts {
display: grid;
grid-template-columns: max-content 1fr;
gap: 0.45rem 1rem;
}
.facts dt {
color: var(--aster-on-surface-muted);
}
.facts dd {
margin: 0;
font-weight: 600;
}
.type-sample {
font:
2rem/1.2 Georgia,
serif;
}
.listing {
padding-inline-start: 1.25rem;
}
.ink-strip {
height: 1.2rem;
background: var(--aster-primary);
border-radius: var(--aster-radius-sm);
}
.ink-proof {
display: grid;
gap: 0.15rem;
border-left: 0.6rem solid;
padding-left: 0.8rem;
}
.ink-proof strong {
font-size: 1.25rem;
letter-spacing: 0.06em;
}
.glyph {
display: inline-grid;
place-items: center;
width: 2rem;
height: 2rem;
border-radius: var(--aster-radius-sm);
color: var(--aster-on-primary-subtle);
background: var(--aster-primary-subtle);
}
.cover-box {
width: min(100%, 18rem);
}
.cover {
display: flex;
min-height: 7.5rem;
height: 100%;
padding: 1rem 1.25rem;
flex-direction: column;
justify-content: space-between;
gap: 1.6rem;
color: #fff;
background: repeating-linear-gradient(150deg, transparent 0 8px, #fff2 8px 9px), #204a48;
}
.cover strong {
font:
italic 2.45rem/1 Georgia,
serif;
}
.cover span {
font: 0.78rem var(--aster-font-mono);
}
.cover.grove {
background-color: #3d4b27;
}
.cover.dune {
background-color: #7c4428;
}
button:not([class]),
.entry {
font: inherit;
font-size: 0.875rem;
padding: 0.45rem 0.8rem;
border: 1px solid var(--aster-border-strong);
border-radius: var(--aster-radius-control);
background: var(--aster-surface);
color: var(--aster-on-surface);
}
button:not([class]) {
cursor: pointer;
font-weight: 600;
}
button:not([class]):hover:enabled {
background: var(--aster-primary-subtle);
}
button:disabled {
cursor: default;
}
:focus-visible {
outline: 2px solid var(--aster-primary);
outline-offset: 3px;
}
output:not(:empty) {
display: block;
color: var(--aster-on-primary-subtle);
font-weight: 600;
font-size: 0.9rem;
}
Site-owned component source and scoped styles
src/ui/icon
import './theme.css';
import { _tpl, _slot, scope, type CompiledTemplate, type SlotView } from '@fierst/aster';
/** Standard Lucide child element tuple (`['path', { d: '...' }]`). */
export type LucideIconNode = readonly [
tag: string,
attrs: Readonly<Record<string, string | number | undefined>>,
children?: readonly LucideIconNode[],
];
/** Standard `@lucide/icons` v1.x tree-shakeable icon data object. */
export interface LucideIconData {
readonly name?: string;
readonly node: readonly LucideIconNode[];
readonly aliases?: readonly string[];
readonly size?: number;
readonly width?: number;
readonly height?: number;
}
/** Accepts either `@lucide/icons` `LucideIconData` or legacy `lucide` / `@lucide/lab` `LucideIconNode[]`. */
export type LucideIconInput = LucideIconData | readonly LucideIconNode[];
const iconScope = scope`
:scope {
display: inline-block;
vertical-align: middle;
flex-shrink: 0;
}
:scope.is-spin {
animation: aster-icon-spin 0.8s linear infinite;
}
@keyframes aster-icon-spin {
to { transform: rotate(360deg); }
}
`;
const ALLOWED_SVG_TAGS = new Set([
'path',
'circle',
'rect',
'line',
'polyline',
'polygon',
'ellipse',
]);
function escapeAttr(val: string | number): string {
return String(val)
.replaceAll('&', '&')
.replaceAll('"', '"')
.replaceAll('<', '<')
.replaceAll('>', '>');
}
function renderIconNodes(nodes: readonly LucideIconNode[]): string {
let out = '';
for (const [tag, attrs, children] of nodes) {
if (!ALLOWED_SVG_TAGS.has(tag)) continue;
let attrStr = '';
for (const [k, v] of Object.entries(attrs)) {
if (v === undefined || k === 'key' || !/^[a-zA-Z][\w.-]*$/.test(k) || /^on/i.test(k))
continue;
attrStr += ` ${k}="${escapeAttr(v)}"`;
}
const inner = children && children.length > 0 ? renderIconNodes(children) : '';
out += `<${tag}${attrStr}>${inner}</${tag}>`;
}
return out;
}
const templateCache = new WeakMap<object, CompiledTemplate>();
function getIconTemplate(input: LucideIconInput): CompiledTemplate {
let cached = templateCache.get(input as object);
if (cached) return cached;
const isDataObj = !Array.isArray(input);
const nodes: readonly LucideIconNode[] = isDataObj ? (input as LucideIconData).node : input;
const vbW = isDataObj
? ((input as LucideIconData).width ?? (input as LucideIconData).size ?? 24)
: 24;
const vbH = isDataObj
? ((input as LucideIconData).height ?? (input as LucideIconData).size ?? 24)
: 24;
const inner = renderIconNodes(nodes);
const html =
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${escapeAttr(vbW)} ${escapeAttr(vbH)}" ` +
`fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" ` +
`data-aster-a0="">${inner}</svg>`;
cached = _tpl(html, [{ kind: 'spread', path: [0] }]);
templateCache.set(input as object, cached);
return cached;
}
export interface IconProps {
/** Tree-shaken icon imported from `@lucide/icons` (or a `LucideIconNode[]` tuple array). */
icon: LucideIconInput;
/** Icon width & height in px or CSS length (default: 18). */
size?: number | string;
/** SVG stroke width (default: 1.75 for AsterUI optical balance). */
strokeWidth?: number;
/** Scale stroke width inversely with `size` so lines stay visually consistent at any scale. */
absoluteStrokeWidth?: boolean;
/** Override stroke color (defaults to `currentColor`). */
color?: string;
/** Animate continuous rotation (ideal for `LoaderCircle`). */
spin?: boolean;
/** Accessible label. When omitted, the icon is treated as decorative (`aria-hidden="true"`). */
label?: string;
class?: string;
[key: string]: any;
}
/**
* AsterUI Lucide Icon component — zero-runtime-overhead Slot-Compiled SVG.
* Works identically in Client DOM, Shadow DOM Web Components, and SSR.
*
* @example
* import { Search } from '@lucide/icons';
* <Icon icon={Search} size={16} />
*/
export function Icon({
icon,
size = 18,
strokeWidth = 1.75,
absoluteStrokeWidth = false,
color,
spin = false,
label,
class: extraClass,
...rest
}: IconProps): SlotView {
const tpl = getIconTemplate(icon);
const iconName = !Array.isArray(icon) ? (icon as LucideIconData).name : undefined;
const numericSize = typeof size === 'number' ? size : Number.parseFloat(size) || 24;
const computedStroke = absoluteStrokeWidth ? (strokeWidth * 24) / numericSize : strokeWidth;
const hasLabel = Boolean(label || rest['aria-label']);
const cls = [
iconScope,
'lucide',
iconName ? `lucide-${iconName}` : '',
spin ? 'is-spin' : '',
extraClass,
]
.filter(Boolean)
.join(' ');
const svgAttrs: Record<string, any> = {
...rest,
width: size,
height: size,
'stroke-width': computedStroke,
class: cls,
};
if (color) svgAttrs.stroke = color;
if (hasLabel) {
svgAttrs.role = rest.role ?? 'img';
if (label) svgAttrs['aria-label'] = label;
} else {
svgAttrs['aria-hidden'] = true;
svgAttrs.focusable = 'false';
}
return _slot(tpl, [svgAttrs]);
}
/** Create a dedicated stateless icon component from any `@lucide/icons` export. */
export function createIcon(
icon: LucideIconInput,
defaults: Omit<IconProps, 'icon'> = {},
): (props?: Omit<IconProps, 'icon'>) => SlotView {
return (props = {}) => Icon({ ...defaults, ...props, icon });
}
Install
sh
npx @fierst/ui@1.0.2 add iconRegistry dependencies: theme. Package dependencies: @lucide/icons.
Exports from ./ui/icon: LucideIconNode, LucideIconData, LucideIconInput, IconProps, Icon, createIcon.
Download the registry source for icon 1.0.2.
API contracts
ts
export type LucideIconNode = readonly [
tag: string,
attrs: Readonly<Record<string, string | number | undefined>>,
children?: readonly LucideIconNode[],
];
export interface LucideIconData {
readonly name?: string;
readonly node: readonly LucideIconNode[];
readonly aliases?: readonly string[];
readonly size?: number;
readonly width?: number;
readonly height?: number;
}
export type LucideIconInput = LucideIconData | readonly LucideIconNode[];
export interface IconProps {
/** Tree-shaken icon imported from `@lucide/icons` (or a `LucideIconNode[]` tuple array). */
icon: LucideIconInput;
/** Icon width & height in px or CSS length (default: 18). */
size?: number | string;
/** SVG stroke width (default: 1.75 for AsterUI optical balance). */
strokeWidth?: number;
/** Scale stroke width inversely with `size` so lines stay visually consistent at any scale. */
absoluteStrokeWidth?: boolean;
/** Override stroke color (defaults to `currentColor`). */
color?: string;
/** Animate continuous rotation (ideal for `LoaderCircle`). */
spin?: boolean;
/** Accessible label. When omitted, the icon is treated as decorative (`aria-hidden="true"`). */
label?: string;
class?: string;
[key: string]: any;
}
export function Icon({
icon,
size = 18,
strokeWidth = 1.75,
absoluteStrokeWidth = false,
color,
spin = false,
label,
class: extraClass,
...rest
}: IconProps): SlotView
export function createIcon(
icon: LucideIconInput,
defaults: Omit<IconProps, 'icon'> = {},
): (props?: Omit<IconProps, 'icon'>) => SlotView