UNPKG

@wordpress/components

Version:
82 lines (81 loc) • 2.94 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let _wordpress_element = require("@wordpress/element"); let _wordpress_primitives = require("@wordpress/primitives"); let ___dashicon_index_tsx = require("../dashicon/index.cjs"); ___dashicon_index_tsx = __toESM(___dashicon_index_tsx); let react_jsx_runtime = require("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__ */ (0, react_jsx_runtime.jsx)(___dashicon_index_tsx.default, { icon, size, ...additionalProps }); if ((0, _wordpress_element.isValidElement)(icon) && ___dashicon_index_tsx.default === icon.type) return (0, _wordpress_element.cloneElement)(icon, { ...additionalProps }); if ("function" === typeof icon) return (0, _wordpress_element.createElement)(icon, { size, ...additionalProps }); if ((0, _wordpress_element.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 === _wordpress_primitives.SVG) { const appliedProps = { ...icon.props, width: size, height: size, ...restProps, ...styleProps }; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_primitives.SVG, { ...appliedProps }); } return (0, _wordpress_element.cloneElement)(icon, { size, width: size, height: size, ...restProps, ...styleProps }); } return icon; } exports.default = Icon; //# sourceMappingURL=index.cjs.map