Blocks / Icon picker

Icon picker

An icon by name: search, Recent, sections, every drawn icon. Stores a string.

import { IconPicker, IconByName } from "@forgeron/ui";
/01 → Compact
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" />
    </>
  );
}
/02 → Page icon
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>
  );
}
/03 → Field

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>
  );
}
/04 → Tone
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
PropTypeDefaultDescription
value / defaultValuestring | nullnullThe 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.
sizenumber24The icon's size in the square, in px (multiples of 12).
labelstring"Icon"What the icon is for: names the trigger and the popover.
placeholderstring"Add icon"The chip and the field without an icon.
recentsKeystring—Remembers the last picks in localStorage under this key. Absent: Recent lasts as long as the picker.
tonesboolean | IconTone[]falseOffers a colour: ink, muted, accent, success, warning, danger.
tone / defaultToneIconTone"ink"The colour, controlled or not. IconByName takes the same tone.
onToneChange(tone: IconTone) => void—A swatch picked.
removablebooleantrueOffers Remove when an icon is set.
randombooleantrueOffers a random icon next to the search.
sections{ id, label, icons, keywords? }[]ICON_SECTIONSThe sections before All icons. Names not drawn are left out.
columnsnumber10Icons per row; the arrows move by row.
open / onOpenChangeboolean, (open: boolean) => void—Opens and closes the popover from outside, e.g. from a shortcut.
childrenReactNode—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.