Skip to content

@public-information-symbols/elements

Terminal window
npm install @public-information-symbols/elements

Call defineCustomElements() once at your application entry point to register all custom elements with the browser.

import { defineCustomElements } from '@public-information-symbols/elements';
defineCustomElements();

By default elements are registered under the pi- prefix. Pass an options object to use a different prefix.

defineCustomElements({ prefix: 'my-' });
// registers <my-ac-001-full-accessibility-or-toilets-accessible>

Use <pi-symbol> when the symbol is not known at build time.

<pi-symbol
symbol-id="ac-001-full-accessibility-or-toilets-accessible"
width="64"
title="Accessible toilets"
></pi-symbol>

Every symbol also has a dedicated tag derived from its ID.

<pi-ac-001-full-accessibility-or-toilets-accessible
width="64"
title="Accessible toilets"
></pi-ac-001-full-accessibility-or-toilets-accessible>
AttributeTypeRequired for <pi-symbol>Description
symbol-idstringYesSymbol ID (only used on the generic <pi-symbol>).
widthstringNoWidth of the rendered SVG in pixels.
heightstringNoHeight of the rendered SVG in pixels.
titlestringNoAccessible name injected as <title> in the SVG.
descriptionstringNoLonger description injected as <desc> in the SVG.

Attributes are observed. Updating them via JavaScript causes the SVG to re-render automatically.

const el = document.querySelector('pi-symbol');
el.setAttribute('symbol-id', 'pf-001-toilets');
el.setAttribute('width', '128');
<template>
<pi-symbol
symbol-id="ac-001-full-accessibility-or-toilets-accessible"
:width="size"
title="Accessible toilets"
/>
</template>

Provide a title attribute so screen readers can announce the symbol. The element automatically adds role="img" and aria-labelledby when a title is present. For purely decorative symbols, set aria-hidden="true" on the element.