UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

101 lines (100 loc) 4.28 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import React from 'react'; import classnames from 'classnames'; import { get, isNil, includes } from 'lodash'; import { EllipsisOutlined } from '@ant-design/icons'; import { Popover, Menu } from 'antd'; import Group from './Group'; import * as styles from './style.mless'; var MoreAction = /** @class */ (function (_super) { __extends(MoreAction, _super); function MoreAction() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.buttonRef = React.createRef(); _this.state = { firstRender: true, visible: true }; _this.hide = function (e) { if (includes(e.propagationPath && e.propagationPath(), _this.buttonRef.current)) { return; } _this.setState({ visible: false }); }; _this.handleVisibleChange = function () { _this.setState(function (state) { return (__assign(__assign({}, state), { visible: !state.visible })); }); }; return _this; } MoreAction.prototype.componentDidMount = function () { this.setState({ visible: false, firstRender: false }); document.addEventListener('click', this.hide); }; MoreAction.prototype.componentWillUnmount = function () { document.removeEventListener('click', this.hide); }; MoreAction.prototype.renderContent = function () { var popupClassName = this.props.popupClassName; var items = React.Children.map(this.props.children, function (child) { if (get(child, 'type') === Menu.SubMenu) { return child; } if (get(child, 'type.displayName') === Group.displayName) { return child; } if (!React.isValidElement(child) || isNil(child.key)) { return null; } return React.createElement(Menu.Item, { key: child.key }, child); }); return (React.createElement(Menu, { className: classnames(styles.moreAction, popupClassName), selectable: false }, items)); }; MoreAction.prototype.render = function () { var _a; var _b = this.props, className = _b.className, placement = _b.placement, trigger = _b.trigger, icon = _b.icon, getPopupContainer = _b.getPopupContainer; var _c = this.state, firstRender = _c.firstRender, visible = _c.visible; return (React.createElement(Popover // hack: forceRender and avoid LazyRenderBox , { // hack: forceRender and avoid LazyRenderBox overlayClassName: classnames((_a = {}, _a[styles.hide] = firstRender || !visible, _a)), className: className, placement: placement, arrowPointAtCenter: true, getPopupContainer: getPopupContainer, visible: true, trigger: trigger, content: this.renderContent() }, React.createElement("div", { onClick: this.handleVisibleChange, ref: this.buttonRef }, icon || React.createElement(EllipsisOutlined, null)))); }; MoreAction.Group = Group; MoreAction.defaultProps = { placement: 'bottom', trigger: 'click' }; return MoreAction; }(React.Component)); export default MoreAction;