ComponentUpdated in v15

Icon

Renders an SVG icon you register by name; ngwr ships none of its own.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrIcon, lucideIcons, provideWrIcons } from 'ngwr/icon';

@Component({ imports: [WrIcon] })
export class MyComponent {}

Register icons

lucideIcons() for Lucide, svgIcon() for any set that ships SVG files.

pnpm add lucide
import { Plus, Trash } from 'lucide';
import { lucideIcons, provideWrIcons } from 'ngwr/icon';

bootstrapApplication(AppComponent, {
  providers: [provideWrIcons(lucideIcons({ plus: Plus, trash: Trash }))],
});

Use

The icon is hidden from screen readers, so an icon-only button needs its own aria-label.

import { WrIcon } from 'ngwr/icon';

@Component({ imports: [WrIcon], templateUrl: './my.html' })
export class MyComponent {}

<wr-icon name="plus" />
<wr-icon name="trash" />

Custom inline SVG

Wrap a one-off SVG in svgIcon() and style it with fill and stroke: style, <style>, <image>, <a>, <foreignObject>, filters and SMIL are removed.

import { svgIcon, provideWrIcons } from 'ngwr/icon';

provideWrIcons([
  svgIcon('brand', '<svg viewBox="0 0 24 24"><path d="…"/></svg>'),
]);

API

NameDescriptionTypeDefault
namerequiredName the icon was registered under in provideWrIcons(). An unregistered name renders nothing and logs in dev mode — ngwr ships no icons itself.WrIconName—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/icon's own element.

VariableDefaultDeclared on
--wr-icon-size1.2em:root

Dependencies

See also