|
1
|
--- |
|
2
|
sidebar_label: "Stacked Drawer" |
|
3
|
--- |
|
4
|
|
|
5
|
import { Table, TypeList } from "docs-ui" |
|
6
|
|
|
7
|
export const metadata = { |
|
8
|
title: `StackedDrawer - Admin Components`, |
|
9
|
} |
|
10
|
|
|
11
|
# {metadata.title} |
|
12
|
|
|
13
|
<Note> |
|
14
|
|
|
15
|
This component is available since Medusa [v2.21.0](https://github.com/medusajs/medusa/releases/tag/v2.21.0). |
|
16
|
|
|
17
|
</Note> |
|
18
|
|
|
19
|
The `StackedDrawer` component renders a drawer above a route modal. The Medusa Admin uses it to let the user pick resources without leaving the form, such as choosing customer groups while configuring a price list. |
|
20
|
|
|
21
|
```tsx |
|
22
|
import { StackedDrawer } from "@medusajs/dashboard/components" |
|
23
|
``` |
|
24
|
|
|
25
|
--- |
|
26
|
|
|
27
|
## Stacked Modals |
|
28
|
|
|
29
|
Render a `StackedDrawer` inside a [RouteDrawer](../route-drawer/page.mdx) or a [RouteFocusModal](../route-focus-modal/page.mdx), which both provide the stacked modal context. Unlike route modals, a `StackedDrawer` is not tied to a route. The user opens it with a trigger, and the parent modal stays mounted underneath. |
|
30
|
|
|
31
|
Every `StackedDrawer` requires an `id` prop. The parent modal uses the ID to track which stacked modal is open, so you can render more than one stacked modal in the same form. |
|
32
|
|
|
33
|
--- |
|
34
|
|
|
35
|
## Example |
|
36
|
|
|
37
|
The following UI route renders a `StackedDrawer` inside a `RouteFocusModal` to select a brand: |
|
38
|
|
|
39
|
```tsx title="src/admin/routes/products/[id]/brand/page.tsx" |
|
40
|
import { Button, Heading } from "@medusajs/ui" |
|
41
|
import { |
|
42
|
RouteFocusModal, |
|
43
|
StackedDrawer, |
|
44
|
} from "@medusajs/dashboard/components" |
|
45
|
|
|
46
|
const STACKED_MODAL_ID = "select-brand" |
|
47
|
|
|
48
|
const ProductBrand = () => { |
|
49
|
return ( |
|
50
|
<RouteFocusModal> |
|
51
|
<RouteFocusModal.Header /> |
|
52
|
<RouteFocusModal.Body> |
|
53
|
<StackedDrawer id={STACKED_MODAL_ID}> |
|
54
|
<StackedDrawer.Trigger asChild> |
|
55
|
<Button variant="secondary" size="small"> |
|
56
|
Select Brand |
|
57
|
</Button> |
|
58
|
</StackedDrawer.Trigger> |
|
59
|
<StackedDrawer.Content> |
|
60
|
<StackedDrawer.Header> |
|
61
|
<StackedDrawer.Title asChild> |
|
62
|
<Heading>Select Brand</Heading> |
|
63
|
</StackedDrawer.Title> |
|
64
|
</StackedDrawer.Header> |
|
65
|
<StackedDrawer.Body> |
|
66
|
<BrandList /> |
|
67
|
</StackedDrawer.Body> |
|
68
|
<StackedDrawer.Footer> |
|
69
|
<StackedDrawer.Close asChild> |
|
70
|
<Button variant="secondary" size="small"> |
|
71
|
Cancel |
|
72
|
</Button> |
|
73
|
</StackedDrawer.Close> |
|
74
|
</StackedDrawer.Footer> |
|
75
|
</StackedDrawer.Content> |
|
76
|
</StackedDrawer> |
|
77
|
</RouteFocusModal.Body> |
|
78
|
</RouteFocusModal> |
|
79
|
) |
|
80
|
} |
|
81
|
|
|
82
|
export default ProductBrand |
|
83
|
``` |
|
84
|
|
|
85
|
--- |
|
86
|
|
|
87
|
## Props |
|
88
|
|
|
89
|
<TypeList |
|
90
|
types={[ |
|
91
|
{ |
|
92
|
name: "id", |
|
93
|
type: "`string`", |
|
94
|
optional: false, |
|
95
|
description: |
|
96
|
"A unique identifier for the drawer. It differentiates stacked modals registered to the same parent modal. This prop is required.", |
|
97
|
}, |
|
98
|
]} |
|
99
|
/> |
|
100
|
|
|
101
|
--- |
|
102
|
|
|
103
|
## Sub-components |
|
104
|
|
|
105
|
<Table> |
|
106
|
<Table.Header> |
|
107
|
<Table.Row> |
|
108
|
<Table.HeaderCell> |
|
109
|
Component |
|
110
|
</Table.HeaderCell> |
|
111
|
<Table.HeaderCell> |
|
112
|
Description |
|
113
|
</Table.HeaderCell> |
|
114
|
</Table.Row> |
|
115
|
</Table.Header> |
|
116
|
<Table.Body> |
|
117
|
<Table.Row> |
|
118
|
<Table.Cell> |
|
119
|
|
|
120
|
`StackedDrawer.Trigger` |
|
121
|
|
|
122
|
</Table.Cell> |
|
123
|
<Table.Cell> |
|
124
|
|
|
125
|
Opens the drawer when clicked. Pass `asChild` to use your own button. |
|
126
|
|
|
127
|
</Table.Cell> |
|
128
|
</Table.Row> |
|
129
|
<Table.Row> |
|
130
|
<Table.Cell> |
|
131
|
|
|
132
|
`StackedDrawer.Content` |
|
133
|
|
|
134
|
</Table.Cell> |
|
135
|
<Table.Cell> |
|
136
|
|
|
137
|
The drawer's content. It renders a transparent overlay so that the parent modal stays visible. |
|
138
|
|
|
139
|
</Table.Cell> |
|
140
|
</Table.Row> |
|
141
|
<Table.Row> |
|
142
|
<Table.Cell> |
|
143
|
|
|
144
|
`StackedDrawer.Header` |
|
145
|
|
|
146
|
</Table.Cell> |
|
147
|
<Table.Cell> |
|
148
|
|
|
149
|
The drawer's header. Place the title and description in it. |
|
150
|
|
|
151
|
</Table.Cell> |
|
152
|
</Table.Row> |
|
153
|
<Table.Row> |
|
154
|
<Table.Cell> |
|
155
|
|
|
156
|
`StackedDrawer.Title` |
|
157
|
|
|
158
|
</Table.Cell> |
|
159
|
<Table.Cell> |
|
160
|
|
|
161
|
The drawer's title. Pass `asChild` to render your own heading element. |
|
162
|
|
|
163
|
</Table.Cell> |
|
164
|
</Table.Row> |
|
165
|
<Table.Row> |
|
166
|
<Table.Cell> |
|
167
|
|
|
168
|
`StackedDrawer.Description` |
|
169
|
|
|
170
|
</Table.Cell> |
|
171
|
<Table.Cell> |
|
172
|
|
|
173
|
An accessible description of the drawer's purpose. |
|
174
|
|
|
175
|
</Table.Cell> |
|
176
|
</Table.Row> |
|
177
|
<Table.Row> |
|
178
|
<Table.Cell> |
|
179
|
|
|
180
|
`StackedDrawer.Body` |
|
181
|
|
|
182
|
</Table.Cell> |
|
183
|
<Table.Cell> |
|
184
|
|
|
185
|
The drawer's scrollable content area. |
|
186
|
|
|
187
|
</Table.Cell> |
|
188
|
</Table.Row> |
|
189
|
<Table.Row> |
|
190
|
<Table.Cell> |
|
191
|
|
|
192
|
`StackedDrawer.Footer` |
|
193
|
|
|
194
|
</Table.Cell> |
|
195
|
<Table.Cell> |
|
196
|
|
|
197
|
The drawer's footer. Place the cancel and confirm buttons in it. |
|
198
|
|
|
199
|
</Table.Cell> |
|
200
|
</Table.Row> |
|
201
|
<Table.Row> |
|
202
|
<Table.Cell> |
|
203
|
|
|
204
|
`StackedDrawer.Close` |
|
205
|
|
|
206
|
</Table.Cell> |
|
207
|
<Table.Cell> |
|
208
|
|
|
209
|
Closes the drawer when clicked, keeping the parent modal open. Pass `asChild` to use your own button. |
|
210
|
|
|
211
|
</Table.Cell> |
|
212
|
</Table.Row> |
|
213
|
</Table.Body> |
|
214
|
</Table> |
|
215
|
|
|
216
|
--- |
|
217
|
|
|
218
|
## useStackedModal |
|
219
|
|
|
220
|
Use the `useStackedModal` hook to control a stacked modal programmatically. For example, close the drawer after the user confirms their selection. |
|
221
|
|
|
222
|
```tsx |
|
223
|
import { useStackedModal } from "@medusajs/dashboard/components" |
|
224
|
``` |
|
225
|
|
|
226
|
Call the hook in a component rendered inside a route modal. It throws an error if you use it elsewhere. |
|
227
|
|
|
228
|
### Returned Values |
|
229
|
|
|
230
|
<TypeList |
|
231
|
types={[ |
|
232
|
{ |
|
233
|
name: "getIsOpen", |
|
234
|
type: "`(id: string) => boolean`", |
|
235
|
optional: false, |
|
236
|
description: |
|
237
|
"Returns whether the stacked modal of the specified ID is open.", |
|
238
|
}, |
|
239
|
{ |
|
240
|
name: "setIsOpen", |
|
241
|
type: "`(id: string, open: boolean) => void`", |
|
242
|
optional: false, |
|
243
|
description: "Opens or closes the stacked modal of the specified ID.", |
|
244
|
}, |
|
245
|
{ |
|
246
|
name: "register", |
|
247
|
type: "`(id: string) => void`", |
|
248
|
optional: false, |
|
249
|
description: |
|
250
|
"Registers a stacked modal in the parent modal. `StackedDrawer` and `StackedFocusModal` call it for you when they mount.", |
|
251
|
}, |
|
252
|
{ |
|
253
|
name: "unregister", |
|
254
|
type: "`(id: string) => void`", |
|
255
|
optional: false, |
|
256
|
description: |
|
257
|
"Removes a stacked modal from the parent modal. The components call it for you when they unmount.", |
|
258
|
}, |
|
259
|
]} |
|
260
|
/> |
|
261
|
|
|
262
|
### Example |
|
263
|
|
|
264
|
```tsx title="src/admin/routes/products/[id]/brand/page.tsx" |
|
265
|
import { Button } from "@medusajs/ui" |
|
266
|
import { useStackedModal } from "@medusajs/dashboard/components" |
|
267
|
|
|
268
|
const BrandList = () => { |
|
269
|
const { setIsOpen } = useStackedModal() |
|
270
|
|
|
271
|
const handleSave = () => { |
|
272
|
setIsOpen("select-brand", false) |
|
273
|
} |
|
274
|
|
|
275
|
return ( |
|
276
|
<Button size="small" onClick={handleSave}> |
|
277
|
Save |
|
278
|
</Button> |
|
279
|
) |
|
280
|
} |
|
281
|
``` |