UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

122 lines (121 loc) 5.59 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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; import * as React from 'react'; import classnames from 'classnames'; import { observer } from 'mobx-react'; import { observable, action } from 'mobx'; import { EllipsisOutlined } from '@ant-design/icons'; import { Popover, Tooltip } from 'antd'; import bind from '../../../utils/bind'; import { formatString } from '../../../services/language'; import * as style from './style.mless'; /** * 资源列表页面表格中操作列表 */ var OptionList = /** @class */ (function (_super) { __extends(OptionList, _super); function OptionList() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.visible = false; return _this; } OptionList.prototype.setVisible = function (visible) { this.visible = visible; }; OptionList.prototype.handleItemClick = function (option) { if (option.disabled || !option.onClick) { return; } this.setVisible(false); option.onClick(option.source); }; OptionList.prototype.render = function () { var e_1, _a; var _this = this; var _b = this.props, className = _b.className, options = _b.options, getPopupContainer = _b.getPopupContainer, children = _b.children; var items = []; var _loop_1 = function (option) { var _a; var key = option.key, text = option.text, title = option.title, disabled = option.disabled, hidden = option.hidden; if (hidden) { return "continue"; } var itemClass = classnames(style.item, (_a = {}, _a[style.disabled] = disabled, _a)); var itemNode = (React.createElement("div", { key: key || text, className: itemClass, onClick: function () { return _this.handleItemClick(option); } }, formatString(text))); if (title) { items.push(React.createElement(Tooltip, { title: formatString(title), getPopupContainer: getPopupContainer, placement: "left" }, itemNode)); } else { items.push(itemNode); } }; try { for (var options_1 = __values(options), options_1_1 = options_1.next(); !options_1_1.done; options_1_1 = options_1.next()) { var option = options_1_1.value; _loop_1(option); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (options_1_1 && !options_1_1.done && (_a = options_1.return)) _a.call(options_1); } finally { if (e_1) throw e_1.error; } } var content = (React.createElement("div", { className: classnames(className, style.list) }, items)); return (React.createElement(Popover, { placement: "bottom", getPopupContainer: getPopupContainer, trigger: "click", open: this.visible, overlayClassName: style.popover, onOpenChange: this.setVisible, content: content }, children || React.createElement(EllipsisOutlined, { className: style.icon }))); }; __decorate([ observable, __metadata("design:type", Boolean) ], OptionList.prototype, "visible", void 0); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], OptionList.prototype, "setVisible", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], OptionList.prototype, "handleItemClick", null); OptionList = __decorate([ observer ], OptionList); return OptionList; }(React.Component)); export default OptionList;