GUILD OF GLEKS UIv21.4.4

gog-icon

Icon

A thin wrapper around the library's built-in SVG set — and, since 21.4.0, around your own as well: register any SVG under a name and it works everywhere a built-in one does. Small on its own, but every other component that needs an icon (button, checkbox, dialog, input field…) renders through it.

Overview

Import the component and drop it into a template.

typescript
import { IconComponent } from '@guildofgleks/ui';

@Component({
  // ...
  imports: [IconComponent],
})

Basic usage — render one of the built-in icons by name:

<gog-icon name="check" />

Examples

All icons

The complete built-in set — 41 glyphs, all from Lucide (ISC licence, notice shipped in the package) and inlined, so the library keeps its single runtime dependency. This gallery is driven off Object.keys(ICON_DEFS) rather than a hand-written list, which is the only way it stays right.

star / star-filled is the one outline/filled pair, for a rating or favourite toggle — the same reason checkbox / checkbox-checked exists. The set is otherwise outline-only on purpose: a solid duplicate of every glyph would double the payload for a distinction almost nothing needs. Register the filled variant you actually want instead.

@for (iconName of iconNames; track iconName) {
  <gog-icon [name]="iconName" />
}

Sizing

There is no size input — icons are sized purely through the --gog-icon-size CSS custom property, settable per-instance or globally through a theme.

<gog-icon name="success" style="--gog-icon-size: 16px" />
<gog-icon name="success" style="--gog-icon-size: 24px" />
<gog-icon name="success" style="--gog-icon-size: 40px" />

Meaningful icon

Icons are aria-hidden by default, since they're almost always paired with a visible text label. For a standalone icon that carries meaning on its own, set ariaHidden to false and supply title.

<gog-icon name="warning" [ariaHidden]="false" title="Warning" />

Custom template

template replaces the SVG entirely — the same mechanism other components use for their own icon override inputs (e.g. checkbox's checkIconTemplate). It costs an <ng-template> at every use site, so reach for it for one-offs; for a whole icon set, register the names instead.

<gog-icon [template]="customDot" />

<ng-template #customDot>
  <span style="width: 1em; height: 1em; border-radius: 50%; background: currentColor; display: block;"></span>
</ng-template>

Your own icons 21.4.0

name is not a closed list. It is typed GogIconName = GogBuiltinIconName | (string & {}): the built-ins autocomplete, and any name you have registered is accepted. Register once, at the root or in any injector below it:

typescript
// app.config.ts — register once, use the name anywhere an icon name is taken
import { provideGogIcons } from '@guildofgleks/ui';

export const appConfig: ApplicationConfig = {
  providers: [
    provideGogIcons({
      cart: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">…</svg>',
      rocket: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">…</svg>',
    }),
  ],
};

From then on the name works anywhere an icon name is taken — not just in gog-icon:

html
<gog-icon name="cart" />
<gog-tag iconName="cart">In basket</gog-tag>
<gog-button iconStart="rocket">Launch</gog-button>

A registered name beats a built-in

This is the point of the registry rather than a side effect: it is how you swap the library's glyphs for your own across every component at once, without touching a single call site.

typescript
// A registered name wins over the built-in of the same name — every checkmark the
// library renders (checkbox, multiselect, toast) becomes yours, with no call site touched.
provideGogIcons({
  check: '<svg viewBox="0 0 24 24">…your checkmark…</svg>',
});

Rules worth knowing

  • It layers down the injector tree. A nested provideGogIcons(...) adds to the parent's set instead of replacing it — the same as provideGogConfig — so a lazy route can register only the three icons it uses and still see the app-wide ones.
  • An unknown name renders nothing and warns in dev mode. It never throws: an icon is decoration, and failing a render over a typo is the worse outcome.
  • Write the SVG for inheritance. Give it a viewBox and stroke="currentColor" (or fill), and no width or height — gog-icon drives size and stroke width from the --gog-icon-* tokens, so a registered icon scales and colours exactly like a built-in.
  • Security — the one part that can actually bite. Registered markup is inserted with bypassSecurityTrustHtml, because Angular's HTML sanitizer strips SVG and would leave you with nothing. That is safe for static markup you authored or imported at build time, and unsafe for anything derived from user input or fetched at runtime. If you need remote icons, fetch them yourself, run them through a real SVG sanitizer, and register the result.

API Reference

Inputs

NameTypeDefaultDescription
nameGogIconName'close'A built-in glyph, or any name registered through provideGogIcons(). Ignored when template is set.
templateTemplateRef<unknown> | nullnullReplaces the SVG entirely with your own markup. For one-offs — for a whole icon set, register the names instead.
titlestring''Accessible label used when ariaHidden is false. Falls back to name if empty.
ariaHiddenbooleantrueIcons are decorative by default and hidden from assistive tech. Set false for a standalone icon that carries its own meaning (with no adjacent text label).

Providers & types

NameTypeDefaultDescription
provideGogIcons(icons)21.4.0Record<string, string> => ProviderRegisters raw <svg> markup by name, app-wide or in any injector below it. A nested call layers onto the parent set rather than replacing it.
GOG_ICONS21.4.0InjectionToken<Readonly<Record<string, string>>>{}The token provideGogIcons writes to. Inject it to read the registered set; you rarely need it directly.

Two type names, and the difference matters when you are enumerating icons: GogBuiltinIconName21.4.0 is the closed union of the 41 glyphs that ship with the library — use it for a gallery or an icon picker, where an exhaustive list is the point. GogIconName is the open one every input takes, so a registered name type-checks.

provideGogIcons is not part of GOG_CONFIG — it is its own provider, so there is no icons key to look for on the Global Configuration page.

Styling Tokens

Every CSS custom property the icon paints with. Override any of them — on a single instance, a subtree, or a theme — to restyle it. See the Theming guide for the full token-layering model, or the Theme Generator to tweak these live.

TokenDescription
--gog-icon-sizeDefault icon size.
--gog-icon-stroke-widthStroke width for outline icons.
--gog-icon-fallback-sizeSize used when no size is set.