Command palette

@yasinsensoy/web

Web · Components

Icon

Renders an IconProp value.

7 exports

Import

import { Icon } from "@yasinsensoy/web";

Icon

componentClient component

Renders an IconProp value. A name is looked up in the icon library given to UIProvider; an element is rendered as-is. Hidden from screen readers (decorative); put text or an aria-label next to icons that carry meaning.

Use it when your own component should accept an icon prop like the library's components do.

Icon({ icon, className }: IconProps): JSX.Element | null

Examples

<Icon icon="save" />
<Icon icon="warning" className="size-5 text-warning" />
<Icon icon={<SaveIcon />} />

IconProps

interface

Props of the Icon component.

NameTypeDescription
iconIconPropThe icon's name or the icon itself. See IconProp.
className?stringClasses for the icon resolved by name (e.g. size-5 text-primary).

Register

interface

Interface extended to introduce the project's icon library to the library. Once extended, every prop taking icon="..." accepts only names from that library and the editor suggests them.

Examples

// ui.d.ts (or the file where you define icons)
import type { icons } from "./icons";

declare module "@yasinsensoy/web" {
  interface Register {
    icons: typeof icons;
  }
}

Icon component. Components from libraries such as lucide-react, @phosphor-icons/react, react-icons, @heroicons/react and your own SVG components fit: any component that takes className and aria-hidden.

type IconComponent = ComponentType<{ className?: string; "aria-hidden"?: boolean | "true" | "false"; }>

Icon components by name: { save: SaveIcon, trash: TrashIcon }.

type IconRegistry = Readonly<Record<string, IconComponent>>

Names in the icon library given to UIProvider. If Register is not extended, any string is accepted.

type IconName = [RegisteredIcons] extends [never] ? string : Extract<keyof RegisteredIcons, string>

Type of icon props. Can be given in two forms:

  • Name: icon="save". Resolved from the icon library given to UIProvider; names are type-checked if Register is extended.
  • Element: icon={<SaveIcon />} or any React content.

Passing false or null shows no icon (to hide the default icon on components that have one).

type IconProp = IconName | Exclude<ReactNode, string | Iterable<ReactNode>>