Debian Codegraph @

node/@patternfly/react-icons/dist/js/createIcon.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.createIcon = exports.createIconBase = void 0;
4 const tslib_1 = require("tslib");
5 const jsx_runtime_1 = require("react/jsx-runtime");
6 const react_1 = require("react");
7 let currentId = 0;
8 /** Returns svg path(s) from a given svg data object. */
9 function getSvgPaths(svgPathData) {
10 return svgPathData && Array.isArray(svgPathData) ? (svgPathData.map((pathObject, index) => ((0, jsx_runtime_1.jsx)("path", { className: pathObject.className, d: pathObject.path }, `${pathObject.path}-${index}`)))) : ((0, jsx_runtime_1.jsx)("path", { d: svgPathData }));
11 }
12 const createInnerSvg = (icon, iconClassName) => {
13 const { xOffset, yOffset, width, height, svgPathData, svgClassName } = icon !== null && icon !== void 0 ? icon : {};
14 const _xOffset = xOffset !== null && xOffset !== void 0 ? xOffset : 0;
15 const _yOffset = yOffset !== null && yOffset !== void 0 ? yOffset : 0;
16 const viewBox = [_xOffset, _yOffset, width, height].join(' ');
17 const classNames = [];
18 if (svgClassName) {
19 classNames.push(svgClassName);
20 }
21 if (iconClassName) {
22 classNames.push(iconClassName);
23 }
24 return ((0, jsx_runtime_1.jsx)("svg", { viewBox: viewBox, className: classNames.join(' '), children: getSvgPaths(svgPathData) }));
25 };
26 /**
27 * Internal API for creating icons. Subject to change at any time. Please use `createIcon` instead.
28 * @internal
29 */
30 function createIconBase({ name, icon, rhUiIcon = null }) {
31 var _a;
32 if (icon == null) {
33 // eslint-disable-next-line no-console
34 console.warn(`@patternfly/react-icons: createIconBase is missing an \`icon\` definition (name: ${name !== null && name !== void 0 ? name : 'unknown'}).`);
35 }
36 return _a = class SVGIcon extends react_1.Component {
37 constructor() {
38 super(...arguments);
39 this.id = `icon-title-${currentId++}`;
40 }
41 render() {
42 const _b = this.props, { title, className: propsClassName, set, noDefaultStyle } = _b, props = tslib_1.__rest(_b, ["title", "className", "set", "noDefaultStyle"]);
43 const hasTitle = Boolean(title);
44 const classNames = ['pf-v6-svg'];
45 if (propsClassName) {
46 classNames.push(propsClassName);
47 }
48 if (set === 'rh-ui' && rhUiIcon === null) {
49 // eslint-disable-next-line no-console
50 console.warn(`Set "rh-ui" was provided for ${name}, but no rh-ui icon data exists for this icon. The default icon will be rendered.`);
51 }
52 if ((set === undefined && rhUiIcon === null) || set !== undefined) {
53 const iconData = set !== undefined && set === 'rh-ui' && rhUiIcon !== null ? rhUiIcon : icon;
54 const { xOffset, yOffset, width, height, svgPathData, svgClassName } = iconData !== null && iconData !== void 0 ? iconData : {};
55 const _xOffset = xOffset !== null && xOffset !== void 0 ? xOffset : 0;
56 const _yOffset = yOffset !== null && yOffset !== void 0 ? yOffset : 0;
57 const viewBox = [_xOffset, _yOffset, width, height].join(' ');
58 if (svgClassName && !noDefaultStyle) {
59 classNames.push(svgClassName);
60 }
61 return ((0, jsx_runtime_1.jsxs)("svg", Object.assign({ className: classNames.join(' '), fill: "currentColor", viewBox: viewBox, "aria-labelledby": hasTitle ? this.id : null, "aria-hidden": hasTitle ? null : true, role: "img", width: "1em", height: "1em" }, props, { children: [hasTitle && (0, jsx_runtime_1.jsx)("title", { id: this.id, children: title }), getSvgPaths(svgPathData)] })));
62 }
63 return ((0, jsx_runtime_1.jsxs)("svg", Object.assign({ className: classNames.join(' '), fill: "currentColor", "aria-labelledby": hasTitle ? this.id : null, "aria-hidden": hasTitle ? null : true, role: "img", width: "1em", height: "1em" }, props, { children: [hasTitle && (0, jsx_runtime_1.jsx)("title", { id: this.id, children: title }), icon && createInnerSvg(icon, 'pf-v6-icon-default'), rhUiIcon && createInnerSvg(rhUiIcon, 'pf-v6-icon-rh-ui')] })));
64 }
65 },
66 _a.displayName = name,
67 _a.defaultProps = {
68 noDefaultStyle: false
69 },
70 _a;
71 }
72 exports.createIconBase = createIconBase;
73 /** Public API for creating icons. Will be maintained up to breaking releases. */
74 function createIcon(props) {
75 const { rhUiIcon = null } = props, rest = tslib_1.__rest(props, ["rhUiIcon"]);
76 const icon = {
77 name: rest.name,
78 width: rest.width,
79 height: rest.height,
80 xOffset: rest.xOffset,
81 yOffset: rest.yOffset,
82 svgClassName: rest.svgClassName,
83 svgPathData: rest.svgPath
84 };
85 return createIconBase({ name: icon.name, icon, rhUiIcon });
86 }
87 exports.createIcon = createIcon;
88 //# sourceMappingURL=createIcon.js.map