Menu

Reference

Attributes and props

AttributeReact propValuesDefault
iconiconIcon name, set:iconRequired
width, heightwidth, heightA number of pixels, a CSS length (2em, 1.5rem, 24px), or auto for the icon's own sizeHeight 1em, width in proportion
colorcolorAny CSS colorThe text color
stroke-widthstrokeWidthA positive number, in units of the icon's gridThe icon's own: 2 for Lucide and Tabler
rotaterotate90deg, 180deg, 270deg, or quarter turns 1, 2, 3No rotation
flipfliphorizontal, vertical, or both: horizontal,verticalNo flip
inlineinlinePresent or absent; true or false in ReactAbsent
labellabelText for screen readersNone: the icon is decorative
placeholderplaceholderskeleton, spinner or noneskeleton, or the value from configure()
noobserver—Present or absentAbsent: an icon loads when it comes near the visible part of the page

Functions

@iconavo-ui/icon and @iconavo-ui/react export the same four functions and share one store of icons and settings for the whole page. Both also export the TypeScript types IconavoIconSet, IconavoIcon and IconavoAlias, the same as in the data packages.

configure(options)

TypeScript
function configure(options: {
  api?: string[];
  cdn?: string[];
  placeholder?: "skeleton" | "spinner" | "none";
  dev?: boolean;
}): void;
OptionWhat it setsDefault
apiHosts that answer batch requests, like the Iconify API["https://api.iconavo.dev"]
cdnHosts with the static layout of cdn.iconavo.dev, one icon per request["https://cdn.iconavo.dev", "https://cdn2.iconavo.dev", "https://iconavo.b-cdn.net"]
placeholderWhat icons show while they load"skeleton"
devDevelopment mode: a dashed frame in place of a missing iconDetected, see Missing icons

addIcons(data)

TypeScript
function addIcons(data: IconavoIconSet | IconavoIconSet[]): void;

Adds icons in IconifyJSON format, one icon set per object. Added icons are never requested from the network. They replace icons with the same names, and icons already on the page redraw. It accepts:

JavaScript
import { addIcons } from "@iconavo-ui/icon";

addIcons({
  prefix: "acme",
  width: 24,
  height: 24,
  icons: {
    logo: { body: '<path fill="currentColor" d="M3 3h18v18H3z"/>' },
  },
});
HTML
<iconavo-icon icon="acme:logo"></iconavo-icon>

A prefix follows the same rules as icon names; an invalid one throws an error. Names listed in not_found are remembered as missing.

loadIcons(names)

TypeScript
function loadIcons(names: string[]): Promise<IconavoIconSet[]>;

Loads icons ahead of time: before a menu opens, or on the server for server rendering. It resolves with one IconifyJSON object per set, holding the loaded icons and, in not_found, the missing names.

It never rejects. It makes one pass over the hosts, at most 5 seconds, and leaves out icons that failed to load; components in the browser retry them later. An invalid name goes to not_found with a warning.

setLoader(prefix, loader)

TypeScript
function setLoader(
  prefix: string,
  loader: ((names: string[]) => Promise<IconavoIconSet | null>) | null,
): void;

Loads one set from your own source instead of the hosts: a server with another format, a database, generated icons. It works for our sets too.

JavaScript
import { setLoader } from "@iconavo-ui/icon";

setLoader("acme", async (names) => {
  const response = await fetch(`/icons/acme.json?icons=${names.join(",")}`);
  if (!response.ok) throw new Error(`Icons: HTTP ${response.status}`);
  return response.json();
});

IconavoProvider (React)

TSX
<IconavoProvider icons={icons}>{children}</IconavoProvider>

Passes icons loaded on the server (IconavoIconSet[], as returned by loadIcons) to the components inside, for the server HTML and for hydration. See Next.js and server rendering.

Loading and errors

While an icon loads

Batches and hosts

Missing icons

Edit this page on GitHub