@rokku-x/react-hook-dialog 0.0.1 → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rokku-x
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # react-hook-dialog
2
2
 
3
+ [![CI](https://github.com/rokku-x/react-hook-dialog/actions/workflows/ci.yml/badge.svg)](https://github.com/rokku-x/react-hook-dialog/actions/workflows/ci.yml)
4
+
3
5
  A powerful and flexible React dialog hook library for confirmation dialogs, alerts, and modals. Built on top of `@rokku-x/react-hook-modal` with a focus on dialog-specific features like action buttons, variants, and customizable styling.
4
6
 
5
7
  ## Features
@@ -9,7 +11,6 @@ A powerful and flexible React dialog hook library for confirmation dialogs, aler
9
11
  - 🧩 **Modular Components** - Composed from reusable Backdrop and DialogWindow components
10
12
  - 📝 **Dialog Actions** - Flexible action button system with left/right positioning
11
13
  - 💅 **Full Customization** - Injectable className and styles at every level
12
- - 🧮 **Zustand State** - Centralized state management with Zustand
13
14
  - ⌨️ **Rich Configuration** - Default configs with per-call overrides
14
15
  - 🎁 **Zero Dependencies** - Only requires React, Zustand, and @rokku-x/react-hook-modal
15
16
  - 📱 **TypeScript Support** - Full type safety out of the box
@@ -132,6 +133,7 @@ Configuration for individual dialog calls.
132
133
  | `classNames` | `DialogClassNames` | Custom CSS classes for elements |
133
134
  | `styles` | `DialogStyles` | Custom inline styles for elements |
134
135
  | `variantStyles` | `DialogVariantStyles` | Custom variant button styles |
136
+ | `isReturnSubmit` | `boolean` | When `true` and `content` is a `<form>`, clicking a submit action returns the serialized form values as the dialog result |
135
137
 
136
138
  ### ModalAction
137
139
 
@@ -141,11 +143,14 @@ Individual action button configuration.
141
143
  |---|---|---|---|
142
144
  | `title` | `React.ReactNode` | ✓ | Button label (string or React element) |
143
145
  | `value` | `ValidValue` | | Value to return when clicked |
144
- | `isCancel` | `boolean` | | Treat as cancel button (respects rejectOnCancel) |
146
+ | `isCancel` | `boolean` | | Treat as cancel button (respects `rejectOnCancel`) |
145
147
  | `isOnLeft` | `boolean` | | Position button on left side of row |
148
+ | `isFocused` | `boolean` | | Request initial focus when the dialog opens (highest focus priority) |
149
+ | `isSubmit` | `boolean` | | Render as `type="submit"` and trigger form submit if `content` is a `<form>` |
150
+ | `noActionReturn` | `boolean` | | Run `onClick` but do _not_ perform default dialog action (`handleAction`) — useful for custom flows |
146
151
  | `variant` | `ModalVariant` | | Visual style variant |
147
- | `className` | `string` | | Additional CSS class |
148
- | `style` | `React.CSSProperties` | | Custom inline styles |
152
+ | `className` | `string` | | Additional CSS class applied to the button |
153
+ | `style` | `React.CSSProperties` | | Custom inline styles applied to the button (highest style priority) |
149
154
  | `onClick` | `((event, action) => void) \| (() => void)` | | Click handler called before default handling |
150
155
 
151
156
  ### ModalVariant
@@ -166,6 +171,23 @@ type ModalVariant = 'primary' | 'secondary' | 'danger' | 'success' | 'warning' |
166
171
  | `info` | Sky (#0ea5e9) | White |
167
172
  | `neutral` | Gray (#6b7280) | White |
168
173
 
174
+ ### Action Flags — Priority & Behavior 🔀
175
+
176
+ - **Focus priority**: `isFocused` (per-action) > close button (if shown) > first action button > dialog container
177
+ - **Click ordering**: `action.onClick` is executed first. Then:
178
+ 1. If `isSubmit` is true and `isReturnSubmit` is also enabled (and `content` is a `<form>`), the form is serialized and its values are returned as the dialog result immediately (no native submit is triggered).
179
+ 2. Else if `isSubmit` is true, the form's `requestSubmit()` is invoked (useful for native validation flows).
180
+ 3. Else if `noActionReturn` is true, the default dialog action is skipped (use to perform custom flows and close the dialog manually).
181
+ 4. Otherwise `handleAction` is called and the dialog resolves/rejects using the action's `value`.
182
+ - **isCancel**: marks a cancel action — dialog resolves or rejects according to `rejectOnCancel` and `defaultCancelValue` settings.
183
+ - **Placement**: `isOnLeft` positions the action on the left side; other actions render on the right.
184
+ - **Style & class precedence** (lowest → highest):
185
+ 1. built-in `baseVariantStyles` (library defaults)
186
+ 2. `ConfirmConfig.variantStyles` (per-call variant overrides)
187
+ 3. `ConfirmConfig.styles.actionButton` (per-call default action button styles)
188
+ 4. `ModalAction.style` (per-action inline style — highest precedence)
189
+ 5. `className` values are appended so per-action `className` and `ConfirmConfig.classNames.actionButton` both apply (per-action classes appear last).
190
+
169
191
  ### DialogClassNames
170
192
 
171
193
  Customize CSS classes for all elements:
@@ -565,6 +587,43 @@ const handleFormSubmit = async (formData: any) => {
565
587
  };
566
588
  ```
567
589
 
590
+ ### Example 15: Form Dialog Returning Values (isReturnSubmit)
591
+
592
+ ```tsx
593
+ const [requestDialog] = useHookDialog();
594
+
595
+ async function openProfileDialog() {
596
+ const result = await requestDialog({
597
+ title: 'Edit Profile',
598
+ content: (
599
+ <form>
600
+ <label>
601
+ Name
602
+ <input name="name" defaultValue="Alice" />
603
+ </label>
604
+ <label>
605
+ Email
606
+ <input name="email" defaultValue="alice@example.com" />
607
+ </label>
608
+ </form>
609
+ ),
610
+ actions: [[
611
+ { title: 'Cancel', isCancel: true },
612
+ // `isSubmit` triggers native submit; when `isReturnSubmit` is enabled on the dialog config, the dialog returns the form values object
613
+ { title: 'Save', isSubmit: true }
614
+ ]],
615
+ isReturnSubmit: true
616
+ });
617
+
618
+ if (result && typeof result === 'object') {
619
+ // `result` is the object built from the submitted form
620
+ console.log('Form values:', result);
621
+ // e.g. result.name, result.email
622
+ }
623
+ }
624
+ ```
625
+
626
+ > Note: `isReturnSubmit` overrides `noActionReturn` and returns the serialized form values as the action `value`. `isSubmit` still triggers `requestSubmit()` to allow native validation flows.
568
627
  ### Example 14: Boolean Result with Custom Values
569
628
 
570
629
  ```tsx
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rokku-x
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.