Skip to content

Commit 4a2c7b3

Browse files
authored
fix: alert animation (vbenjs#5927)
1 parent 36bf6fc commit 4a2c7b3

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

packages/@core/ui-kit/popup-ui/src/alert/alert.ts

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export type AlertProps = {
3636
contentMasking?: boolean;
3737
/** 弹窗的图标(在标题的前面) */
3838
icon?: Component | IconType;
39+
/**
40+
* 弹窗遮罩模糊效果
41+
*/
42+
overlayBlur?: number;
3943
/** 是否显示取消按钮 */
4044
showCancel?: boolean;
4145
/** 弹窗标题 */

packages/@core/ui-kit/popup-ui/src/alert/alert.vue

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Component } from 'vue';
33
44
import type { AlertProps } from './alert';
55
6-
import { computed, h, nextTick, ref, watch } from 'vue';
6+
import { computed, h, nextTick, ref } from 'vue';
77
88
import { useSimpleLocale } from '@vben-core/composables';
99
import {
@@ -39,14 +39,12 @@ const open = defineModel<boolean>('open', { default: false });
3939
const { $t } = useSimpleLocale();
4040
const components = globalShareState.getComponents();
4141
const isConfirm = ref(false);
42-
watch(open, async (val) => {
43-
await nextTick();
44-
if (val) {
45-
isConfirm.value = false;
46-
} else {
47-
emits('closed', isConfirm.value);
48-
}
49-
});
42+
43+
function onAlertClosed() {
44+
emits('closed', isConfirm.value);
45+
isConfirm.value = false;
46+
}
47+
5048
const getIconRender = computed(() => {
5149
let iconRender: Component | null = null;
5250
if (props.icon) {
@@ -100,6 +98,7 @@ function handleCancel() {
10098
10199
const loading = ref(false);
102100
async function handleOpenChange(val: boolean) {
101+
await nextTick();
103102
if (!val && props.beforeClose) {
104103
loading.value = true;
105104
try {
@@ -120,15 +119,16 @@ async function handleOpenChange(val: boolean) {
120119
<AlertDialogContent
121120
:open="open"
122121
:centered="centered"
122+
:overlay-blur="overlayBlur"
123123
@opened="emits('opened')"
124+
@closed="onAlertClosed"
124125
:class="
125126
cn(
126127
containerClass,
127-
'left-0 right-0 top-[10vh] mx-auto flex max-h-[80%] flex-col p-0 duration-300 sm:rounded-[var(--radius)] md:w-[520px] md:max-w-[80%]',
128+
'left-0 right-0 mx-auto flex max-h-[80%] flex-col p-0 duration-300 sm:rounded-[var(--radius)] md:w-[520px] md:max-w-[80%]',
128129
{
129130
'border-border border': bordered,
130131
'shadow-3xl': !bordered,
131-
'top-1/2 !-translate-y-1/2': centered,
132132
},
133133
)
134134
"

packages/@core/ui-kit/shadcn-ui/src/ui/alert-dialog/AlertDialogContent.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ defineExpose({
6161

6262
<template>
6363
<AlertDialogPortal>
64-
<Transition name="fade">
64+
<Transition name="fade" appear>
6565
<AlertDialogOverlay
6666
v-if="open && modal"
6767
:style="{
@@ -80,7 +80,17 @@ defineExpose({
8080
v-bind="forwarded"
8181
:class="
8282
cn(
83-
'z-popup bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-top-[48%] w-full p-6 shadow-lg outline-none sm:rounded-xl',
83+
'z-popup bg-background w-full p-6 shadow-lg outline-none sm:rounded-xl',
84+
'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
85+
'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',
86+
{
87+
'data-[state=open]:slide-in-from-top-[48%] data-[state=closed]:slide-out-to-top-[48%]':
88+
!centered,
89+
'data-[state=open]:slide-in-from-top-[98%] data-[state=closed]:slide-out-to-top-[148%]':
90+
centered,
91+
'top-[10vh]': !centered,
92+
'top-1/2 -translate-y-1/2': centered,
93+
},
8494
props.class,
8595
)
8696
"

playground/src/views/examples/modal/index.vue

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function openConfirm() {
138138
}, 1000);
139139
});
140140
},
141+
centered: false,
141142
content: '这是一个确认弹窗',
142143
icon: 'question',
143144
})
@@ -160,6 +161,7 @@ async function openPrompt() {
160161
componentProps: { placeholder: '不能吃芝士...' },
161162
content: '中午吃了什么?',
162163
icon: 'question',
164+
overlayBlur: 3,
163165
})
164166
.then((res) => {
165167
message.success(`用户输入了:${res}`);

0 commit comments

Comments
 (0)