@hitachivantara/uikit-react-icons
Version:
NEXT Design System icons packaged as a set of React components.
71 lines (70 loc) • 2.16 kB
JavaScript
import { getSizeStyles } from "./utils.js";
import { HvIconContainer } from "./IconContainer.js";
import { forwardRef, memo } from "react";
import styled from "@emotion/styled";
import { getColor } from "@hitachivantara/uikit-styles";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/IconBase.tsx
var getColorVars = (colorArray) => {
return colorArray.reduce((acc, value, index) => {
acc[`--color-${index + 1}`] = value;
return acc;
}, {});
};
var getIconColors = (palette = [], color) => {
const colorArray = [...palette];
if (typeof color === "string") colorArray[0] = color;
else if (Array.isArray(color)) colorArray.forEach((_, i) => {
colorArray[i] = color[i];
});
return colorArray;
};
var StyledSvg = styled("svg")({
margin: "auto",
color: "inherit",
fill: "currentcolor",
width: "1em",
height: "1em",
fontSize: "inherit"
});
var IconBaseInternal = (props, ref) => {
const { children, palette, iconName, viewBox, title: titleProp, "aria-label": ariaLabel, color, size, iconSize, style: styleProp, svgProps, ...others } = props;
const [color0, ...otherColors] = getIconColors(palette, color).map((c) => getColor(c));
const title = titleProp ?? ariaLabel;
return /* @__PURE__ */ jsx(HvIconContainer, {
ref,
"data-name": iconName,
style: {
...!(!color && palette?.length === 1 && palette?.[0] === "text") && { color: color0 },
...getColorVars(otherColors),
...getSizeStyles(iconName ?? "", size),
...styleProp
},
size: size ?? iconSize,
...others,
children: /* @__PURE__ */ jsxs(StyledSvg, {
viewBox,
focusable: false,
role: title ? "img" : "none",
...svgProps,
children: [title ? /* @__PURE__ */ jsx("title", { children: title }) : null, children]
})
});
};
var IconBase = memo(forwardRef(IconBaseInternal));
var createHvIcon = (iconName, viewBox, palette, children) => {
const IconComponent = (props, ref) => {
return /* @__PURE__ */ jsx(IconBase, {
ref,
iconName,
viewBox,
palette,
...props,
children
});
};
IconComponent.displayName = `HvIcon${iconName}`;
return memo(forwardRef(IconComponent));
};
//#endregion
export { IconBase, createHvIcon };