@rokku-x/react-hook-dialog 1.0.2 → 1.0.4

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
@@ -72,13 +72,6 @@ function MyComponent() {
72
72
  }
73
73
  ```
74
74
 
75
- ## Bundle Size
76
-
77
- - ESM: ~4.06 kB gzipped (13.48 kB raw)
78
- - CJS: ~3.48 kB gzipped (9.21 kB raw)
79
-
80
- Measured with Vite build for v0.0.1.
81
-
82
75
  ## API Reference
83
76
 
84
77
  ### useHookDialog
@@ -276,6 +269,8 @@ function DeleteConfirm() {
276
269
  }
277
270
  ```
278
271
 
272
+ ![Example 1 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-1.png)
273
+
279
274
  ### Example 2: Multiple Action Rows
280
275
 
281
276
  ```tsx
@@ -294,6 +289,8 @@ await requestDialog({
294
289
  });
295
290
  ```
296
291
 
292
+ ![Example 2 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-2.png)
293
+
297
294
  ### Example 3: Custom Styling
298
295
 
299
296
  ```tsx
@@ -318,6 +315,8 @@ await requestDialog({
318
315
  });
319
316
  ```
320
317
 
318
+ ![Example 3 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-3.png)
319
+
321
320
  ### Example 4: Custom Button Variants
322
321
 
323
322
  ```tsx
@@ -338,6 +337,8 @@ await requestDialog({
338
337
  });
339
338
  ```
340
339
 
340
+ ![Example 4 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-4.png)
341
+
341
342
  ### Example 5: Button Click Handlers
342
343
 
343
344
  ```tsx
@@ -357,6 +358,8 @@ await requestDialog({
357
358
  });
358
359
  ```
359
360
 
361
+ ![Example 5 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-5.png)
362
+
360
363
  ### Example 6: Rich Content
361
364
 
362
365
  ```tsx
@@ -377,6 +380,8 @@ await requestDialog({
377
380
  });
378
381
  ```
379
382
 
383
+ ![Example 6 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-6.png)
384
+
380
385
  ### Example 7: Default Configuration
381
386
 
382
387
  ```tsx
@@ -395,6 +400,8 @@ await requestDialog({
395
400
  });
396
401
  ```
397
402
 
403
+ ![Example 7 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-7.png)
404
+
398
405
  ### Example 8: Alert Dialog
399
406
 
400
407
  ```tsx
@@ -413,6 +420,8 @@ async function showAlert(message: string) {
413
420
  showAlert('Operation completed successfully!');
414
421
  ```
415
422
 
423
+ ![Example 8 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-8.png)
424
+
416
425
  ### Example 9: Multiple Choice with Different Values
417
426
 
418
427
  ```tsx
@@ -439,6 +448,8 @@ const handleSaveOptions = async () => {
439
448
  };
440
449
  ```
441
450
 
451
+ ![Example 9 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-9.png)
452
+
442
453
  ### Example 10: Numeric Rating Dialog
443
454
 
444
455
  ```tsx
@@ -468,6 +479,8 @@ const handleRating = async () => {
468
479
  };
469
480
  ```
470
481
 
482
+ ![Example 10 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-10.png)
483
+
471
484
  ### Example 11: Conditional Actions Based on Result
472
485
 
473
486
  ```tsx
@@ -515,6 +528,8 @@ const handleFileOperation = async () => {
515
528
  };
516
529
  ```
517
530
 
531
+ ![Example 11 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-11.png)
532
+
518
533
  ### Example 12: Handle Cancel vs Reject
519
534
 
520
535
  ```tsx
@@ -544,6 +559,8 @@ const handleWithErrorHandling = async () => {
544
559
  };
545
560
  ```
546
561
 
562
+ ![Example 12 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-12.png)
563
+
547
564
  ### Example 13: Form Submission with Validation
548
565
 
549
566
  ```tsx
@@ -587,6 +604,33 @@ const handleFormSubmit = async (formData: any) => {
587
604
  };
588
605
  ```
589
606
 
607
+ ![Example 13 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-13.png)
608
+
609
+ ### Example 14: Boolean Result with Custom Values
610
+
611
+ ```tsx
612
+ const [requestDialog] = useHookDialog();
613
+
614
+ const handleLogout = async () => {
615
+ const shouldLogout = await requestDialog({
616
+ title: 'Confirm Logout',
617
+ content: 'Are you sure you want to log out?',
618
+ actions: [[
619
+ { title: 'Stay Logged In', variant: 'secondary', value: false },
620
+ { title: 'Log Out', variant: 'danger', value: true }
621
+ ]]
622
+ });
623
+
624
+ if (shouldLogout) {
625
+ // Perform logout
626
+ sessionStorage.clear();
627
+ window.location.href = '/login';
628
+ }
629
+ };
630
+ ```
631
+
632
+ ![Example 14 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-14.png)
633
+
590
634
  ### Example 15: Form Dialog Returning Values (isReturnSubmit)
591
635
 
592
636
  ```tsx
@@ -623,40 +667,9 @@ async function openProfileDialog() {
623
667
  }
624
668
  ```
625
669
 
626
- > Note: `isReturnSubmit` overrides `noActionReturn` and returns the serialized form values as the action `value`. `isSubmit` still triggers `requestSubmit()` to allow native validation flows.
627
- ### Example 14: Boolean Result with Custom Values
628
-
629
- ```tsx
630
- const [requestDialog] = useHookDialog();
670
+ ![Example 15 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-15.png)
631
671
 
632
- const handleLogout = async () => {
633
- const shouldLogout = await requestDialog({
634
- title: 'Confirm Logout',
635
- content: 'Are you sure you want to log out?',
636
- actions: [[
637
- { title: 'Stay Logged In', variant: 'secondary', value: false },
638
- { title: 'Log Out', variant: 'danger', value: true }
639
- ]]
640
- });
641
-
642
- if (shouldLogout) {
643
- // Perform logout
644
- sessionStorage.clear();
645
- window.location.href = '/login';
646
- }
647
- };
648
- ```
649
-
650
- ## Best Practices
651
-
652
- 1. **Mount `BaseModalRenderer` at root level** - Required for modals to render
653
- 2. **Use default configs for consistency** - Set common styles/behaviors once
654
- 3. **Provide meaningful button labels** - Users should know what each button does
655
- 4. **Use appropriate variants** - Use `danger` for destructive actions, `success` for confirmations
656
- 5. **Keep content concise** - Dialogs should be focused and brief
657
- 6. **Handle both resolve and reject** - Account for cancellation scenarios
658
- 7. **Use `isOnLeft` for secondary actions** - Helps with visual hierarchy
659
- 8. **Customize responsibly** - Maintain accessibility and usability standards
672
+ > Note: `isReturnSubmit` overrides `noActionReturn` and returns the serialized form values as the action `value`. `isSubmit` still triggers `requestSubmit()` to allow native validation flows.
660
673
 
661
674
  ## Types
662
675
 
@@ -684,6 +697,17 @@ Custom styles for each variant type.
684
697
  - ARIA labels provided for interactive elements
685
698
  - Supports custom ARIA attributes via className injection
686
699
 
700
+ ## Best Practices
701
+
702
+ 1. **Mount `BaseModalRenderer` at root level** - Required for modals to render
703
+ 2. **Use default configs for consistency** - Set common styles/behaviors once
704
+ 3. **Provide meaningful button labels** - Users should know what each button does
705
+ 4. **Use appropriate variants** - Use `danger` for destructive actions, `success` for confirmations
706
+ 5. **Keep content concise** - Dialogs should be focused and brief
707
+ 6. **Handle both resolve and reject** - Account for cancellation scenarios
708
+ 7. **Use `isOnLeft` for secondary actions** - Helps with visual hierarchy
709
+ 8. **Customize responsibly** - Maintain accessibility and usability standards
710
+
687
711
  ## Troubleshooting
688
712
 
689
713
  ### Dialog not appearing
@@ -699,6 +723,14 @@ Custom styles for each variant type.
699
723
  - Ensure action buttons have appropriate `value` or are configured as cancel buttons
700
724
  - Check that action click handlers don't prevent default behavior
701
725
 
726
+
727
+ ## Bundle Size
728
+
729
+ - ESM: ~4.06 kB gzipped (13.48 kB raw)
730
+ - CJS: ~3.48 kB gzipped (9.21 kB raw)
731
+
732
+ Measured with Vite build for v0.0.1.
733
+
702
734
  ## License
703
735
 
704
736
  MIT
package/dist/README.md CHANGED
@@ -72,13 +72,6 @@ function MyComponent() {
72
72
  }
73
73
  ```
74
74
 
75
- ## Bundle Size
76
-
77
- - ESM: ~4.06 kB gzipped (13.48 kB raw)
78
- - CJS: ~3.48 kB gzipped (9.21 kB raw)
79
-
80
- Measured with Vite build for v0.0.1.
81
-
82
75
  ## API Reference
83
76
 
84
77
  ### useHookDialog
@@ -276,6 +269,8 @@ function DeleteConfirm() {
276
269
  }
277
270
  ```
278
271
 
272
+ ![Example 1 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-1.png)
273
+
279
274
  ### Example 2: Multiple Action Rows
280
275
 
281
276
  ```tsx
@@ -294,6 +289,8 @@ await requestDialog({
294
289
  });
295
290
  ```
296
291
 
292
+ ![Example 2 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-2.png)
293
+
297
294
  ### Example 3: Custom Styling
298
295
 
299
296
  ```tsx
@@ -318,6 +315,8 @@ await requestDialog({
318
315
  });
319
316
  ```
320
317
 
318
+ ![Example 3 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-3.png)
319
+
321
320
  ### Example 4: Custom Button Variants
322
321
 
323
322
  ```tsx
@@ -338,6 +337,8 @@ await requestDialog({
338
337
  });
339
338
  ```
340
339
 
340
+ ![Example 4 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-4.png)
341
+
341
342
  ### Example 5: Button Click Handlers
342
343
 
343
344
  ```tsx
@@ -357,6 +358,8 @@ await requestDialog({
357
358
  });
358
359
  ```
359
360
 
361
+ ![Example 5 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-5.png)
362
+
360
363
  ### Example 6: Rich Content
361
364
 
362
365
  ```tsx
@@ -377,6 +380,8 @@ await requestDialog({
377
380
  });
378
381
  ```
379
382
 
383
+ ![Example 6 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-6.png)
384
+
380
385
  ### Example 7: Default Configuration
381
386
 
382
387
  ```tsx
@@ -395,6 +400,8 @@ await requestDialog({
395
400
  });
396
401
  ```
397
402
 
403
+ ![Example 7 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-7.png)
404
+
398
405
  ### Example 8: Alert Dialog
399
406
 
400
407
  ```tsx
@@ -413,6 +420,8 @@ async function showAlert(message: string) {
413
420
  showAlert('Operation completed successfully!');
414
421
  ```
415
422
 
423
+ ![Example 8 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-8.png)
424
+
416
425
  ### Example 9: Multiple Choice with Different Values
417
426
 
418
427
  ```tsx
@@ -439,6 +448,8 @@ const handleSaveOptions = async () => {
439
448
  };
440
449
  ```
441
450
 
451
+ ![Example 9 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-9.png)
452
+
442
453
  ### Example 10: Numeric Rating Dialog
443
454
 
444
455
  ```tsx
@@ -468,6 +479,8 @@ const handleRating = async () => {
468
479
  };
469
480
  ```
470
481
 
482
+ ![Example 10 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-10.png)
483
+
471
484
  ### Example 11: Conditional Actions Based on Result
472
485
 
473
486
  ```tsx
@@ -515,6 +528,8 @@ const handleFileOperation = async () => {
515
528
  };
516
529
  ```
517
530
 
531
+ ![Example 11 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-11.png)
532
+
518
533
  ### Example 12: Handle Cancel vs Reject
519
534
 
520
535
  ```tsx
@@ -544,6 +559,8 @@ const handleWithErrorHandling = async () => {
544
559
  };
545
560
  ```
546
561
 
562
+ ![Example 12 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-12.png)
563
+
547
564
  ### Example 13: Form Submission with Validation
548
565
 
549
566
  ```tsx
@@ -587,6 +604,33 @@ const handleFormSubmit = async (formData: any) => {
587
604
  };
588
605
  ```
589
606
 
607
+ ![Example 13 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-13.png)
608
+
609
+ ### Example 14: Boolean Result with Custom Values
610
+
611
+ ```tsx
612
+ const [requestDialog] = useHookDialog();
613
+
614
+ const handleLogout = async () => {
615
+ const shouldLogout = await requestDialog({
616
+ title: 'Confirm Logout',
617
+ content: 'Are you sure you want to log out?',
618
+ actions: [[
619
+ { title: 'Stay Logged In', variant: 'secondary', value: false },
620
+ { title: 'Log Out', variant: 'danger', value: true }
621
+ ]]
622
+ });
623
+
624
+ if (shouldLogout) {
625
+ // Perform logout
626
+ sessionStorage.clear();
627
+ window.location.href = '/login';
628
+ }
629
+ };
630
+ ```
631
+
632
+ ![Example 14 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-14.png)
633
+
590
634
  ### Example 15: Form Dialog Returning Values (isReturnSubmit)
591
635
 
592
636
  ```tsx
@@ -623,40 +667,9 @@ async function openProfileDialog() {
623
667
  }
624
668
  ```
625
669
 
626
- > Note: `isReturnSubmit` overrides `noActionReturn` and returns the serialized form values as the action `value`. `isSubmit` still triggers `requestSubmit()` to allow native validation flows.
627
- ### Example 14: Boolean Result with Custom Values
628
-
629
- ```tsx
630
- const [requestDialog] = useHookDialog();
670
+ ![Example 15 Screenshot](https://jgd.qzz.io/screenshots/react-hook-dialog-example-15.png)
631
671
 
632
- const handleLogout = async () => {
633
- const shouldLogout = await requestDialog({
634
- title: 'Confirm Logout',
635
- content: 'Are you sure you want to log out?',
636
- actions: [[
637
- { title: 'Stay Logged In', variant: 'secondary', value: false },
638
- { title: 'Log Out', variant: 'danger', value: true }
639
- ]]
640
- });
641
-
642
- if (shouldLogout) {
643
- // Perform logout
644
- sessionStorage.clear();
645
- window.location.href = '/login';
646
- }
647
- };
648
- ```
649
-
650
- ## Best Practices
651
-
652
- 1. **Mount `BaseModalRenderer` at root level** - Required for modals to render
653
- 2. **Use default configs for consistency** - Set common styles/behaviors once
654
- 3. **Provide meaningful button labels** - Users should know what each button does
655
- 4. **Use appropriate variants** - Use `danger` for destructive actions, `success` for confirmations
656
- 5. **Keep content concise** - Dialogs should be focused and brief
657
- 6. **Handle both resolve and reject** - Account for cancellation scenarios
658
- 7. **Use `isOnLeft` for secondary actions** - Helps with visual hierarchy
659
- 8. **Customize responsibly** - Maintain accessibility and usability standards
672
+ > Note: `isReturnSubmit` overrides `noActionReturn` and returns the serialized form values as the action `value`. `isSubmit` still triggers `requestSubmit()` to allow native validation flows.
660
673
 
661
674
  ## Types
662
675
 
@@ -684,6 +697,17 @@ Custom styles for each variant type.
684
697
  - ARIA labels provided for interactive elements
685
698
  - Supports custom ARIA attributes via className injection
686
699
 
700
+ ## Best Practices
701
+
702
+ 1. **Mount `BaseModalRenderer` at root level** - Required for modals to render
703
+ 2. **Use default configs for consistency** - Set common styles/behaviors once
704
+ 3. **Provide meaningful button labels** - Users should know what each button does
705
+ 4. **Use appropriate variants** - Use `danger` for destructive actions, `success` for confirmations
706
+ 5. **Keep content concise** - Dialogs should be focused and brief
707
+ 6. **Handle both resolve and reject** - Account for cancellation scenarios
708
+ 7. **Use `isOnLeft` for secondary actions** - Helps with visual hierarchy
709
+ 8. **Customize responsibly** - Maintain accessibility and usability standards
710
+
687
711
  ## Troubleshooting
688
712
 
689
713
  ### Dialog not appearing
@@ -699,6 +723,14 @@ Custom styles for each variant type.
699
723
  - Ensure action buttons have appropriate `value` or are configured as cancel buttons
700
724
  - Check that action click handlers don't prevent default behavior
701
725
 
726
+
727
+ ## Bundle Size
728
+
729
+ - ESM: ~4.06 kB gzipped (13.48 kB raw)
730
+ - CJS: ~3.48 kB gzipped (9.21 kB raw)
731
+
732
+ Measured with Vite build for v0.0.1.
733
+
702
734
  ## License
703
735
 
704
736
  MIT
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),t=require("../constants/theme.cjs.js"),o=require("../utils/utils.cjs.js"),n=require("@rokku-x/react-hook-modal"),i=require("react"),a=n.ModalWindow;exports.default=function({modalWindowId:s,handleAction:l,handleClose:r,config:c}){const{actions:u=[],title:d,backdropCancel:f,showCloseButton:m,classNames:p={},styles:h={},variantStyles:g={}}=c;let{content:y}=c;const b=(u.length?u:[[{title:"OK",variant:"primary"}]]).filter(e=>e&&e.length),x={...t.baseVariantStyles,...g},k=i.useRef(null),v=i.useRef(null),j=i.useRef(null);return i.useEffect(()=>{const e=k.current;if(!e)return;const t=document.activeElement;if(v.current)v.current.focus();else{const t=e.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");t?t.focus():(e.setAttribute("tabindex","-1"),e.focus())}const o=t=>{if("Escape"===t.key)t.stopPropagation(),r(s);else if("Tab"===t.key){const o=Array.from(e.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")).filter(Boolean);if(0===o.length)return void t.preventDefault();const n=o[0],i=o[o.length-1];t.shiftKey?document.activeElement===n&&(t.preventDefault(),i.focus()):document.activeElement===i&&(t.preventDefault(),n.focus())}};return e.addEventListener("keydown",o),()=>{e.removeEventListener("keydown",o),t&&t.focus&&t.focus()}},[r,s]),o.IsForm(y)&&(y=i.cloneElement(y,{ref:j})),e.jsx(n.ModalBackdrop,{onClick:()=>f&&r(s),className:p.backdrop||"",style:h.backdrop,children:e.jsxs(a,{ref:k,role:"dialog","aria-modal":"true","aria-labelledby":d?`${s}-title`:void 0,className:p.dialog||"",style:h.dialog,children:[m&&e.jsx("button",{type:"button",className:`hook-dialog-close-button ${p.closeButton||""}`,"aria-label":"Close",onClick:()=>r(s),style:{position:"absolute",top:0,right:0,transform:"translate(75%, -75%)",width:32,height:32,background:"none",border:"none",fontSize:21,cursor:"pointer",lineHeight:1,color:"#555",...h.closeButton},children:"×"}),d&&e.jsx("h3",{id:`${s}-title`,className:`hook-dialog-title ${p.title||""}`,style:{margin:"0 0 15px",fontSize:20,...h.title},children:d}),y&&e.jsx("div",{className:`hook-dialog-content ${p.content||""}`,style:{marginBottom:15,color:"#555",...h.content},children:y}),e.jsx("div",{className:`hook-dialog-actions ${p.actions||""}`,style:{display:"flex",flexDirection:"column",gap:10,paddingTop:15,...h.actions},children:b.map((t,n)=>{const i=t.filter(e=>e.isOnLeft),a=t.filter(e=>!e.isOnLeft),r=(t,n)=>{const i=x[t.variant||"secondary"]||x.secondary;return e.jsx("button",{ref:e=>{t.isFocused&&e&&(v.current=e)},"data-action-focused":t.isFocused?"true":void 0,className:`hook-dialog-action-button hook-dialog-action-${t.variant||"secondary"} ${p.actionButton||""} ${t.className||""}`,onClick:e=>{try{t.onClick?.(e,t)}catch{}return t.isSubmit&&c.isReturnSubmit&&j.current?l(s,t,o.FormDataToObject(new FormData(j.current))):(t.isSubmit&&j.current?.requestSubmit(),t.noActionReturn?e.stopPropagation():void l(s,t))},style:{border:"none",borderRadius:15,padding:"10px 18px",fontSize:14,fontWeight:800,cursor:"pointer",...i,...h.actionButton,...t.style||{}},children:t.title},`${t.title}-${n}`)};return e.jsxs("div",{className:`hook-dialog-actions-row ${p.actionsRow||""}`,style:{display:"flex",gap:8,justifyContent:"space-between",...h.actionsRow},children:[e.jsx("div",{className:"hook-dialog-actions-left",style:{display:"flex",gap:8},children:i.map((e,t)=>r(e,t))}),e.jsx("div",{className:"hook-dialog-actions-right",style:{display:"flex",gap:8},children:a.map((e,t)=>r(e,t))})]},n)})})]})})};
@@ -0,0 +1,6 @@
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import{baseVariantStyles as o}from"../constants/theme.esm.js";import{IsForm as n,FormDataToObject as i}from"../utils/utils.esm.js";import{ModalBackdrop as a,ModalWindow as l}from"@rokku-x/react-hook-modal";import r,{useRef as s,useEffect as c}from"react";const d=l;function u({modalWindowId:l,handleAction:u,handleClose:m,config:f}){const{actions:p=[],title:h,backdropCancel:g,showCloseButton:y,classNames:b={},styles:k={},variantStyles:v={}}=f;let{content:x}=f;const N=(p.length?p:[[{title:"OK",variant:"primary"}]]).filter(t=>t&&t.length),$={...o,...v},w=s(null),S=s(null),C=s(null);return c(()=>{const t=w.current;if(!t)return;const e=document.activeElement;if(S.current)S.current.focus();else{const e=t.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");e?e.focus():(t.setAttribute("tabindex","-1"),t.focus())}const o=e=>{if("Escape"===e.key)e.stopPropagation(),m(l);else if("Tab"===e.key){const o=Array.from(t.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")).filter(Boolean);if(0===o.length)return void e.preventDefault();const n=o[0],i=o[o.length-1];e.shiftKey?document.activeElement===n&&(e.preventDefault(),i.focus()):document.activeElement===i&&(e.preventDefault(),n.focus())}};return t.addEventListener("keydown",o),()=>{t.removeEventListener("keydown",o),e&&e.focus&&e.focus()}},[m,l]),n(x)&&(x=r.cloneElement(x,{ref:C})),/* @__PURE__ */t(a,{onClick:()=>g&&m(l),className:b.backdrop||"",style:k.backdrop,children:/* @__PURE__ */e(d,{ref:w,role:"dialog","aria-modal":"true","aria-labelledby":h?`${l}-title`:void 0,className:b.dialog||"",style:k.dialog,children:[y&&/* @__PURE__ */t("button",{type:"button",className:`hook-dialog-close-button ${b.closeButton||""}`,"aria-label":"Close",onClick:()=>m(l),style:{position:"absolute",top:0,right:0,transform:"translate(75%, -75%)",width:32,height:32,background:"none",border:"none",fontSize:21,cursor:"pointer",lineHeight:1,color:"#555",...k.closeButton},children:"×"}),h&&/* @__PURE__ */t("h3",{id:`${l}-title`,className:`hook-dialog-title ${b.title||""}`,style:{margin:"0 0 15px",fontSize:20,...k.title},children:h}),x&&/* @__PURE__ */t("div",{className:`hook-dialog-content ${b.content||""}`,style:{marginBottom:15,color:"#555",...k.content},children:x}),
2
+ /* @__PURE__ */t("div",{className:`hook-dialog-actions ${b.actions||""}`,style:{display:"flex",flexDirection:"column",gap:10,paddingTop:15,...k.actions},children:N.map((o,n)=>{const a=o.filter(t=>t.isOnLeft),r=o.filter(t=>!t.isOnLeft),s=(e,o)=>{const n=$[e.variant||"secondary"]||$.secondary;/* @__PURE__ */
3
+ return t("button",{ref:t=>{e.isFocused&&t&&(S.current=t)},"data-action-focused":e.isFocused?"true":void 0,className:`hook-dialog-action-button hook-dialog-action-${e.variant||"secondary"} ${b.actionButton||""} ${e.className||""}`,onClick:t=>{try{e.onClick?.(t,e)}catch{}return e.isSubmit&&f.isReturnSubmit&&C.current?u(l,e,i(new FormData(C.current))):(e.isSubmit&&C.current?.requestSubmit(),e.noActionReturn?t.stopPropagation():void u(l,e))},style:{border:"none",borderRadius:15,padding:"10px 18px",fontSize:14,fontWeight:800,cursor:"pointer",...n,...k.actionButton,...e.style||{}},children:e.title},`${e.title}-${o}`)};/* @__PURE__ */
4
+ return e("div",{className:`hook-dialog-actions-row ${b.actionsRow||""}`,style:{display:"flex",gap:8,justifyContent:"space-between",...k.actionsRow},children:[
5
+ /* @__PURE__ */t("div",{className:"hook-dialog-actions-left",style:{display:"flex",gap:8},children:a.map((t,e)=>s(t,e))}),
6
+ /* @__PURE__ */t("div",{className:"hook-dialog-actions-right",style:{display:"flex",gap:8},children:r.map((t,e)=>s(t,e))})]},n)})})]})})}export{u as default};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.baseVariantStyles={primary:{backgroundColor:"#2563eb",color:"#fff"},secondary:{backgroundColor:"#e5e7eb",color:"#111"},danger:{backgroundColor:"#dc2626",color:"#fff"},success:{backgroundColor:"#16a34a",color:"#fff"},warning:{backgroundColor:"#f59e0b",color:"#111"},info:{backgroundColor:"#0ea5e9",color:"#fff"},neutral:{backgroundColor:"#6b7280",color:"#fff"}};
@@ -0,0 +1 @@
1
+ const o={primary:{backgroundColor:"#2563eb",color:"#fff"},secondary:{backgroundColor:"#e5e7eb",color:"#111"},danger:{backgroundColor:"#dc2626",color:"#fff"},success:{backgroundColor:"#16a34a",color:"#fff"},warning:{backgroundColor:"#f59e0b",color:"#111"},info:{backgroundColor:"#0ea5e9",color:"#fff"},neutral:{backgroundColor:"#6b7280",color:"#fff"}};export{o as baseVariantStyles};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react"),a=require("@rokku-x/react-hook-modal"),s=require("../components/ModalWindow.cjs.js"),t=require("../store/dialogStore.cjs.js");exports.default=function(o){const{instances:n,addInstance:l,removeInstance:c,getInstance:r}=t.useDialogStore(),i=a.useBaseModal(),u=e.useCallback(e=>{const a=r(e);a&&(i.popModal(e),!1!==a.config.rejectOnCancel?a.reject(a.config.defaultCancelValue):a.resolve(a.config.defaultCancelValue),c(e))},[r,c,i]),d=e.useCallback((e,a)=>{const s=r(e);s&&(i.popModal(e),a.isCancel&&!1!==s.config.rejectOnCancel?s.reject(a.value):s.resolve(a.value),c(e))},[r,c,i]);return[function(a){return new Promise((t,n)=>{const c=Math.random().toString(36).substring(2,6),r={...o,...a,classNames:{...o?.classNames,...a.classNames},styles:{...o?.styles,...a.styles},variantStyles:{...o?.variantStyles,...a.variantStyles}},f={id:c,config:r,resolve:t,reject:n};l(f),f.id=i.pushModal(c,e.createElement(s.default,{config:r,modalWindowId:c,handleClose:u,handleAction:d}))})}]};
@@ -0,0 +1 @@
1
+ import e,{useCallback as o}from"react";import{useBaseModal as t}from"@rokku-x/react-hook-modal";import n from"../components/ModalWindow.esm.js";import{useDialogStore as a}from"../store/dialogStore.esm.js";function s(s){const{instances:l,addInstance:r,removeInstance:c,getInstance:i}=a(),d=t(),m=o(e=>{const o=i(e);o&&(d.popModal(e),!1!==o.config.rejectOnCancel?o.reject(o.config.defaultCancelValue):o.resolve(o.config.defaultCancelValue),c(e))},[i,c,d]),f=o((e,o)=>{const t=i(e);t&&(d.popModal(e),o.isCancel&&!1!==t.config.rejectOnCancel?t.reject(o.value):t.resolve(o.value),c(e))},[i,c,d]);return[function(o){return new Promise((t,a)=>{const l=Math.random().toString(36).substring(2,6),c={...s,...o,classNames:{...s?.classNames,...o.classNames},styles:{...s?.styles,...o.styles},variantStyles:{...s?.variantStyles,...o.variantStyles}},i={id:l,config:c,resolve:t,reject:a};r(i),i.id=d.pushModal(l,e.createElement(n,{config:c,modalWindowId:l,handleClose:m,handleAction:f}))})}]}export{s as default};
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("@rokku-x/react-hook-modal"),p=require("react"),d=require("react/jsx-runtime"),$=require("zustand"),D={primary:{backgroundColor:"#2563eb",color:"#fff"},secondary:{backgroundColor:"#e5e7eb",color:"#111"},danger:{backgroundColor:"#dc2626",color:"#fff"},success:{backgroundColor:"#16a34a",color:"#fff"},warning:{backgroundColor:"#f59e0b",color:"#111"},info:{backgroundColor:"#0ea5e9",color:"#fff"},neutral:{backgroundColor:"#6b7280",color:"#fff"}};function w(t){const u={};return t.forEach((n,s)=>{if(s in u){const a=u[s];Array.isArray(a)?a.push(n):u[s]=[a,n]}else u[s]=n}),u}const A=t=>p.isValidElement(t)&&(t.type==="form"||typeof t.type=="string"&&t.type.toLowerCase()==="form"),q=j.ModalWindow;function O({modalWindowId:t,handleAction:u,handleClose:n,config:s}){const{actions:a=[],title:g,backdropCancel:R,showCloseButton:N,classNames:f={},styles:o={},variantStyles:r={}}=s;let{content:l}=s;const y=(a.length?a:[[{title:"OK",variant:"primary"}]]).filter(c=>c&&c.length),h={...D,...r},x=()=>R&&n(t),M=p.useRef(null),B=p.useRef(null),C=p.useRef(null);return p.useEffect(()=>{const c=M.current;if(!c)return;const k=document.activeElement;if(B.current)B.current.focus();else{const i=c.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");i?i.focus():(c.setAttribute("tabindex","-1"),c.focus())}const S=i=>{if(i.key==="Escape")i.stopPropagation(),n(t);else if(i.key==="Tab"){const b=Array.from(c.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")).filter(Boolean);if(b.length===0){i.preventDefault();return}const e=b[0],m=b[b.length-1];i.shiftKey?document.activeElement===e&&(i.preventDefault(),m.focus()):document.activeElement===m&&(i.preventDefault(),e.focus())}};return c.addEventListener("keydown",S),()=>{c.removeEventListener("keydown",S),k&&k.focus&&k.focus()}},[n,t]),A(l)&&(l=p.cloneElement(l,{ref:C})),d.jsx(j.ModalBackdrop,{onClick:x,className:f.backdrop||"",style:o.backdrop,children:d.jsxs(q,{ref:M,role:"dialog","aria-modal":"true","aria-labelledby":g?`${t}-title`:void 0,className:f.dialog||"",style:o.dialog,children:[N&&d.jsx("button",{type:"button",className:`hook-dialog-close-button ${f.closeButton||""}`,"aria-label":"Close",onClick:()=>n(t),style:{position:"absolute",top:0,right:0,transform:"translate(75%, -75%)",width:32,height:32,background:"none",border:"none",fontSize:21,cursor:"pointer",lineHeight:1,color:"#555",...o.closeButton},children:"×"}),g&&d.jsx("h3",{id:`${t}-title`,className:`hook-dialog-title ${f.title||""}`,style:{margin:"0 0 15px",fontSize:20,...o.title},children:g}),l&&d.jsx("div",{className:`hook-dialog-content ${f.content||""}`,style:{marginBottom:15,color:"#555",...o.content},children:l}),d.jsx("div",{className:`hook-dialog-actions ${f.actions||""}`,style:{display:"flex",flexDirection:"column",gap:10,paddingTop:15,...o.actions},children:y.map((c,k)=>{const S=c.filter(e=>e.isOnLeft),i=c.filter(e=>!e.isOnLeft),b=(e,m)=>{const E=h[e.variant||"secondary"]||h.secondary;return d.jsx("button",{ref:v=>{e.isFocused&&v&&(B.current=v)},"data-action-focused":e.isFocused?"true":void 0,className:`hook-dialog-action-button hook-dialog-action-${e.variant||"secondary"} ${f.actionButton||""} ${e.className||""}`,onClick:v=>{if(e.onClick?.(v,e),e.isSubmit&&s.isReturnSubmit&&C.current)return u(t,e,w(new FormData(C.current)));if(e.isSubmit&&C.current?.requestSubmit(),e.noActionReturn)return v.stopPropagation();u(t,e)},style:{border:"none",borderRadius:15,padding:"10px 18px",fontSize:14,fontWeight:800,cursor:"pointer",...E,...o.actionButton,...e.style||{}},children:e.title},`${e.title}-${m}`)};return d.jsxs("div",{className:`hook-dialog-actions-row ${f.actionsRow||""}`,style:{display:"flex",gap:8,justifyContent:"space-between",...o.actionsRow},children:[d.jsx("div",{className:"hook-dialog-actions-left",style:{display:"flex",gap:8},children:S.map((e,m)=>b(e,m))}),d.jsx("div",{className:"hook-dialog-actions-right",style:{display:"flex",gap:8},children:i.map((e,m)=>b(e,m))})]},k)})})]})})}const F=$.create((t,u)=>({instances:[],addInstance:n=>t(s=>({instances:[...s.instances,n]})),removeInstance:n=>t(s=>({instances:s.instances.filter(a=>a.id!==n)})),getInstance:n=>u().instances.find(s=>s.id===n)}));function L(t){const{instances:u,addInstance:n,removeInstance:s,getInstance:a}=F(),g=j.useBaseModal(),R=p.useCallback(o=>{const r=a(o);r&&(g.popModal(o),r.config.rejectOnCancel!==!1?r.reject(r.config.defaultCancelValue):r.resolve(r.config.defaultCancelValue),s(o))},[a,s,g]),N=p.useCallback((o,r)=>{const l=a(o);l&&(g.popModal(o),r.isCancel&&l.config.rejectOnCancel!==!1?l.reject(r.value):l.resolve(r.value),s(o))},[a,s,g]);function f(o){return new Promise((r,l)=>{const y=Math.random().toString(36).substring(2,6),h={...t,...o,classNames:{...t?.classNames,...o.classNames},styles:{...t?.styles,...o.styles},variantStyles:{...t?.variantStyles,...o.variantStyles}},x={id:y,config:h,resolve:r,reject:l};n(x),x.id=g.pushModal(y,p.createElement(O,{config:h,modalWindowId:y,handleClose:R,handleAction:N}))})}return[f]}Object.defineProperty(exports,"BaseModalRenderer",{enumerable:!0,get:()=>j.BaseModalRenderer});exports.useHookDialog=L;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@rokku-x/react-hook-modal"),o=require("./hooks/useHookDialog.cjs.js");Object.defineProperty(exports,"BaseModalRenderer",{enumerable:!0,get:()=>e.BaseModalRenderer}),exports.useHookDialog=o.default;
package/dist/index.esm.js CHANGED
@@ -1,192 +1 @@
1
- "use client";
2
- import { ModalBackdrop as A, ModalWindow as j, useBaseModal as F } from "@rokku-x/react-hook-modal";
3
- import { BaseModalRenderer as X } from "@rokku-x/react-hook-modal";
4
- import R, { useRef as E, useEffect as O, useCallback as M } from "react";
5
- import { jsx as p, jsxs as w } from "react/jsx-runtime";
6
- import { create as L } from "zustand";
7
- const V = {
8
- primary: { backgroundColor: "#2563eb", color: "#fff" },
9
- secondary: { backgroundColor: "#e5e7eb", color: "#111" },
10
- danger: { backgroundColor: "#dc2626", color: "#fff" },
11
- success: { backgroundColor: "#16a34a", color: "#fff" },
12
- warning: { backgroundColor: "#f59e0b", color: "#111" },
13
- info: { backgroundColor: "#0ea5e9", color: "#fff" },
14
- neutral: { backgroundColor: "#6b7280", color: "#fff" }
15
- };
16
- function q(t) {
17
- const u = {};
18
- return t.forEach((s, n) => {
19
- if (n in u) {
20
- const a = u[n];
21
- Array.isArray(a) ? a.push(s) : u[n] = [a, s];
22
- } else
23
- u[n] = s;
24
- }), u;
25
- }
26
- const z = (t) => R.isValidElement(t) && (t.type === "form" || typeof t.type == "string" && t.type.toLowerCase() === "form"), I = j;
27
- function K({ modalWindowId: t, handleAction: u, handleClose: s, config: n }) {
28
- const { actions: a = [], title: d, backdropCancel: S, showCloseButton: N, classNames: f = {}, styles: o = {}, variantStyles: r = {} } = n;
29
- let { content: l } = n;
30
- const y = (a.length ? a : [[{ title: "OK", variant: "primary" }]]).filter((i) => i && i.length), b = { ...V, ...r }, k = () => S && s(t), $ = E(null), B = E(null), x = E(null);
31
- return O(() => {
32
- const i = $.current;
33
- if (!i) return;
34
- const h = document.activeElement;
35
- if (B.current)
36
- B.current.focus();
37
- else {
38
- const c = i.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
39
- c ? c.focus() : (i.setAttribute("tabindex", "-1"), i.focus());
40
- }
41
- const C = (c) => {
42
- if (c.key === "Escape")
43
- c.stopPropagation(), s(t);
44
- else if (c.key === "Tab") {
45
- const g = Array.from(i.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")).filter(Boolean);
46
- if (g.length === 0) {
47
- c.preventDefault();
48
- return;
49
- }
50
- const e = g[0], m = g[g.length - 1];
51
- c.shiftKey ? document.activeElement === e && (c.preventDefault(), m.focus()) : document.activeElement === m && (c.preventDefault(), e.focus());
52
- }
53
- };
54
- return i.addEventListener("keydown", C), () => {
55
- i.removeEventListener("keydown", C), h && h.focus && h.focus();
56
- };
57
- }, [s, t]), z(l) && (l = R.cloneElement(l, { ref: x })), /* @__PURE__ */ p(
58
- A,
59
- {
60
- onClick: k,
61
- className: f.backdrop || "",
62
- style: o.backdrop,
63
- children: /* @__PURE__ */ w(
64
- I,
65
- {
66
- ref: $,
67
- role: "dialog",
68
- "aria-modal": "true",
69
- "aria-labelledby": d ? `${t}-title` : void 0,
70
- className: f.dialog || "",
71
- style: o.dialog,
72
- children: [
73
- N && /* @__PURE__ */ p(
74
- "button",
75
- {
76
- type: "button",
77
- className: `hook-dialog-close-button ${f.closeButton || ""}`,
78
- "aria-label": "Close",
79
- onClick: () => s(t),
80
- style: {
81
- position: "absolute",
82
- top: 0,
83
- right: 0,
84
- transform: "translate(75%, -75%)",
85
- width: 32,
86
- height: 32,
87
- background: "none",
88
- border: "none",
89
- fontSize: 21,
90
- cursor: "pointer",
91
- lineHeight: 1,
92
- color: "#555",
93
- ...o.closeButton
94
- },
95
- children: "×"
96
- }
97
- ),
98
- d && /* @__PURE__ */ p("h3", { id: `${t}-title`, className: `hook-dialog-title ${f.title || ""}`, style: { margin: "0 0 15px", fontSize: 20, ...o.title }, children: d }),
99
- l && /* @__PURE__ */ p("div", { className: `hook-dialog-content ${f.content || ""}`, style: { marginBottom: 15, color: "#555", ...o.content }, children: l }),
100
- /* @__PURE__ */ p("div", { className: `hook-dialog-actions ${f.actions || ""}`, style: { display: "flex", flexDirection: "column", gap: 10, paddingTop: 15, ...o.actions }, children: y.map((i, h) => {
101
- const C = i.filter((e) => e.isOnLeft), c = i.filter((e) => !e.isOnLeft), g = (e, m) => {
102
- const D = b[e.variant || "secondary"] || b.secondary;
103
- return /* @__PURE__ */ p(
104
- "button",
105
- {
106
- ref: (v) => {
107
- e.isFocused && v && (B.current = v);
108
- },
109
- "data-action-focused": e.isFocused ? "true" : void 0,
110
- className: `hook-dialog-action-button hook-dialog-action-${e.variant || "secondary"} ${f.actionButton || ""} ${e.className || ""}`,
111
- onClick: (v) => {
112
- if (e.onClick?.(v, e), e.isSubmit && n.isReturnSubmit && x.current) return u(t, e, q(new FormData(x.current)));
113
- if (e.isSubmit && x.current?.requestSubmit(), e.noActionReturn) return v.stopPropagation();
114
- u(t, e);
115
- },
116
- style: {
117
- border: "none",
118
- borderRadius: 15,
119
- padding: "10px 18px",
120
- fontSize: 14,
121
- fontWeight: 800,
122
- cursor: "pointer",
123
- ...D,
124
- ...o.actionButton,
125
- ...e.style || {}
126
- },
127
- children: e.title
128
- },
129
- `${e.title}-${m}`
130
- );
131
- };
132
- return /* @__PURE__ */ w("div", { className: `hook-dialog-actions-row ${f.actionsRow || ""}`, style: { display: "flex", gap: 8, justifyContent: "space-between", ...o.actionsRow }, children: [
133
- /* @__PURE__ */ p("div", { className: "hook-dialog-actions-left", style: { display: "flex", gap: 8 }, children: C.map((e, m) => g(e, m)) }),
134
- /* @__PURE__ */ p("div", { className: "hook-dialog-actions-right", style: { display: "flex", gap: 8 }, children: c.map((e, m) => g(e, m)) })
135
- ] }, h);
136
- }) })
137
- ]
138
- }
139
- )
140
- }
141
- );
142
- }
143
- const P = L((t, u) => ({
144
- instances: [],
145
- addInstance: (s) => t((n) => ({
146
- instances: [...n.instances, s]
147
- })),
148
- removeInstance: (s) => t((n) => ({
149
- instances: n.instances.filter((a) => a.id !== s)
150
- })),
151
- getInstance: (s) => u().instances.find((n) => n.id === s)
152
- }));
153
- function Q(t) {
154
- const { instances: u, addInstance: s, removeInstance: n, getInstance: a } = P(), d = F(), S = M((o) => {
155
- const r = a(o);
156
- r && (d.popModal(o), r.config.rejectOnCancel !== !1 ? r.reject(r.config.defaultCancelValue) : r.resolve(r.config.defaultCancelValue), n(o));
157
- }, [a, n, d]), N = M((o, r) => {
158
- const l = a(o);
159
- l && (d.popModal(o), r.isCancel && l.config.rejectOnCancel !== !1 ? l.reject(r.value) : l.resolve(r.value), n(o));
160
- }, [a, n, d]);
161
- function f(o) {
162
- return new Promise((r, l) => {
163
- const y = Math.random().toString(36).substring(2, 6), b = {
164
- ...t,
165
- ...o,
166
- classNames: {
167
- ...t?.classNames,
168
- ...o.classNames
169
- },
170
- styles: {
171
- ...t?.styles,
172
- ...o.styles
173
- },
174
- variantStyles: {
175
- ...t?.variantStyles,
176
- ...o.variantStyles
177
- }
178
- }, k = {
179
- id: y,
180
- config: b,
181
- resolve: r,
182
- reject: l
183
- };
184
- s(k), k.id = d.pushModal(y, R.createElement(K, { config: b, modalWindowId: y, handleClose: S, handleAction: N }));
185
- });
186
- }
187
- return [f];
188
- }
189
- export {
190
- X as BaseModalRenderer,
191
- Q as useHookDialog
192
- };
1
+ import{BaseModalRenderer as o}from"@rokku-x/react-hook-modal";import{default as a}from"./hooks/useHookDialog.esm.js";export{o as BaseModalRenderer,a as useHookDialog};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("zustand").create((e,n)=>({instances:[],addInstance:n=>e(e=>({instances:[...e.instances,n]})),removeInstance:n=>e(e=>({instances:e.instances.filter(e=>e.id!==n)})),getInstance:e=>n().instances.find(n=>n.id===e)}));exports.useDialogStore=e;
@@ -0,0 +1 @@
1
+ import{create as n}from"zustand";const s=n((n,s)=>({instances:[],addInstance:s=>n(n=>({instances:[...n.instances,s]})),removeInstance:s=>n(n=>({instances:n.instances.filter(n=>n.id!==s)})),getInstance:n=>s().instances.find(s=>s.id===n)}));export{s as useDialogStore};
@@ -1 +1,238 @@
1
- export { }
1
+ /**
2
+ * Valid return values from dialog actions.
3
+ * Can be string, number, boolean, or undefined.
4
+ */
5
+ export type ValidValue = string | number | boolean | undefined;
6
+ /**
7
+ * Available button variant types for styling action buttons.
8
+ */
9
+ export declare const variantTypes: readonly ["primary", "secondary", "danger", "success", "warning", "info", "neutral"];
10
+ /**
11
+ * Type union of all available button variants.
12
+ * @see variantTypes
13
+ */
14
+ export type ModalVariant = typeof variantTypes[number];
15
+ /**
16
+ * Configuration for an individual action button in a dialog.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * const action: ModalAction = {
21
+ * title: 'Delete',
22
+ * value: true,
23
+ * variant: 'danger',
24
+ * onClick: (e) => console.log('Clicked!')
25
+ * };
26
+ * ```
27
+ */
28
+ export interface ModalAction {
29
+ /** The label or content displayed on the button */
30
+ title: React.ReactNode;
31
+ /** The value returned when this action is clicked */
32
+ value?: ValidValue;
33
+ /** If true, treats this as a cancel button (respects rejectOnCancel config) */
34
+ isCancel?: boolean;
35
+ /** If true, positions the button on the left side of the row */
36
+ isOnLeft?: boolean;
37
+ /** If true, this action should receive initial focus when the dialog opens */
38
+ isFocused?: boolean;
39
+ /** Visual style variant for the button */
40
+ variant?: ModalVariant;
41
+ /** Additional CSS class to apply to the button */
42
+ className?: string;
43
+ /** Inline styles to apply to the button */
44
+ style?: React.CSSProperties;
45
+ /** If true, renders the button as `type="submit"` to participate in native form submission */
46
+ isSubmit?: boolean;
47
+ /** If true, the button will NOT perform the default dialog action (won't call `handleAction`) — useful for custom handlers */
48
+ noActionReturn?: boolean;
49
+ /**
50
+ * Click handler called before the default action handling.
51
+ * Can receive both the event and action object, or just be called with no args.
52
+ */
53
+ onClick?: ((event: React.MouseEvent<HTMLButtonElement>, action: ModalAction) => void) | (() => void);
54
+ }
55
+ /**
56
+ * Custom CSS class names for dialog elements.
57
+ * All properties are optional and will be appended to default classes.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * const classNames: DialogClassNames = {
62
+ * dialog: 'my-custom-dialog',
63
+ * actionButton: 'my-button'
64
+ * };
65
+ * ```
66
+ */
67
+ export interface DialogClassNames {
68
+ /** CSS class for the backdrop overlay */
69
+ backdrop?: string;
70
+ /** CSS class for the dialog container */
71
+ dialog?: string;
72
+ /** CSS class for the close button */
73
+ closeButton?: string;
74
+ /** CSS class for the title element */
75
+ title?: string;
76
+ /** CSS class for the content container */
77
+ content?: string;
78
+ /** CSS class for the actions container */
79
+ actions?: string;
80
+ /** CSS class for each action button row */
81
+ actionsRow?: string;
82
+ /** CSS class for action buttons */
83
+ actionButton?: string;
84
+ }
85
+ /**
86
+ * Custom inline styles for dialog elements.
87
+ * All properties are optional and will be merged with default styles.
88
+ *
89
+ * @example
90
+ * ```tsx
91
+ * const styles: DialogStyles = {
92
+ * dialog: { borderRadius: '20px' },
93
+ * actionButton: { fontWeight: 'bold' }
94
+ * };
95
+ * ```
96
+ */
97
+ export interface DialogStyles {
98
+ /** Inline styles for the backdrop overlay */
99
+ backdrop?: React.CSSProperties;
100
+ /** Inline styles for the dialog container */
101
+ dialog?: React.CSSProperties;
102
+ /** Inline styles for the close button */
103
+ closeButton?: React.CSSProperties;
104
+ /** Inline styles for the title element */
105
+ title?: React.CSSProperties;
106
+ /** Inline styles for the content container */
107
+ content?: React.CSSProperties;
108
+ /** Inline styles for the actions container */
109
+ actions?: React.CSSProperties;
110
+ /** Inline styles for each action button row */
111
+ actionsRow?: React.CSSProperties;
112
+ /** Inline styles for action buttons */
113
+ actionButton?: React.CSSProperties;
114
+ }
115
+ /**
116
+ * Custom styles for button variants.
117
+ * Allows overriding the default color scheme for each variant type.
118
+ *
119
+ * @example
120
+ * ```tsx
121
+ * const variantStyles: DialogVariantStyles = {
122
+ * primary: { backgroundColor: '#7c3aed', color: '#fff' }
123
+ * };
124
+ * ```
125
+ */
126
+ export type DialogVariantStyles = Partial<Record<ModalVariant, React.CSSProperties>>;
127
+ /**
128
+ * Configuration options for a dialog call.
129
+ *
130
+ * @example
131
+ * ```tsx
132
+ * const config: ConfirmConfig = {
133
+ * title: 'Confirm',
134
+ * content: 'Are you sure?',
135
+ * actions: [[
136
+ * { title: 'Cancel', isCancel: true },
137
+ * { title: 'OK', variant: 'primary', value: true }
138
+ * ]]
139
+ * };
140
+ * ```
141
+ */
142
+ export interface ConfirmConfig {
143
+ /** Dialog title (can be string or React element) */
144
+ title?: React.ReactNode;
145
+ /** Dialog content (can be string or React element) */
146
+ content?: React.ReactNode;
147
+ /** If true, allows closing the dialog by clicking the backdrop (default: false) */
148
+ backdropCancel?: boolean;
149
+ /** If true, rejects the promise on cancel instead of resolving (default: true) */
150
+ rejectOnCancel?: boolean;
151
+ /** Value returned/rejected when dialog is cancelled */
152
+ defaultCancelValue?: ValidValue;
153
+ /** If true, shows the X close button in the top-right corner (default: false) */
154
+ showCloseButton?: boolean;
155
+ /** Custom CSS class names for dialog elements */
156
+ classNames?: DialogClassNames;
157
+ /** Custom inline styles for dialog elements */
158
+ styles?: DialogStyles;
159
+ /** Custom styles for button variants */
160
+ variantStyles?: DialogVariantStyles;
161
+ /**
162
+ * Array of action button rows. Each inner array represents a row of buttons.
163
+ * Buttons without isOnLeft flag are positioned on the right.
164
+ */
165
+ actions?: ModalAction[][];
166
+ /**
167
+ * If true and `content` is a `<form>`, clicking a submit action will return the submitted
168
+ * form values as the dialog result instead of using the action's `value`.
169
+ */
170
+ isReturnSubmit?: boolean;
171
+ }
172
+ /**
173
+ * Default configuration options for the useHookDialog hook.
174
+ * These settings apply to all dialogs created by the hook unless overridden per-call.
175
+ *
176
+ * @example
177
+ * ```tsx
178
+ * const defaultConfig: UseHookDialogConfig = {
179
+ * showCloseButton: false,
180
+ * backdropCancel: false,
181
+ * styles: { dialog: { maxWidth: '500px' } }
182
+ * };
183
+ * ```
184
+ */
185
+ export interface UseHookDialogConfig {
186
+ /** If true, allows closing dialogs by clicking the backdrop (default: false) */
187
+ backdropCancel?: boolean;
188
+ /** If true, rejects the promise on cancel instead of resolving (default: true) */
189
+ rejectOnCancel?: boolean;
190
+ /** Default value returned/rejected when dialog is cancelled */
191
+ defaultCancelValue?: ValidValue;
192
+ /** If true, shows the X close button in the top-right corner (default: false) */
193
+ showCloseButton?: boolean;
194
+ /** Default CSS class names for dialog elements */
195
+ classNames?: DialogClassNames;
196
+ /** Default inline styles for dialog elements */
197
+ styles?: DialogStyles;
198
+ /** Default styles for button variants */
199
+ variantStyles?: DialogVariantStyles;
200
+ }
201
+ /**
202
+ * Internal interface representing a dialog instance in the store.
203
+ * Extends ConfirmConfig with instance-specific properties.
204
+ * @internal
205
+ */
206
+ export interface ConfirmInstance<T = ValidValue> extends ConfirmConfig {
207
+ /** Unique identifier for this dialog instance */
208
+ id: string;
209
+ /** The configuration used for this dialog */
210
+ config: ConfirmConfig;
211
+ /** Promise resolve function */
212
+ resolve: (value: T) => void;
213
+ /** Promise reject function */
214
+ reject: (reason?: any) => void;
215
+ }
216
+ /**
217
+ * Props for the ModalWindow component.
218
+ * @internal
219
+ */
220
+ export interface ModalWindowProps {
221
+ /** Callback to close the modal */
222
+ handleClose: (id: string) => void;
223
+ /** Callback when an action button is clicked */
224
+ handleAction: HandleActionCallback;
225
+ /** Dialog configuration */
226
+ config: ConfirmConfig;
227
+ /** Unique identifier for this modal window */
228
+ modalWindowId: string;
229
+ }
230
+ interface HandleActionCallback {
231
+ (id: string, action: ModalAction, formValues: FormDataObject): void;
232
+ (id: string, action: ModalAction): void;
233
+ }
234
+ /**
235
+ * Friendly Form Data object type
236
+ */
237
+ export type FormDataObject = Record<string, FormDataEntryValue | FormDataEntryValue[]>;
238
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");exports.FormDataToObject=function(e){const t={};return e.forEach((e,r)=>{if(r in t){const o=t[r];Array.isArray(o)?o.push(e):t[r]=[o,e]}else t[r]=e}),t},exports.IsForm=t=>e.isValidElement(t)&&("form"===t.type||"string"==typeof t.type&&"form"===t.type.toLowerCase());
@@ -0,0 +1 @@
1
+ import r from"react";function t(r){const t={};return r.forEach((r,e)=>{if(e in t){const o=t[e];Array.isArray(o)?o.push(r):t[e]=[o,r]}else t[e]=r}),t}const e=t=>r.isValidElement(t)&&("form"===t.type||"string"==typeof t.type&&"form"===t.type.toLowerCase());export{t as FormDataToObject,e as IsForm};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokku-x/react-hook-dialog",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "author": "rokku-x",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,24 +8,8 @@
8
8
  },
9
9
  "main": "dist/index.cjs.js",
10
10
  "module": "dist/index.esm.js",
11
- "devDependencies": {
12
- "@changesets/cli": "^2.29.8",
13
- "@testing-library/jest-dom": "^6.9.1",
14
- "@testing-library/react": "^14.3.1",
15
- "@testing-library/user-event": "^14.6.1",
16
- "@types/jest": "^30.0.0",
17
- "@types/react": "^18.3.27",
18
- "@types/react-dom": "^18.3.7",
19
- "jsdom": "^24.1.3",
20
- "@vitejs/plugin-react": "^5.1.2",
21
- "typescript": "^5.9.3",
22
- "vite": "^7.3.1",
23
- "vite-plugin-dts": "^4.5.4",
24
- "vitest": "^1.6.1",
25
- "copyfiles": "^2.4.1"
26
- },
27
11
  "peerDependencies": {
28
- "@rokku-x/react-hook-modal": "^0.7.8",
12
+ "@rokku-x/react-hook-modal": "^0.9.0",
29
13
  "react": "^18.0.0",
30
14
  "react-dom": "^18.0.0",
31
15
  "zustand": "^5.0.10"
@@ -66,20 +50,6 @@
66
50
  "react-modal"
67
51
  ],
68
52
  "license": "MIT",
69
- "publishConfig": {
70
- "access": "public",
71
- "provenance": true
72
- },
73
- "scripts": {
74
- "build": "vite build && copyfiles -u 1 \"src/types/**/*.d.ts\" dist/ && copyfiles README.md LICENSE dist/",
75
- "publish:first": "npm publish --access public --provenance false",
76
- "dev": "vite",
77
- "preview": "vite preview",
78
- "test": "vitest",
79
- "changeset": "changeset",
80
- "version:changeset": "changeset version",
81
- "publish:changeset": "changeset publish --access public"
82
- },
83
53
  "sideEffects": false,
84
54
  "types": "dist/index.d.ts",
85
55
  "typesVersions": {
@@ -89,4 +59,4 @@
89
59
  ]
90
60
  }
91
61
  }
92
- }
62
+ }