@manhphi1309/dialog 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +264 -12
- package/dist/index.cjs +419 -2
- package/dist/index.d.cts +324 -13
- package/dist/index.d.mts +324 -13
- package/dist/index.mjs +389 -3
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,23 +1,111 @@
|
|
|
1
|
+
import * as React from "react";
|
|
1
2
|
import { Dialog as Dialog$1 } from "radix-ui";
|
|
2
|
-
import
|
|
3
|
+
import { Drawer } from "@manhphi1309/drawer";
|
|
3
4
|
|
|
4
|
-
//#region
|
|
5
|
+
//#region src/dialog.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Root dialog component. Controls open/close state and provides context
|
|
8
|
+
* to all child primitives via Radix `Dialog.Root`.
|
|
9
|
+
*
|
|
10
|
+
* Can be used as **uncontrolled** (via `defaultOpen`) or **controlled**
|
|
11
|
+
* (via `open` + `onOpenChange`).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Uncontrolled
|
|
15
|
+
* <Dialog>
|
|
16
|
+
* <DialogTrigger>Open</DialogTrigger>
|
|
17
|
+
* <DialogContent>...</DialogContent>
|
|
18
|
+
* </Dialog>
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Controlled
|
|
22
|
+
* const [open, setOpen] = useState(false)
|
|
23
|
+
* <Dialog open={open} onOpenChange={setOpen}>
|
|
24
|
+
* <DialogContent>...</DialogContent>
|
|
25
|
+
* </Dialog>
|
|
26
|
+
*/
|
|
5
27
|
declare function Dialog({
|
|
6
28
|
...props
|
|
7
|
-
}: React.ComponentProps<typeof Dialog$1.Root>):
|
|
29
|
+
}: React.ComponentProps<typeof Dialog$1.Root>): React.JSX.Element;
|
|
30
|
+
/**
|
|
31
|
+
* The element that opens the dialog when activated (clicked / keyboard).
|
|
32
|
+
* Thin wrapper around Radix `Dialog.Trigger`.
|
|
33
|
+
*
|
|
34
|
+
* Use `asChild` to compose with your own element instead of the default button.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* <DialogTrigger asChild>
|
|
38
|
+
* <Button variant="outline">Open</Button>
|
|
39
|
+
* </DialogTrigger>
|
|
40
|
+
*/
|
|
8
41
|
declare function DialogTrigger({
|
|
9
42
|
...props
|
|
10
|
-
}: React.ComponentProps<typeof Dialog$1.Trigger>):
|
|
43
|
+
}: React.ComponentProps<typeof Dialog$1.Trigger>): React.JSX.Element;
|
|
44
|
+
/**
|
|
45
|
+
* Renders its children into a **portal** appended to `document.body`,
|
|
46
|
+
* outside the current DOM tree. This ensures the dialog always appears
|
|
47
|
+
* above other content and is never clipped by parent `overflow` or `z-index`.
|
|
48
|
+
*
|
|
49
|
+
* You rarely need to use this directly — `DialogContent` already wraps its
|
|
50
|
+
* output in a portal automatically.
|
|
51
|
+
*/
|
|
11
52
|
declare function DialogPortal({
|
|
12
53
|
...props
|
|
13
|
-
}: React.ComponentProps<typeof Dialog$1.Portal>):
|
|
54
|
+
}: React.ComponentProps<typeof Dialog$1.Portal>): React.JSX.Element;
|
|
55
|
+
/**
|
|
56
|
+
* A primitive close trigger. Closes the dialog when activated.
|
|
57
|
+
* Use `asChild` to compose with a custom element.
|
|
58
|
+
*
|
|
59
|
+
* Prefer the built-in `showCloseButton` prop on `DialogContent` or
|
|
60
|
+
* `DialogFooter` for standard close affordances. Use this component
|
|
61
|
+
* when you need a completely custom close action inside the dialog body.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* <DialogClose asChild>
|
|
65
|
+
* <Button variant="ghost">Cancel</Button>
|
|
66
|
+
* </DialogClose>
|
|
67
|
+
*/
|
|
14
68
|
declare function DialogClose({
|
|
15
69
|
...props
|
|
16
|
-
}: React.ComponentProps<typeof Dialog$1.Close>):
|
|
70
|
+
}: React.ComponentProps<typeof Dialog$1.Close>): React.JSX.Element;
|
|
71
|
+
/**
|
|
72
|
+
* The semi-transparent **backdrop** rendered behind the dialog panel.
|
|
73
|
+
* Covers the full viewport (`fixed inset-0`) with a slight blur and dark tint.
|
|
74
|
+
*
|
|
75
|
+
* Animates:
|
|
76
|
+
* - **Open** → `fade-in-0`
|
|
77
|
+
* - **Close** → `fade-out-0`
|
|
78
|
+
*
|
|
79
|
+
* You rarely need to use this directly — `DialogContent` renders it
|
|
80
|
+
* automatically via `DialogPortal`.
|
|
81
|
+
*/
|
|
17
82
|
declare function DialogOverlay({
|
|
18
83
|
className,
|
|
19
84
|
...props
|
|
20
|
-
}: React.ComponentProps<typeof Dialog$1.Overlay>):
|
|
85
|
+
}: React.ComponentProps<typeof Dialog$1.Overlay>): React.JSX.Element;
|
|
86
|
+
/**
|
|
87
|
+
* The **visible panel** of the dialog. Rendered centred on screen via
|
|
88
|
+
* `position: fixed; top: 50%; left: 50%; translate(-50%, -50%)`.
|
|
89
|
+
* Automatically wraps itself in `DialogPortal` and renders `DialogOverlay`
|
|
90
|
+
* behind it.
|
|
91
|
+
*
|
|
92
|
+
* By default a ghost ✕ button is positioned in the top-right corner.
|
|
93
|
+
* Pass `showCloseButton={false}` to remove it when you want to control
|
|
94
|
+
* close behaviour exclusively from the footer.
|
|
95
|
+
*
|
|
96
|
+
* Animates:
|
|
97
|
+
* - **Open** → `fade-in-0 + zoom-in-95`
|
|
98
|
+
* - **Close** → `fade-out-0 + zoom-out-95`
|
|
99
|
+
*
|
|
100
|
+
* @param showCloseButton - Whether to render the ✕ ghost button in the
|
|
101
|
+
* top-right corner. Defaults to `true`.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* <DialogContent showCloseButton={false}>
|
|
105
|
+
* <DialogHeader>...</DialogHeader>
|
|
106
|
+
* <DialogFooter showCloseButton>...</DialogFooter>
|
|
107
|
+
* </DialogContent>
|
|
108
|
+
*/
|
|
21
109
|
declare function DialogContent({
|
|
22
110
|
className,
|
|
23
111
|
children,
|
|
@@ -25,11 +113,36 @@ declare function DialogContent({
|
|
|
25
113
|
...props
|
|
26
114
|
}: React.ComponentProps<typeof Dialog$1.Content> & {
|
|
27
115
|
showCloseButton?: boolean;
|
|
28
|
-
}):
|
|
116
|
+
}): React.JSX.Element;
|
|
117
|
+
/**
|
|
118
|
+
* Layout wrapper for the **top section** of a dialog.
|
|
119
|
+
* Stacks children vertically with `gap-2`. Typically contains
|
|
120
|
+
* `DialogTitle` and optionally `DialogDescription`.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* <DialogHeader>
|
|
124
|
+
* <DialogTitle>Confirm deletion</DialogTitle>
|
|
125
|
+
* <DialogDescription>This action is irreversible.</DialogDescription>
|
|
126
|
+
* </DialogHeader>
|
|
127
|
+
*/
|
|
29
128
|
declare function DialogHeader({
|
|
30
129
|
className,
|
|
31
130
|
...props
|
|
32
|
-
}: React.ComponentProps<"div">):
|
|
131
|
+
}: React.ComponentProps<"div">): React.JSX.Element;
|
|
132
|
+
/**
|
|
133
|
+
* Layout wrapper for the **bottom action area** of a dialog.
|
|
134
|
+
* Bleeds to the content panel edges (`-mx-4 -mb-4`), adds a top border
|
|
135
|
+
* and a subtle muted background tint. Actions stack vertically on mobile
|
|
136
|
+
* and align to the right on `sm+` screens.
|
|
137
|
+
*
|
|
138
|
+
* @param showCloseButton - When `true`, appends an outline `Close` button
|
|
139
|
+
* wired to `DialogClose` after any provided `children`. Defaults to `false`.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* <DialogFooter showCloseButton>
|
|
143
|
+
* <Button type="submit">Save</Button>
|
|
144
|
+
* </DialogFooter>
|
|
145
|
+
*/
|
|
33
146
|
declare function DialogFooter({
|
|
34
147
|
className,
|
|
35
148
|
showCloseButton,
|
|
@@ -37,14 +150,212 @@ declare function DialogFooter({
|
|
|
37
150
|
...props
|
|
38
151
|
}: React.ComponentProps<"div"> & {
|
|
39
152
|
showCloseButton?: boolean;
|
|
40
|
-
}):
|
|
153
|
+
}): React.JSX.Element;
|
|
154
|
+
/**
|
|
155
|
+
* The **accessible title** of the dialog. Rendered as a Radix `Dialog.Title`,
|
|
156
|
+
* which is automatically linked to the dialog content via `aria-labelledby`.
|
|
157
|
+
* Screen readers announce this text when the dialog opens.
|
|
158
|
+
*
|
|
159
|
+
* Styled with the heading font token at `text-base font-medium`.
|
|
160
|
+
*
|
|
161
|
+
* @remarks Required for accessibility. Every dialog should have a title,
|
|
162
|
+
* even if visually hidden with `className="sr-only"`.
|
|
163
|
+
*/
|
|
41
164
|
declare function DialogTitle({
|
|
42
165
|
className,
|
|
43
166
|
...props
|
|
44
|
-
}: React.ComponentProps<typeof Dialog$1.Title>):
|
|
167
|
+
}: React.ComponentProps<typeof Dialog$1.Title>): React.JSX.Element;
|
|
168
|
+
/**
|
|
169
|
+
* The **accessible description** of the dialog. Rendered as a Radix
|
|
170
|
+
* `Dialog.Description`, which is linked to the dialog content via
|
|
171
|
+
* `aria-describedby`. Screen readers read this after the title.
|
|
172
|
+
*
|
|
173
|
+
* Styled as small muted text. Anchor tags (`<a>`) inside the description
|
|
174
|
+
* are automatically underlined and change colour on hover.
|
|
175
|
+
*
|
|
176
|
+
* @remarks Optional but recommended. Omit only if the dialog content itself
|
|
177
|
+
* is sufficiently self-descriptive.
|
|
178
|
+
*/
|
|
45
179
|
declare function DialogDescription({
|
|
46
180
|
className,
|
|
47
181
|
...props
|
|
48
|
-
}: React.ComponentProps<typeof Dialog$1.Description>):
|
|
182
|
+
}: React.ComponentProps<typeof Dialog$1.Description>): React.JSX.Element;
|
|
49
183
|
//#endregion
|
|
50
|
-
|
|
184
|
+
//#region src/responsive-dialog.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Adaptive root component that switches between `Dialog` and `Drawer`
|
|
187
|
+
* depending on screen width:
|
|
188
|
+
* - **Desktop (≥ 768 px)** → renders `Dialog` (centred modal overlay)
|
|
189
|
+
* - **Mobile (< 768 px)** → renders `Drawer` (bottom-sheet panel)
|
|
190
|
+
*
|
|
191
|
+
* All props are forwarded unchanged to the active primitive, so `open`,
|
|
192
|
+
* `defaultOpen`, `onOpenChange`, and `modal` all behave identically to
|
|
193
|
+
* the standard `Dialog` root.
|
|
194
|
+
*
|
|
195
|
+
* **Drawer-Specific Props (Mobile Only)**
|
|
196
|
+
* You can pass Vaul-specific props like `snapPoints`. They are cleanly ignored on desktop.
|
|
197
|
+
* - **IMPORTANT:** If you provide `snapPoints`, you must also provide `fadeFromIndex` as a strict number.
|
|
198
|
+
* - **IMPORTANT:** If you pass `activeSnapPoint`, you must also pass `setActiveSnapPoint` and manage it via state (e.g. `useState`). Do not hardcode `activeSnapPoint` without a setter, otherwise the Drawer will glitch and aggressively snap back when dragged.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* <ResponsiveDialog>
|
|
202
|
+
* <ResponsiveDialogTrigger asChild>
|
|
203
|
+
* <Button>Open</Button>
|
|
204
|
+
* </ResponsiveDialogTrigger>
|
|
205
|
+
* <ResponsiveDialogContent>
|
|
206
|
+
* <ResponsiveDialogHeader>
|
|
207
|
+
* <ResponsiveDialogTitle>Title</ResponsiveDialogTitle>
|
|
208
|
+
* </ResponsiveDialogHeader>
|
|
209
|
+
* </ResponsiveDialogContent>
|
|
210
|
+
* </ResponsiveDialog>
|
|
211
|
+
*/
|
|
212
|
+
declare function ResponsiveDialog({
|
|
213
|
+
children,
|
|
214
|
+
snapPoints,
|
|
215
|
+
activeSnapPoint,
|
|
216
|
+
setActiveSnapPoint,
|
|
217
|
+
fadeFromIndex,
|
|
218
|
+
shouldScaleBackground,
|
|
219
|
+
dismissible,
|
|
220
|
+
snap,
|
|
221
|
+
...props
|
|
222
|
+
}: React.ComponentProps<typeof Dialog$1.Root> & Partial<React.ComponentProps<typeof Drawer>> & {
|
|
223
|
+
snap?: boolean;
|
|
224
|
+
}): React.JSX.Element;
|
|
225
|
+
/**
|
|
226
|
+
* The element that opens the responsive dialog/drawer when activated.
|
|
227
|
+
*
|
|
228
|
+
* - **Desktop** → `DialogTrigger` (Radix `Dialog.Trigger`)
|
|
229
|
+
* - **Mobile** → `DrawerTrigger` (Vaul `Drawer.Trigger`)
|
|
230
|
+
*
|
|
231
|
+
* Use `asChild` to render your own element as the trigger instead of
|
|
232
|
+
* the default button wrapper.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* <ResponsiveDialogTrigger asChild>
|
|
236
|
+
* <Button variant="outline">Open</Button>
|
|
237
|
+
* </ResponsiveDialogTrigger>
|
|
238
|
+
*/
|
|
239
|
+
declare function ResponsiveDialogTrigger({
|
|
240
|
+
children,
|
|
241
|
+
...props
|
|
242
|
+
}: React.ComponentProps<typeof Dialog$1.Trigger>): React.JSX.Element;
|
|
243
|
+
/**
|
|
244
|
+
* A close trigger that targets the correct primitive for the current
|
|
245
|
+
* viewport:
|
|
246
|
+
* - **Desktop** → `DialogClose` (Radix `Dialog.Close`)
|
|
247
|
+
* - **Mobile** → `DrawerClose` (Vaul `Drawer.Close`)
|
|
248
|
+
*
|
|
249
|
+
* Use `asChild` to wrap a custom element.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* <ResponsiveDialogClose asChild>
|
|
253
|
+
* <Button variant="ghost">Cancel</Button>
|
|
254
|
+
* </ResponsiveDialogClose>
|
|
255
|
+
*/
|
|
256
|
+
declare function ResponsiveDialogClose({
|
|
257
|
+
children,
|
|
258
|
+
...props
|
|
259
|
+
}: React.ComponentProps<typeof Dialog$1.Close>): React.JSX.Element;
|
|
260
|
+
/**
|
|
261
|
+
* The visible panel of the responsive dialog. Delegates to the
|
|
262
|
+
* appropriate primitive:
|
|
263
|
+
* - **Desktop** → `DialogContent` — centred modal with fade + zoom animations.
|
|
264
|
+
* The ✕ close button is shown by default (`showCloseButton={true}`).
|
|
265
|
+
* - **Mobile** → `DrawerContent` — bottom-sheet panel with a drag handle.
|
|
266
|
+
* `showCloseButton` has **no effect** on mobile; the drawer is closed
|
|
267
|
+
* via swipe gesture or the drag handle.
|
|
268
|
+
*
|
|
269
|
+
* @param showCloseButton - Show/hide the ✕ button in the top-right corner
|
|
270
|
+
* on desktop. Has no effect on mobile. Defaults to `true`.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* // Hide the ✕ button and force close via footer only (desktop)
|
|
274
|
+
* <ResponsiveDialogContent showCloseButton={false}>
|
|
275
|
+
* ...
|
|
276
|
+
* </ResponsiveDialogContent>
|
|
277
|
+
*/
|
|
278
|
+
declare function ResponsiveDialogContent({
|
|
279
|
+
className,
|
|
280
|
+
children,
|
|
281
|
+
showCloseButton,
|
|
282
|
+
...props
|
|
283
|
+
}: React.ComponentProps<typeof Dialog$1.Content> & {
|
|
284
|
+
showCloseButton?: boolean;
|
|
285
|
+
}): React.JSX.Element;
|
|
286
|
+
/**
|
|
287
|
+
* Layout wrapper for the **top section** of the responsive dialog/drawer.
|
|
288
|
+
*
|
|
289
|
+
* - **Desktop** → `DialogHeader` — vertical stack with `gap-2`
|
|
290
|
+
* - **Mobile** → `DrawerHeader` — vertically centred text for bottom/top
|
|
291
|
+
* drawers, left-aligned for side drawers
|
|
292
|
+
*
|
|
293
|
+
* Typically contains `ResponsiveDialogTitle` and optionally
|
|
294
|
+
* `ResponsiveDialogDescription`.
|
|
295
|
+
*/
|
|
296
|
+
declare function ResponsiveDialogHeader({
|
|
297
|
+
className,
|
|
298
|
+
leftNode,
|
|
299
|
+
rightNode,
|
|
300
|
+
children,
|
|
301
|
+
...props
|
|
302
|
+
}: React.ComponentProps<"div"> & {
|
|
303
|
+
leftNode?: React.ReactNode;
|
|
304
|
+
rightNode?: React.ReactNode;
|
|
305
|
+
}): React.JSX.Element;
|
|
306
|
+
/**
|
|
307
|
+
* Layout wrapper for the **bottom action area** of the responsive
|
|
308
|
+
* dialog/drawer.
|
|
309
|
+
*
|
|
310
|
+
* - **Desktop** → `DialogFooter` — bleeds to panel edges, top border,
|
|
311
|
+
* actions aligned right on `sm+`
|
|
312
|
+
* - **Mobile** → `DrawerFooter` — `mt-auto` stacked column at the bottom
|
|
313
|
+
* of the drawer
|
|
314
|
+
*
|
|
315
|
+
* @param showCloseButton - When `true`, appends a close button after
|
|
316
|
+
* `children`. On **desktop** this is a `DialogClose`-wrapped outline
|
|
317
|
+
* button; on **mobile** this is a `DrawerClose`-wrapped outline button.
|
|
318
|
+
* Defaults to `false`.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* <ResponsiveDialogFooter showCloseButton>
|
|
322
|
+
* <Button type="submit">Save</Button>
|
|
323
|
+
* </ResponsiveDialogFooter>
|
|
324
|
+
*/
|
|
325
|
+
declare function ResponsiveDialogFooter({
|
|
326
|
+
className,
|
|
327
|
+
children,
|
|
328
|
+
showCloseButton,
|
|
329
|
+
...props
|
|
330
|
+
}: React.ComponentProps<"div"> & {
|
|
331
|
+
showCloseButton?: boolean;
|
|
332
|
+
}): React.JSX.Element;
|
|
333
|
+
/**
|
|
334
|
+
* The **accessible title** of the responsive dialog/drawer.
|
|
335
|
+
*
|
|
336
|
+
* - **Desktop** → `DialogTitle` (linked via `aria-labelledby`)
|
|
337
|
+
* - **Mobile** → `DrawerTitle` (linked via `aria-labelledby`)
|
|
338
|
+
*
|
|
339
|
+
* Screen readers announce this text when the panel opens.
|
|
340
|
+
*
|
|
341
|
+
* @remarks Required for accessibility on both desktop and mobile.
|
|
342
|
+
*/
|
|
343
|
+
declare function ResponsiveDialogTitle({
|
|
344
|
+
className,
|
|
345
|
+
...props
|
|
346
|
+
}: React.ComponentProps<typeof Dialog$1.Title>): React.JSX.Element;
|
|
347
|
+
/**
|
|
348
|
+
* The **accessible description** of the responsive dialog/drawer.
|
|
349
|
+
*
|
|
350
|
+
* - **Desktop** → `DialogDescription` (linked via `aria-describedby`)
|
|
351
|
+
* - **Mobile** → `DrawerDescription` (linked via `aria-describedby`)
|
|
352
|
+
*
|
|
353
|
+
* @remarks Optional but recommended. Provides supplementary context for
|
|
354
|
+
* screen reader users after the title is announced.
|
|
355
|
+
*/
|
|
356
|
+
declare function ResponsiveDialogDescription({
|
|
357
|
+
className,
|
|
358
|
+
...props
|
|
359
|
+
}: React.ComponentProps<typeof Dialog$1.Description>): React.JSX.Element;
|
|
360
|
+
//#endregion
|
|
361
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, ResponsiveDialog, ResponsiveDialogClose, ResponsiveDialogContent, ResponsiveDialogDescription, ResponsiveDialogFooter, ResponsiveDialogHeader, ResponsiveDialogTitle, ResponsiveDialogTrigger };
|