UNPKG

ukelli-ui

Version:

Base on React's UI lib. Make frontend's dev simpler and faster.

139 lines (138 loc) 5.66 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 (b.hasOwnProperty(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); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; import React, { PureComponent } from 'react'; import { Call, DebounceClass, UUID } from 'basic-helper'; import { PopoverEntity } from '../popover/popover-entity'; import { Icon } from '../icon'; import { $T } from '../config'; var debounce = new DebounceClass(); var TitleDOM = function (_a) { var title = _a.title; var isArr = Array.isArray(title); var titleDOM = isArr ? title.map(function (text, idx) { return (React.createElement("p", { key: text }, idx + 1, ". ", $T(text))); }) : $T(title); return (React.createElement("div", { style: { padding: '5px 10px' } }, titleDOM)); }; var Div = function (_a) { var classNames = _a.classNames, children = _a.children, n = _a.n, props = __rest(_a, ["classNames", "children", "n"]); return (React.createElement("span", __assign({}, props), React.createElement(Icon, { n: n }), children)); }; /** * 提供简单的提示按钮 * * @export * @class ToolTip * @extends {PureComponent} */ var ToolTip = /** @class */ (function (_super) { __extends(ToolTip, _super); function ToolTip() { var _this = _super !== null && _super.apply(this, arguments) || this; // constructor(props) { // super(props); // } _this.componentWillUnmount = function () { if (_this.Popover) _this.Popover.destroy(); }; _this.newPopover = function () { if (!_this.Popover) { _this.Popover = new PopoverEntity({ id: UUID(), fixed: true }); } return _this.Popover; }; _this.handleMouseEnter = function (e) { var _popover = _this.newPopover(); var _a = _this.props, title = _a.title, position = _a.position, _b = _a.color, color = _b === void 0 ? 'black' : _b; _popover.show({ elem: e.target, props: { position: position, showCloseBtn: false, enableTabIndex: false, className: 'icon-tip', type: color }, children: React.createElement(TitleDOM, { title: title }), }); }; _this.handleMouseLeave = function (e) { _this.Popover.close(); }; _this.handleClick = function (e) { var _a = _this.props, clickToClose = _a.clickToClose, onClick = _a.onClick; Call(onClick, e); if (clickToClose) { _this.Popover && _this.Popover.close(); } else { debounce.exec(function () { var title = _this.props.title; _this.Popover && _this.Popover.show({ children: React.createElement(TitleDOM, { title: title }), }); }, 15); } }; return _this; } ToolTip.prototype.render = function () { var _a = this.props, title = _a.title, clickToClose = _a.clickToClose, onClick = _a.onClick, position = _a.position, component = _a.component, children = _a.children, _b = _a.classNames, classNames = _b === void 0 ? [] : _b, other = __rest(_a, ["title", "clickToClose", "onClick", "position", "component", "children", "classNames"]); // const Com = component; var Com = children ? Div : component || Icon; return (React.createElement(Com, __assign({}, other, { onMouseEnter: this.handleMouseEnter, onMouseLeave: this.handleMouseLeave, onClick: this.handleClick, classNames: __spreadArrays(classNames, ['relative']) }), children)); }; ToolTip.defaultProps = { position: 'bottom', classNames: [] }; return ToolTip; }(PureComponent)); export default ToolTip;