@data-slot/dialog 0.2.167 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +99 -93
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -13,6 +13,7 @@ npm install @data-slot/dialog
13
13
  ```html
14
14
  <div data-slot="dialog">
15
15
  <button data-slot="dialog-trigger">Open Dialog</button>
16
+ <div data-slot="dialog-overlay" hidden></div>
16
17
  <div data-slot="dialog-content" hidden>
17
18
  <h2 data-slot="dialog-title">Dialog Title</h2>
18
19
  <p data-slot="dialog-description">Dialog description text.</p>
@@ -29,7 +30,9 @@ npm install @data-slot/dialog
29
30
 
30
31
  ## API
31
32
 
32
- ### `create(scope?)`
33
+ ### Initialization
34
+
35
+ #### `create(scope?)`
33
36
 
34
37
  Auto-discover and bind all dialog instances in a scope (defaults to `document`).
35
38
 
@@ -39,7 +42,7 @@ import { create } from "@data-slot/dialog";
39
42
  const controllers = create(); // Returns DialogController[]
40
43
  ```
41
44
 
42
- ### `createDialog(root, options?)`
45
+ #### `createDialog(root, options?)`
43
46
 
44
47
  Create a controller for a specific element.
45
48
 
@@ -55,16 +58,32 @@ const dialog = createDialog(element, {
55
58
  });
56
59
  ```
57
60
 
58
- ### Options
61
+ ### Slots
59
62
 
60
- | Option | Type | Default | Description |
61
- |--------|------|---------|-------------|
62
- | `defaultOpen` | `boolean` | `false` | Initial open state |
63
- | `closeOnClickOutside` | `boolean` | `true` | Close when clicking outside content |
64
- | `closeOnEscape` | `boolean` | `true` | Close when pressing Escape |
65
- | `lockScroll` | `boolean` | `true` | Lock body scroll when open |
66
- | `alertDialog` | `boolean` | `false` | Use alertdialog role for confirmations |
67
- | `onOpenChange` | `(open: boolean) => void` | `undefined` | Callback when open state changes |
63
+ #### Runtime Slots
64
+
65
+ - `dialog` - Root element that manages the open state and receives dialog events.
66
+ - `dialog-trigger` - Optional button that toggles the dialog.
67
+ - `dialog-portal` - Optional wrapper moved to `document.body` while the dialog is open.
68
+ - `dialog-overlay` - Required backdrop; clicking it dismisses the dialog when outside-click dismissal is enabled.
69
+ - `dialog-content` - Required modal panel with dialog semantics and focus management.
70
+ - `dialog-title` - Optional title used for the panel's `aria-labelledby`.
71
+ - `dialog-description` - Optional description used for the panel's `aria-describedby`.
72
+ - `dialog-close` - Optional button that closes the dialog; multiple close buttons are supported.
73
+
74
+ #### Markup
75
+
76
+ ```html
77
+ <div data-slot="dialog">
78
+ <button data-slot="dialog-trigger">Open</button>
79
+ <div data-slot="dialog-overlay" hidden></div>
80
+ <div data-slot="dialog-content" role="dialog">
81
+ <h2 data-slot="dialog-title">Title</h2>
82
+ <p data-slot="dialog-description">Description</p>
83
+ <button data-slot="dialog-close">Close</button>
84
+ </div>
85
+ </div>
86
+ ```
68
87
 
69
88
  ### Data Attributes
70
89
 
@@ -92,6 +111,17 @@ Boolean attributes: present or `"true"` = true, `"false"` = false, absent = defa
92
111
  </div>
93
112
  ```
94
113
 
114
+ ### Options
115
+
116
+ | Option | Type | Default | Description |
117
+ |--------|------|---------|-------------|
118
+ | `defaultOpen` | `boolean` | `false` | Initial open state |
119
+ | `closeOnClickOutside` | `boolean` | `true` | Close when clicking outside content |
120
+ | `closeOnEscape` | `boolean` | `true` | Close when pressing Escape |
121
+ | `lockScroll` | `boolean` | `true` | Lock body scroll when open |
122
+ | `alertDialog` | `boolean` | `false` | Use alertdialog role for confirmations |
123
+ | `onOpenChange` | `(open: boolean) => void` | `undefined` | Callback when open state changes |
124
+
95
125
  ### Controller
96
126
 
97
127
  | Method/Property | Description |
@@ -102,31 +132,61 @@ Boolean attributes: present or `"true"` = true, `"false"` = false, absent = defa
102
132
  | `isOpen` | Current open state (readonly `boolean`) |
103
133
  | `destroy()` | Cleanup all event listeners |
104
134
 
105
- ## Markup Structure
135
+ #### Controller Destruction
106
136
 
107
- ```html
108
- <div data-slot="dialog">
109
- <button data-slot="dialog-trigger">Open</button>
110
- <div data-slot="dialog-content" role="dialog">
111
- <h2 data-slot="dialog-title">Title</h2>
112
- <p data-slot="dialog-description">Description</p>
113
- <button data-slot="dialog-close">Close</button>
114
- </div>
115
- </div>
137
+ `destroy()` permanently disposes the controller and hides any open surface without
138
+ emitting an additional change event. Repeated destruction is safe; methods on the
139
+ old controller become no-ops. Create a new controller on the same root to rebind it.
140
+
141
+ Destruction restores prior focus, falling back to a surviving trigger if the prior
142
+ target was removed. Destroying an unopened modal does not move focus.
143
+
144
+ ### Events
145
+
146
+ #### Outbound Events
147
+
148
+ Listen for changes via custom events:
149
+
150
+ ```javascript
151
+ element.addEventListener("dialog:change", (e) => {
152
+ console.log("Dialog open:", e.detail.open);
153
+ });
154
+ ```
155
+
156
+ #### Inbound Events
157
+
158
+ Control the dialog via events:
159
+
160
+ | Event | Detail | Description |
161
+ |-------|--------|-------------|
162
+ | `dialog:set` | `{ open: boolean }` | Set open state programmatically |
163
+
164
+ ```javascript
165
+ // Open the dialog
166
+ element.dispatchEvent(
167
+ new CustomEvent("dialog:set", { detail: { open: true } })
168
+ );
169
+
170
+ // Close the dialog
171
+ element.dispatchEvent(
172
+ new CustomEvent("dialog:set", { detail: { open: false } })
173
+ );
116
174
  ```
117
175
 
118
- ### Required Slots
176
+ ##### Deprecated Shapes
119
177
 
120
- - `dialog-content` - The dialog panel (required)
178
+ The following shape is deprecated and will be removed in v1.0:
121
179
 
122
- ### Optional Slots
180
+ ```javascript
181
+ // Deprecated: { value: boolean }
182
+ element.dispatchEvent(
183
+ new CustomEvent("dialog:set", { detail: { value: true } })
184
+ );
185
+ ```
123
186
 
124
- - `dialog-trigger` - Button to open the dialog
125
- - `dialog-title` - Title for `aria-labelledby`
126
- - `dialog-description` - Description for `aria-describedby`
127
- - `dialog-close` - Button to close the dialog
187
+ Use `{ open: boolean }` instead.
128
188
 
129
- ## Styling
189
+ ### Styling
130
190
 
131
191
  Dialog exposes both `data-state="open|closed"` and popup-style animation hooks:
132
192
 
@@ -192,13 +252,21 @@ With Tailwind:
192
252
  ></div>
193
253
  <div
194
254
  data-slot="dialog-content"
195
- class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-lg bg-white p-6 opacity-0 scale-95 transition-all duration-200 data-[open]:opacity-100 data-[open]:scale-100 data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95"
255
+ class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white p-6 opacity-0 scale-95 transition-all duration-200 data-[open]:opacity-100 data-[open]:scale-100 data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95"
196
256
  >
197
257
  <!-- Dialog content -->
198
258
  </div>
199
259
  ```
200
260
 
201
- ## Accessibility
261
+ ### Keyboard Navigation
262
+
263
+ | Key | Action |
264
+ |-----|--------|
265
+ | `Escape` | Close dialog |
266
+ | `Tab` | Cycle focus within dialog |
267
+ | `Shift+Tab` | Cycle focus backwards |
268
+
269
+ ### Accessibility
202
270
 
203
271
  The component automatically handles:
204
272
 
@@ -211,68 +279,6 @@ The component automatically handles:
211
279
  - Focus trap within dialog
212
280
  - Focus restoration on close
213
281
 
214
- ## Keyboard Navigation
215
-
216
- | Key | Action |
217
- |-----|--------|
218
- | `Escape` | Close dialog |
219
- | `Tab` | Cycle focus within dialog |
220
- | `Shift+Tab` | Cycle focus backwards |
221
-
222
- ## Events
223
-
224
- ### Outbound Events
225
-
226
- Listen for changes via custom events:
227
-
228
- ```javascript
229
- element.addEventListener("dialog:change", (e) => {
230
- console.log("Dialog open:", e.detail.open);
231
- });
232
- ```
233
-
234
- ### Inbound Events
235
-
236
- Control the dialog via events:
237
-
238
- | Event | Detail | Description |
239
- |-------|--------|-------------|
240
- | `dialog:set` | `{ open: boolean }` | Set open state programmatically |
241
-
242
- ```javascript
243
- // Open the dialog
244
- element.dispatchEvent(
245
- new CustomEvent("dialog:set", { detail: { open: true } })
246
- );
247
-
248
- // Close the dialog
249
- element.dispatchEvent(
250
- new CustomEvent("dialog:set", { detail: { open: false } })
251
- );
252
- ```
253
-
254
- #### Deprecated Shapes
255
-
256
- The following shape is deprecated and will be removed in v1.0:
257
-
258
- ```javascript
259
- // Deprecated: { value: boolean }
260
- element.dispatchEvent(
261
- new CustomEvent("dialog:set", { detail: { value: true } })
262
- );
263
- ```
264
-
265
- Use `{ open: boolean }` instead.
266
-
267
- ## Controller destruction
268
-
269
- `destroy()` permanently disposes the controller and hides any open surface without
270
- emitting an additional change event. Repeated destruction is safe; methods on the
271
- old controller become no-ops. Create a new controller on the same root to rebind it.
272
-
273
- Destruction restores prior focus, falling back to a surviving trigger if the prior
274
- target was removed. Destroying an unopened modal does not move focus.
275
-
276
282
  ## License
277
283
 
278
284
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/dialog",
3
- "version": "0.2.167",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -35,6 +35,6 @@
35
35
  ],
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@data-slot/core": "0.2.167"
38
+ "@data-slot/core": "1.0.0"
39
39
  }
40
40
  }