UNPKG

@drivy/cobalt

Version:

Opinionated design system for Drivy's projects.

37 lines (36 loc) 1.8 kB
import { jsx } from "react/jsx-runtime"; import classnames from "classnames"; import * as __rspack_external__icons_index_js_f89abfcf from "../../icons/index.js"; import { icons, theme } from "../../tokens/index.js"; import { camelize, eqSet } from "../utils/index.js"; export * from "./__generated__/index.js"; if (!eqSet(new Set(Object.keys(__rspack_external__icons_index_js_f89abfcf)), 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] = __rspack_external__icons_index_js_f89abfcf[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 = classnames(className, `cobalt-Icon cobalt-Icon--${source}`, { [`c-fill-${camelize(color || "")}`]: color, "cobalt-Icon--size16": 16 === size, "cobalt-Icon--size20": 20 === size, "cobalt-Icon--size32": 32 === size, "cobalt-Icon--contained": contained }); const iconSource = BUNDLED_ICONS[source]; if (null == iconSource) throw new Error(`Icon '${source}' can not be found. Did you add the source, export it and run 'pnpm run icons:update'?`); return /*#__PURE__*/ jsx("span", { className: computedClassName, dangerouslySetInnerHTML: { __html: iconSource } }); }; const components_Icon = Icon; export default components_Icon; export { BUNDLED_ICONS, Icon, iconColors, isIconSource }; //# sourceMappingURL=index.js.map