UNPKG

@drivy/cobalt

Version:

Opinionated design system for Drivy's projects.

35 lines (32 loc) 1.7 kB
import { jsx } from 'react/jsx-runtime'; import cx from 'classnames'; import * as index from '../../icons/index.js'; import { icons, theme } from '../../tokens/index.js'; import 'lodash.throttle'; import camelize from '../utils/camelize.js'; import eqSet from '../utils/eqSet.js'; if (!eqSet(new Set(Object.keys(index)), new Set(Object.keys(icons.icons)))) throw new Error("Icon sources and tokens are not consistent. Did you add the source, export it and run 'pnpm run icons:update'"); const BUNDLED_ICONS = Object.freeze(Object.keys(icons.icons).reduce((bundledIcons, name) => { bundledIcons[name] = index[name]; return bundledIcons; }, {})); const iconColors = [...Object.keys(theme)]; const isIconSource = (source) => Object.keys(icons.icons).includes(source); const Icon = ({ source, color, size = 24, contained = false, className, }) => { const computedClassName = cx(className, `cobalt-Icon cobalt-Icon--${source}`, { [`c-fill-${camelize(color || "")}`]: color, "cobalt-Icon--size16": size === 16, "cobalt-Icon--size20": size === 20, "cobalt-Icon--size32": size === 32, "cobalt-Icon--contained": contained, }); const iconSource = BUNDLED_ICONS[source]; if (iconSource == null) throw new Error(`Icon '${source}' can not be found. Did you add the source, export it and run 'pnpm run icons:update'?`); return (jsx("span", { className: computedClassName, // biome-ignore lint/security/noDangerouslySetInnerHtml: Legacy icon component dangerouslySetInnerHTML: { __html: iconSource } })); }; export { BUNDLED_ICONS, Icon, Icon as default, iconColors, isIconSource }; //# sourceMappingURL=index.js.map