UNPKG

@hitachivantara/uikit-react-icons

Version:

NEXT Design System icons packaged as a set of React components.

121 lines (120 loc) 3.42 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const jsxRuntime = require("react/jsx-runtime"); const react = require("react"); const styled = require("@emotion/styled"); const uikitStyles = require("@hitachivantara/uikit-styles"); const IconContainer = require("./IconContainer.cjs"); const utils = require("./utils.cjs"); const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; const styled__default = /* @__PURE__ */ _interopDefault(styled); const getColorVars = (colorArray) => { return colorArray.reduce((acc, value, index) => { acc[`--color-${index + 1}`] = value; return acc; }, {}); }; const getIconColors = (palette = [], color, semantic, inverted = false) => { const colorArray = [...palette]; if (typeof color === "string") { colorArray[0] = color; } else if (Array.isArray(color)) { colorArray.forEach((_, i) => { colorArray[i] = color[i]; }); } if (semantic) { colorArray[0] = uikitStyles.theme.colors?.[semantic] || colorArray[0]; } if (inverted && colorArray[1]) { colorArray[1] = colorArray[0]; colorArray[0] = "none"; } return colorArray; }; const StyledSvg = styled__default.default("svg")({ margin: "auto", color: "inherit", fill: "currentcolor", width: "1em", height: "1em", fontSize: "inherit" }); const IconBaseInternal = (props, ref) => { const { // internal props children, palette, iconName, viewBox, // deprecated props viewbox: viewBoxProp, height, width, semantic, inverted, // standard props title: titleProp, // keep aria-label for `HvTooltip`+icon compatibility "aria-label": ariaLabel, color, size, iconSize, style: styleProp, svgProps, ...others } = props; const colorArray = getIconColors(palette, color, semantic, inverted); const [color0, ...otherColors] = colorArray.map((c) => uikitStyles.getColor(c)); const title = titleProp ?? ariaLabel; const inheritColor = !color && palette?.length === 1 && palette?.[0] === "secondary"; return /* @__PURE__ */ jsxRuntime.jsx( IconContainer.HvIconContainer, { ref, "data-name": iconName, style: { ...!inheritColor && { color: color0 }, ...getColorVars(otherColors), ...utils.getSizeStyles(iconName ?? "", size), ...styleProp }, size: size ?? iconSize, ...others, children: /* @__PURE__ */ jsxRuntime.jsxs( StyledSvg, { viewBox: viewBoxProp ?? viewBox, focusable: false, role: title ? "img" : "none", style: width && height ? { width, height } : void 0, ...svgProps, children: [ title ? /* @__PURE__ */ jsxRuntime.jsx("title", { children: title }) : null, children ] } ) } ); }; const IconBase = react.memo(react.forwardRef(IconBaseInternal)); const createHvIcon = (iconName, viewBox, palette, children) => { const IconComponent = (props, ref) => { return /* @__PURE__ */ jsxRuntime.jsx( IconBase, { ref, iconName, viewBox, palette, ...props, children } ); }; IconComponent.displayName = `HvIcon${iconName}`; return react.memo(react.forwardRef(IconComponent)); }; exports.IconBase = IconBase; exports.createHvIcon = createHvIcon;