@manhphi1309/dialog 0.1.1 → 0.2.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 CHANGED
@@ -1,15 +1,11 @@
1
1
  # @manhphi1309/dialog
2
2
 
3
- A custom dialog component for the shadcn-custom monorepo.
3
+ A fully-accessible dialog package built on top of [Radix UI Dialog](https://www.radix-ui.com/primitives/docs/components/dialog). Ships two complete component families:
4
4
 
5
- ## Subcomponents
5
+ - **`Dialog*`** — standard modal dialog, always renders as a centered overlay
6
+ - **`ResponsiveDialog*`** — adaptive wrapper that switches to a bottom `Drawer` on mobile screens (< 768 px)
6
7
 
7
- - `Dialog`
8
-
9
- ## Dependencies
10
-
11
- - `@manhphi1309/utils`
12
- - `class-variance-authority`
8
+ ---
13
9
 
14
10
  ## Installation
15
11
 
@@ -17,12 +13,245 @@ A custom dialog component for the shadcn-custom monorepo.
17
13
  npm install @manhphi1309/dialog
18
14
  ```
19
15
 
20
- ## Usage Example
16
+ ---
17
+
18
+ ## Dependencies
19
+
20
+ | Package | Role |
21
+ | --------------------- | --------------------------------------------- |
22
+ | `@manhphi1309/button` | Close / action buttons inside dialogs |
23
+ | `@manhphi1309/drawer` | Mobile fallback used by `ResponsiveDialog*` |
24
+ | `@manhphi1309/hooks` | `useIsMobile()` for the responsive breakpoint |
25
+ | `@manhphi1309/utils` | `cn()` class-name helper |
26
+
27
+ ---
28
+
29
+ ## Dialog Family
30
+
31
+ A set of composable primitives that always render as a centred modal overlay, regardless of screen size.
32
+
33
+ ### `Dialog`
34
+
35
+ The **root** component. Controls open/close state and provides context to all children. Thin wrapper around `Radix Dialog.Root`.
36
+
37
+ ```tsx
38
+ <Dialog open={open} onOpenChange={setOpen}>
39
+ ...
40
+ </Dialog>
41
+ ```
42
+
43
+ | Prop | Type | Notes |
44
+ | -------------- | ------------------------- | -------------------------------------------------------------- |
45
+ | `open` | `boolean` | Controlled open state |
46
+ | `onOpenChange` | `(open: boolean) => void` | Called when open state changes |
47
+ | `defaultOpen` | `boolean` | Uncontrolled initial state |
48
+ | `modal` | `boolean` | Default `true` — traps focus and blocks background interaction |
49
+
50
+ ---
51
+
52
+ ### `DialogTrigger`
53
+
54
+ Wraps the element that **opens** the dialog when clicked. Passes through all props to the underlying `Radix Dialog.Trigger`. Use `asChild` to compose with your own element.
55
+
56
+ ```tsx
57
+ <DialogTrigger asChild>
58
+ <Button>Open</Button>
59
+ </DialogTrigger>
60
+ ```
61
+
62
+ ---
63
+
64
+ ### `DialogPortal`
65
+
66
+ Renders its children into a **portal** outside the current DOM tree (appended to `document.body`). Ensures the dialog appears above all other content and avoids z-index / overflow issues.
67
+
68
+ > Usually you do not use this directly — `DialogContent` includes it automatically.
69
+
70
+ ---
71
+
72
+ ### `DialogOverlay`
73
+
74
+ The **backdrop** behind the dialog content. Renders a fixed, full-screen semi-transparent layer (`bg-black/10`) with a backdrop blur on supported browsers.
75
+
76
+ **Animations:**
77
+
78
+ - Open → `fade-in-0`
79
+ - Close → `fade-out-0`
80
+
81
+ > Usually you do not use this directly — `DialogContent` includes it automatically.
82
+
83
+ ---
84
+
85
+ ### `DialogContent`
86
+
87
+ The **visible panel** of the dialog. Renders centred on screen (`top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2`), inside a portal with an overlay underneath. Comes with a ✕ ghost button in the top-right corner by default.
88
+
89
+ **Animations:**
90
+
91
+ - Open → `fade-in-0 + zoom-in-95`
92
+ - Close → `fade-out-0 + zoom-out-95`
93
+
94
+ | Prop | Type | Default | Notes |
95
+ | ----------------- | --------- | ------- | ------------------------------------------------------- |
96
+ | `showCloseButton` | `boolean` | `true` | Show/hide the built-in ✕ button in the top-right corner |
97
+ | `className` | `string` | — | Extra classes merged on the content panel |
98
+
99
+ ```tsx
100
+ <DialogContent showCloseButton={false}>...</DialogContent>
101
+ ```
102
+
103
+ ---
104
+
105
+ ### `DialogHeader`
106
+
107
+ A **layout wrapper** for the top section of a dialog. Stacks children vertically with `gap-2`. Typically holds `DialogTitle` and `DialogDescription`.
108
+
109
+ ```tsx
110
+ <DialogHeader>
111
+ <DialogTitle>Title</DialogTitle>
112
+ <DialogDescription>Optional description.</DialogDescription>
113
+ </DialogHeader>
114
+ ```
115
+
116
+ ---
117
+
118
+ ### `DialogTitle`
119
+
120
+ The **accessible title** of the dialog. Rendered as a Radix `Dialog.Title` (connected to `aria-labelledby` on the content). Styled with `text-base font-medium leading-none` using the heading font.
121
+
122
+ > Required for accessibility — screen readers announce this when the dialog opens.
123
+
124
+ ---
125
+
126
+ ### `DialogDescription`
127
+
128
+ The **accessible description** of the dialog. Rendered as a Radix `Dialog.Description` (connected to `aria-describedby` on the content). Styled as small muted text. Links inside it are automatically underlined.
129
+
130
+ > Optional but recommended for accessibility.
131
+
132
+ ---
133
+
134
+ ### `DialogFooter`
135
+
136
+ A **layout wrapper** for the bottom action area. Bleeds to the edges of the content panel (`-mx-4 -mb-4`), adds a top border and `bg-muted/50` tint. Actions stack vertically on mobile, align right horizontally on `sm+`.
137
+
138
+ | Prop | Type | Default | Notes |
139
+ | ----------------- | --------- | ------- | -------------------------------------------------------- |
140
+ | `showCloseButton` | `boolean` | `false` | Appends a `Close` outline button wired to `Dialog.Close` |
141
+
142
+ ```tsx
143
+ <DialogFooter showCloseButton>
144
+ <Button type="submit">Save</Button>
145
+ </DialogFooter>
146
+ ```
147
+
148
+ ---
149
+
150
+ ### `DialogClose`
151
+
152
+ A bare **close trigger** primitive. Closes the dialog when activated. Use `asChild` to compose with a custom element.
153
+
154
+ ```tsx
155
+ <DialogClose asChild>
156
+ <Button variant="ghost">Cancel</Button>
157
+ </DialogClose>
158
+ ```
159
+
160
+ ---
161
+
162
+ ## ResponsiveDialog Family
163
+
164
+ Drop-in replacements for the `Dialog*` components. Each one checks `useIsMobile()` (breakpoint: `768 px`) and renders the appropriate primitive:
165
+
166
+ | Component | Desktop (≥ 768 px) | Mobile (< 768 px) |
167
+ | ----------------------------- | ------------------- | ------------------- |
168
+ | `ResponsiveDialog` | `Dialog` | `Drawer` |
169
+ | `ResponsiveDialogTrigger` | `DialogTrigger` | `DrawerTrigger` |
170
+ | `ResponsiveDialogClose` | `DialogClose` | `DrawerClose` |
171
+ | `ResponsiveDialogContent` | `DialogContent` | `DrawerContent` |
172
+ | `ResponsiveDialogHeader` | `DialogHeader` | `DrawerHeader` |
173
+ | `ResponsiveDialogFooter` | `DialogFooter` | `DrawerFooter` |
174
+ | `ResponsiveDialogTitle` | `DialogTitle` | `DrawerTitle` |
175
+ | `ResponsiveDialogDescription` | `DialogDescription` | `DrawerDescription` |
176
+
177
+ All props are forwarded to the underlying component unchanged. `showCloseButton` on `ResponsiveDialogContent` and `ResponsiveDialogFooter` works the same way as on their dialog counterparts, including the correct close primitive for the active variant.
178
+
179
+ > **Note:** `ResponsiveDialogContent` does **not** forward `showCloseButton` to `DrawerContent` (the Drawer handles close via the handle bar and swipe gesture). The prop is only meaningful on desktop.
180
+
181
+ ---
182
+
183
+ ## Usage
184
+
185
+ ### Standard Dialog
186
+
187
+ ```tsx
188
+ import { Button } from "@manhphi1309/button"
189
+ import {
190
+ Dialog,
191
+ DialogContent,
192
+ DialogDescription,
193
+ DialogFooter,
194
+ DialogHeader,
195
+ DialogTitle,
196
+ DialogTrigger,
197
+ } from "@manhphi1309/dialog"
198
+
199
+ export default function DeleteConfirm() {
200
+ return (
201
+ <Dialog>
202
+ <DialogTrigger asChild>
203
+ <Button variant="destructive">Delete account</Button>
204
+ </DialogTrigger>
205
+ <DialogContent>
206
+ <DialogHeader>
207
+ <DialogTitle>Are you absolutely sure?</DialogTitle>
208
+ <DialogDescription>
209
+ This action cannot be undone. Your account will be permanently
210
+ deleted.
211
+ </DialogDescription>
212
+ </DialogHeader>
213
+ <DialogFooter showCloseButton>
214
+ <Button variant="destructive">Delete</Button>
215
+ </DialogFooter>
216
+ </DialogContent>
217
+ </Dialog>
218
+ )
219
+ }
220
+ ```
221
+
222
+ ### Responsive Dialog (Dialog on desktop, Drawer on mobile)
21
223
 
22
224
  ```tsx
23
- import { Dialog } from "@manhphi1309/dialog"
225
+ import { Button } from "@manhphi1309/button"
226
+ import {
227
+ ResponsiveDialog,
228
+ ResponsiveDialogContent,
229
+ ResponsiveDialogDescription,
230
+ ResponsiveDialogFooter,
231
+ ResponsiveDialogHeader,
232
+ ResponsiveDialogTitle,
233
+ ResponsiveDialogTrigger,
234
+ } from "@manhphi1309/dialog"
24
235
 
25
- export default function App() {
26
- return <Dialog>Hello World</Dialog>
236
+ export default function EditProfile() {
237
+ return (
238
+ <ResponsiveDialog>
239
+ <ResponsiveDialogTrigger asChild>
240
+ <Button>Edit Profile</Button>
241
+ </ResponsiveDialogTrigger>
242
+ <ResponsiveDialogContent>
243
+ <ResponsiveDialogHeader>
244
+ <ResponsiveDialogTitle>Edit profile</ResponsiveDialogTitle>
245
+ <ResponsiveDialogDescription>
246
+ Make changes to your profile here.
247
+ </ResponsiveDialogDescription>
248
+ </ResponsiveDialogHeader>
249
+ {/* form content */}
250
+ <ResponsiveDialogFooter>
251
+ <Button type="submit">Save changes</Button>
252
+ </ResponsiveDialogFooter>
253
+ </ResponsiveDialogContent>
254
+ </ResponsiveDialog>
255
+ )
27
256
  }
28
257
  ```