8
8
withDirectives ,
9
9
watch ,
10
10
ref ,
11
+ Ref ,
12
+ watchEffect ,
11
13
} from 'vue'
12
14
import {
13
15
SlideDirection ,
@@ -77,18 +79,11 @@ export const CDrawer: ComponentWithProps<
77
79
} ,
78
80
emits : [ 'update:modelValue' , 'close' , 'escape' ] ,
79
81
setup ( props , { slots, attrs, emit } ) {
82
+ const isOpen = computed ( ( ) => props . modelValue ! )
83
+
80
84
const handleUpdateModelValue = ( val : boolean ) => {
81
85
emit ( 'update:modelValue' , val )
82
86
}
83
- const closeDrawer = ( ) => {
84
- emit ( 'update:modelValue' , false )
85
- }
86
-
87
- const isOpen = ref ( props . modelValue )
88
-
89
- watch ( isOpen , ( newVal ) => {
90
- emit ( 'update:modelValue' , newVal )
91
- } )
92
87
93
88
const context : CDrawerContext = computed ( ( ) => ( {
94
89
placement : props . placement ,
@@ -99,18 +94,23 @@ export const CDrawer: ComponentWithProps<
99
94
const drawerStyleConfig = theme . components ?. Drawer
100
95
101
96
CDrawerContextProvider ( context )
102
- return ( ) => (
103
- < CModal
104
- v-model = { isOpen . value }
105
- onClose = { closeDrawer }
106
- { ...props }
107
- { ...attrs }
108
- label = 'drawer'
109
- styleConfig = { drawerStyleConfig }
110
- >
111
- { slots }
112
- </ CModal >
113
- )
97
+
98
+ return ( ) => {
99
+ const { modelValue, "onUpdate:modelValue" : updateModelValue , ...rest } = props
100
+ return (
101
+ < CModal
102
+ { ...rest }
103
+ { ...attrs }
104
+ modelValue = { isOpen . value }
105
+ /* eslint-disable-next-line */
106
+ onUpdate :modelValue = { handleUpdateModelValue }
107
+ label = 'drawer'
108
+ styleConfig = { drawerStyleConfig }
109
+ >
110
+ { slots }
111
+ </ CModal >
112
+ )
113
+ }
114
114
} ,
115
115
} )
116
116
@@ -166,7 +166,7 @@ export const CDrawerContent: ComponentWithProps<
166
166
} )
167
167
}
168
168
169
- watch ( modelValue , ( newVal ) => {
169
+ watch ( modelValue ! , ( newVal ) => {
170
170
if ( ! newVal ) {
171
171
leave ( ( ) => null )
172
172
}
@@ -183,32 +183,31 @@ export const CDrawerContent: ComponentWithProps<
183
183
184
184
const transitionVariant = computed ( ( ) => placementToVariant ( placement ! ) )
185
185
186
- return ( ) => (
187
- < chakra . div
188
- { ...containerProps . value }
189
- __label = "modal__content-container"
190
- __css = { dialogContainerStyles . value }
191
- >
192
- { modelValue . value &&
193
- ( ( ) =>
186
+ return ( ) => {
187
+ return < chakra . div
188
+ { ...containerProps . value }
189
+ __label = "modal__content-container"
190
+ __css = { dialogContainerStyles . value }
191
+ >
192
+ { modelValue ! . value &&
194
193
withDirectives (
195
194
< chakra . section
196
195
{ ...dialogProps . value }
197
196
style = { transitionStyles . value }
198
197
__css = { dialogStyles . value }
199
198
{ ...attrs }
200
199
>
201
- { ( ) => slots ?. default ?. ( ) }
200
+ { slots }
202
201
</ chakra . section > ,
203
202
[
204
203
[
205
204
MotionDirective ( TransitionVariants [ transitionVariant . value ] ) ,
206
205
transitionId . value ,
207
206
] ,
208
207
]
209
- ) ) }
210
- </ chakra . div >
211
- )
208
+ ) }
209
+ </ chakra . div >
210
+ }
212
211
} ,
213
212
} )
214
213
0 commit comments