UNPKG

zent

Version:

一套前端设计语言和基于React的实现

87 lines (86 loc) 4.95 kB
import { __assign, __extends } from "tslib"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Component, createRef } from 'react'; import cx from 'classnames'; import Popover from '../popover'; import { exposePopover } from '../popover/withPopover'; import getArrowPosition from '../utils/getArrowPosition'; import Action from './Action'; import noop from '../utils/noop'; var Trigger = Popover.Trigger; var Pop = (function (_super) { __extends(Pop, _super); function Pop() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.popoverRef = createRef(); _this.isUnmounted = false; _this.state = { confirmPending: false, cancelPending: false, }; _this.changePending = function (key, pending, callback) { var _a; if (_this.isUnmounted) { return; } _this.setState((_a = {}, _a[key] = pending, _a), callback); }; return _this; } Pop.prototype.adjustPosition = function () { var popover = this.popoverRef.current; if (popover) { popover.adjustPosition(); } }; Pop.prototype.getWrappedPopover = function () { return this.popoverRef.current; }; Pop.prototype.renderTrigger = function () { var props = this.props; switch (props.trigger) { case 'click': return (_jsx(Trigger.Click, __assign({ closeOnClickOutside: props.closeOnClickOutside }, { children: props.children }), void 0)); case 'hover': return (_jsx(Trigger.Hover, __assign({ showDelay: props.mouseEnterDelay, hideDelay: props.mouseLeaveDelay, anchorOnly: props.anchorOnly, fixMouseEventsOnDisabledChildren: props.fixMouseEventsOnDisabledChildren }, { children: props.children }), void 0)); case 'focus': return _jsx(Trigger.Focus, { children: props.children }, void 0); case 'none': return _jsx(Popover.Anchor, { children: props.children }, void 0); default: throw new Error('Pop trigger not assigned'); } }; Pop.prototype.componentWillUnmount = function () { this.isUnmounted = true; }; Pop.prototype.render = function () { var _a = this.props, className = _a.className, style = _a.style, trigger = _a.trigger, visible = _a.visible, onShow = _a.onShow, onClose = _a.onClose, position = _a.position, cushion = _a.cushion, header = _a.header, content = _a.content, centerArrow = _a.centerArrow, onBeforeClose = _a.onBeforeClose, onBeforeShow = _a.onBeforeShow, onPositionUpdated = _a.onPositionUpdated, onPositionReady = _a.onPositionReady, containerSelector = _a.containerSelector, onCancel = _a.onCancel, onConfirm = _a.onConfirm, confirmText = _a.confirmText, cancelText = _a.cancelText, type = _a.type; var hasHeader = header != null; var onVisibleChange = this.props.onVisibleChange; if (trigger === 'none') { onVisibleChange = onVisibleChange || noop; } var _b = this.state, confirmPending = _b.confirmPending, cancelPending = _b.cancelPending; var closePending = confirmPending || cancelPending; return (_jsxs(Popover, __assign({ ref: this.popoverRef, visible: closePending ? true : visible, onVisibleChange: closePending ? noop : onVisibleChange, className: cx('zent-pop-v2', className, { 'zent-pop-v2--has-header': hasHeader, 'zent-pop-v2--no-header': !hasHeader, }), style: style, cushion: cushion, position: getArrowPosition(position, centerArrow), onShow: onShow, onClose: onClose, onBeforeClose: onBeforeClose, onBeforeShow: onBeforeShow, onPositionUpdated: onPositionUpdated, onPositionReady: onPositionReady, containerSelector: containerSelector }, { children: [this.renderTrigger(), _jsxs(Popover.Content, { children: [hasHeader && _jsx("div", __assign({ className: "zent-pop-v2-header", "data-zv": '10.0.17' }, { children: header }), void 0), _jsxs("div", __assign({ className: "zent-pop-v2-inner", "data-zv": '10.0.17' }, { children: [content, (onCancel || onConfirm) && (_jsx(Action, { onConfirm: onConfirm, onCancel: onCancel, confirmText: confirmText, cancelText: cancelText, confirmPending: confirmPending, cancelPending: cancelPending, changePending: this.changePending, type: type }, void 0))] }), void 0), _jsx("div", { className: "zent-pop-v2-arrow", "data-zv": '10.0.17' }, void 0)] }, void 0)] }), void 0)); }; Pop.defaultProps = { trigger: 'none', position: 'top-center', cushion: 10, type: 'primary', mouseLeaveDelay: 200, mouseEnterDelay: 200, containerSelector: 'body', }; Pop.withPop = exposePopover('pop'); return Pop; }(Component)); export { Pop }; export default Pop;