@@ -14,23 +14,14 @@ import {
14
14
PropType ,
15
15
reactive ,
16
16
ComputedRef ,
17
- Ref ,
18
17
toRefs ,
19
18
computed ,
20
19
ToRefs ,
21
20
mergeProps ,
22
- onMounted ,
23
- watchEffect ,
24
21
UnwrapRef ,
25
22
watch ,
26
- ref ,
27
- cloneVNode ,
28
- getCurrentInstance ,
29
23
withDirectives ,
30
- nextTick ,
31
24
unref ,
32
- Transition ,
33
- onUnmounted ,
34
25
} from 'vue'
35
26
import {
36
27
chakra ,
@@ -39,25 +30,15 @@ import {
39
30
useMultiStyleConfig ,
40
31
useStyles ,
41
32
} from '@chakra-ui/vue-system'
42
- import {
43
- createContext ,
44
- TemplateRef ,
45
- useRef ,
46
- VueComponentInstance ,
47
- } from '@chakra-ui/vue-utils'
33
+ import { createContext , TemplateRef , useRef } from '@chakra-ui/vue-utils'
48
34
import { CPortal } from '@chakra-ui/c-portal'
49
- import {
50
- CFocusLock ,
51
- FocusLockProps ,
52
- useFocusLock ,
53
- } from '@chakra-ui/c-focus-lock'
35
+ import { CFocusLock , FocusLockProps } from '@chakra-ui/c-focus-lock'
54
36
import { CScrollLock , BodyScrollLockDirective } from '@chakra-ui/c-scroll-lock'
55
37
import { CMotion } from '@chakra-ui/c-motion'
38
+ import { CCloseButton } from '@chakra-ui/c-close-button'
56
39
import { MotionDirective } from '@vueuse/motion'
57
40
58
41
import { useModal , UseModalOptions , UseModalReturn } from './use-modal'
59
- import { focus , FocusableElement } from '@chakra-ui/utils'
60
- import { FocusTarget } from 'focus-trap'
61
42
62
43
type ScrollBehavior = 'inside' | 'outside'
63
44
type MotionPreset = 'slideInBottom' | 'slideInRight' | 'scale' | 'none'
@@ -231,6 +212,7 @@ export const CModal = defineComponent({
231
212
setup ( props , { slots, attrs, emit } ) {
232
213
const closeModal = ( ) => {
233
214
emit ( 'update:is-open' , false )
215
+ console . log ( 'CLOSING MODAL =============' )
234
216
}
235
217
236
218
const handleEscape = ( event : KeyboardEvent ) => {
@@ -246,8 +228,6 @@ export const CModal = defineComponent({
246
228
// @ts -expect-error
247
229
const modal = useModal ( modalOptions )
248
230
249
- console . log ( modal )
250
-
251
231
ModalContextProvider (
252
232
computed ( ( ) => ( {
253
233
...modal ,
@@ -353,49 +333,41 @@ export const CModalContent = defineComponent({
353
333
finalFocusRef : context . value . finalFocusRef ?. value ,
354
334
restoreFocus : context . value . returnFocusOnClose ?. value ,
355
335
} ,
356
- ( ) =>
357
- h (
358
- Transition ,
359
- {
360
- css : false ,
361
- } ,
362
- ( ) =>
363
- context . value . isOpen . value && [
364
- withDirectives (
365
- h (
366
- chakra ( 'section' , {
367
- __css : dialogStyles . value ,
368
- label : 'modal__content' ,
369
- } ) ,
370
- {
371
- ...attrs ,
372
- ...context . value . dialogProps . value ,
373
- } ,
374
- slots
375
- ) ,
376
- [
377
- [
378
- MotionDirective ,
379
- {
380
- initial : {
381
- scale : 0.5 ,
382
- opacity : 0 ,
383
- } ,
384
- enter : {
385
- scale : 1 ,
386
- opacity : 1 ,
387
- translateY : 0 ,
388
- } ,
389
- leave : {
390
- scale : 0.5 ,
391
- opacity : 0 ,
392
- } ,
393
- } ,
394
- ] ,
395
- ]
396
- ) ,
397
- ]
398
- )
336
+ ( ) => [
337
+ withDirectives (
338
+ h (
339
+ chakra ( 'section' , {
340
+ __css : dialogStyles . value ,
341
+ label : 'modal__content' ,
342
+ } ) ,
343
+ {
344
+ ...attrs ,
345
+ ...context . value . dialogProps . value ,
346
+ } ,
347
+ slots
348
+ ) ,
349
+ [
350
+ [
351
+ MotionDirective ,
352
+ {
353
+ initial : {
354
+ scale : 0.5 ,
355
+ opacity : 0 ,
356
+ } ,
357
+ enter : {
358
+ scale : 1 ,
359
+ opacity : 1 ,
360
+ translateY : 0 ,
361
+ } ,
362
+ leave : {
363
+ scale : 0.5 ,
364
+ opacity : 0 ,
365
+ } ,
366
+ } ,
367
+ ] ,
368
+ ]
369
+ ) ,
370
+ ]
399
371
) ,
400
372
]
401
373
) ,
@@ -433,23 +405,26 @@ export const CModalOverlay = defineComponent({
433
405
h (
434
406
chakra ( 'div' , {
435
407
label : 'modal__overlay' ,
408
+ __css : overlayStyle . value ,
436
409
} ) ,
437
- {
438
- __css : {
439
- ...overlayStyle . value ,
440
- } ,
441
- ...attrs ,
442
- }
410
+ attrs
443
411
) ,
444
412
]
445
413
)
446
414
} ,
447
415
} )
448
416
417
+ /**
418
+ * CModalHeader
419
+ *
420
+ * Component that houses the title of the modal.
421
+ *
422
+ * @see Docs https://next.vue.chakra-ui.com/docs/components/modal
423
+ */
449
424
export const CModalHeader = defineComponent ( {
450
425
name : 'CModalHeader' ,
451
426
setup ( _ , { attrs, slots } ) {
452
- const context = useModalContext ( )
427
+ const { hasHeader , headerId } = unref ( useModalContext ( ) )
453
428
const styles = useStyles ( )
454
429
const headerStyles = computed < SystemStyleObject > ( ( ) => ( {
455
430
flex : 0 ,
@@ -459,20 +434,122 @@ export const CModalHeader = defineComponent({
459
434
const [ headerRef , headerEl ] = useRef ( )
460
435
461
436
watch ( headerEl , ( el ) => {
462
- context . value . hasHeader . value = ! ! el
437
+ hasHeader . value = ! ! el
463
438
} )
464
439
465
440
return ( ) =>
466
441
h (
467
442
chakra ( 'header' , {
443
+ label : 'modal__header' ,
468
444
__css : headerStyles . value ,
469
445
} ) ,
470
446
{
471
447
...attrs ,
472
448
ref : headerRef ,
473
- id : context . value . headerId . value ,
449
+ id : headerId . value ,
450
+ } ,
451
+ slots
452
+ )
453
+ } ,
454
+ } )
455
+
456
+ /**
457
+ * CModalBody
458
+ *
459
+ * Component that houses the body of the modal.
460
+ *
461
+ * @see Docs https://next.vue.chakra-ui.com/docs/components/modal
462
+ */
463
+ export const CModalBody = defineComponent ( {
464
+ name : 'CModalBody' ,
465
+ setup ( _ , { slots, attrs } ) {
466
+ const { bodyId, hasBody } = unref ( useModalContext ( ) )
467
+ const styles = useStyles ( )
468
+
469
+ const [ bodyRef , bodyEl ] = useRef ( )
470
+
471
+ /**
472
+ * Used to bind the `aria-descibedby` attribute
473
+ */
474
+ watch ( bodyEl , ( el ) => {
475
+ hasBody . value = ! ! el
476
+ } )
477
+
478
+ return ( ) =>
479
+ h (
480
+ chakra ( 'div' , {
481
+ label : 'modal__body' ,
482
+ __css : styles . value . body ,
483
+ } ) ,
484
+ {
485
+ id : bodyId . value ,
486
+ ...attrs ,
487
+ ref : bodyRef ,
474
488
} ,
475
489
slots
476
490
)
477
491
} ,
478
492
} )
493
+
494
+ /**
495
+ * CModalFooter
496
+ *
497
+ * Component that houses the footer of the modal.
498
+ *
499
+ * @see Docs https://next.vue.chakra-ui.com/docs/components/modal
500
+ */
501
+ export const CModalFooter = defineComponent ( {
502
+ name : 'CModalFooter' ,
503
+ setup ( _ , { slots, attrs } ) {
504
+ const styles = useStyles ( )
505
+
506
+ const footerStyles = computed < SystemStyleObject > ( ( ) => ( {
507
+ display : 'flex' ,
508
+ alignItems : 'center' ,
509
+ justifyContent : 'flex-end' ,
510
+ ...styles . value . footer ,
511
+ } ) )
512
+
513
+ return ( ) =>
514
+ h (
515
+ chakra ( 'div' , {
516
+ label : 'modal__body' ,
517
+ __css : footerStyles . value ,
518
+ } ) ,
519
+ attrs ,
520
+ slots
521
+ )
522
+ } ,
523
+ } )
524
+
525
+ /**
526
+ * CModalCloseButton
527
+ *
528
+ * Used to close the modal. It internally invokes the `closeModal` event,
529
+ * but also emits the `@click` event to the user.
530
+ *
531
+ * @see Docs https://next.vue.chakra-ui.com/docs/components/modal
532
+ */
533
+ export const CModalCloseButton = defineComponent ( {
534
+ name : 'CModalCloseButton' ,
535
+ emits : [ 'click' ] ,
536
+ setup ( _ , { attrs, emit } ) {
537
+ const { closeModal } = unref ( useModalContext ( ) )
538
+ const styles = useStyles ( )
539
+
540
+ return ( ) =>
541
+ h (
542
+ chakra ( CCloseButton , {
543
+ label : 'modal__close-button' ,
544
+ __css : styles . value . closeButton ,
545
+ } ) ,
546
+ {
547
+ ...attrs ,
548
+ onClick : ( e : MouseEvent | TouchEvent ) => {
549
+ closeModal ( )
550
+ emit ( 'click' , e )
551
+ } ,
552
+ }
553
+ )
554
+ } ,
555
+ } )
0 commit comments