Icon picker
An icon by name: search, Recent, sections, every drawn icon. Stores a string.
import { IconPicker, IconByName } from "@forgeron/ui";import { IconPicker } from "@forgeron/ui";
export default function Compact() {
return (
<>
<IconPicker label="Page icon" defaultValue="rocket-01" />
<IconPicker label="Project icon" variant="chip" defaultValue="anvil" />
</>
);
}Onboarding checklist
import { IconPicker } from "@forgeron/ui";
import { useState } from "react";
// The page of Notes: the icon in its square over the title, "Add icon" when there is none.
export default function PageIcon() {
const [icon, setIcon] = useState<string | null>("note-01");
return (
<div style={{ display: "grid", gap: 12, justifyItems: "start" }}>
<IconPicker
label="Page icon"
size={48}
value={icon}
onChange={setIcon}
recentsKey="ui-gallery:page-icons"
/>
<span style={{ font: "600 22px/28px var(--font-sans)" }}>Onboarding checklist</span>
</div>
);
}Shown in the sidebar and the breadcrumb.
import { Field, IconPicker } from "@forgeron/ui";
export default function FormField() {
return (
<Field label="Folder icon" hint="Shown in the sidebar and the breadcrumb.">
{(props) => (
<IconPicker label="Folder icon" variant="field" defaultValue="folder-01" {...props} />
)}
</Field>
);
}Customers
import { IconByName, IconPicker, type IconTone } from "@forgeron/ui";
import { useState } from "react";
// A colour with the icon, as for a table of the data hub: the same name and tone drawn elsewhere.
export default function Tone() {
const [icon, setIcon] = useState<string | null>("database");
const [tone, setTone] = useState<IconTone>("accent");
return (
<div style={{ display: "flex", gap: 16, alignItems: "center" }}>
<IconPicker
label="Table icon"
value={icon}
onChange={setIcon}
tones
tone={tone}
onToneChange={setTone}
/>
<span style={{ display: "inline-flex", gap: 8, alignItems: "center" }}>
<IconByName name={icon} size={12} tone={tone} />
Customers
</span>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
value / defaultValue | string | null | null | The icon's name, e.g. rocket-01: store it as is. Controlled or not. |
onChange | (name: string | null) => void | — | A pick, or null when the icon is removed. |
variant | "square" | "chip" | "field" | "square" | A page's icon in its frame; a chip on a record; a form control with its caret. |
size | number | 24 | The icon's size in the square, in px (multiples of 12). |
label | string | "Icon" | What the icon is for: names the trigger and the popover. |
placeholder | string | "Add icon" | The chip and the field without an icon. |
recentsKey | string | — | Remembers the last picks in localStorage under this key. Absent: Recent lasts as long as the picker. |
tones | boolean | IconTone[] | false | Offers a colour: ink, muted, accent, success, warning, danger. |
tone / defaultTone | IconTone | "ink" | The colour, controlled or not. IconByName takes the same tone. |
onToneChange | (tone: IconTone) => void | — | A swatch picked. |
removable | boolean | true | Offers Remove when an icon is set. |
random | boolean | true | Offers a random icon next to the search. |
sections | { id, label, icons, keywords? }[] | ICON_SECTIONS | The sections before All icons. Names not drawn are left out. |
columns | number | 10 | Icons per row; the arrows move by row. |
open / onOpenChange | boolean, (open: boolean) => void | — | Opens and closes the popover from outside, e.g. from a shortcut. |
children | ReactNode | — | Drawn in the trigger in place of the icon. |
IconByName | { name, size?, tone?, title?, className? } | — | Draws a stored name. The common set draws at once; any other loads the catalog chunk behind a dim square. |
loadIconCatalog | () => Promise<IconCatalog> | — | Starts the one lazy chunk of every icon early, e.g. on hover of a list. |