Icons by name
Render an icon from a string, for icon pickers and content from a CMS.
When to use it
Import icons as components whenever you know them while writing code. Use CooliconsIcon when the name comes from data, like an icon picker or a CMS field. It loads all icons of one style and corner radius on first use, about 80 KB gzipped for Line and 310 KB for Bulk.
Use
import { CooliconsIcon } from "@coolicons/react/dynamic";
<CooliconsIcon name="house" variant="fill" radius="round" />The dynamic entry is a client component.
The package calls the style variant. While a style loads, and for an unknown name, it renders an empty svg of the same size, so the layout does not jump.
Props
| Prop | Default | What it does |
|---|---|---|
name | required | Icon name, like house |
variant | line | line, duocolor, duotone, fill or bulk |
radius | regular | sharp, regular or round |
size | 24 | Width and height. A number is pixels, a string can be any CSS length, like 1.25rem or 1em. |
strokeWidth | 2 | Stroke width of Line, Duocolor and Duotone. Fill and Bulk have no strokes and ignore it. |
secondaryColor | currentColor | Color of the second path in Duocolor, Duotone and Bulk. Line, Fill and icons without a second path ignore it. |
secondaryOpacity | 0.4 or 0.2 | Opacity of the second path: 0.4 in Duocolor and Bulk, 0.2 in Duotone. |
title | none | Adds a <title> and role="img". Without a title the icon gets aria-hidden="true". |
List and preload
The same entry exports icons, every name with its category and, for aliases, the name it points to. preload loads a style ahead of time, for example when a picker opens.
import { CooliconsIcon, icons, preload } from "@coolicons/react/dynamic";
preload("duotone", "round");
const arrows = icons.filter((icon) => icon.category === "Arrow");TypeScript users get IconName, IconCategory and CooliconsIconProps from the same entry.