@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
35 lines • 1.59 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElementOrIcon = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const icon_1 = require("../icon/icon");
const iconHost_1 = require("../icon/iconHost");
const ElementOrIconComponent = ({ basic = false, ...props }, ref) => {
const { icon: element, ...rest } = props;
if (!element) {
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
}
// element as string
if (typeof element === 'string') {
return basic ? ((0, jsx_runtime_1.jsx)(icon_1.IconBasic, { ...rest, ref: ref, icon: element })) : ((0, jsx_runtime_1.jsx)(iconHost_1.IconHost, { ...rest, ref: ref, icon: element }));
}
// element as jsx element
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: element });
};
/**
* ElementOrIcon component is a component that can be used to display either an element or an icon.
* It offers flexibility in rendering either icons or more complex components within a given context.
* @param {IElementOrIcon} props
* @returns {JSX.Element}
* @constructor
* @example
* <ElementOrIcon icon="icon" />
* <ElementOrIcon icon={<Icon icon="icon" />} />
* <ElementOrIcon icon={<Button variant="primary">Button</Button>} />
*/
exports.ElementOrIcon = react_1.default.forwardRef(ElementOrIconComponent);
//# sourceMappingURL=elementOrIcon.js.map