Skip to content

@ghs-hazard-pictograms/react

Terminal window
npm install @ghs-hazard-pictograms/react

Every pictogram is available as a named React component. The component name is the pictogram ID converted to PascalCase.

import { Ghs01ExplosivesExplodingBomb } from '@ghs-hazard-pictograms/react';
export default function App() {
return <Ghs01ExplosivesExplodingBomb width={64} height={64} title="Explosives" />;
}

Component names follow the pattern Ghs{nn}{Category}{Name}, e.g.:

Pictogram IDComponent name
ghs01-explosives-exploding-bombGhs01ExplosivesExplodingBomb
ghs02-flammable-flameGhs02FlammableFlame
ghs06-toxic-skull-crossbonesGhs06ToxicSkullCrossbones

Use PictogramById when the pictogram is determined at runtime.

import { PictogramById } from '@ghs-hazard-pictograms/react';
export default function HazardIcon({ id }: { id: string }) {
return <PictogramById id={id} width={64} height={64} />;
}
PropTypeRequiredDefaultDescription
widthnumberNo24Width of the SVG in pixels
heightnumberNo24Height of the SVG in pixels
titlestringNopictogram nameAccessible title rendered as <title>
descriptionstringNoAccessible description rendered as <desc>
PropTypeRequiredDescription
idstringYesPictogram ID, e.g. ghs01-explosives-exploding-bomb

All components and props are fully typed. Import the shared Pictogram type from @ghs-hazard-pictograms/core if you need to work with pictogram data alongside the components.

import type { Pictogram } from '@ghs-hazard-pictograms/core';

Each component renders an inline SVG. When title is provided a <title> element is injected and the SVG gains aria-labelledby pointing to that title. When description is also provided a <desc> element is added and included in aria-labelledby.

If the pictogram is purely decorative, pass aria-hidden="true" as a prop to suppress it from the accessibility tree.

<Ghs01ExplosivesExplodingBomb aria-hidden="true" width={24} />