Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 34x | import React from 'react'; const ICONS = {}; function addIcon(iconName, iconSVG) { Iif (ICONS[iconName]) { console.warn(`Icon ${iconName} already exists.`); } ICONS[iconName] = iconSVG; } /** * Return the matching SVG Icon as a React Component. * Results in an inlined SVG Element. If there's no match, * return `null` */ export default function getIcon(key, props) { const icon = ICONS[key]; Iif (!key || !icon) { return React.createElement('div', null, 'Missing Icon ' + key); } if (typeof icon === 'string' && icon.endsWith('.png')) { return React.createElement('img', { src: icon, ...props }); } else { return React.createElement(icon, props); } } export { getIcon, ICONS, addIcon }; |