Skip to content

Icon

<tpg-icon></tpg-icon>

The icon component is a utility component that encapsulates a lot of the iconography conserns of the design system. It can be used standalone, as demonstrated on this page, but is also embedded in many components in the rest of the library. Usually, one should be able to add icons to the correct spots in a design, by passing the relevant constant to another component. You shouldn’t have much need to use this component directly, given that a higher-level component exists for your use-case.

The constant in question is one of a large array exported by the package @tpg/grammar-web-icons, which contains the entire iconography of the design system.

Applications that are bundled will only contain the data for the icons that have been imported and used in this fashion. All other icons contained in @tpg/grammar-web-icons will be stripped out.

NOTE: the name of the attribute for the icon constant is subject to change in the near future.

Examples

Icon constant template

To support tree shaking unused icons in production apps, their SVGs are imported as constants and injected into grammar components as attributes or properties. In Vue or React this is a simple matter syntactically, but in vanilla you will have to query the elements at runtime from JS to do this.

For the icon component, the attribute for this is called icon-template (property: iconTemplate).

Size

Use the size attribute to set the size of the icon.

Nofill

Use the nofill attribute to have the icon use the colors from the svg. This is needed in cases where the SVG itself defines the colors that are to be filled, rather than leaving it to theming. In such cases, omitting this attribute will result in a black icon, which is probably not what you want.

Tables

Properties

Attribute Property Description Type Default Value
icon-template iconTemplate URI-encoded SVG for the icon to be rendered IconConstant | '' ''
size size Size of the icon IconSize 'medium'
nofill nofill Boolean that specifies if the icon should not be filled, but keep its native colors boolean false

Events

Event name Reactjs attribute Description
No events found.

Functions

Name Description Arguments
No functions found.

Slots

Name Description
No slots found.

CSS Parts

Attribute Description
No CSS parts found.

Sandbox