@patternfly/react-icons
Version:
PatternFly 4 Icons as React Components
55 lines • 2.12 kB
JavaScript
import { __rest } from "tslib";
import * as React from 'react';
export var IconSize;
(function (IconSize) {
IconSize["sm"] = "sm";
IconSize["md"] = "md";
IconSize["lg"] = "lg";
IconSize["xl"] = "xl";
})(IconSize || (IconSize = {}));
export const getSize = (size) => {
switch (size) {
case IconSize.sm:
return '1em';
case IconSize.md:
return '1.5em';
case IconSize.lg:
return '2em';
case IconSize.xl:
return '3em';
default:
return '1em';
}
};
let currentId = 0;
/**
* Factory to create Icon class components for consumers
*/
export function createIcon({ name, xOffset = 0, yOffset = 0, width, height, svgPath }) {
var _a;
return _a = class SVGIcon extends React.Component {
constructor() {
super(...arguments);
this.id = `icon-title-${currentId++}`;
}
render() {
const _a = this.props, { size, color, title, noVerticalAlign } = _a, props = __rest(_a, ["size", "color", "title", "noVerticalAlign"]);
const hasTitle = Boolean(title);
const heightWidth = getSize(size);
const baseAlign = -0.125 * Number.parseFloat(heightWidth);
const style = noVerticalAlign ? null : { verticalAlign: `${baseAlign}em` };
const viewBox = [xOffset, yOffset, width, height].join(' ');
return (React.createElement("svg", Object.assign({ style: style, fill: color, height: heightWidth, width: heightWidth, viewBox: viewBox, "aria-labelledby": hasTitle ? this.id : null, "aria-hidden": hasTitle ? null : true, role: "img" }, props),
hasTitle && React.createElement("title", { id: this.id }, title),
React.createElement("path", { d: svgPath })));
}
},
_a.displayName = name,
_a.defaultProps = {
color: 'currentColor',
size: IconSize.sm,
noVerticalAlign: false
},
_a;
}
//# sourceMappingURL=createIcon.js.map