@saas-ui/modals 1.5.1 → 1.5.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @saas-ui/modals
2
2
 
3
+ ## 1.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - d424898: Prevent input error in FormDialog to block cancel/close the modal.
8
+ - Updated dependencies [335acba]
9
+ - @saas-ui/forms@1.5.2
10
+
3
11
  ## 1.5.1
4
12
 
5
13
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,EAIL,SAAS,EACT,WAAW,EACX,aAAa,EACb,aAAa,EACd,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAa,cAAc,EAAE,MAAM,SAAS,CAAA;AAEnD,MAAM,WAAW,eAAe,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CAC7E,SAAQ,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,EACtC,IAAI,CACF,SAAS,CAAC,YAAY,CAAC,EACrB,QAAQ,GACR,eAAe,GACf,UAAU,GACV,UAAU,GACV,SAAS,GACT,UAAU,GACV,MAAM,GACN,gBAAgB,GAChB,kBAAkB,GAClB,kBAAkB,GAClB,2BAA2B,GAC3B,cAAc,GACd,YAAY,CACf;IACH;;;OAGG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B;AAED,eAAO,MAAM,UAAU;;MA6ElB,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,EAIL,SAAS,EACT,WAAW,EACX,aAAa,EACb,aAAa,EACd,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAa,cAAc,EAAE,MAAM,SAAS,CAAA;AAEnD,MAAM,WAAW,eAAe,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CAC7E,SAAQ,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,EACtC,IAAI,CACF,SAAS,CAAC,YAAY,CAAC,EACrB,QAAQ,GACR,eAAe,GACf,UAAU,GACV,UAAU,GACV,SAAS,GACT,UAAU,GACV,MAAM,GACN,gBAAgB,GAChB,kBAAkB,GAClB,kBAAkB,GAClB,2BAA2B,GAC3B,cAAc,GACd,YAAY,CACf;IACH;;;OAGG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B;AAED,eAAO,MAAM,UAAU;;MA+ElB,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("react"),n=require("@chakra-ui/react"),r=require("@saas-ui/button"),t=require("@chakra-ui/utils"),o=require("@saas-ui/forms");function l(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var i=/*#__PURE__*/l(e);function a(){return a=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},a.apply(this,arguments)}function u(e,n){if(null==e)return{};var r,t,o={},l=Object.keys(e);for(t=0;t<l.length;t++)n.indexOf(r=l[t])>=0||(o[r]=e[r]);return o}var c=["title","cancelLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","closeOnConfirm","leastDestructiveFocus","onClose","onCancel","onConfirm","children"],s=function(e){var t=e.title,o=e.cancelLabel,l=void 0===o?"Cancel":o,s=e.confirmLabel,d=void 0===s?"Confirm":s,f=e.cancelProps,m=e.confirmProps,p=e.buttonGroupProps,v=e.isOpen,C=e.closeOnCancel,h=void 0===C||C,E=e.closeOnConfirm,y=void 0===E||E,O=e.leastDestructiveFocus,b=void 0===O?"cancel":O,M=e.onClose,g=e.onCancel,D=e.onConfirm,x=e.children,F=u(e,c),B=i.useRef(null),P=i.useRef(null);/*#__PURE__*/return i.createElement(n.AlertDialog,a({isOpen:v,onClose:M},F,{leastDestructiveRef:"cancel"===b?B:P}),/*#__PURE__*/i.createElement(n.AlertDialogOverlay,null,/*#__PURE__*/i.createElement(n.AlertDialogContent,null,/*#__PURE__*/i.createElement(n.AlertDialogHeader,null,t),/*#__PURE__*/i.createElement(n.AlertDialogBody,null,x),/*#__PURE__*/i.createElement(n.AlertDialogFooter,null,/*#__PURE__*/i.createElement(r.ButtonGroup,p,/*#__PURE__*/i.createElement(r.Button,a({ref:B},f,{onClick:function(){null==g||g(),h&&M()}}),l),/*#__PURE__*/i.createElement(r.Button,a({ref:P},m,{onClick:function(){null==D||D(),y&&M()}}),d))))))},d=["title","children","isOpen","onClose","hideCloseButton","hideOverlay"],f=["footer","children"],m=function(e){var r=e.title,t=e.children,o=e.isOpen,l=e.onClose,c=e.hideCloseButton,s=e.hideOverlay,f=u(e,d);/*#__PURE__*/return i.createElement(n.Drawer,a({isOpen:o,onClose:l},f),!s&&/*#__PURE__*/i.createElement(n.DrawerOverlay,null),/*#__PURE__*/i.createElement(n.DrawerContent,null,/*#__PURE__*/i.createElement(n.DrawerHeader,null,r),!c&&/*#__PURE__*/i.createElement(n.DrawerCloseButton,null),t))},p=function(e){var r=e.footer,t=e.children,o=u(e,f);/*#__PURE__*/return i.createElement(m,o,/*#__PURE__*/i.createElement(n.DrawerBody,null,t),r&&/*#__PURE__*/i.createElement(n.DrawerFooter,null,r))},v=["title","footer","children","isOpen","onClose","hideCloseButton","hideOverlay"],C=["children"],h=function(e){var r=e.title,t=e.footer,o=e.children,l=e.isOpen,c=e.onClose,s=e.hideCloseButton,d=e.hideOverlay,f=u(e,v);/*#__PURE__*/return i.createElement(n.Modal,a({isOpen:l,onClose:c},f),!d&&/*#__PURE__*/i.createElement(n.ModalOverlay,null),/*#__PURE__*/i.createElement(n.ModalContent,null,r&&/*#__PURE__*/i.createElement(n.ModalHeader,null,r),!s&&/*#__PURE__*/i.createElement(n.ModalCloseButton,null),o,t&&/*#__PURE__*/i.createElement(n.ModalFooter,null,t)))},E=function(e){var r=e.children,t=u(e,C);/*#__PURE__*/return i.createElement(h,t,/*#__PURE__*/i.createElement(n.ModalBody,null,r))},y=["onClose","onCloseComplete"],O=["rootProps","title","footer","initialFocusRef","hideCloseButton","motionPreset"],b=["ref"],M=n.createStylesContext("MenuDialog")[0],g=function(e){var r=e.onClose,t=e.onCloseComplete,o=u(e,y);/*#__PURE__*/return i.createElement(n.Menu,a({variant:"dialog",onClose:function(){null==r||r(),null==t||t()}},o))},D=n.forwardRef(function(e,r){var t=e.title,o=e.footer,l=e.initialFocusRef,c=e.hideCloseButton,s=e.motionPreset,d=u(e,O),f=n.useMenuContext(),m=f.isOpen,p=f.onClose,v=f.menuRef,C=n.useMenuList(d,r),E=C.ref,y=u(C,b),g=n.useMultiStyleConfig("Menu",e);/*#__PURE__*/return i.createElement(h,{isOpen:m,onClose:p,initialFocusRef:l||v,title:t,hideCloseButton:c,motionPreset:s},/*#__PURE__*/i.createElement(M,{value:g},/*#__PURE__*/i.createElement(n.chakra.div,a({},y,{ref:E,__css:a({outline:0,maxHeight:"80vh",overflowY:"auto"},g.list,{boxShadow:"none",border:0})}))),o&&/*#__PURE__*/i.createElement(n.ModalFooter,null,o))}),x=["children","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","cancelLabel","submitLabel","footer","isOpen","onClose"],F=n.forwardRef(function(e,r){var l=e.children,c=e.schema,s=e.resolver,d=e.fieldResolver,f=e.defaultValues,m=e.onChange,p=e.onSubmit,v=e.onError,C=e.reValidateMode,E=e.shouldFocusError,y=void 0===E||E,O=e.shouldUnregister,b=e.shouldUseNativeValidation,M=e.criteriaMode,g=e.delayError,D=e.cancelLabel,F=e.submitLabel,B=e.footer,P=e.isOpen,w=e.onClose,R=u(e,x),j={ref:r,schema:c,resolver:s,defaultValues:f,onChange:m,onSubmit:p,onError:v,reValidateMode:C,shouldFocusError:y,shouldUnregister:O,shouldUseNativeValidation:b,criteriaMode:M,delayError:g};/*#__PURE__*/return i.createElement(h,a({isOpen:P,onClose:w},R),/*#__PURE__*/i.createElement(o.Form,j,function(e){/*#__PURE__*/return i.createElement(i.Fragment,null,/*#__PURE__*/i.createElement(n.ModalBody,null,t.runIfFn(l,e)||/*#__PURE__*/i.createElement(o.Fields,{schema:c,fieldResolver:d,focusFirstField:!0})),B||/*#__PURE__*/i.createElement(n.ModalFooter,null,/*#__PURE__*/i.createElement(n.Button,{variant:"ghost",mr:3,onClick:w},D||"Cancel"),/*#__PURE__*/i.createElement(o.SubmitButton,null,F||"Submit")))}))}),B=["id","type","scope","component"],P=["title","body","children"],w=i.createContext(null),R={id:null,props:null,type:"modal"},j={alert:s,confirm:s,drawer:p,modal:E,menu:g,form:F},L=function(){return i.useContext(w)};exports.BaseDrawer=m,exports.BaseModal=h,exports.ConfirmDialog=s,exports.Drawer=p,exports.FormDialog=F,exports.MenuDialog=g,exports.MenuDialogList=D,exports.Modal=E,exports.ModalsContext=w,exports.ModalsProvider=function(e){var n=e.children,r=e.modals,t=i.useMemo(function(){return new Set},[]),o=i.useState({modal:R}),l=o[0],c=o[1],s=i.useMemo(function(){var e=a({},j,r);return function(n){return void 0===n&&(n="modal"),e[n]||e.modal}},[r]),d=function(e,n){if(!n)return c({modal:e});c(function(r){var t;return a({},r,((t={})[n]=e,t))})},f=function(e){"function"==typeof e&&(e={component:e});var n=e.id,r=void 0===n?t.size+1:n,o=e.type,l=void 0===o?"modal":o,i=e.scope,a=void 0===i?"modal":i,c=e.component,s={id:r,props:u(e,B),type:l,scope:a,component:c,isOpen:!0};return t.add(s),d(s,a),r},m=function(e,n){try{var r,o=[].concat(Array.from(t)),l=o.filter(function(n){return n.id===e})[0];return l?Promise.resolve(null==(r=l.props)||null==r.onClose?void 0:r.onClose({force:n})).then(function(e){if(!1!==e){var n=o.filter(function(e){return e.scope===l.scope});d(1===n.length?a({},l,{isOpen:!1}):n.length>1?n[n.length-2]:{id:null,props:null,type:l.type},l.scope)}}):Promise.resolve()}catch(e){return Promise.reject(e)}},p={open:f,drawer:function(e){return f(a({},e,{type:"drawer"}))},alert:function(e){return f(a({},e,{scope:"alert",type:"alert",cancelProps:{display:"none"},confirmProps:{label:"OK"},leastDestructiveFocus:"confirm"}))},confirm:function(e){return f(a({},e,{scope:"alert",type:"confirm"}))},menu:function(e){return f(a({},e,{type:"menu"}))},form:function(e){return f(a({},e,{type:"form"}))},close:m,closeAll:function(){t.forEach(function(e){var n;return null==(n=e.props)||null==n.onClose?void 0:n.onClose({force:!0})}),t.clear(),d(R)}},v=i.useMemo(function(){return Object.entries(l).map(function(e){var n=e[0],r=e[1],o=r.component||s(r.type),l=r.props||{},c=l.title,f=l.body,p=l.children,v=u(l,P);/*#__PURE__*/return i.createElement(o,a({key:n,title:c,children:f||p},v,{isOpen:!!r.isOpen,onClose:function(){return m(r.id)},onCloseComplete:function(){return function(e){var n=[].concat(Array.from(t)),r=n.filter(function(n){return n.id===e})[0];t.delete(r),1===n.filter(function(e){return e.scope===r.scope}).length&&d(R,r.scope)}(r.id)}}))})},[l]);/*#__PURE__*/return i.createElement(w.Provider,{value:p},v,n)},exports.useModals=function(){return L()},exports.useModalsContext=L;
1
+ var e=require("react"),n=require("@chakra-ui/react"),r=require("@saas-ui/button"),t=require("@chakra-ui/utils"),o=require("@saas-ui/forms");function l(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var i=/*#__PURE__*/l(e);function a(){return a=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},a.apply(this,arguments)}function u(e,n){if(null==e)return{};var r,t,o={},l=Object.keys(e);for(t=0;t<l.length;t++)n.indexOf(r=l[t])>=0||(o[r]=e[r]);return o}var c=["title","cancelLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","closeOnConfirm","leastDestructiveFocus","onClose","onCancel","onConfirm","children"],s=function(e){var t=e.title,o=e.cancelLabel,l=void 0===o?"Cancel":o,s=e.confirmLabel,d=void 0===s?"Confirm":s,f=e.cancelProps,m=e.confirmProps,p=e.buttonGroupProps,v=e.isOpen,C=e.closeOnCancel,h=void 0===C||C,E=e.closeOnConfirm,y=void 0===E||E,O=e.leastDestructiveFocus,b=void 0===O?"cancel":O,M=e.onClose,g=e.onCancel,D=e.onConfirm,x=e.children,F=u(e,c),B=i.useRef(null),P=i.useRef(null);/*#__PURE__*/return i.createElement(n.AlertDialog,a({isOpen:v,onClose:M},F,{leastDestructiveRef:"cancel"===b?B:P}),/*#__PURE__*/i.createElement(n.AlertDialogOverlay,null,/*#__PURE__*/i.createElement(n.AlertDialogContent,null,/*#__PURE__*/i.createElement(n.AlertDialogHeader,null,t),/*#__PURE__*/i.createElement(n.AlertDialogBody,null,x),/*#__PURE__*/i.createElement(n.AlertDialogFooter,null,/*#__PURE__*/i.createElement(r.ButtonGroup,p,/*#__PURE__*/i.createElement(r.Button,a({ref:B},f,{onClick:function(){null==g||g(),h&&M()}}),l),/*#__PURE__*/i.createElement(r.Button,a({ref:P},m,{onClick:function(){null==D||D(),y&&M()}}),d))))))},d=["title","children","isOpen","onClose","hideCloseButton","hideOverlay"],f=["footer","children"],m=function(e){var r=e.title,t=e.children,o=e.isOpen,l=e.onClose,c=e.hideCloseButton,s=e.hideOverlay,f=u(e,d);/*#__PURE__*/return i.createElement(n.Drawer,a({isOpen:o,onClose:l},f),!s&&/*#__PURE__*/i.createElement(n.DrawerOverlay,null),/*#__PURE__*/i.createElement(n.DrawerContent,null,/*#__PURE__*/i.createElement(n.DrawerHeader,null,r),!c&&/*#__PURE__*/i.createElement(n.DrawerCloseButton,null),t))},p=function(e){var r=e.footer,t=e.children,o=u(e,f);/*#__PURE__*/return i.createElement(m,o,/*#__PURE__*/i.createElement(n.DrawerBody,null,t),r&&/*#__PURE__*/i.createElement(n.DrawerFooter,null,r))},v=["title","footer","children","isOpen","onClose","hideCloseButton","hideOverlay"],C=["children"],h=function(e){var r=e.title,t=e.footer,o=e.children,l=e.isOpen,c=e.onClose,s=e.hideCloseButton,d=e.hideOverlay,f=u(e,v);/*#__PURE__*/return i.createElement(n.Modal,a({isOpen:l,onClose:c},f),!d&&/*#__PURE__*/i.createElement(n.ModalOverlay,null),/*#__PURE__*/i.createElement(n.ModalContent,null,r&&/*#__PURE__*/i.createElement(n.ModalHeader,null,r),!s&&/*#__PURE__*/i.createElement(n.ModalCloseButton,null),o,t&&/*#__PURE__*/i.createElement(n.ModalFooter,null,t)))},E=function(e){var r=e.children,t=u(e,C);/*#__PURE__*/return i.createElement(h,t,/*#__PURE__*/i.createElement(n.ModalBody,null,r))},y=["onClose","onCloseComplete"],O=["rootProps","title","footer","initialFocusRef","hideCloseButton","motionPreset"],b=["ref"],M=n.createStylesContext("MenuDialog")[0],g=function(e){var r=e.onClose,t=e.onCloseComplete,o=u(e,y);/*#__PURE__*/return i.createElement(n.Menu,a({variant:"dialog",onClose:function(){null==r||r(),null==t||t()}},o))},D=n.forwardRef(function(e,r){var t=e.title,o=e.footer,l=e.initialFocusRef,c=e.hideCloseButton,s=e.motionPreset,d=u(e,O),f=n.useMenuContext(),m=f.isOpen,p=f.onClose,v=f.menuRef,C=n.useMenuList(d,r),E=C.ref,y=u(C,b),g=n.useMultiStyleConfig("Menu",e);/*#__PURE__*/return i.createElement(h,{isOpen:m,onClose:p,initialFocusRef:l||v,title:t,hideCloseButton:c,motionPreset:s},/*#__PURE__*/i.createElement(M,{value:g},/*#__PURE__*/i.createElement(n.chakra.div,a({},y,{ref:E,__css:a({outline:0,maxHeight:"80vh",overflowY:"auto"},g.list,{boxShadow:"none",border:0})}))),o&&/*#__PURE__*/i.createElement(n.ModalFooter,null,o))}),x=["children","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","mode","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","cancelLabel","submitLabel","footer","isOpen","onClose"],F=n.forwardRef(function(e,r){var l=e.children,c=e.schema,s=e.resolver,d=e.fieldResolver,f=e.defaultValues,m=e.onChange,p=e.onSubmit,v=e.onError,C=e.mode,E=e.reValidateMode,y=e.shouldFocusError,O=void 0===y||y,b=e.shouldUnregister,M=e.shouldUseNativeValidation,g=e.criteriaMode,D=e.delayError,F=void 0===D?100:D,B=e.cancelLabel,P=e.submitLabel,w=e.footer,R=e.isOpen,j=e.onClose,L=u(e,x),S={ref:r,schema:c,resolver:s,defaultValues:f,onChange:m,onSubmit:p,onError:v,mode:C,reValidateMode:E,shouldFocusError:O,shouldUnregister:b,shouldUseNativeValidation:M,criteriaMode:g,delayError:F};/*#__PURE__*/return i.createElement(h,a({isOpen:R,onClose:j},L),/*#__PURE__*/i.createElement(o.Form,S,function(e){/*#__PURE__*/return i.createElement(i.Fragment,null,/*#__PURE__*/i.createElement(n.ModalBody,null,t.runIfFn(l,e)||/*#__PURE__*/i.createElement(o.Fields,{schema:c,fieldResolver:d,focusFirstField:!0})),w||/*#__PURE__*/i.createElement(n.ModalFooter,null,/*#__PURE__*/i.createElement(n.Button,{variant:"ghost",mr:3,onClick:j},B||"Cancel"),/*#__PURE__*/i.createElement(o.SubmitButton,null,P||"Submit")))}))}),B=["id","type","scope","component"],P=["title","body","children"],w=i.createContext(null),R={id:null,props:null,type:"modal"},j={alert:s,confirm:s,drawer:p,modal:E,menu:g,form:F},L=function(){return i.useContext(w)};exports.BaseDrawer=m,exports.BaseModal=h,exports.ConfirmDialog=s,exports.Drawer=p,exports.FormDialog=F,exports.MenuDialog=g,exports.MenuDialogList=D,exports.Modal=E,exports.ModalsContext=w,exports.ModalsProvider=function(e){var n=e.children,r=e.modals,t=i.useMemo(function(){return new Set},[]),o=i.useState({modal:R}),l=o[0],c=o[1],s=i.useMemo(function(){var e=a({},j,r);return function(n){return void 0===n&&(n="modal"),e[n]||e.modal}},[r]),d=function(e,n){if(!n)return c({modal:e});c(function(r){var t;return a({},r,((t={})[n]=e,t))})},f=function(e){"function"==typeof e&&(e={component:e});var n=e.id,r=void 0===n?t.size+1:n,o=e.type,l=void 0===o?"modal":o,i=e.scope,a=void 0===i?"modal":i,c=e.component,s={id:r,props:u(e,B),type:l,scope:a,component:c,isOpen:!0};return t.add(s),d(s,a),r},m=function(e,n){try{var r,o=[].concat(Array.from(t)),l=o.filter(function(n){return n.id===e})[0];return l?Promise.resolve(null==(r=l.props)||null==r.onClose?void 0:r.onClose({force:n})).then(function(e){if(!1!==e){var n=o.filter(function(e){return e.scope===l.scope});d(1===n.length?a({},l,{isOpen:!1}):n.length>1?n[n.length-2]:{id:null,props:null,type:l.type},l.scope)}}):Promise.resolve()}catch(e){return Promise.reject(e)}},p={open:f,drawer:function(e){return f(a({},e,{type:"drawer"}))},alert:function(e){return f(a({},e,{scope:"alert",type:"alert",cancelProps:{display:"none"},confirmProps:{label:"OK"},leastDestructiveFocus:"confirm"}))},confirm:function(e){return f(a({},e,{scope:"alert",type:"confirm"}))},menu:function(e){return f(a({},e,{type:"menu"}))},form:function(e){return f(a({},e,{type:"form"}))},close:m,closeAll:function(){t.forEach(function(e){var n;return null==(n=e.props)||null==n.onClose?void 0:n.onClose({force:!0})}),t.clear(),d(R)}},v=i.useMemo(function(){return Object.entries(l).map(function(e){var n=e[0],r=e[1],o=r.component||s(r.type),l=r.props||{},c=l.title,f=l.body,p=l.children,v=u(l,P);/*#__PURE__*/return i.createElement(o,a({key:n,title:c,children:f||p},v,{isOpen:!!r.isOpen,onClose:function(){return m(r.id)},onCloseComplete:function(){return function(e){var n=[].concat(Array.from(t)),r=n.filter(function(n){return n.id===e})[0];t.delete(r),1===n.filter(function(e){return e.scope===r.scope}).length&&d(R,r.scope)}(r.id)}}))})},[l]);/*#__PURE__*/return i.createElement(w.Provider,{value:p},v,n)},exports.useModals=function(){return L()},exports.useModalsContext=L;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/dialog.tsx","../src/drawer.tsx","../src/modal.tsx","../src/menu.tsx","../src/form.tsx","../src/provider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n} from '@chakra-ui/react'\n\nimport {\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@saas-ui/button'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked\n */\n onConfirm?: () => void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n {cancelLabel}\n </Button>\n <Button\n ref={confirmRef}\n {...confirmProps}\n onClick={() => {\n onConfirm?.()\n\n closeOnConfirm && onClose()\n }}\n >\n {confirmLabel}\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n} from '@chakra-ui/react'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n children?: React.ReactNode\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent>\n <DrawerHeader>{title}</DrawerHeader>\n {!hideCloseButton && <DrawerCloseButton />}\n {children}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { footer, children, ...rest } = props\n return (\n <BaseDrawer {...rest}>\n <DrawerBody>{children}</DrawerBody>\n\n {footer && <DrawerFooter>{footer}</DrawerFooter>}\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n} from '@chakra-ui/react'\n\nexport interface BaseModalProps extends ChakraModalProps {\n /**\n * The modal title\n */\n title?: React.ReactNode\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n footer,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent>\n {title && <ModalHeader>{title}</ModalHeader>}\n {!hideCloseButton && <ModalCloseButton />}\n {children}\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport const Modal: React.FC<BaseModalProps> = (props) => {\n const { children, ...rest } = props\n return (\n <BaseModal {...rest}>\n <ModalBody>{children}</ModalBody>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport {\n ModalFooter,\n chakra,\n forwardRef,\n useMenuContext,\n useMenuList,\n createStylesContext,\n useMultiStyleConfig,\n Menu,\n MenuListProps,\n} from '@chakra-ui/react'\n\nimport {} from '@chakra-ui/system'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nconst [StylesProvider] = createStylesContext('MenuDialog')\n\nexport interface MenuDialogProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const MenuDialog: React.FC<MenuDialogProps> = (props) => {\n const { onClose, onCloseComplete, ...rest } = props\n\n return (\n <Menu\n variant=\"dialog\"\n onClose={() => {\n onClose?.()\n // Not supported in Menu, so we call it here instead\n // @todo Refactor this in v2?\n onCloseComplete?.()\n }}\n {...rest}\n />\n )\n}\n\nexport interface MenuDialogListProps\n extends Omit<\n BaseModalProps,\n 'isOpen' | 'onClose' | 'children' | 'scrollBehavior'\n >,\n Omit<MenuListProps, 'title'> {}\n\nexport const MenuDialogList = forwardRef<MenuDialogListProps, 'div'>(\n (props, forwardedRef) => {\n const {\n rootProps,\n title,\n footer,\n initialFocusRef,\n hideCloseButton,\n motionPreset,\n ...rest\n } = props\n\n const { isOpen, onClose, menuRef } = useMenuContext()\n\n const { ref, ...ownProps } = useMenuList(rest, forwardedRef)\n\n const styles = useMultiStyleConfig('Menu', props)\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={initialFocusRef || menuRef}\n title={title}\n hideCloseButton={hideCloseButton}\n motionPreset={motionPreset}\n >\n {/* We forward the styles again, otherwise the modal styles will be picked up */}\n <StylesProvider value={styles}>\n <chakra.div\n {...ownProps}\n ref={ref as React.Ref<HTMLDivElement>}\n __css={{\n outline: 0,\n maxHeight: '80vh', // can override this in theme\n overflowY: 'auto', // can override this in theme\n ...styles.list,\n boxShadow: 'none',\n border: 0,\n }}\n />\n </StylesProvider>\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n }\n)\n","import * as React from 'react'\n\nimport { ModalBody, ModalFooter, Button, forwardRef } from '@chakra-ui/react'\nimport { runIfFn } from '@chakra-ui/utils'\n\nimport {\n Form,\n Fields,\n SubmitButton,\n FormProps,\n FieldValues,\n FieldResolver,\n UseFormReturn,\n} from '@saas-ui/forms'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport interface FormDialogProps<TFieldValues extends FieldValues = FieldValues>\n extends Omit<BaseModalProps, 'children'>,\n Pick<\n FormProps<TFieldValues>,\n | 'schema'\n | 'defaultValues'\n | 'onChange'\n | 'onSubmit'\n | 'onError'\n | 'resolver'\n | 'mode'\n | 'reValidateMode'\n | 'shouldFocusError'\n | 'shouldUnregister'\n | 'shouldUseNativeValidation'\n | 'criteriaMode'\n | 'delayError'\n > {\n /**\n * The modal footer, will be wrapped with `ModalFooter`.\n * Defaults to a cancel and submit button.\n */\n footer?: React.ReactNode\n /**\n * The cancel button label\n * @default \"Cancel\"\n */\n cancelLabel?: React.ReactNode\n /**\n * The submit button label\n * @default \"Submit\"\n */\n submitLabel?: React.ReactNode\n /**\n * If no children are passed, this will auto render fields based on the supplied schema.\n */\n children?: React.ReactNode\n /**\n * A schema field resolver used to auto generate form fields.\n */\n fieldResolver?: FieldResolver\n}\n\nexport const FormDialog = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormDialogProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n children,\n schema,\n resolver,\n fieldResolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n reValidateMode,\n shouldFocusError = true,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n cancelLabel,\n submitLabel,\n footer,\n isOpen,\n onClose,\n ...rest\n } = props\n\n const formProps = {\n ref,\n schema,\n resolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n return (\n <BaseModal isOpen={isOpen} onClose={onClose} {...rest}>\n <Form {...formProps}>\n {(form) => (\n <>\n <ModalBody>\n {runIfFn(children, form) || (\n <Fields\n schema={schema}\n fieldResolver={fieldResolver}\n focusFirstField\n />\n )}\n </ModalBody>\n\n {footer || (\n <ModalFooter>\n <Button variant=\"ghost\" mr={3} onClick={onClose}>\n {cancelLabel || 'Cancel'}\n </Button>\n <SubmitButton>{submitLabel || 'Submit'}</SubmitButton>\n </ModalFooter>\n )}\n </>\n )}\n </Form>\n </BaseModal>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormDialogProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { Modal, BaseModalProps } from './modal'\nimport { Drawer, DrawerProps } from './drawer'\nimport { ConfirmDialog, ConfirmDialogProps } from './dialog'\nimport { MenuDialog, MenuDialogProps } from './menu'\nimport { FormDialog, FormDialogProps } from './form'\n\nexport interface ModalsContextValue {\n open: (options: OpenOptions) => ModalId\n drawer: (options: DrawerOptions) => ModalId\n alert: (options: ConfirmDialogOptions) => ModalId\n confirm: (options: ConfirmDialogOptions) => ModalId\n menu: (options: MenuDialogOptions) => ModalId\n form: (options: FormDialogOptions) => ModalId\n close: (id: ModalId) => void\n closeAll: () => void\n}\n\nexport const ModalsContext = React.createContext<ModalsContextValue | null>(\n null\n)\n\ninterface ModalsProviderProps {\n children: React.ReactNode\n modals?: Record<string, React.FC<any>>\n}\n\nexport type ModalId = string | number\n\ninterface ModalOptions\n extends Omit<BaseModalProps, 'onClose' | 'isOpen' | 'children'> {\n onClose?: (args: { force?: boolean }) => Promise<boolean | undefined> | void\n body?: React.ReactNode\n children?: React.ReactNode\n [key: string]: any\n}\n\nexport interface DrawerOptions\n extends ModalOptions,\n Omit<DrawerProps, 'onClose' | 'isOpen' | 'children' | 'title' | 'size'> {}\n\nexport interface ConfirmDialogOptions\n extends ModalOptions,\n Omit<ConfirmDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface MenuDialogOptions\n extends ModalOptions,\n Omit<MenuDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface FormDialogOptions\n extends ModalOptions,\n Omit<FormDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface OpenOptions extends ModalOptions {\n type?: ModalTypes\n scope?: ModalScopes\n}\n\nexport type ModalScopes = 'modal' | 'alert'\n\nexport type ModalTypes =\n | 'modal'\n | 'drawer'\n | 'alert'\n | 'confirm'\n | 'menu'\n | string\n\nexport interface ModalConfig<\n TModalOptions extends ModalOptions = ModalOptions\n> {\n /**\n * The modal id, autogenerated when not set.\n * Can be used to close modals.\n */\n id?: ModalId | null\n /**\n * The modal props\n */\n props?: TModalOptions | null\n /**\n * The modal scope\n * Modals can only have one level per scope.\n * The default scopes are 'modal' and 'alert', alerts can be openend above modals.\n */\n scope?: ModalScopes | string\n /**\n * The modal type to open.\n * Build in types are 'modal', 'drawer', 'alert', 'confirm'\n *\n * Custom types can be configured using the `modals` prop of `ModalProvider`\n */\n type?: ModalTypes\n /**\n * Render a custom modal component.\n * This will ignore the `type` param.\n */\n component?: React.FC<BaseModalProps>\n /**\n * Whether the modal is open or not.\n * This is used internally to keep track of the modal state.\n */\n isOpen?: boolean\n}\n\nconst initialModalState: ModalConfig = {\n id: null,\n props: null,\n type: 'modal',\n}\n\nconst defaultModals = {\n alert: ConfirmDialog,\n confirm: ConfirmDialog,\n drawer: Drawer,\n modal: Modal,\n menu: MenuDialog,\n form: FormDialog,\n}\n\nexport function ModalsProvider({ children, modals }: ModalsProviderProps) {\n // Note that updating the Set doesn't trigger a re-render,\n // use in conjuction with setActiveModals\n const _instances = React.useMemo(() => new Set<ModalConfig>(), [])\n\n const [activeModals, setActiveModals] = React.useState<\n Record<string, ModalConfig>\n >({\n modal: initialModalState,\n })\n\n const getModalComponent = React.useMemo(() => {\n const _modals: Record<string, React.FC<any>> = {\n ...defaultModals,\n ...modals,\n }\n\n return (type: ModalTypes = 'modal') => {\n const component = _modals[type] || _modals.modal\n\n return component\n }\n }, [modals])\n\n const setActiveModal = (modal: ModalConfig, scope?: string) => {\n if (!scope) {\n return setActiveModals({\n modal,\n })\n }\n setActiveModals((prevState) => ({\n ...prevState,\n [scope]: modal,\n }))\n }\n\n const open = <T extends ModalOptions>(\n options: T | React.FC<BaseModalProps>\n ): ModalId => {\n if (typeof options === 'function') {\n const component: React.FC<BaseModalProps> = options\n options = {\n component,\n } as unknown as T\n }\n\n const {\n id = _instances.size + 1,\n type = 'modal',\n scope = 'modal',\n component,\n ...props\n } = options\n\n const modal: ModalConfig<T> = {\n id,\n props: props as T,\n type,\n scope,\n component,\n isOpen: true,\n }\n\n _instances.add(modal)\n setActiveModal(modal, scope)\n\n return id\n }\n\n const drawer = (options: DrawerOptions): ModalId => {\n return open<DrawerOptions>({\n ...options,\n type: 'drawer',\n })\n }\n\n const alert = (options: ConfirmDialogOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'alert',\n cancelProps: {\n display: 'none',\n },\n confirmProps: {\n label: 'OK',\n },\n leastDestructiveFocus: 'confirm',\n })\n }\n\n const confirm = (options: ConfirmDialogOptions): ModalId => {\n return open<ConfirmDialogOptions>({\n ...options,\n scope: 'alert',\n type: 'confirm',\n })\n }\n\n const menu = (options: MenuDialogOptions): ModalId => {\n return open<MenuDialogOptions>({\n ...options,\n type: 'menu',\n })\n }\n\n const form = (options: FormDialogOptions): ModalId => {\n return open<FormDialogOptions>({\n ...options,\n type: 'form',\n })\n }\n\n const close = async (id?: ModalId | null, force?: boolean) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n if (!modal) {\n return\n }\n\n const shouldClose = await modal.props?.onClose?.({ force })\n if (shouldClose === false) {\n return\n }\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(\n {\n ...modal,\n isOpen: false,\n },\n modal.scope\n )\n } else if (scoped.length > 1) {\n setActiveModal(scoped[scoped.length - 2], modal.scope)\n } else {\n setActiveModal(\n {\n id: null,\n props: null,\n type: modal.type, // Keep type same as last modal type to make sure the animation isn't interrupted\n },\n modal.scope\n )\n }\n }\n\n const closeComplete = (id?: ModalId | null) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n _instances.delete(modal)\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(initialModalState, modal.scope)\n }\n }\n\n const closeAll = () => {\n _instances.forEach((modal) => modal.props?.onClose?.({ force: true }))\n _instances.clear()\n\n setActiveModal(initialModalState)\n }\n\n const context = {\n open,\n drawer,\n alert,\n confirm,\n menu,\n form,\n close,\n closeAll,\n }\n\n const content = React.useMemo(\n () =>\n Object.entries(activeModals).map(([scope, config]) => {\n const Component = config.component || getModalComponent(config.type)\n\n const { title, body, children, ...props } = config.props || {}\n\n return (\n <Component\n key={scope}\n title={title}\n children={body || children}\n {...props}\n isOpen={!!config.isOpen}\n onClose={() => close(config.id)}\n onCloseComplete={() => closeComplete(config.id)}\n />\n )\n }),\n [activeModals]\n )\n\n return (\n <ModalsContext.Provider value={context}>\n {content}\n {children}\n </ModalsContext.Provider>\n )\n}\n\nexport const useModalsContext = () =>\n React.useContext(ModalsContext) as ModalsContextValue\n\nexport const useModals = () => {\n return useModalsContext()\n}\n"],"names":["_excluded","ConfirmDialog","props","title","cancelLabel","_props$cancelLabel","_props$confirmLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","_props$closeOnCancel","closeOnConfirm","_props$closeOnConfirm","_props$leastDestructi","leastDestructiveFocus","onClose","onCancel","onConfirm","children","rest","_objectWithoutPropertiesLoose","cancelRef","React","useRef","confirmRef","createElement","AlertDialog","_extends","leastDestructiveRef","AlertDialogOverlay","AlertDialogContent","AlertDialogHeader","AlertDialogBody","AlertDialogFooter","ButtonGroup","Button","ref","onClick","_excluded2","hideCloseButton","hideOverlay","ChakraDrawer","DrawerOverlay","DrawerContent","DrawerHeader","DrawerCloseButton","Drawer","footer","BaseDrawer","DrawerBody","DrawerFooter","ChakraModal","Modal","ModalOverlay","ModalContent","ModalHeader","ModalCloseButton","ModalFooter","BaseModal","ModalBody","_excluded3","StylesProvider","createStylesContext","MenuDialog","onCloseComplete","Menu","variant","MenuDialogList","forwardRef","forwardedRef","rootProps","initialFocusRef","motionPreset","_useMenuContext","useMenuContext","menuRef","useMenuList","ownProps","_useMenuList","styles","useMultiStyleConfig","value","chakra","div","__css","outline","maxHeight","overflowY","list","boxShadow","border","FormDialog","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","reValidateMode","_props$shouldFocusErr","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","submitLabel","formProps","Form","form","Fragment","runIfFn","Fields","focusFirstField","mr","SubmitButton","ModalsContext","createContext","id","type","defaultModals","alert","confirm","drawer","modal","menu","useModalsContext","useContext","_ref","modals","useMemo","Set","useState","initialModalState","activeModals","_React$useState","setActiveModals","getModalComponent","_modals","setActiveModal","scope","prevState","_extends2","open","options","component","_instances","size","_options$type","_options$scope","add","close","force","_modal$props","Array","from","filter","shouldClose","scoped","length","Promise","resolve","e","reject","context","display","label","closeAll","forEach","_modal$props2","clear","content","Object","entries","map","_ref4","config","Component","_ref5","body","key","closeComplete","_ref3","Provider"],"mappings":"0xBAAA,IAAAA,EAAA,CAAA,QAAA,cAAA,eAAA,cAAA,eAAA,mBAAA,SAAA,gBAAA,iBAAA,wBAAA,UAAA,WAAA,YAAA,YAsE0BC,EAAiC,SAACC,GAC1D,IACEC,EAeED,EAfFC,MAeED,EAAAA,EAdFE,YAAAA,OAAW,IAAAC,EAAG,SAAQA,EAAAC,EAcpBJ,EAbFK,aAAAA,OAAY,IAAAD,EAAG,UAASA,EACxBE,EAYEN,EAZFM,YACAC,EAWEP,EAXFO,aACAC,EAUER,EAVFQ,iBACAC,EASET,EATFS,OASET,EAAAA,EARFU,cAAAA,OAAgB,IAAAC,GAQdX,EAAAA,EAAAA,EAPFY,eAAAA,OAAc,IAAAC,GAAOA,EAAAC,EAOnBd,EANFe,sBAAAA,OAAqB,IAAAD,EAAG,SAAQA,EAChCE,EAKEhB,EALFgB,QACAC,EAIEjB,EAJFiB,SACAC,EAGElB,EAHFkB,UACAC,EAEEnB,EAFFmB,SACGC,EAAIC,EACLrB,EAAKF,GAEHwB,EAAYC,EAAMC,OAAO,MACzBC,EAAaF,EAAMC,OAAO,mBAEhC,OACED,EAAAG,cAACC,cAAWC,EAAA,CACVnB,OAAQA,EACRO,QAASA,GACLI,EACJ,CAAAS,oBAC4B,WAA1Bd,EAAqCO,EAAYG,iBAGnDF,EAACG,cAAAI,EAAAA,mBACC,kBAAAP,EAAAG,cAACK,EAAkBA,mBAAA,kBACjBR,EAACG,cAAAM,oBAAmB/B,KAAAA,gBAEpBsB,EAACG,cAAAO,EAAAA,gBAAiBd,KAAAA,gBAElBI,EAAAG,cAACQ,EAAiBA,kBAAA,kBAChBX,EAACG,cAAAS,EAAAA,YAAgB3B,eACfe,EAAAG,cAACU,EAAMA,OAAAR,EAAA,CACLS,IAAKf,GACDhB,EAAW,CACfgC,QAAS,WACC,MAARrB,GAAAA,IAEAP,GAAiBM,GACnB,IAECd,gBAEHqB,EAAAG,cA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,EAAMyB,EAAO1D,GAAG,EAC/BtD,gBAAiB,WAAMqH,OA9CX,SAAC/D,GACrB,IAAMW,YAAayB,MAAMC,KAAKT,IACxBtB,EAAQK,EAAO2B,OAAO,SAAChC,GAAUA,OAAAA,EAAMN,KAAOA,CAAE,GAAE,GAExD4B,SAAkBtB,GAII,IAFPK,EAAO2B,OAAO,SAAA0B,GAAe1C,OAAP0C,EAAL1C,QAAsBhB,EAAMgB,KAAK,GAEtDmB,QACTpB,EAAeN,EAAmBT,EAAMgB,MAE5C,CAmCiCyC,CAAcL,EAAO1D,GAAG,IAGrD,EAAE,EACJ,CAACgB,iBAGH,OACEhH,EAAAG,cAAC2F,EAAcmE,SAAQ,CAACtG,MAAOmF,GAC5BO,EACAzJ,EAGP,oBAKyB,WACvB,OAAuB4G,GACzB"}
1
+ {"version":3,"file":"index.js","sources":["../src/dialog.tsx","../src/drawer.tsx","../src/modal.tsx","../src/menu.tsx","../src/form.tsx","../src/provider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n} from '@chakra-ui/react'\n\nimport {\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@saas-ui/button'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked\n */\n onConfirm?: () => void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n {cancelLabel}\n </Button>\n <Button\n ref={confirmRef}\n {...confirmProps}\n onClick={() => {\n onConfirm?.()\n\n closeOnConfirm && onClose()\n }}\n >\n {confirmLabel}\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n} from '@chakra-ui/react'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n children?: React.ReactNode\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent>\n <DrawerHeader>{title}</DrawerHeader>\n {!hideCloseButton && <DrawerCloseButton />}\n {children}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { footer, children, ...rest } = props\n return (\n <BaseDrawer {...rest}>\n <DrawerBody>{children}</DrawerBody>\n\n {footer && <DrawerFooter>{footer}</DrawerFooter>}\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n} from '@chakra-ui/react'\n\nexport interface BaseModalProps extends ChakraModalProps {\n /**\n * The modal title\n */\n title?: React.ReactNode\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n footer,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent>\n {title && <ModalHeader>{title}</ModalHeader>}\n {!hideCloseButton && <ModalCloseButton />}\n {children}\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport const Modal: React.FC<BaseModalProps> = (props) => {\n const { children, ...rest } = props\n return (\n <BaseModal {...rest}>\n <ModalBody>{children}</ModalBody>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport {\n ModalFooter,\n chakra,\n forwardRef,\n useMenuContext,\n useMenuList,\n createStylesContext,\n useMultiStyleConfig,\n Menu,\n MenuListProps,\n} from '@chakra-ui/react'\n\nimport {} from '@chakra-ui/system'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nconst [StylesProvider] = createStylesContext('MenuDialog')\n\nexport interface MenuDialogProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const MenuDialog: React.FC<MenuDialogProps> = (props) => {\n const { onClose, onCloseComplete, ...rest } = props\n\n return (\n <Menu\n variant=\"dialog\"\n onClose={() => {\n onClose?.()\n // Not supported in Menu, so we call it here instead\n // @todo Refactor this in v2?\n onCloseComplete?.()\n }}\n {...rest}\n />\n )\n}\n\nexport interface MenuDialogListProps\n extends Omit<\n BaseModalProps,\n 'isOpen' | 'onClose' | 'children' | 'scrollBehavior'\n >,\n Omit<MenuListProps, 'title'> {}\n\nexport const MenuDialogList = forwardRef<MenuDialogListProps, 'div'>(\n (props, forwardedRef) => {\n const {\n rootProps,\n title,\n footer,\n initialFocusRef,\n hideCloseButton,\n motionPreset,\n ...rest\n } = props\n\n const { isOpen, onClose, menuRef } = useMenuContext()\n\n const { ref, ...ownProps } = useMenuList(rest, forwardedRef)\n\n const styles = useMultiStyleConfig('Menu', props)\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={initialFocusRef || menuRef}\n title={title}\n hideCloseButton={hideCloseButton}\n motionPreset={motionPreset}\n >\n {/* We forward the styles again, otherwise the modal styles will be picked up */}\n <StylesProvider value={styles}>\n <chakra.div\n {...ownProps}\n ref={ref as React.Ref<HTMLDivElement>}\n __css={{\n outline: 0,\n maxHeight: '80vh', // can override this in theme\n overflowY: 'auto', // can override this in theme\n ...styles.list,\n boxShadow: 'none',\n border: 0,\n }}\n />\n </StylesProvider>\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n }\n)\n","import * as React from 'react'\n\nimport { ModalBody, ModalFooter, Button, forwardRef } from '@chakra-ui/react'\nimport { runIfFn } from '@chakra-ui/utils'\n\nimport {\n Form,\n Fields,\n SubmitButton,\n FormProps,\n FieldValues,\n FieldResolver,\n UseFormReturn,\n} from '@saas-ui/forms'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport interface FormDialogProps<TFieldValues extends FieldValues = FieldValues>\n extends Omit<BaseModalProps, 'children'>,\n Pick<\n FormProps<TFieldValues>,\n | 'schema'\n | 'defaultValues'\n | 'onChange'\n | 'onSubmit'\n | 'onError'\n | 'resolver'\n | 'mode'\n | 'reValidateMode'\n | 'shouldFocusError'\n | 'shouldUnregister'\n | 'shouldUseNativeValidation'\n | 'criteriaMode'\n | 'delayError'\n > {\n /**\n * The modal footer, will be wrapped with `ModalFooter`.\n * Defaults to a cancel and submit button.\n */\n footer?: React.ReactNode\n /**\n * The cancel button label\n * @default \"Cancel\"\n */\n cancelLabel?: React.ReactNode\n /**\n * The submit button label\n * @default \"Submit\"\n */\n submitLabel?: React.ReactNode\n /**\n * If no children are passed, this will auto render fields based on the supplied schema.\n */\n children?: React.ReactNode\n /**\n * A schema field resolver used to auto generate form fields.\n */\n fieldResolver?: FieldResolver\n}\n\nexport const FormDialog = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormDialogProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n children,\n schema,\n resolver,\n fieldResolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError = true,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError = 100,\n cancelLabel,\n submitLabel,\n footer,\n isOpen,\n onClose,\n ...rest\n } = props\n\n const formProps = {\n ref,\n schema,\n resolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n return (\n <BaseModal isOpen={isOpen} onClose={onClose} {...rest}>\n <Form {...formProps}>\n {(form) => (\n <>\n <ModalBody>\n {runIfFn(children, form) || (\n <Fields\n schema={schema}\n fieldResolver={fieldResolver}\n focusFirstField\n />\n )}\n </ModalBody>\n\n {footer || (\n <ModalFooter>\n <Button variant=\"ghost\" mr={3} onClick={onClose}>\n {cancelLabel || 'Cancel'}\n </Button>\n <SubmitButton>{submitLabel || 'Submit'}</SubmitButton>\n </ModalFooter>\n )}\n </>\n )}\n </Form>\n </BaseModal>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormDialogProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { Modal, BaseModalProps } from './modal'\nimport { Drawer, DrawerProps } from './drawer'\nimport { ConfirmDialog, ConfirmDialogProps } from './dialog'\nimport { MenuDialog, MenuDialogProps } from './menu'\nimport { FormDialog, FormDialogProps } from './form'\n\nexport interface ModalsContextValue {\n open: (options: OpenOptions) => ModalId\n drawer: (options: DrawerOptions) => ModalId\n alert: (options: ConfirmDialogOptions) => ModalId\n confirm: (options: ConfirmDialogOptions) => ModalId\n menu: (options: MenuDialogOptions) => ModalId\n form: (options: FormDialogOptions) => ModalId\n close: (id: ModalId) => void\n closeAll: () => void\n}\n\nexport const ModalsContext = React.createContext<ModalsContextValue | null>(\n null\n)\n\ninterface ModalsProviderProps {\n children: React.ReactNode\n modals?: Record<string, React.FC<any>>\n}\n\nexport type ModalId = string | number\n\ninterface ModalOptions\n extends Omit<BaseModalProps, 'onClose' | 'isOpen' | 'children'> {\n onClose?: (args: { force?: boolean }) => Promise<boolean | undefined> | void\n body?: React.ReactNode\n children?: React.ReactNode\n [key: string]: any\n}\n\nexport interface DrawerOptions\n extends ModalOptions,\n Omit<DrawerProps, 'onClose' | 'isOpen' | 'children' | 'title' | 'size'> {}\n\nexport interface ConfirmDialogOptions\n extends ModalOptions,\n Omit<ConfirmDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface MenuDialogOptions\n extends ModalOptions,\n Omit<MenuDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface FormDialogOptions\n extends ModalOptions,\n Omit<FormDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface OpenOptions extends ModalOptions {\n type?: ModalTypes\n scope?: ModalScopes\n}\n\nexport type ModalScopes = 'modal' | 'alert'\n\nexport type ModalTypes =\n | 'modal'\n | 'drawer'\n | 'alert'\n | 'confirm'\n | 'menu'\n | string\n\nexport interface ModalConfig<\n TModalOptions extends ModalOptions = ModalOptions\n> {\n /**\n * The modal id, autogenerated when not set.\n * Can be used to close modals.\n */\n id?: ModalId | null\n /**\n * The modal props\n */\n props?: TModalOptions | null\n /**\n * The modal scope\n * Modals can only have one level per scope.\n * The default scopes are 'modal' and 'alert', alerts can be openend above modals.\n */\n scope?: ModalScopes | string\n /**\n * The modal type to open.\n * Build in types are 'modal', 'drawer', 'alert', 'confirm'\n *\n * Custom types can be configured using the `modals` prop of `ModalProvider`\n */\n type?: ModalTypes\n /**\n * Render a custom modal component.\n * This will ignore the `type` param.\n */\n component?: React.FC<BaseModalProps>\n /**\n * Whether the modal is open or not.\n * This is used internally to keep track of the modal state.\n */\n isOpen?: boolean\n}\n\nconst initialModalState: ModalConfig = {\n id: null,\n props: null,\n type: 'modal',\n}\n\nconst defaultModals = {\n alert: ConfirmDialog,\n confirm: ConfirmDialog,\n drawer: Drawer,\n modal: Modal,\n menu: MenuDialog,\n form: FormDialog,\n}\n\nexport function ModalsProvider({ children, modals }: ModalsProviderProps) {\n // Note that updating the Set doesn't trigger a re-render,\n // use in conjuction with setActiveModals\n const _instances = React.useMemo(() => new Set<ModalConfig>(), [])\n\n const [activeModals, setActiveModals] = React.useState<\n Record<string, ModalConfig>\n >({\n modal: initialModalState,\n })\n\n const getModalComponent = React.useMemo(() => {\n const _modals: Record<string, React.FC<any>> = {\n ...defaultModals,\n ...modals,\n }\n\n return (type: ModalTypes = 'modal') => {\n const component = _modals[type] || _modals.modal\n\n return component\n }\n }, [modals])\n\n const setActiveModal = (modal: ModalConfig, scope?: string) => {\n if (!scope) {\n return setActiveModals({\n modal,\n })\n }\n setActiveModals((prevState) => ({\n ...prevState,\n [scope]: modal,\n }))\n }\n\n const open = <T extends ModalOptions>(\n options: T | React.FC<BaseModalProps>\n ): ModalId => {\n if (typeof options === 'function') {\n const component: React.FC<BaseModalProps> = options\n options = {\n component,\n } as unknown as T\n }\n\n const {\n id = _instances.size + 1,\n type = 'modal',\n scope = 'modal',\n component,\n ...props\n } = options\n\n const modal: ModalConfig<T> = {\n id,\n props: props as T,\n type,\n scope,\n component,\n isOpen: true,\n }\n\n _instances.add(modal)\n setActiveModal(modal, scope)\n\n return id\n }\n\n const drawer = (options: DrawerOptions): ModalId => {\n return open<DrawerOptions>({\n ...options,\n type: 'drawer',\n })\n }\n\n const alert = (options: ConfirmDialogOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'alert',\n cancelProps: {\n display: 'none',\n },\n confirmProps: {\n label: 'OK',\n },\n leastDestructiveFocus: 'confirm',\n })\n }\n\n const confirm = (options: ConfirmDialogOptions): ModalId => {\n return open<ConfirmDialogOptions>({\n ...options,\n scope: 'alert',\n type: 'confirm',\n })\n }\n\n const menu = (options: MenuDialogOptions): ModalId => {\n return open<MenuDialogOptions>({\n ...options,\n type: 'menu',\n })\n }\n\n const form = (options: FormDialogOptions): ModalId => {\n return open<FormDialogOptions>({\n ...options,\n type: 'form',\n })\n }\n\n const close = async (id?: ModalId | null, force?: boolean) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n if (!modal) {\n return\n }\n\n const shouldClose = await modal.props?.onClose?.({ force })\n if (shouldClose === false) {\n return\n }\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(\n {\n ...modal,\n isOpen: false,\n },\n modal.scope\n )\n } else if (scoped.length > 1) {\n setActiveModal(scoped[scoped.length - 2], modal.scope)\n } else {\n setActiveModal(\n {\n id: null,\n props: null,\n type: modal.type, // Keep type same as last modal type to make sure the animation isn't interrupted\n },\n modal.scope\n )\n }\n }\n\n const closeComplete = (id?: ModalId | null) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n _instances.delete(modal)\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(initialModalState, modal.scope)\n }\n }\n\n const closeAll = () => {\n _instances.forEach((modal) => modal.props?.onClose?.({ force: true }))\n _instances.clear()\n\n setActiveModal(initialModalState)\n }\n\n const context = {\n open,\n drawer,\n alert,\n confirm,\n menu,\n form,\n close,\n closeAll,\n }\n\n const content = React.useMemo(\n () =>\n Object.entries(activeModals).map(([scope, config]) => {\n const Component = config.component || getModalComponent(config.type)\n\n const { title, body, children, ...props } = config.props || {}\n\n return (\n <Component\n key={scope}\n title={title}\n children={body || children}\n {...props}\n isOpen={!!config.isOpen}\n onClose={() => close(config.id)}\n onCloseComplete={() => closeComplete(config.id)}\n />\n )\n }),\n [activeModals]\n )\n\n return (\n <ModalsContext.Provider value={context}>\n {content}\n {children}\n </ModalsContext.Provider>\n )\n}\n\nexport const useModalsContext = () =>\n React.useContext(ModalsContext) as ModalsContextValue\n\nexport const useModals = () => {\n return useModalsContext()\n}\n"],"names":["_excluded","ConfirmDialog","props","title","cancelLabel","_props$cancelLabel","_props$confirmLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","_props$closeOnCancel","closeOnConfirm","_props$closeOnConfirm","_props$leastDestructi","leastDestructiveFocus","onClose","onCancel","onConfirm","children","rest","_objectWithoutPropertiesLoose","cancelRef","React","useRef","confirmRef","createElement","AlertDialog","_extends","leastDestructiveRef","AlertDialogOverlay","AlertDialogContent","AlertDialogHeader","AlertDialogBody","AlertDialogFooter","ButtonGroup","Button","ref","onClick","_excluded2","hideCloseButton","hideOverlay","ChakraDrawer","DrawerOverlay","DrawerContent","DrawerHeader","DrawerCloseButton","Drawer","footer","BaseDrawer","DrawerBody","DrawerFooter","ChakraModal","Modal","ModalOverlay","ModalContent","ModalHeader","ModalCloseButton","ModalFooter","BaseModal","ModalBody","_excluded3","StylesProvider","createStylesContext","MenuDialog","onCloseComplete","Menu","variant","MenuDialogList","forwardRef","forwardedRef","rootProps","initialFocusRef","motionPreset","_useMenuContext","useMenuContext","menuRef","useMenuList","ownProps","_useMenuList","styles","useMultiStyleConfig","value","chakra","div","__css","outline","maxHeight","overflowY","list","boxShadow","border","FormDialog","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","mode","reValidateMode","shouldFocusError","_props$shouldFocusErr","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","_props$delayError","submitLabel","formProps","Form","form","Fragment","runIfFn","Fields","focusFirstField","mr","SubmitButton","ModalsContext","createContext","id","type","defaultModals","alert","confirm","drawer","modal","menu","useModalsContext","useContext","_ref","modals","useMemo","Set","useState","initialModalState","activeModals","_React$useState","setActiveModals","getModalComponent","_modals","setActiveModal","scope","prevState","_extends2","open","options","component","_instances","size","_options$type","_options$scope","add","close","force","_modal$props","Array","from","filter","shouldClose","scoped","length","Promise","resolve","e","reject","context","display","label","closeAll","forEach","_modal$props2","clear","content","Object","entries","map","_ref4","config","Component","_ref5","body","key","closeComplete","_ref3","Provider"],"mappings":"0xBAAA,IAAAA,EAAA,CAAA,QAAA,cAAA,eAAA,cAAA,eAAA,mBAAA,SAAA,gBAAA,iBAAA,wBAAA,UAAA,WAAA,YAAA,YAsE0BC,EAAiC,SAACC,GAC1D,IACEC,EAeED,EAfFC,MAeED,EAAAA,EAdFE,YAAAA,OAAW,I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AO2B,OAAO,SAAChC,GAAUA,OAAAA,EAAMN,KAAOA,CAAE,GAAE,GAExD4B,SAAkBtB,GAII,IAFPK,EAAO2B,OAAO,SAAA0B,GAAe1C,OAAP0C,EAAL1C,QAAsBhB,EAAMgB,KAAK,GAEtDmB,QACTpB,EAAeN,EAAmBT,EAAMgB,MAE5C,CAmCiCyC,CAAcL,EAAO1D,GAAG,IAGrD,EAAE,EACJ,CAACgB,iBAGH,OACElH,EAAAG,cAAC6F,EAAcmE,SAAQ,CAACxG,MAAOqF,GAC5BO,EACA3J,EAGP,oBAKyB,WACvB,OAAuB8G,GACzB"}
@@ -1,2 +1,2 @@
1
- import*as e from"react";import{AlertDialog as n,AlertDialogOverlay as l,AlertDialogContent as t,AlertDialogHeader as o,AlertDialogBody as r,AlertDialogFooter as s,Drawer as a,DrawerOverlay as i,DrawerContent as c,DrawerHeader as u,DrawerCloseButton as m,DrawerBody as d,DrawerFooter as p,Modal as f,ModalOverlay as h,ModalContent as C,ModalHeader as E,ModalCloseButton as O,ModalFooter as v,ModalBody as y,createStylesContext as b,forwardRef as g,useMenuContext as P,useMenuList as F,useMultiStyleConfig as M,chakra as R,Menu as w,Button as V}from"@chakra-ui/react";import{ButtonGroup as B,Button as L}from"@saas-ui/button";import{runIfFn as k}from"@chakra-ui/utils";import{Form as S,Fields as x,SubmitButton as D}from"@saas-ui/forms";function U(){return U=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var l=arguments[n];for(var t in l)Object.prototype.hasOwnProperty.call(l,t)&&(e[t]=l[t])}return e},U.apply(this,arguments)}function j(e,n){if(null==e)return{};var l,t,o={},r=Object.keys(e);for(t=0;t<r.length;t++)n.indexOf(l=r[t])>=0||(o[l]=e[l]);return o}const A=["title","cancelLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","closeOnConfirm","leastDestructiveFocus","onClose","onCancel","onConfirm","children"],N=a=>{const{title:i,cancelLabel:c="Cancel",confirmLabel:u="Confirm",cancelProps:m,confirmProps:d,buttonGroupProps:p,isOpen:f,closeOnCancel:h=!0,closeOnConfirm:C=!0,leastDestructiveFocus:E="cancel",onClose:O,onCancel:v,onConfirm:y,children:b}=a,g=j(a,A),P=e.useRef(null),F=e.useRef(null);/*#__PURE__*/return e.createElement(n,U({isOpen:f,onClose:O},g,{leastDestructiveRef:"cancel"===E?P:F}),/*#__PURE__*/e.createElement(l,null,/*#__PURE__*/e.createElement(t,null,/*#__PURE__*/e.createElement(o,null,i),/*#__PURE__*/e.createElement(r,null,b),/*#__PURE__*/e.createElement(s,null,/*#__PURE__*/e.createElement(B,p,/*#__PURE__*/e.createElement(L,U({ref:P},m,{onClick:()=>{null==v||v(),h&&O()}}),c),/*#__PURE__*/e.createElement(L,U({ref:F},d,{onClick:()=>{null==y||y(),C&&O()}}),u))))))},G=["title","children","isOpen","onClose","hideCloseButton","hideOverlay"],_=["footer","children"],z=n=>{const{title:l,children:t,isOpen:o,onClose:r,hideCloseButton:s,hideOverlay:d}=n,p=j(n,G);/*#__PURE__*/return e.createElement(a,U({isOpen:o,onClose:r},p),!d&&/*#__PURE__*/e.createElement(i,null),/*#__PURE__*/e.createElement(c,null,/*#__PURE__*/e.createElement(u,null,l),!s&&/*#__PURE__*/e.createElement(m,null),t))},H=n=>{const{footer:l,children:t}=n,o=j(n,_);/*#__PURE__*/return e.createElement(z,o,/*#__PURE__*/e.createElement(d,null,t),l&&/*#__PURE__*/e.createElement(p,null,l))},K=["title","footer","children","isOpen","onClose","hideCloseButton","hideOverlay"],Y=["children"],q=n=>{const{title:l,footer:t,children:o,isOpen:r,onClose:s,hideCloseButton:a,hideOverlay:i}=n,c=j(n,K);/*#__PURE__*/return e.createElement(f,U({isOpen:r,onClose:s},c),!i&&/*#__PURE__*/e.createElement(h,null),/*#__PURE__*/e.createElement(C,null,l&&/*#__PURE__*/e.createElement(E,null,l),!a&&/*#__PURE__*/e.createElement(O,null),o,t&&/*#__PURE__*/e.createElement(v,null,t)))},I=n=>{const{children:l}=n,t=j(n,Y);/*#__PURE__*/return e.createElement(q,t,/*#__PURE__*/e.createElement(y,null,l))},J=["onClose","onCloseComplete"],Q=["rootProps","title","footer","initialFocusRef","hideCloseButton","motionPreset"],T=["ref"],[W]=b("MenuDialog"),X=n=>{const{onClose:l,onCloseComplete:t}=n,o=j(n,J);/*#__PURE__*/return e.createElement(w,U({variant:"dialog",onClose:()=>{null==l||l(),null==t||t()}},o))},Z=g((n,l)=>{const{title:t,footer:o,initialFocusRef:r,hideCloseButton:s,motionPreset:a}=n,i=j(n,Q),{isOpen:c,onClose:u,menuRef:m}=P(),d=F(i,l),{ref:p}=d,f=j(d,T),h=M("Menu",n);/*#__PURE__*/return e.createElement(q,{isOpen:c,onClose:u,initialFocusRef:r||m,title:t,hideCloseButton:s,motionPreset:a},/*#__PURE__*/e.createElement(W,{value:h},/*#__PURE__*/e.createElement(R.div,U({},f,{ref:p,__css:U({outline:0,maxHeight:"80vh",overflowY:"auto"},h.list,{boxShadow:"none",border:0})}))),o&&/*#__PURE__*/e.createElement(v,null,o))}),$=["children","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","cancelLabel","submitLabel","footer","isOpen","onClose"],ee=g((n,l)=>{const{children:t,schema:o,resolver:r,fieldResolver:s,defaultValues:a,onChange:i,onSubmit:c,onError:u,reValidateMode:m,shouldFocusError:d=!0,shouldUnregister:p,shouldUseNativeValidation:f,criteriaMode:h,delayError:C,cancelLabel:E,submitLabel:O,footer:b,isOpen:g,onClose:P}=n,F=j(n,$),M={ref:l,schema:o,resolver:r,defaultValues:a,onChange:i,onSubmit:c,onError:u,reValidateMode:m,shouldFocusError:d,shouldUnregister:p,shouldUseNativeValidation:f,criteriaMode:h,delayError:C};/*#__PURE__*/return e.createElement(q,U({isOpen:g,onClose:P},F),/*#__PURE__*/e.createElement(S,M,n=>/*#__PURE__*/e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(y,null,k(t,n)||/*#__PURE__*/e.createElement(x,{schema:o,fieldResolver:s,focusFirstField:!0})),b||/*#__PURE__*/e.createElement(v,null,/*#__PURE__*/e.createElement(V,{variant:"ghost",mr:3,onClick:P},E||"Cancel"),/*#__PURE__*/e.createElement(D,null,O||"Submit")))))}),ne=["id","type","scope","component"],le=["title","body","children"],te=e.createContext(null),oe={id:null,props:null,type:"modal"},re={alert:N,confirm:N,drawer:H,modal:I,menu:X,form:ee};function se({children:n,modals:l}){const t=e.useMemo(()=>new Set,[]),[o,r]=e.useState({modal:oe}),s=e.useMemo(()=>{const e=U({},re,l);return(n="modal")=>e[n]||e.modal},[l]),a=(e,n)=>{if(!n)return r({modal:e});r(l=>U({},l,{[n]:e}))},i=e=>{"function"==typeof e&&(e={component:e});const{id:n=t.size+1,type:l="modal",scope:o="modal",component:r}=e,s={id:n,props:j(e,ne),type:l,scope:o,component:r,isOpen:!0};return t.add(s),a(s,o),n},c=async(e,n)=>{var l;const o=[...Array.from(t)],r=o.filter(n=>n.id===e)[0];if(!r)return;if(!1===await(null==(l=r.props)||null==l.onClose?void 0:l.onClose({force:n})))return;const s=o.filter(({scope:e})=>e===r.scope);a(1===s.length?U({},r,{isOpen:!1}):s.length>1?s[s.length-2]:{id:null,props:null,type:r.type},r.scope)},u={open:i,drawer:e=>i(U({},e,{type:"drawer"})),alert:e=>i(U({},e,{scope:"alert",type:"alert",cancelProps:{display:"none"},confirmProps:{label:"OK"},leastDestructiveFocus:"confirm"})),confirm:e=>i(U({},e,{scope:"alert",type:"confirm"})),menu:e=>i(U({},e,{type:"menu"})),form:e=>i(U({},e,{type:"form"})),close:c,closeAll:()=>{t.forEach(e=>{var n;return null==(n=e.props)||null==n.onClose?void 0:n.onClose({force:!0})}),t.clear(),a(oe)}},m=e.useMemo(()=>Object.entries(o).map(([n,l])=>{const o=l.component||s(l.type),r=l.props||{},{title:i,body:u,children:m}=r,d=j(r,le);/*#__PURE__*/return e.createElement(o,U({key:n,title:i,children:u||m},d,{isOpen:!!l.isOpen,onClose:()=>c(l.id),onCloseComplete:()=>(e=>{const n=[...Array.from(t)],l=n.filter(n=>n.id===e)[0];t.delete(l),1===n.filter(({scope:e})=>e===l.scope).length&&a(oe,l.scope)})(l.id)}))}),[o]);/*#__PURE__*/return e.createElement(te.Provider,{value:u},m,n)}const ae=()=>e.useContext(te),ie=()=>ae();export{z as BaseDrawer,q as BaseModal,N as ConfirmDialog,H as Drawer,ee as FormDialog,X as MenuDialog,Z as MenuDialogList,I as Modal,te as ModalsContext,se as ModalsProvider,ie as useModals,ae as useModalsContext};
1
+ import*as e from"react";import{AlertDialog as n,AlertDialogOverlay as l,AlertDialogContent as o,AlertDialogHeader as t,AlertDialogBody as r,AlertDialogFooter as s,Drawer as a,DrawerOverlay as i,DrawerContent as c,DrawerHeader as u,DrawerCloseButton as m,DrawerBody as d,DrawerFooter as p,Modal as f,ModalOverlay as h,ModalContent as C,ModalHeader as E,ModalCloseButton as O,ModalFooter as v,ModalBody as y,createStylesContext as b,forwardRef as g,useMenuContext as P,useMenuList as F,useMultiStyleConfig as M,chakra as R,Menu as w,Button as V}from"@chakra-ui/react";import{ButtonGroup as B,Button as L}from"@saas-ui/button";import{runIfFn as k}from"@chakra-ui/utils";import{Form as S,Fields as x,SubmitButton as D}from"@saas-ui/forms";function U(){return U=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var l=arguments[n];for(var o in l)Object.prototype.hasOwnProperty.call(l,o)&&(e[o]=l[o])}return e},U.apply(this,arguments)}function j(e,n){if(null==e)return{};var l,o,t={},r=Object.keys(e);for(o=0;o<r.length;o++)n.indexOf(l=r[o])>=0||(t[l]=e[l]);return t}const A=["title","cancelLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","closeOnConfirm","leastDestructiveFocus","onClose","onCancel","onConfirm","children"],N=a=>{const{title:i,cancelLabel:c="Cancel",confirmLabel:u="Confirm",cancelProps:m,confirmProps:d,buttonGroupProps:p,isOpen:f,closeOnCancel:h=!0,closeOnConfirm:C=!0,leastDestructiveFocus:E="cancel",onClose:O,onCancel:v,onConfirm:y,children:b}=a,g=j(a,A),P=e.useRef(null),F=e.useRef(null);/*#__PURE__*/return e.createElement(n,U({isOpen:f,onClose:O},g,{leastDestructiveRef:"cancel"===E?P:F}),/*#__PURE__*/e.createElement(l,null,/*#__PURE__*/e.createElement(o,null,/*#__PURE__*/e.createElement(t,null,i),/*#__PURE__*/e.createElement(r,null,b),/*#__PURE__*/e.createElement(s,null,/*#__PURE__*/e.createElement(B,p,/*#__PURE__*/e.createElement(L,U({ref:P},m,{onClick:()=>{null==v||v(),h&&O()}}),c),/*#__PURE__*/e.createElement(L,U({ref:F},d,{onClick:()=>{null==y||y(),C&&O()}}),u))))))},G=["title","children","isOpen","onClose","hideCloseButton","hideOverlay"],_=["footer","children"],z=n=>{const{title:l,children:o,isOpen:t,onClose:r,hideCloseButton:s,hideOverlay:d}=n,p=j(n,G);/*#__PURE__*/return e.createElement(a,U({isOpen:t,onClose:r},p),!d&&/*#__PURE__*/e.createElement(i,null),/*#__PURE__*/e.createElement(c,null,/*#__PURE__*/e.createElement(u,null,l),!s&&/*#__PURE__*/e.createElement(m,null),o))},H=n=>{const{footer:l,children:o}=n,t=j(n,_);/*#__PURE__*/return e.createElement(z,t,/*#__PURE__*/e.createElement(d,null,o),l&&/*#__PURE__*/e.createElement(p,null,l))},K=["title","footer","children","isOpen","onClose","hideCloseButton","hideOverlay"],Y=["children"],q=n=>{const{title:l,footer:o,children:t,isOpen:r,onClose:s,hideCloseButton:a,hideOverlay:i}=n,c=j(n,K);/*#__PURE__*/return e.createElement(f,U({isOpen:r,onClose:s},c),!i&&/*#__PURE__*/e.createElement(h,null),/*#__PURE__*/e.createElement(C,null,l&&/*#__PURE__*/e.createElement(E,null,l),!a&&/*#__PURE__*/e.createElement(O,null),t,o&&/*#__PURE__*/e.createElement(v,null,o)))},I=n=>{const{children:l}=n,o=j(n,Y);/*#__PURE__*/return e.createElement(q,o,/*#__PURE__*/e.createElement(y,null,l))},J=["onClose","onCloseComplete"],Q=["rootProps","title","footer","initialFocusRef","hideCloseButton","motionPreset"],T=["ref"],[W]=b("MenuDialog"),X=n=>{const{onClose:l,onCloseComplete:o}=n,t=j(n,J);/*#__PURE__*/return e.createElement(w,U({variant:"dialog",onClose:()=>{null==l||l(),null==o||o()}},t))},Z=g((n,l)=>{const{title:o,footer:t,initialFocusRef:r,hideCloseButton:s,motionPreset:a}=n,i=j(n,Q),{isOpen:c,onClose:u,menuRef:m}=P(),d=F(i,l),{ref:p}=d,f=j(d,T),h=M("Menu",n);/*#__PURE__*/return e.createElement(q,{isOpen:c,onClose:u,initialFocusRef:r||m,title:o,hideCloseButton:s,motionPreset:a},/*#__PURE__*/e.createElement(W,{value:h},/*#__PURE__*/e.createElement(R.div,U({},f,{ref:p,__css:U({outline:0,maxHeight:"80vh",overflowY:"auto"},h.list,{boxShadow:"none",border:0})}))),t&&/*#__PURE__*/e.createElement(v,null,t))}),$=["children","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","mode","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","cancelLabel","submitLabel","footer","isOpen","onClose"],ee=g((n,l)=>{const{children:o,schema:t,resolver:r,fieldResolver:s,defaultValues:a,onChange:i,onSubmit:c,onError:u,mode:m,reValidateMode:d,shouldFocusError:p=!0,shouldUnregister:f,shouldUseNativeValidation:h,criteriaMode:C,delayError:E=100,cancelLabel:O,submitLabel:b,footer:g,isOpen:P,onClose:F}=n,M=j(n,$),R={ref:l,schema:t,resolver:r,defaultValues:a,onChange:i,onSubmit:c,onError:u,mode:m,reValidateMode:d,shouldFocusError:p,shouldUnregister:f,shouldUseNativeValidation:h,criteriaMode:C,delayError:E};/*#__PURE__*/return e.createElement(q,U({isOpen:P,onClose:F},M),/*#__PURE__*/e.createElement(S,R,n=>/*#__PURE__*/e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(y,null,k(o,n)||/*#__PURE__*/e.createElement(x,{schema:t,fieldResolver:s,focusFirstField:!0})),g||/*#__PURE__*/e.createElement(v,null,/*#__PURE__*/e.createElement(V,{variant:"ghost",mr:3,onClick:F},O||"Cancel"),/*#__PURE__*/e.createElement(D,null,b||"Submit")))))}),ne=["id","type","scope","component"],le=["title","body","children"],oe=e.createContext(null),te={id:null,props:null,type:"modal"},re={alert:N,confirm:N,drawer:H,modal:I,menu:X,form:ee};function se({children:n,modals:l}){const o=e.useMemo(()=>new Set,[]),[t,r]=e.useState({modal:te}),s=e.useMemo(()=>{const e=U({},re,l);return(n="modal")=>e[n]||e.modal},[l]),a=(e,n)=>{if(!n)return r({modal:e});r(l=>U({},l,{[n]:e}))},i=e=>{"function"==typeof e&&(e={component:e});const{id:n=o.size+1,type:l="modal",scope:t="modal",component:r}=e,s={id:n,props:j(e,ne),type:l,scope:t,component:r,isOpen:!0};return o.add(s),a(s,t),n},c=async(e,n)=>{var l;const t=[...Array.from(o)],r=t.filter(n=>n.id===e)[0];if(!r)return;if(!1===await(null==(l=r.props)||null==l.onClose?void 0:l.onClose({force:n})))return;const s=t.filter(({scope:e})=>e===r.scope);a(1===s.length?U({},r,{isOpen:!1}):s.length>1?s[s.length-2]:{id:null,props:null,type:r.type},r.scope)},u={open:i,drawer:e=>i(U({},e,{type:"drawer"})),alert:e=>i(U({},e,{scope:"alert",type:"alert",cancelProps:{display:"none"},confirmProps:{label:"OK"},leastDestructiveFocus:"confirm"})),confirm:e=>i(U({},e,{scope:"alert",type:"confirm"})),menu:e=>i(U({},e,{type:"menu"})),form:e=>i(U({},e,{type:"form"})),close:c,closeAll:()=>{o.forEach(e=>{var n;return null==(n=e.props)||null==n.onClose?void 0:n.onClose({force:!0})}),o.clear(),a(te)}},m=e.useMemo(()=>Object.entries(t).map(([n,l])=>{const t=l.component||s(l.type),r=l.props||{},{title:i,body:u,children:m}=r,d=j(r,le);/*#__PURE__*/return e.createElement(t,U({key:n,title:i,children:u||m},d,{isOpen:!!l.isOpen,onClose:()=>c(l.id),onCloseComplete:()=>(e=>{const n=[...Array.from(o)],l=n.filter(n=>n.id===e)[0];o.delete(l),1===n.filter(({scope:e})=>e===l.scope).length&&a(te,l.scope)})(l.id)}))}),[t]);/*#__PURE__*/return e.createElement(oe.Provider,{value:u},m,n)}const ae=()=>e.useContext(oe),ie=()=>ae();export{z as BaseDrawer,q as BaseModal,N as ConfirmDialog,H as Drawer,ee as FormDialog,X as MenuDialog,Z as MenuDialogList,I as Modal,oe as ModalsContext,se as ModalsProvider,ie as useModals,ae as useModalsContext};
2
2
  //# sourceMappingURL=index.modern.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.mjs","sources":["../src/dialog.tsx","../src/drawer.tsx","../src/modal.tsx","../src/menu.tsx","../src/form.tsx","../src/provider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n} from '@chakra-ui/react'\n\nimport {\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@saas-ui/button'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked\n */\n onConfirm?: () => void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n {cancelLabel}\n </Button>\n <Button\n ref={confirmRef}\n {...confirmProps}\n onClick={() => {\n onConfirm?.()\n\n closeOnConfirm && onClose()\n }}\n >\n {confirmLabel}\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n} from '@chakra-ui/react'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n children?: React.ReactNode\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent>\n <DrawerHeader>{title}</DrawerHeader>\n {!hideCloseButton && <DrawerCloseButton />}\n {children}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { footer, children, ...rest } = props\n return (\n <BaseDrawer {...rest}>\n <DrawerBody>{children}</DrawerBody>\n\n {footer && <DrawerFooter>{footer}</DrawerFooter>}\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n} from '@chakra-ui/react'\n\nexport interface BaseModalProps extends ChakraModalProps {\n /**\n * The modal title\n */\n title?: React.ReactNode\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n footer,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent>\n {title && <ModalHeader>{title}</ModalHeader>}\n {!hideCloseButton && <ModalCloseButton />}\n {children}\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport const Modal: React.FC<BaseModalProps> = (props) => {\n const { children, ...rest } = props\n return (\n <BaseModal {...rest}>\n <ModalBody>{children}</ModalBody>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport {\n ModalFooter,\n chakra,\n forwardRef,\n useMenuContext,\n useMenuList,\n createStylesContext,\n useMultiStyleConfig,\n Menu,\n MenuListProps,\n} from '@chakra-ui/react'\n\nimport {} from '@chakra-ui/system'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nconst [StylesProvider] = createStylesContext('MenuDialog')\n\nexport interface MenuDialogProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const MenuDialog: React.FC<MenuDialogProps> = (props) => {\n const { onClose, onCloseComplete, ...rest } = props\n\n return (\n <Menu\n variant=\"dialog\"\n onClose={() => {\n onClose?.()\n // Not supported in Menu, so we call it here instead\n // @todo Refactor this in v2?\n onCloseComplete?.()\n }}\n {...rest}\n />\n )\n}\n\nexport interface MenuDialogListProps\n extends Omit<\n BaseModalProps,\n 'isOpen' | 'onClose' | 'children' | 'scrollBehavior'\n >,\n Omit<MenuListProps, 'title'> {}\n\nexport const MenuDialogList = forwardRef<MenuDialogListProps, 'div'>(\n (props, forwardedRef) => {\n const {\n rootProps,\n title,\n footer,\n initialFocusRef,\n hideCloseButton,\n motionPreset,\n ...rest\n } = props\n\n const { isOpen, onClose, menuRef } = useMenuContext()\n\n const { ref, ...ownProps } = useMenuList(rest, forwardedRef)\n\n const styles = useMultiStyleConfig('Menu', props)\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={initialFocusRef || menuRef}\n title={title}\n hideCloseButton={hideCloseButton}\n motionPreset={motionPreset}\n >\n {/* We forward the styles again, otherwise the modal styles will be picked up */}\n <StylesProvider value={styles}>\n <chakra.div\n {...ownProps}\n ref={ref as React.Ref<HTMLDivElement>}\n __css={{\n outline: 0,\n maxHeight: '80vh', // can override this in theme\n overflowY: 'auto', // can override this in theme\n ...styles.list,\n boxShadow: 'none',\n border: 0,\n }}\n />\n </StylesProvider>\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n }\n)\n","import * as React from 'react'\n\nimport { ModalBody, ModalFooter, Button, forwardRef } from '@chakra-ui/react'\nimport { runIfFn } from '@chakra-ui/utils'\n\nimport {\n Form,\n Fields,\n SubmitButton,\n FormProps,\n FieldValues,\n FieldResolver,\n UseFormReturn,\n} from '@saas-ui/forms'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport interface FormDialogProps<TFieldValues extends FieldValues = FieldValues>\n extends Omit<BaseModalProps, 'children'>,\n Pick<\n FormProps<TFieldValues>,\n | 'schema'\n | 'defaultValues'\n | 'onChange'\n | 'onSubmit'\n | 'onError'\n | 'resolver'\n | 'mode'\n | 'reValidateMode'\n | 'shouldFocusError'\n | 'shouldUnregister'\n | 'shouldUseNativeValidation'\n | 'criteriaMode'\n | 'delayError'\n > {\n /**\n * The modal footer, will be wrapped with `ModalFooter`.\n * Defaults to a cancel and submit button.\n */\n footer?: React.ReactNode\n /**\n * The cancel button label\n * @default \"Cancel\"\n */\n cancelLabel?: React.ReactNode\n /**\n * The submit button label\n * @default \"Submit\"\n */\n submitLabel?: React.ReactNode\n /**\n * If no children are passed, this will auto render fields based on the supplied schema.\n */\n children?: React.ReactNode\n /**\n * A schema field resolver used to auto generate form fields.\n */\n fieldResolver?: FieldResolver\n}\n\nexport const FormDialog = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormDialogProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n children,\n schema,\n resolver,\n fieldResolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n reValidateMode,\n shouldFocusError = true,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n cancelLabel,\n submitLabel,\n footer,\n isOpen,\n onClose,\n ...rest\n } = props\n\n const formProps = {\n ref,\n schema,\n resolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n return (\n <BaseModal isOpen={isOpen} onClose={onClose} {...rest}>\n <Form {...formProps}>\n {(form) => (\n <>\n <ModalBody>\n {runIfFn(children, form) || (\n <Fields\n schema={schema}\n fieldResolver={fieldResolver}\n focusFirstField\n />\n )}\n </ModalBody>\n\n {footer || (\n <ModalFooter>\n <Button variant=\"ghost\" mr={3} onClick={onClose}>\n {cancelLabel || 'Cancel'}\n </Button>\n <SubmitButton>{submitLabel || 'Submit'}</SubmitButton>\n </ModalFooter>\n )}\n </>\n )}\n </Form>\n </BaseModal>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormDialogProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { Modal, BaseModalProps } from './modal'\nimport { Drawer, DrawerProps } from './drawer'\nimport { ConfirmDialog, ConfirmDialogProps } from './dialog'\nimport { MenuDialog, MenuDialogProps } from './menu'\nimport { FormDialog, FormDialogProps } from './form'\n\nexport interface ModalsContextValue {\n open: (options: OpenOptions) => ModalId\n drawer: (options: DrawerOptions) => ModalId\n alert: (options: ConfirmDialogOptions) => ModalId\n confirm: (options: ConfirmDialogOptions) => ModalId\n menu: (options: MenuDialogOptions) => ModalId\n form: (options: FormDialogOptions) => ModalId\n close: (id: ModalId) => void\n closeAll: () => void\n}\n\nexport const ModalsContext = React.createContext<ModalsContextValue | null>(\n null\n)\n\ninterface ModalsProviderProps {\n children: React.ReactNode\n modals?: Record<string, React.FC<any>>\n}\n\nexport type ModalId = string | number\n\ninterface ModalOptions\n extends Omit<BaseModalProps, 'onClose' | 'isOpen' | 'children'> {\n onClose?: (args: { force?: boolean }) => Promise<boolean | undefined> | void\n body?: React.ReactNode\n children?: React.ReactNode\n [key: string]: any\n}\n\nexport interface DrawerOptions\n extends ModalOptions,\n Omit<DrawerProps, 'onClose' | 'isOpen' | 'children' | 'title' | 'size'> {}\n\nexport interface ConfirmDialogOptions\n extends ModalOptions,\n Omit<ConfirmDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface MenuDialogOptions\n extends ModalOptions,\n Omit<MenuDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface FormDialogOptions\n extends ModalOptions,\n Omit<FormDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface OpenOptions extends ModalOptions {\n type?: ModalTypes\n scope?: ModalScopes\n}\n\nexport type ModalScopes = 'modal' | 'alert'\n\nexport type ModalTypes =\n | 'modal'\n | 'drawer'\n | 'alert'\n | 'confirm'\n | 'menu'\n | string\n\nexport interface ModalConfig<\n TModalOptions extends ModalOptions = ModalOptions\n> {\n /**\n * The modal id, autogenerated when not set.\n * Can be used to close modals.\n */\n id?: ModalId | null\n /**\n * The modal props\n */\n props?: TModalOptions | null\n /**\n * The modal scope\n * Modals can only have one level per scope.\n * The default scopes are 'modal' and 'alert', alerts can be openend above modals.\n */\n scope?: ModalScopes | string\n /**\n * The modal type to open.\n * Build in types are 'modal', 'drawer', 'alert', 'confirm'\n *\n * Custom types can be configured using the `modals` prop of `ModalProvider`\n */\n type?: ModalTypes\n /**\n * Render a custom modal component.\n * This will ignore the `type` param.\n */\n component?: React.FC<BaseModalProps>\n /**\n * Whether the modal is open or not.\n * This is used internally to keep track of the modal state.\n */\n isOpen?: boolean\n}\n\nconst initialModalState: ModalConfig = {\n id: null,\n props: null,\n type: 'modal',\n}\n\nconst defaultModals = {\n alert: ConfirmDialog,\n confirm: ConfirmDialog,\n drawer: Drawer,\n modal: Modal,\n menu: MenuDialog,\n form: FormDialog,\n}\n\nexport function ModalsProvider({ children, modals }: ModalsProviderProps) {\n // Note that updating the Set doesn't trigger a re-render,\n // use in conjuction with setActiveModals\n const _instances = React.useMemo(() => new Set<ModalConfig>(), [])\n\n const [activeModals, setActiveModals] = React.useState<\n Record<string, ModalConfig>\n >({\n modal: initialModalState,\n })\n\n const getModalComponent = React.useMemo(() => {\n const _modals: Record<string, React.FC<any>> = {\n ...defaultModals,\n ...modals,\n }\n\n return (type: ModalTypes = 'modal') => {\n const component = _modals[type] || _modals.modal\n\n return component\n }\n }, [modals])\n\n const setActiveModal = (modal: ModalConfig, scope?: string) => {\n if (!scope) {\n return setActiveModals({\n modal,\n })\n }\n setActiveModals((prevState) => ({\n ...prevState,\n [scope]: modal,\n }))\n }\n\n const open = <T extends ModalOptions>(\n options: T | React.FC<BaseModalProps>\n ): ModalId => {\n if (typeof options === 'function') {\n const component: React.FC<BaseModalProps> = options\n options = {\n component,\n } as unknown as T\n }\n\n const {\n id = _instances.size + 1,\n type = 'modal',\n scope = 'modal',\n component,\n ...props\n } = options\n\n const modal: ModalConfig<T> = {\n id,\n props: props as T,\n type,\n scope,\n component,\n isOpen: true,\n }\n\n _instances.add(modal)\n setActiveModal(modal, scope)\n\n return id\n }\n\n const drawer = (options: DrawerOptions): ModalId => {\n return open<DrawerOptions>({\n ...options,\n type: 'drawer',\n })\n }\n\n const alert = (options: ConfirmDialogOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'alert',\n cancelProps: {\n display: 'none',\n },\n confirmProps: {\n label: 'OK',\n },\n leastDestructiveFocus: 'confirm',\n })\n }\n\n const confirm = (options: ConfirmDialogOptions): ModalId => {\n return open<ConfirmDialogOptions>({\n ...options,\n scope: 'alert',\n type: 'confirm',\n })\n }\n\n const menu = (options: MenuDialogOptions): ModalId => {\n return open<MenuDialogOptions>({\n ...options,\n type: 'menu',\n })\n }\n\n const form = (options: FormDialogOptions): ModalId => {\n return open<FormDialogOptions>({\n ...options,\n type: 'form',\n })\n }\n\n const close = async (id?: ModalId | null, force?: boolean) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n if (!modal) {\n return\n }\n\n const shouldClose = await modal.props?.onClose?.({ force })\n if (shouldClose === false) {\n return\n }\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(\n {\n ...modal,\n isOpen: false,\n },\n modal.scope\n )\n } else if (scoped.length > 1) {\n setActiveModal(scoped[scoped.length - 2], modal.scope)\n } else {\n setActiveModal(\n {\n id: null,\n props: null,\n type: modal.type, // Keep type same as last modal type to make sure the animation isn't interrupted\n },\n modal.scope\n )\n }\n }\n\n const closeComplete = (id?: ModalId | null) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n _instances.delete(modal)\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(initialModalState, modal.scope)\n }\n }\n\n const closeAll = () => {\n _instances.forEach((modal) => modal.props?.onClose?.({ force: true }))\n _instances.clear()\n\n setActiveModal(initialModalState)\n }\n\n const context = {\n open,\n drawer,\n alert,\n confirm,\n menu,\n form,\n close,\n closeAll,\n }\n\n const content = React.useMemo(\n () =>\n Object.entries(activeModals).map(([scope, config]) => {\n const Component = config.component || getModalComponent(config.type)\n\n const { title, body, children, ...props } = config.props || {}\n\n return (\n <Component\n key={scope}\n title={title}\n children={body || children}\n {...props}\n isOpen={!!config.isOpen}\n onClose={() => close(config.id)}\n onCloseComplete={() => closeComplete(config.id)}\n />\n )\n }),\n [activeModals]\n )\n\n return (\n <ModalsContext.Provider value={context}>\n {content}\n {children}\n </ModalsContext.Provider>\n )\n}\n\nexport const useModalsContext = () =>\n React.useContext(ModalsContext) as ModalsContextValue\n\nexport const useModals = () => {\n return useModalsContext()\n}\n"],"names":["ConfirmDialog","props","title","cancelLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","closeOnConfirm","leastDestructiveFocus","onClose","onCancel","onConfirm","children","rest","cancelRef","React","useRef","confirmRef","createElement","AlertDialog","leastDestructiveRef","AlertDialogOverlay","AlertDialogContent","AlertDialogHeader","AlertDialogBody","AlertDialogFooter","ButtonGroup","Button","_extends","ref","onClick","_excluded","_excluded2","BaseDrawer","hideCloseButton","hideOverlay","ChakraDrawer","DrawerOverlay","DrawerContent","DrawerHeader","DrawerCloseButton","Drawer","footer","DrawerBody","DrawerFooter","BaseModal","_objectWithoutPropertiesLoose","ChakraModal","ModalOverlay","ModalContent","ModalHeader","ModalCloseButton","ModalFooter","Modal","ModalBody","StylesProvider","createStylesContext","MenuDialog","onCloseComplete","Menu","variant","forwardRef","forwardedRef","initialFocusRef","motionPreset","menuRef","useMenuContext","_useMenuList","useMenuList","ownProps","_excluded3","styles","useMultiStyleConfig","value","chakra","div","__css","outline","maxHeight","overflowY","list","boxShadow","border","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","submitLabel","formProps","Form","form","Fragment","runIfFn","Fields","focusFirstField","mr","SubmitButton","createContext","initialModalState","id","type","alert","confirm","drawer","modal","menu","FormDialog","ModalsProvider","modals","_instances","useMemo","Set","activeModals","setActiveModals","useState","getModalComponent","_modals","defaultModals","setActiveModal","scope","prevState","open","options","component","size","add","close","async","force","_modal$props","Array","from","filter","scoped","length","context","display","label","closeAll","forEach","_modal$props2","clear","content","Object","entries","map","config","_ref","body","Component","key","delete","closeComplete","ModalsContext","Provider","useModalsContext","useContext","useModals"],"mappings":"oxCAsEaA,EAA+CC,IAC1D,MAAMC,MACJA,EAAKC,YACLA,EAAc,SAAQC,aACtBA,EAAe,UAASC,YACxBA,EAAWC,aACXA,EAAYC,iBACZA,EAAgBC,OAChBA,EAAMC,cACNA,GAAgB,EAAIC,eACpBA,GAAiB,EAAIC,sBACrBA,EAAwB,SAAQC,QAChCA,EAAOC,SACPA,EAAQC,UACRA,EAASC,SACTA,GAEEd,EADCe,EACDf,EAAAA,KAEEgB,EAAYC,EAAMC,OAAO,MACzBC,EAAaF,EAAMC,OAAO,mBAEhC,OACED,EAACG,cAAAC,KACCd,OAAQA,EACRI,QAASA,GACLI,EAAI,CACRO,oBAC4B,WAA1BZ,EAAqCM,EAAYG,iBAGnDF,EA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AAMS,EAAS,IAAIsB,MAAMC,KAAKtB,IACnBL,EAAGI,EAAOwB,OAAQ5B,GAAUA,EAAML,KAAOA,GAAI,GAExDU,EAAW0C,OAAO/C,GAII,IAFPI,EAAOwB,OAAO,EAAGb,WAAYA,IAAUf,EAAMe,OAEjDe,QACThB,EAAepB,GAAmBM,EAAMe,MACzC,EAoC8BiC,CAAcN,EAAO/C,MAAI,GAIxD,CAACa,iBAGH,OACE1G,EAACG,cAAAgJ,GAAcC,SAAQ,CAAC1F,MAAOuE,GAC5BO,EACA3I,EAGP,CAEawJ,SAAmB,IAC9BrJ,EAAMsJ,WAAWH,IAEGI,GAAG,IACAF"}
1
+ {"version":3,"file":"index.modern.mjs","sources":["../src/dialog.tsx","../src/drawer.tsx","../src/modal.tsx","../src/menu.tsx","../src/form.tsx","../src/provider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n} from '@chakra-ui/react'\n\nimport {\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@saas-ui/button'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked\n */\n onConfirm?: () => void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n {cancelLabel}\n </Button>\n <Button\n ref={confirmRef}\n {...confirmProps}\n onClick={() => {\n onConfirm?.()\n\n closeOnConfirm && onClose()\n }}\n >\n {confirmLabel}\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n} from '@chakra-ui/react'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n children?: React.ReactNode\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent>\n <DrawerHeader>{title}</DrawerHeader>\n {!hideCloseButton && <DrawerCloseButton />}\n {children}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { footer, children, ...rest } = props\n return (\n <BaseDrawer {...rest}>\n <DrawerBody>{children}</DrawerBody>\n\n {footer && <DrawerFooter>{footer}</DrawerFooter>}\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n} from '@chakra-ui/react'\n\nexport interface BaseModalProps extends ChakraModalProps {\n /**\n * The modal title\n */\n title?: React.ReactNode\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n footer,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent>\n {title && <ModalHeader>{title}</ModalHeader>}\n {!hideCloseButton && <ModalCloseButton />}\n {children}\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport const Modal: React.FC<BaseModalProps> = (props) => {\n const { children, ...rest } = props\n return (\n <BaseModal {...rest}>\n <ModalBody>{children}</ModalBody>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport {\n ModalFooter,\n chakra,\n forwardRef,\n useMenuContext,\n useMenuList,\n createStylesContext,\n useMultiStyleConfig,\n Menu,\n MenuListProps,\n} from '@chakra-ui/react'\n\nimport {} from '@chakra-ui/system'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nconst [StylesProvider] = createStylesContext('MenuDialog')\n\nexport interface MenuDialogProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const MenuDialog: React.FC<MenuDialogProps> = (props) => {\n const { onClose, onCloseComplete, ...rest } = props\n\n return (\n <Menu\n variant=\"dialog\"\n onClose={() => {\n onClose?.()\n // Not supported in Menu, so we call it here instead\n // @todo Refactor this in v2?\n onCloseComplete?.()\n }}\n {...rest}\n />\n )\n}\n\nexport interface MenuDialogListProps\n extends Omit<\n BaseModalProps,\n 'isOpen' | 'onClose' | 'children' | 'scrollBehavior'\n >,\n Omit<MenuListProps, 'title'> {}\n\nexport const MenuDialogList = forwardRef<MenuDialogListProps, 'div'>(\n (props, forwardedRef) => {\n const {\n rootProps,\n title,\n footer,\n initialFocusRef,\n hideCloseButton,\n motionPreset,\n ...rest\n } = props\n\n const { isOpen, onClose, menuRef } = useMenuContext()\n\n const { ref, ...ownProps } = useMenuList(rest, forwardedRef)\n\n const styles = useMultiStyleConfig('Menu', props)\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={initialFocusRef || menuRef}\n title={title}\n hideCloseButton={hideCloseButton}\n motionPreset={motionPreset}\n >\n {/* We forward the styles again, otherwise the modal styles will be picked up */}\n <StylesProvider value={styles}>\n <chakra.div\n {...ownProps}\n ref={ref as React.Ref<HTMLDivElement>}\n __css={{\n outline: 0,\n maxHeight: '80vh', // can override this in theme\n overflowY: 'auto', // can override this in theme\n ...styles.list,\n boxShadow: 'none',\n border: 0,\n }}\n />\n </StylesProvider>\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n }\n)\n","import * as React from 'react'\n\nimport { ModalBody, ModalFooter, Button, forwardRef } from '@chakra-ui/react'\nimport { runIfFn } from '@chakra-ui/utils'\n\nimport {\n Form,\n Fields,\n SubmitButton,\n FormProps,\n FieldValues,\n FieldResolver,\n UseFormReturn,\n} from '@saas-ui/forms'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport interface FormDialogProps<TFieldValues extends FieldValues = FieldValues>\n extends Omit<BaseModalProps, 'children'>,\n Pick<\n FormProps<TFieldValues>,\n | 'schema'\n | 'defaultValues'\n | 'onChange'\n | 'onSubmit'\n | 'onError'\n | 'resolver'\n | 'mode'\n | 'reValidateMode'\n | 'shouldFocusError'\n | 'shouldUnregister'\n | 'shouldUseNativeValidation'\n | 'criteriaMode'\n | 'delayError'\n > {\n /**\n * The modal footer, will be wrapped with `ModalFooter`.\n * Defaults to a cancel and submit button.\n */\n footer?: React.ReactNode\n /**\n * The cancel button label\n * @default \"Cancel\"\n */\n cancelLabel?: React.ReactNode\n /**\n * The submit button label\n * @default \"Submit\"\n */\n submitLabel?: React.ReactNode\n /**\n * If no children are passed, this will auto render fields based on the supplied schema.\n */\n children?: React.ReactNode\n /**\n * A schema field resolver used to auto generate form fields.\n */\n fieldResolver?: FieldResolver\n}\n\nexport const FormDialog = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormDialogProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n children,\n schema,\n resolver,\n fieldResolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError = true,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError = 100,\n cancelLabel,\n submitLabel,\n footer,\n isOpen,\n onClose,\n ...rest\n } = props\n\n const formProps = {\n ref,\n schema,\n resolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n return (\n <BaseModal isOpen={isOpen} onClose={onClose} {...rest}>\n <Form {...formProps}>\n {(form) => (\n <>\n <ModalBody>\n {runIfFn(children, form) || (\n <Fields\n schema={schema}\n fieldResolver={fieldResolver}\n focusFirstField\n />\n )}\n </ModalBody>\n\n {footer || (\n <ModalFooter>\n <Button variant=\"ghost\" mr={3} onClick={onClose}>\n {cancelLabel || 'Cancel'}\n </Button>\n <SubmitButton>{submitLabel || 'Submit'}</SubmitButton>\n </ModalFooter>\n )}\n </>\n )}\n </Form>\n </BaseModal>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormDialogProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { Modal, BaseModalProps } from './modal'\nimport { Drawer, DrawerProps } from './drawer'\nimport { ConfirmDialog, ConfirmDialogProps } from './dialog'\nimport { MenuDialog, MenuDialogProps } from './menu'\nimport { FormDialog, FormDialogProps } from './form'\n\nexport interface ModalsContextValue {\n open: (options: OpenOptions) => ModalId\n drawer: (options: DrawerOptions) => ModalId\n alert: (options: ConfirmDialogOptions) => ModalId\n confirm: (options: ConfirmDialogOptions) => ModalId\n menu: (options: MenuDialogOptions) => ModalId\n form: (options: FormDialogOptions) => ModalId\n close: (id: ModalId) => void\n closeAll: () => void\n}\n\nexport const ModalsContext = React.createContext<ModalsContextValue | null>(\n null\n)\n\ninterface ModalsProviderProps {\n children: React.ReactNode\n modals?: Record<string, React.FC<any>>\n}\n\nexport type ModalId = string | number\n\ninterface ModalOptions\n extends Omit<BaseModalProps, 'onClose' | 'isOpen' | 'children'> {\n onClose?: (args: { force?: boolean }) => Promise<boolean | undefined> | void\n body?: React.ReactNode\n children?: React.ReactNode\n [key: string]: any\n}\n\nexport interface DrawerOptions\n extends ModalOptions,\n Omit<DrawerProps, 'onClose' | 'isOpen' | 'children' | 'title' | 'size'> {}\n\nexport interface ConfirmDialogOptions\n extends ModalOptions,\n Omit<ConfirmDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface MenuDialogOptions\n extends ModalOptions,\n Omit<MenuDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface FormDialogOptions\n extends ModalOptions,\n Omit<FormDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface OpenOptions extends ModalOptions {\n type?: ModalTypes\n scope?: ModalScopes\n}\n\nexport type ModalScopes = 'modal' | 'alert'\n\nexport type ModalTypes =\n | 'modal'\n | 'drawer'\n | 'alert'\n | 'confirm'\n | 'menu'\n | string\n\nexport interface ModalConfig<\n TModalOptions extends ModalOptions = ModalOptions\n> {\n /**\n * The modal id, autogenerated when not set.\n * Can be used to close modals.\n */\n id?: ModalId | null\n /**\n * The modal props\n */\n props?: TModalOptions | null\n /**\n * The modal scope\n * Modals can only have one level per scope.\n * The default scopes are 'modal' and 'alert', alerts can be openend above modals.\n */\n scope?: ModalScopes | string\n /**\n * The modal type to open.\n * Build in types are 'modal', 'drawer', 'alert', 'confirm'\n *\n * Custom types can be configured using the `modals` prop of `ModalProvider`\n */\n type?: ModalTypes\n /**\n * Render a custom modal component.\n * This will ignore the `type` param.\n */\n component?: React.FC<BaseModalProps>\n /**\n * Whether the modal is open or not.\n * This is used internally to keep track of the modal state.\n */\n isOpen?: boolean\n}\n\nconst initialModalState: ModalConfig = {\n id: null,\n props: null,\n type: 'modal',\n}\n\nconst defaultModals = {\n alert: ConfirmDialog,\n confirm: ConfirmDialog,\n drawer: Drawer,\n modal: Modal,\n menu: MenuDialog,\n form: FormDialog,\n}\n\nexport function ModalsProvider({ children, modals }: ModalsProviderProps) {\n // Note that updating the Set doesn't trigger a re-render,\n // use in conjuction with setActiveModals\n const _instances = React.useMemo(() => new Set<ModalConfig>(), [])\n\n const [activeModals, setActiveModals] = React.useState<\n Record<string, ModalConfig>\n >({\n modal: initialModalState,\n })\n\n const getModalComponent = React.useMemo(() => {\n const _modals: Record<string, React.FC<any>> = {\n ...defaultModals,\n ...modals,\n }\n\n return (type: ModalTypes = 'modal') => {\n const component = _modals[type] || _modals.modal\n\n return component\n }\n }, [modals])\n\n const setActiveModal = (modal: ModalConfig, scope?: string) => {\n if (!scope) {\n return setActiveModals({\n modal,\n })\n }\n setActiveModals((prevState) => ({\n ...prevState,\n [scope]: modal,\n }))\n }\n\n const open = <T extends ModalOptions>(\n options: T | React.FC<BaseModalProps>\n ): ModalId => {\n if (typeof options === 'function') {\n const component: React.FC<BaseModalProps> = options\n options = {\n component,\n } as unknown as T\n }\n\n const {\n id = _instances.size + 1,\n type = 'modal',\n scope = 'modal',\n component,\n ...props\n } = options\n\n const modal: ModalConfig<T> = {\n id,\n props: props as T,\n type,\n scope,\n component,\n isOpen: true,\n }\n\n _instances.add(modal)\n setActiveModal(modal, scope)\n\n return id\n }\n\n const drawer = (options: DrawerOptions): ModalId => {\n return open<DrawerOptions>({\n ...options,\n type: 'drawer',\n })\n }\n\n const alert = (options: ConfirmDialogOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'alert',\n cancelProps: {\n display: 'none',\n },\n confirmProps: {\n label: 'OK',\n },\n leastDestructiveFocus: 'confirm',\n })\n }\n\n const confirm = (options: ConfirmDialogOptions): ModalId => {\n return open<ConfirmDialogOptions>({\n ...options,\n scope: 'alert',\n type: 'confirm',\n })\n }\n\n const menu = (options: MenuDialogOptions): ModalId => {\n return open<MenuDialogOptions>({\n ...options,\n type: 'menu',\n })\n }\n\n const form = (options: FormDialogOptions): ModalId => {\n return open<FormDialogOptions>({\n ...options,\n type: 'form',\n })\n }\n\n const close = async (id?: ModalId | null, force?: boolean) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n if (!modal) {\n return\n }\n\n const shouldClose = await modal.props?.onClose?.({ force })\n if (shouldClose === false) {\n return\n }\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(\n {\n ...modal,\n isOpen: false,\n },\n modal.scope\n )\n } else if (scoped.length > 1) {\n setActiveModal(scoped[scoped.length - 2], modal.scope)\n } else {\n setActiveModal(\n {\n id: null,\n props: null,\n type: modal.type, // Keep type same as last modal type to make sure the animation isn't interrupted\n },\n modal.scope\n )\n }\n }\n\n const closeComplete = (id?: ModalId | null) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n _instances.delete(modal)\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(initialModalState, modal.scope)\n }\n }\n\n const closeAll = () => {\n _instances.forEach((modal) => modal.props?.onClose?.({ force: true }))\n _instances.clear()\n\n setActiveModal(initialModalState)\n }\n\n const context = {\n open,\n drawer,\n alert,\n confirm,\n menu,\n form,\n close,\n closeAll,\n }\n\n const content = React.useMemo(\n () =>\n Object.entries(activeModals).map(([scope, config]) => {\n const Component = config.component || getModalComponent(config.type)\n\n const { title, body, children, ...props } = config.props || {}\n\n return (\n <Component\n key={scope}\n title={title}\n children={body || children}\n {...props}\n isOpen={!!config.isOpen}\n onClose={() => close(config.id)}\n onCloseComplete={() => closeComplete(config.id)}\n />\n )\n }),\n [activeModals]\n )\n\n return (\n <ModalsContext.Provider value={context}>\n {content}\n {children}\n </ModalsContext.Provider>\n )\n}\n\nexport const useModalsContext = () =>\n React.useContext(ModalsContext) as ModalsContextValue\n\nexport const useModals = () => {\n return useModalsContext()\n}\n"],"names":["ConfirmDialog","props","title","cancelLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","closeOnConfirm","leastDestructiveFocus","onClose","onCancel","onConfirm","children","rest","cancelRef","React","useRef","confirmRef","createElement","AlertDialog","leastDestructiveRef","AlertDialogOverlay","AlertDialogContent","AlertDialogHeader","AlertDialogBody","AlertDialogFooter","ButtonGroup","Button","_extends","ref","onClick","_excluded","_excluded2","BaseDrawer","hideCloseButton","hideOverlay","ChakraDrawer","DrawerOverlay","DrawerContent","DrawerHeader","DrawerCloseButton","Drawer","footer","DrawerBody","DrawerFooter","BaseModal","_objectWithoutPropertiesLoose","ChakraModal","ModalOverlay","ModalContent","ModalHeader","ModalCloseButton","ModalFooter","Modal","ModalBody","StylesProvider","createStylesContext","MenuDialog","onCloseComplete","Menu","variant","forwardRef","forwardedRef","initialFocusRef","motionPreset","menuRef","useMenuContext","_useMenuList","useMenuList","ownProps","_excluded3","styles","useMultiStyleConfig","value","chakra","div","__css","outline","maxHeight","overflowY","list","boxShadow","border","FormDialog","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","mode","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","submitLabel","Form","formProps","form","Fragment","runIfFn","Fields","focusFirstField","mr","SubmitButton","createContext","initialModalState","id","type","alert","confirm","drawer","modal","menu","ModalsProvider","modals","_instances","useMemo","Set","activeModals","setActiveModals","useState","getModalComponent","_modals","defaultModals","setActiveModal","scope","prevState","open","options","component","size","add","close","async","force","_modal$props","Array","from","filter","scoped","length","context","display","label","closeAll","forEach","_modal$props2","clear","content","Object","entries","map","config","_ref","body","Component","key","delete","closeComplete","ModalsContext","Provider","useModalsContext","useContext","useModals"],"mappings":"oxCAsEaA,EAA+CC,IAC1D,MAAMC,MACJA,EAAKC,YACLA,EAAc,SAAQC,aACtBA,EAAe,UAASC,YACxBA,EAAWC,aACXA,EAAYC,iBACZA,EAAgBC,OAChBA,EAAMC,cACNA,GAAgB,EAAIC,eACpBA,GAAiB,EAAIC,sBACrBA,EAAwB,SAAQC,QAChCA,EAAOC,SACPA,EAAQC,UACRA,EAASC,SACTA,GAEEd,EADCe,EACDf,EAAAA,KAEEgB,EAAYC,EAAMC,OAAO,MACzBC,EAAaF,EAAMC,OAAO,mBAEhC,OACED,EAACG,cAAAC,KACCd,OAAQA,EACRI,QAASA,GACLI,EAAI,CACRO,oBAC4B,WAA1BZ,EAAqCM,EAAYG,i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,IAC5BpD,gBAAiB,IA9CJoD,KACrB,MAAMQ,EAAS,IAAIsB,MAAMC,KAAKtB,IACnBJ,EAAGG,EAAOwB,OAAQ3B,GAAUA,EAAML,KAAOA,GAAI,GAExDS,EAAW0C,OAAO9C,GAII,IAFPG,EAAOwB,OAAO,EAAGb,WAAYA,IAAUd,EAAMc,OAEjDe,QACThB,EAAenB,GAAmBM,EAAMc,MACzC,EAoC8BiC,CAAcN,EAAO9C,MAAI,GAIxD,CAACY,iBAGH,OACE3G,EAACG,cAAAiJ,GAAcC,SAAQ,CAAC3F,MAAOwE,GAC5BO,EACA5I,EAGP,CAEayJ,SAAmB,IAC9BtJ,EAAMuJ,WAAWH,IAEGI,GAAG,IACAF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saas-ui/modals",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "A modal manager for Chakra UI",
5
5
  "source": "src/index.ts",
6
6
  "exports": {
@@ -58,7 +58,7 @@
58
58
  "dependencies": {
59
59
  "@chakra-ui/utils": "^2.0.14",
60
60
  "@saas-ui/button": "1.4.0",
61
- "@saas-ui/forms": "1.5.1",
61
+ "@saas-ui/forms": "1.5.2",
62
62
  "@saas-ui/menu": "1.4.0"
63
63
  },
64
64
  "peerDependencies": {
package/src/form.tsx CHANGED
@@ -72,12 +72,13 @@ export const FormDialog = forwardRef(
72
72
  onChange,
73
73
  onSubmit,
74
74
  onError,
75
+ mode,
75
76
  reValidateMode,
76
77
  shouldFocusError = true,
77
78
  shouldUnregister,
78
79
  shouldUseNativeValidation,
79
80
  criteriaMode,
80
- delayError,
81
+ delayError = 100,
81
82
  cancelLabel,
82
83
  submitLabel,
83
84
  footer,
@@ -94,6 +95,7 @@ export const FormDialog = forwardRef(
94
95
  onChange,
95
96
  onSubmit,
96
97
  onError,
98
+ mode,
97
99
  reValidateMode,
98
100
  shouldFocusError,
99
101
  shouldUnregister,