1
1
import * as Dialog from '@radix-ui/react-dialog'
2
- import { createElement , memo , useCallback , useId , useMemo , useRef } from 'react'
3
- import { AnimatePresence , m } from 'framer-motion'
2
+ import {
3
+ createElement ,
4
+ memo ,
5
+ useCallback ,
6
+ useEffect ,
7
+ useId ,
8
+ useMemo ,
9
+ useRef ,
10
+ } from 'react'
11
+ import { AnimatePresence , m , useAnimationControls } from 'framer-motion'
4
12
import { atom , useAtomValue , useSetAtom } from 'jotai'
5
13
import type { Target , Transition } from 'framer-motion'
6
14
import type { FC , PropsWithChildren } from 'react'
@@ -10,6 +18,7 @@ import { Divider } from '~/components/ui/divider'
10
18
import { DialogOverlay } from '~/components/ui/dlalog/DialogOverlay'
11
19
import { microReboundPreset } from '~/constants/spring'
12
20
import { useIsClient } from '~/hooks/common/use-is-client'
21
+ import { stopPropagation } from '~/lib/dom'
13
22
import { jotaiStore } from '~/lib/store'
14
23
import { clsxm } from '~/utils/helper'
15
24
@@ -118,26 +127,47 @@ export const Modal: Component<{
118
127
} ,
119
128
[ close ] ,
120
129
)
130
+ const animateController = useAnimationControls ( )
131
+ useEffect ( ( ) => {
132
+ animateController . start ( enterStyle )
133
+ } , [ ] )
121
134
return (
122
135
< Dialog . Root open onOpenChange = { onClose } >
123
136
< Dialog . Portal >
124
137
< DialogOverlay />
125
138
< Dialog . Content asChild >
126
- < div className = "fixed inset-0 z-[20] flex center" >
139
+ < div
140
+ className = "fixed inset-0 z-[20] flex center"
141
+ onClick = { ( ) => {
142
+ animateController
143
+ . start ( {
144
+ scale : 1.05 ,
145
+ transition : {
146
+ duration : 0.06 ,
147
+ } ,
148
+ } )
149
+ . then ( ( ) => {
150
+ animateController . start ( {
151
+ scale : 1 ,
152
+ } )
153
+ } )
154
+ } }
155
+ >
127
156
< m . div
128
157
style = { useMemo ( ( ) => ( { zIndex : 99 + index } ) , [ index ] ) }
129
158
exit = { initialStyle }
130
159
initial = { initialStyle }
131
- animate = { enterStyle }
160
+ animate = { animateController }
132
161
transition = { modalTransition }
133
162
className = { clsxm (
134
163
'relative flex flex-col overflow-hidden rounded-lg' ,
135
- 'bg-slate-50/90 dark:bg-neutral-900/90 ' ,
164
+ 'bg-slate-50/10 dark:bg-neutral-900/80 ' ,
136
165
'p-2 shadow-2xl shadow-stone-300 backdrop-blur-sm dark:shadow-stone-800' ,
137
166
'max-h-[70vh] min-w-[300px] max-w-[90vw] lg:max-h-[calc(100vh-20rem)] lg:max-w-[50vw]' ,
138
167
'border border-slate-200 dark:border-neutral-800' ,
139
168
item . modalClassName ,
140
169
) }
170
+ onClick = { stopPropagation }
141
171
>
142
172
< Dialog . Title className = "flex-shrink-0 px-4 py-2 text-lg font-medium" >
143
173
{ item . title }
0 commit comments