The Icon component renders a vector icon from the library’s SVG sprite by name. It supports default props via UIProvider/ui.config.ts and theming via CSS variables.
import React from "react";
import {Icon, SvgSprite} from "addon-ui";
export function Example() {
return (
<>
{/* Render the sprite once in your app, typically near the root */}
<SvgSprite />
{/* Basic */}
<Icon name="close" />
{/* Size (width/height default to `size`) */}
<Icon name="menu" size={28} />
{/* Custom width/height (overrides size-derived values) */}
<Icon name="star" width={20} height={16} />
{/* Styling color via CSS (uses currentColor) */}
<Icon name="heart" size={24} style={{color: "#e91e63"}} />
</>
);
}Only the prop name, type, and default are listed below.
| Prop | Type | Default |
|---|---|---|
name |
string |
— |
size |
number |
24 |
width |
number |
size |
height |
number |
size |
SVG <svg> attrs |
all standard SVG props | — |
Notes:
widthandheightdefault to the value ofsizeunless provided explicitly.- When an icon
nameis not found in the sprite, a fallback square with a placeholder symbol is rendered and a warning is logged in the console.
Only variables actually referenced in src/components/Icon/icon.module.scss are listed, with their exact fallback chains. If a variable has no explicit fallback in the stylesheet, it is marked as “none (define in theme)”.
| Variable | Fallback chain |
|---|---|
--icon-color |
var(--icon-color) (none) |
--icon-color-hover |
var(--icon-color-hover) (none) |
--icon-scale |
var(--icon-scale, 1) |
Provide Icon defaults and register icons via theme/config:
// ui.config.ts
import {defineConfig} from "addon-ui/config";
// import SVGs as React components (via your bundler's ?react or svgr setup)
import CloseIcon from "./icons/close.svg?react";
import MenuIcon from "./icons/menu.svg?react";
import StarIcon from "./icons/star.svg?react";
export default defineConfig({
components: {
icon: {
size: 24,
// You can also predefine common SVG props here (except name), e.g.:
// role: "img",
// focusable: false,
},
},
icons: {
close: CloseIcon,
menu: MenuIcon,
star: StarIcon,
// ... more icons
},
});Or at runtime with the provider:
import {UIProvider} from "addon-ui";
import CloseIcon from "./icons/close.svg?react";
<UIProvider
components={{
icon: {
size: 20,
},
}}
icons={{
close: CloseIcon,
}}
>
{/* ... */}
</UIProvider>;- Prefer providing an accessible name using one of:
aria-labeldirectly on the Icon- a
<title>element (e.g., viachildreninside Icon if you customize) or surrounding label
- Mark purely decorative icons as
aria-hidden="true". - Icons inherit
colorfrom CSS. Ensure sufficient contrast for meaningful icons.