1
- import {
2
- ark ,
3
- Dialog ,
4
- DialogBackdrop ,
5
- DialogCloseTrigger ,
6
- DialogContent ,
7
- DialogDescription ,
8
- DialogPositioner ,
9
- DialogTitle ,
10
- DialogTrigger ,
11
- } from "@ark-ui/react" ;
1
+ import { ark , Dialog as ArkDialog } from "@ark-ui/react" ;
12
2
import { FiX as CloseIcon } from "react-icons/fi" ;
13
3
14
4
import Icon from "components/Icon/Icon" ;
15
5
import { Flex , panda } from "generated/panda/jsx" ;
16
6
import { drawer } from "generated/panda/recipes" ;
17
- import { getContextualChildren } from "lib/util" ;
7
+ import { createStyleContext , getContextualChildren } from "lib/util" ;
18
8
19
9
import type { DialogProps } from "@ark-ui/react" ;
20
10
import type { DialogContext } from "@ark-ui/react/dialog/dialog-context" ;
21
11
import type { DrawerVariantProps } from "generated/panda/recipes" ;
22
- import type { ReactNode } from "react" ;
12
+ import type { ComponentPropsWithoutRef , ReactNode } from "react" ;
13
+
14
+ const { withProvider, withContext } = createStyleContext ( drawer ) ;
23
15
24
16
export interface DrawerProps extends DialogProps , DrawerVariantProps {
25
17
trigger ?: ReactNode ;
26
18
title ?: string ;
27
19
description ?: string ;
28
20
headerAddon ?: ReactNode ;
29
21
footer ?: ReactNode | ( ( props : DialogContext ) => ReactNode ) ;
22
+ /** Drawer content (body) container props. */
23
+ contentProps ?: ComponentPropsWithoutRef < typeof DrawerContent > ;
30
24
}
31
25
26
+ export const DrawerRoot = withProvider ( panda ( ArkDialog . Root ) , "root" ) ;
27
+
28
+ export const DrawerTrigger = withContext ( panda ( ArkDialog . Trigger ) , "trigger" ) ;
29
+
30
+ export const DrawerBackdrop = withContext (
31
+ panda ( ArkDialog . Backdrop ) ,
32
+ "backdrop"
33
+ ) ;
34
+
35
+ export const DrawerCloseTrigger = withContext (
36
+ panda ( ArkDialog . CloseTrigger ) ,
37
+ "closeTrigger"
38
+ ) ;
39
+
40
+ export const DrawerPositioner = withContext (
41
+ panda ( ArkDialog . Positioner ) ,
42
+ "positioner"
43
+ ) ;
44
+
45
+ export const DrawerContent = withContext ( panda ( ArkDialog . Content ) , "content" ) ;
46
+
47
+ export const DrawerTitle = withContext ( panda ( ArkDialog . Title ) , "title" ) ;
48
+
49
+ export const DrawerDescription = withContext (
50
+ panda ( ArkDialog . Description ) ,
51
+ "description"
52
+ ) ;
53
+
54
+ export const DrawerHeader = withContext ( panda ( ark . div ) , "header" ) ;
55
+
56
+ export const DrawerBody = withContext ( panda ( ark . div ) , "body" ) ;
57
+
58
+ export const DrawerFooter = withContext ( panda ( ark . div ) , "footer" ) ;
59
+
32
60
/**
33
61
* A panel that slides in from the edge of the screen.
34
62
*/
@@ -38,69 +66,51 @@ const Drawer = ({
38
66
description,
39
67
headerAddon,
40
68
footer,
69
+ contentProps,
41
70
children,
42
- alignment,
43
- placement,
44
71
...rest
45
- } : DrawerProps ) => {
46
- const classes = drawer ( { alignment, placement } ) ;
47
-
48
- const PandaContainer = panda ( ark . div ) ;
49
-
50
- return (
51
- < Dialog lazyMount unmountOnExit { ...rest } >
52
- { ( ctx ) => (
53
- < >
54
- { trigger && (
55
- < DialogTrigger className = { classes . trigger } asChild >
56
- { trigger }
57
- </ DialogTrigger >
58
- ) }
59
-
60
- < DialogBackdrop className = { classes . backdrop } />
61
-
62
- < DialogPositioner className = { classes . positioner } >
63
- < DialogContent className = { classes . content } >
64
- < PandaContainer className = { classes . header } >
65
- { headerAddon && headerAddon }
66
-
67
- < Flex direction = "column" gap = { 1 } >
68
- { title && (
69
- < DialogTitle className = { classes . title } > { title } </ DialogTitle >
70
- ) }
71
-
72
- { description && (
73
- < DialogDescription className = { classes . description } >
74
- { description }
75
- </ DialogDescription >
76
- ) }
77
- </ Flex >
78
-
79
- < DialogCloseTrigger
80
- aria-label = "close button"
81
- className = { classes . closeTrigger }
82
- >
83
- < Icon color = "fg.primary" >
84
- < CloseIcon />
85
- </ Icon >
86
- </ DialogCloseTrigger >
87
- </ PandaContainer >
88
-
89
- < PandaContainer className = { classes . body } asChild >
90
- { getContextualChildren ( { ctx, children } ) }
91
- </ PandaContainer >
92
-
93
- { footer && (
94
- < PandaContainer className = { classes . footer } asChild >
95
- { getContextualChildren ( { ctx, children : footer } ) }
96
- </ PandaContainer >
97
- ) }
98
- </ DialogContent >
99
- </ DialogPositioner >
100
- </ >
101
- ) }
102
- </ Dialog >
103
- ) ;
104
- } ;
72
+ } : DrawerProps ) => (
73
+ < DrawerRoot lazyMount unmountOnExit { ...rest } >
74
+ { ( ctx ) => (
75
+ < >
76
+ { trigger && < DrawerTrigger asChild > { trigger } </ DrawerTrigger > }
77
+
78
+ < DrawerBackdrop />
79
+
80
+ < DrawerPositioner >
81
+ < DrawerContent { ...contentProps } >
82
+ < DrawerHeader >
83
+ { headerAddon && headerAddon }
84
+
85
+ < Flex direction = "column" gap = { 1 } >
86
+ { title && < DrawerTitle > { title } </ DrawerTitle > }
87
+
88
+ { description && (
89
+ < DrawerDescription > { description } </ DrawerDescription >
90
+ ) }
91
+ </ Flex >
92
+
93
+ < DrawerCloseTrigger aria-label = "close button" >
94
+ < Icon color = "fg.primary" >
95
+ < CloseIcon />
96
+ </ Icon >
97
+ </ DrawerCloseTrigger >
98
+ </ DrawerHeader >
99
+
100
+ < DrawerBody asChild >
101
+ { getContextualChildren ( { ctx, children } ) }
102
+ </ DrawerBody >
103
+
104
+ { footer && (
105
+ < DrawerFooter asChild >
106
+ { getContextualChildren ( { ctx, children : footer } ) }
107
+ </ DrawerFooter >
108
+ ) }
109
+ </ DrawerContent >
110
+ </ DrawerPositioner >
111
+ </ >
112
+ ) }
113
+ </ DrawerRoot >
114
+ ) ;
105
115
106
116
export default Drawer ;
0 commit comments