1
1
// Utilities
2
2
import { h , mergeProps , Transition , TransitionGroup } from 'vue'
3
- import { propsFactory } from '@/util'
3
+ import { isObject , propsFactory } from '@/util'
4
4
5
5
// Types
6
- import type { Component , FunctionalComponent , PropType , TransitionProps } from 'vue'
6
+ import type { Component , FunctionalComponent , Prop , TransitionProps } from 'vue'
7
7
8
8
export const makeTransitionProps = propsFactory ( {
9
9
transition : {
10
- type : [ Boolean , String , Object ] as PropType < string | boolean | TransitionProps & { component ?: Component } > ,
10
+ type : null ,
11
11
default : 'fade-transition' ,
12
12
validator : val => val !== true ,
13
- } ,
13
+ } as Prop < null | string | boolean | TransitionProps & { component ?: Component } > ,
14
14
} , 'transition' )
15
15
16
16
interface MaybeTransitionProps extends TransitionProps {
17
- transition ?: string | boolean | TransitionProps & { component ?: any }
17
+ transition ?: null | string | boolean | TransitionProps & { component ?: any }
18
18
disabled ?: boolean
19
19
group ?: boolean
20
20
}
@@ -25,19 +25,25 @@ export const MaybeTransition: FunctionalComponent<MaybeTransitionProps> = (props
25
25
const {
26
26
component = group ? TransitionGroup : Transition ,
27
27
...customProps
28
- } = typeof transition === 'object' ? transition : { }
28
+ } = isObject ( transition ) ? transition : { }
29
+
30
+ let transitionProps
31
+ if ( isObject ( transition ) ) {
32
+ transitionProps = mergeProps (
33
+ customProps ,
34
+ JSON . parse ( JSON . stringify ( { disabled, group } ) ) ,
35
+ rest ,
36
+ )
37
+ } else {
38
+ transitionProps = mergeProps (
39
+ { name : disabled || ! transition ? '' : transition } ,
40
+ rest ,
41
+ )
42
+ }
29
43
30
44
return h (
31
45
component ,
32
- mergeProps (
33
- typeof transition === 'string'
34
- ? { name : disabled ? '' : transition }
35
- : customProps as any ,
36
- typeof transition === 'string'
37
- ? { }
38
- : Object . fromEntries ( Object . entries ( { disabled, group } ) . filter ( ( [ _ , v ] ) => v !== undefined ) ) ,
39
- rest as any ,
40
- ) ,
46
+ transitionProps ,
41
47
slots
42
48
)
43
49
}
0 commit comments