@gechiui/components
Version:
UI components for GeChiUI.
73 lines (61 loc) • 1.44 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
/**
* GeChiUI dependencies
*/
import { cloneElement, createElement, Component, isValidElement } from '@gechiui/element';
import { SVG } from '@gechiui/primitives';
/**
* Internal dependencies
*/
import Dashicon from '../dashicon';
function Icon(_ref) {
let {
icon = null,
size = 24,
...additionalProps
} = _ref;
if ('string' === typeof icon) {
return createElement(Dashicon, _extends({
icon: icon
}, additionalProps));
}
if (isValidElement(icon) && Dashicon === icon.type) {
return cloneElement(icon, { ...additionalProps
});
}
if ('function' === typeof icon) {
if (icon.prototype instanceof Component) {
return createElement(icon, {
size,
...additionalProps
});
}
return icon({
size,
...additionalProps
});
}
if (icon && (icon.type === 'svg' || icon.type === SVG)) {
const appliedProps = {
width: size,
height: size,
...icon.props,
...additionalProps
};
return createElement(SVG, appliedProps);
}
if (isValidElement(icon)) {
return cloneElement(icon, {
// @ts-ignore Just forwarding the size prop along
size,
...additionalProps
});
}
return icon;
}
export default Icon;
//# sourceMappingURL=index.js.map