UNPKG

ant-design-vue

Version:

An enterprise-class UI design language and Vue-based implementation

111 lines (97 loc) 3.03 kB
import { createVNode as _createVNode, isVNode as _isVNode } from "vue"; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import { defineComponent } from 'vue'; import PropTypes from '../_util/vue-types'; import Button from '../button'; import BaseMixin from '../_util/BaseMixin'; import buttonTypes from '../button/buttonTypes'; import { getSlot, findDOMNode } from '../_util/props-util'; function _isSlot(s) { return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !_isVNode(s); } var ButtonType = buttonTypes().type; var ActionButtonProps = { type: ButtonType, actionFn: PropTypes.func, closeModal: PropTypes.func, autofocus: PropTypes.looseBool, buttonProps: PropTypes.object }; export default defineComponent({ mixins: [BaseMixin], props: ActionButtonProps, setup: function setup() { return { timeoutId: undefined }; }, data: function data() { return { loading: false }; }, mounted: function mounted() { var _this = this; if (this.autofocus) { this.timeoutId = setTimeout(function () { return findDOMNode(_this).focus(); }); } }, beforeUnmount: function beforeUnmount() { clearTimeout(this.timeoutId); }, methods: { onClick: function onClick() { var _this2 = this; var actionFn = this.actionFn, closeModal = this.closeModal; if (actionFn) { var ret; if (actionFn.length) { ret = actionFn(closeModal); } else { ret = actionFn(); if (!ret) { closeModal(); } } if (ret && ret.then) { this.setState({ loading: true }); ret.then(function () { // It's unnecessary to set loading=false, for the Modal will be unmounted after close. // this.setState({ loading: false }); closeModal.apply(void 0, arguments); }, function (e) { // Emit error when catch promise reject // eslint-disable-next-line no-console console.error(e); // See: https://github.com/ant-design/ant-design/issues/6183 _this2.setState({ loading: false }); }); } } else { closeModal(); } } }, render: function render() { var _slot; var type = this.type, loading = this.loading, buttonProps = this.buttonProps; var props = _extends({ type: type, onClick: this.onClick, loading: loading }, buttonProps); return _createVNode(Button, props, _isSlot(_slot = getSlot(this)) ? _slot : { default: function _default() { return [_slot]; } }); } });