UNPKG

@wordpress/components

Version:
55 lines (54 loc) • 1.53 kB
import { cloneElement, createElement, isValidElement } from "@wordpress/element"; import { SVG } from "@wordpress/primitives"; import Dashicon from "../dashicon/index.mjs"; import { jsx } from "react/jsx-runtime"; // packages/components/src/icon/index.tsx /** * Renders a raw icon without any initial styling or wrappers. * * ```jsx * import { wordpress } from '@wordpress/icons'; * * <Icon icon={ wordpress } /> * ``` */ function Icon({ icon = null, size = "string" === typeof icon ? 20 : 24, ...additionalProps }) { if ("string" === typeof icon) return /* @__PURE__ */ jsx(Dashicon, { icon, size, ...additionalProps }); if (isValidElement(icon) && Dashicon === icon.type) return cloneElement(icon, { ...additionalProps }); if ("function" === typeof icon) return createElement(icon, { size, ...additionalProps }); if (isValidElement(icon)) { const { style: consumerStyle, ...restProps } = additionalProps; const mergedStyle = icon.props.style || consumerStyle ? { ...icon.props.style, ...consumerStyle } : void 0; const styleProps = mergedStyle ? { style: mergedStyle } : {}; if (icon.type === "svg" || icon.type === SVG) { const appliedProps = { ...icon.props, width: size, height: size, ...restProps, ...styleProps }; return /* @__PURE__ */ jsx(SVG, { ...appliedProps }); } return cloneElement(icon, { size, width: size, height: size, ...restProps, ...styleProps }); } return icon; } export { Icon as default }; //# sourceMappingURL=index.mjs.map