/** * @file 组件 modal/Modal * @author baozhixin * @borrows https://ant.design/components/modal-cn/ */ import * as I from './interface'; import Base from 'santd/base'; import {classCreator} from '../core/util'; import Dialog from './Dialog'; import button from '../button'; import icon from '../icon'; import localeReceiver from '../locale-provider/receiver'; import {Component} from 'san'; const prefixCls = classCreator('modal')(); export default class Modal extends Base { static components = { 's-button': button, 's-icon': icon } static computed: I.Computed = { ...localeReceiver.computed, wrapClass(this: Modal) { const centered = this.data.get('centered'); const wrapClassName = this.data.get('wrapClassName'); let classArr = [wrapClassName]; !!centered && classArr.push(`${prefixCls}-centered`); return classArr.join(' '); } } initData(): I.State { return { componentName: 'Modal', width: 520, transitionName: 'zoom', maskTransitionName: 'fade', confirmLoading: false, visible: false, okType: 'primary' }; } inited(this: TBase) { this.dispatch('santd_add_locale_receiver', this); } dialog: Component<{}> | null = null; attached() { if (!this.dialog) { const {getContainer, ...props} = this.data.get(); this.data.set('_PROPS_', props); this.dialog = new Dialog({ owner: this, source: /* html */ ` {{cancelText || locale.cancelText}} {{okText || locale.okText}} ` }); const container = getContainer ? getContainer() : document.body; this.dialog.attach(container); } } handleCancel(e: MouseEvent): void { this.fire('cancel', e); } handleOk(e: MouseEvent): void { this.fire('ok', e); } afterClose(): void { this.fire('afterClose'); } static template = '
'; };