UNPKG

@uimkit/uikit-react

Version:

<img style="width:64px" src="https://mgmt.uimkit.chat/media/img/avatar.png"/>

39 lines (36 loc) 2.54 kB
import React__default, { forwardRef, useImperativeHandle, useState } from 'react'; import { Icon } from '../Icon/Icon.js'; import { IconTypes } from '../Icon/type.js'; import { Popup } from '../Popup/index.js'; import { usePluginsElement } from './hooks/usePluginsElement.js'; function PluginsWithContext(props, ref) { var _a = props.plugins, plugins = _a === void 0 ? [] : _a, showNumber = props.showNumber, MoreIcon = props.MoreIcon, _b = props.className, className = _b === void 0 ? '' : _b, _c = props.customClass, customClass = _c === void 0 ? '' : _c, root = props.root, handleVisible = props.handleVisible; useImperativeHandle(ref, function () { return ({ closeMore: function () { setShow(false); }, }); }); var _d = usePluginsElement({ plugins: plugins, showNumber: showNumber }), showPicker = _d.showPicker, elements = _d.elements; var _e = useState(false), show = _e[0], setShow = _e[1]; var handleShow = function (e) { e.stopPropagation(); setShow(!show); }; return ((showPicker.length > 0 || (elements === null || elements === void 0 ? void 0 : elements.length) > 0) && (React__default.createElement("ul", { className: "plugin ".concat(className) }, (showPicker === null || showPicker === void 0 ? void 0 : showPicker.length) > 0 && showPicker.map(function (Item, index) { var key = "".concat(Item).concat(index); return (React__default.createElement("li", { className: "plugin-item", key: key }, Item)); }), (elements === null || elements === void 0 ? void 0 : elements.length) > 0 && (React__default.createElement("div", { className: "plugin-popup" }, React__default.createElement("div", { role: "menuitem", tabIndex: 0, className: "more", onClick: handleShow }, !MoreIcon && React__default.createElement(Icon, { width: 20, height: 20, type: IconTypes.ADD }), MoreIcon && MoreIcon), React__default.createElement(Popup, { className: "plugin-popup-box ".concat(customClass), show: show, close: handleShow, root: root, handleVisible: handleVisible }, React__default.createElement("ul", null, elements.map(function (Item, index) { var key = "".concat(Item).concat(index); return (React__default.createElement("li", { className: "plugin-item", key: key }, Item)); })))))))); } var Plugins = forwardRef(PluginsWithContext); export { Plugins }; //# sourceMappingURL=index.js.map