From 597f34b8da2953c74c921969f8de9f10cbe6054a Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 7 Feb 2021 14:05:43 +0800 Subject: [PATCH] types(Dialog): use tsx (#8097) --- src/dialog/{Dialog.js => Dialog.tsx} | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) rename src/dialog/{Dialog.js => Dialog.tsx} (89%) diff --git a/src/dialog/Dialog.js b/src/dialog/Dialog.tsx similarity index 89% rename from src/dialog/Dialog.js rename to src/dialog/Dialog.tsx index f59792fd8..aee9c89a4 100644 --- a/src/dialog/Dialog.js +++ b/src/dialog/Dialog.tsx @@ -1,7 +1,7 @@ -import { reactive } from 'vue'; +import { PropType, reactive } from 'vue'; // Utils -import { callInterceptor } from '../utils/interceptor'; +import { callInterceptor, Interceptor } from '../utils/interceptor'; import { createNamespace, addUnit, pick } from '../utils'; import { BORDER_TOP, BORDER_LEFT } from '../utils/constant'; @@ -13,6 +13,9 @@ import ActionBarButton from '../action-bar-button'; const [createComponent, bem, t] = createNamespace('dialog'); +export type DialogAction = 'confirm' | 'cancel'; +export type DialogMessageAlign = 'left' | 'center' | 'right'; + const popupKeys = [ ...Object.keys(popupSharedProps), 'transition', @@ -26,11 +29,11 @@ export default createComponent({ theme: String, width: [Number, String], message: String, - callback: Function, + callback: Function as PropType<(action?: DialogAction) => void>, allowHtml: Boolean, className: null, - beforeClose: Function, - messageAlign: String, + beforeClose: Function as PropType, + messageAlign: String as PropType, showCancelButton: Boolean, cancelButtonText: String, cancelButtonColor: String, @@ -59,18 +62,18 @@ export default createComponent({ cancel: false, }); - const onUpdateShow = (value) => { + const onUpdateShow = (value: boolean) => { emit('update:show', value); }; - const close = (action) => { + const close = (action: DialogAction) => { onUpdateShow(false); if (props.callback) { props.callback(action); } }; - const handleAction = (action) => { + const handleAction = (action: DialogAction) => { // should not trigger close event when hidden if (!props.show) { return; @@ -119,6 +122,7 @@ export default createComponent({ const { title, message, allowHtml, messageAlign } = props; if (message) { const hasTitle = title || slots.title; + return (
{props.showCancelButton && (