Debian Codegraph @

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

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