mui-modal-provider
Advanced tools
Comparing version 1.5.1 to 2.0.0
import React from 'react'; | ||
declare type Props = { | ||
children: React.ReactNode; | ||
beta?: boolean; | ||
/** | ||
* Enable it if you want to use mui < 5 version | ||
*/ | ||
legacy?: boolean; | ||
}; | ||
export default function ModalProvider({ children, beta }: Props): JSX.Element; | ||
export default function ModalProvider({ children, legacy }: Props): JSX.Element; | ||
export {}; |
@@ -174,4 +174,4 @@ 'use strict'; | ||
var children = _ref.children, | ||
_ref$beta = _ref.beta, | ||
beta = _ref$beta === void 0 ? false : _ref$beta; | ||
_ref$legacy = _ref.legacy, | ||
legacy = _ref$legacy === void 0 ? false : _ref$legacy; | ||
@@ -307,3 +307,3 @@ var _React$useReducer = React__default.useReducer(reducer, initialState), | ||
if (beta) { | ||
if (!legacy) { | ||
extraProps = { | ||
@@ -310,0 +310,0 @@ TransitionProps: _extends({}, props === null || props === void 0 ? void 0 : props.TransitionProps, { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o,e,t=require("react"),n=(o=t)&&"object"==typeof o&&"default"in o?o.default:o;function r(){return(r=Object.assign||function(o){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n])}return o}).apply(this,arguments)}function a(o,e){if(null==o)return{};var t,n,r={},a=Object.keys(o);for(n=0;n<a.length;n++)e.indexOf(t=a[n])>=0||(r[t]=o[t]);return r}!function(o){o.SHOW="SHOW",o.HIDE="HIDE",o.UPDATE="UPDATE",o.DESTROY="DESTROY",o.DESTROY_BY_ROOT_ID="DESTROY_BY_ROOT_ID",o.UNKNOWN="UNKNOWN"}(e||(e={}));var i={};function s(o,t){switch(t.type){case e.SHOW:var n,a=t.payload,i=a.options;return r({},o,((n={})[a.id]={component:a.component,props:r({},a.props,{open:!0}),options:i},n));case e.HIDE:var s,d=t.payload.id;return o[d]?r({},o,((s={})[d]=r({},o[d],{props:r({},o[d].props,{open:!1})}),s)):o;case e.UPDATE:var u,l=t.payload,c=l.id;return o[c]?r({},o,((u={})[c]=r({},o[c],{props:r({},o[c].props,l.props)}),u)):o;case e.DESTROY:var p=t.payload.id,f=r({},o);return delete f[p],f;case e.DESTROY_BY_ROOT_ID:var y=t.payload.rootId;return Object.keys(o).filter((function(o){return o.split(".")[0]!==y})).reduce((function(e,t){var n;return r({},e,((n={})[t]=o[t],n))}),{});default:throw new Error("Unexpected action")}}var d=t.createContext({state:i,hideModal:function(){},showModal:function(){return{id:"id",hide:function(){},destroy:function(){},update:function(){}}},destroyModal:function(){},updateModal:function(){},destroyModalsByRootId:function(){}}),u=function(o){void 0===o&&(o=8);for(var e=[],t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=t.length,r=0;r<o;r++)e[r]=t.charAt(Math.floor(Math.random()*n));return e.join("")},l={disableAutoDestroy:!1};exports.default=function(o){var t=o.children,l=o.beta,c=void 0!==l&&l,p=n.useReducer(s,i),f=p[0],y=p[1],O=n.useCallback((function(o,t){var n=a(t,["open"]);o?y({type:e.UPDATE,payload:{id:o,props:n}}):console.error("[ERROR]: Modal ID is missing")}),[y]),v=n.useCallback((function(o){o?y({type:e.HIDE,payload:{id:o}}):console.error("[ERROR]: Modal ID is missing")}),[y]),E=n.useCallback((function(o){o?y({type:e.DESTROY,payload:{id:o}}):console.error("[ERROR]: Modal ID is missing")}),[y]),R=n.useCallback((function(o){o?y({type:e.DESTROY_BY_ROOT_ID,payload:{rootId:o}}):console.error("[ERROR]: Modal root ID is missing")}),[y]),D=n.useCallback((function(o,t,n){var r=u(8);return n&&n.rootId&&(r=n.rootId+"."+r),y({type:e.SHOW,payload:{id:r,component:o,props:t,options:n}}),{id:r,hide:function(){return v(r)},destroy:function(){return E(r)},update:function(o){return O(r,o)}}}),[y,v,E,O]);return n.createElement(d.Provider,{value:{state:f,updateModal:O,hideModal:v,destroyModal:E,showModal:D,destroyModalsByRootId:R}},t,Object.keys(f).map((function(o){var e,t=f[o],a=t.component,i=t.props,s=t.options,d=function(){var e,t;(null==i?void 0:i.onExited)&&i.onExited.apply(i,arguments),(null==i||null===(e=i.TransitionProps)||void 0===e?void 0:e.onExited)&&(t=i.TransitionProps).onExited.apply(t,arguments),E(o)};return e=c?{TransitionProps:r({},null==i?void 0:i.TransitionProps,{onExited:d})}:{onExited:d},n.createElement(a,Object.assign({},i,{key:o,onClose:function(){s&&s.destroyOnClose?E(o):v(o),i&&i.onClose&&i.onClose.apply(i,arguments)}},s&&!s.destroyOnClose&&e))})))},exports.useModal=function(o){void 0===o&&(o=l);var e=r({},l,o).disableAutoDestroy,n=t.useContext(d),i=n.showModal,s=n.destroyModalsByRootId,c=a(n,["showModal","destroyModalsByRootId"]),p=t.useRef(u(6));return t.useEffect((function(){return function(){e||s(p.current)}}),[e,s]),r({showModal:t.useCallback((function(o,e,t){return i(o,e,r({rootId:p.current},t))}),[i])},c)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o,e,t=require("react"),n=(o=t)&&"object"==typeof o&&"default"in o?o.default:o;function r(){return(r=Object.assign||function(o){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n])}return o}).apply(this,arguments)}function a(o,e){if(null==o)return{};var t,n,r={},a=Object.keys(o);for(n=0;n<a.length;n++)e.indexOf(t=a[n])>=0||(r[t]=o[t]);return r}!function(o){o.SHOW="SHOW",o.HIDE="HIDE",o.UPDATE="UPDATE",o.DESTROY="DESTROY",o.DESTROY_BY_ROOT_ID="DESTROY_BY_ROOT_ID",o.UNKNOWN="UNKNOWN"}(e||(e={}));var i={};function s(o,t){switch(t.type){case e.SHOW:var n,a=t.payload,i=a.options;return r({},o,((n={})[a.id]={component:a.component,props:r({},a.props,{open:!0}),options:i},n));case e.HIDE:var s,d=t.payload.id;return o[d]?r({},o,((s={})[d]=r({},o[d],{props:r({},o[d].props,{open:!1})}),s)):o;case e.UPDATE:var u,l=t.payload,c=l.id;return o[c]?r({},o,((u={})[c]=r({},o[c],{props:r({},o[c].props,l.props)}),u)):o;case e.DESTROY:var p=t.payload.id,f=r({},o);return delete f[p],f;case e.DESTROY_BY_ROOT_ID:var y=t.payload.rootId;return Object.keys(o).filter((function(o){return o.split(".")[0]!==y})).reduce((function(e,t){var n;return r({},e,((n={})[t]=o[t],n))}),{});default:throw new Error("Unexpected action")}}var d=t.createContext({state:i,hideModal:function(){},showModal:function(){return{id:"id",hide:function(){},destroy:function(){},update:function(){}}},destroyModal:function(){},updateModal:function(){},destroyModalsByRootId:function(){}}),u=function(o){void 0===o&&(o=8);for(var e=[],t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=t.length,r=0;r<o;r++)e[r]=t.charAt(Math.floor(Math.random()*n));return e.join("")},l={disableAutoDestroy:!1};exports.default=function(o){var t=o.children,l=o.legacy,c=void 0!==l&&l,p=n.useReducer(s,i),f=p[0],y=p[1],O=n.useCallback((function(o,t){var n=a(t,["open"]);o?y({type:e.UPDATE,payload:{id:o,props:n}}):console.error("[ERROR]: Modal ID is missing")}),[y]),v=n.useCallback((function(o){o?y({type:e.HIDE,payload:{id:o}}):console.error("[ERROR]: Modal ID is missing")}),[y]),E=n.useCallback((function(o){o?y({type:e.DESTROY,payload:{id:o}}):console.error("[ERROR]: Modal ID is missing")}),[y]),R=n.useCallback((function(o){o?y({type:e.DESTROY_BY_ROOT_ID,payload:{rootId:o}}):console.error("[ERROR]: Modal root ID is missing")}),[y]),D=n.useCallback((function(o,t,n){var r=u(8);return n&&n.rootId&&(r=n.rootId+"."+r),y({type:e.SHOW,payload:{id:r,component:o,props:t,options:n}}),{id:r,hide:function(){return v(r)},destroy:function(){return E(r)},update:function(o){return O(r,o)}}}),[y,v,E,O]);return n.createElement(d.Provider,{value:{state:f,updateModal:O,hideModal:v,destroyModal:E,showModal:D,destroyModalsByRootId:R}},t,Object.keys(f).map((function(o){var e,t=f[o],a=t.component,i=t.props,s=t.options,d=function(){var e,t;(null==i?void 0:i.onExited)&&i.onExited.apply(i,arguments),(null==i||null===(e=i.TransitionProps)||void 0===e?void 0:e.onExited)&&(t=i.TransitionProps).onExited.apply(t,arguments),E(o)};return e=c?{onExited:d}:{TransitionProps:r({},null==i?void 0:i.TransitionProps,{onExited:d})},n.createElement(a,Object.assign({},i,{key:o,onClose:function(){s&&s.destroyOnClose?E(o):v(o),i&&i.onClose&&i.onClose.apply(i,arguments)}},s&&!s.destroyOnClose&&e))})))},exports.useModal=function(o){void 0===o&&(o=l);var e=r({},l,o).disableAutoDestroy,n=t.useContext(d),i=n.showModal,s=n.destroyModalsByRootId,c=a(n,["showModal","destroyModalsByRootId"]),p=t.useRef(u(6));return t.useEffect((function(){return function(){e||s(p.current)}}),[e,s]),r({showModal:t.useCallback((function(o,e,t){return i(o,e,r({rootId:p.current},t))}),[i])},c)}; | ||
//# sourceMappingURL=mui-modal-provider.cjs.production.min.js.map |
@@ -167,4 +167,4 @@ import React, { createContext, useContext, useRef, useEffect, useCallback } from 'react'; | ||
var children = _ref.children, | ||
_ref$beta = _ref.beta, | ||
beta = _ref$beta === void 0 ? false : _ref$beta; | ||
_ref$legacy = _ref.legacy, | ||
legacy = _ref$legacy === void 0 ? false : _ref$legacy; | ||
@@ -300,3 +300,3 @@ var _React$useReducer = React.useReducer(reducer, initialState), | ||
if (beta) { | ||
if (!legacy) { | ||
extraProps = { | ||
@@ -303,0 +303,0 @@ TransitionProps: _extends({}, props === null || props === void 0 ? void 0 : props.TransitionProps, { |
{ | ||
"version": "1.5.1", | ||
"version": "2.0.0", | ||
"license": "MIT", | ||
@@ -44,3 +44,3 @@ "name": "mui-modal-provider", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build" | ||
"prepare": "install-peers && tsdx build" | ||
}, | ||
@@ -58,2 +58,8 @@ "husky": { | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"branches": [ | ||
"master" | ||
] | ||
}, | ||
"jest": { | ||
@@ -101,4 +107,6 @@ "collectCoverage": true, | ||
"husky": "^4.2.5", | ||
"install-peers-cli": "^2.2.0", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"semantic-release": "^18.0.1", | ||
"tsdx": "^0.13.3", | ||
@@ -105,0 +113,0 @@ "tslib": "^2.1.0", |
@@ -22,8 +22,8 @@ # mui-modal-provider | ||
import ModalProvider, { useModal } from 'mui-modal-provider'; | ||
import Dialog, { DialogProps } from '@material-ui/core/Dialog'; | ||
import DialogTitle from '@material-ui/core/DialogTitle'; | ||
import Button from '@material-ui/core/Button'; | ||
import Dialog, { DialogProps } from '@mui/material/Dialog'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import Button from '@mui/material/Button'; | ||
type Props = DialogProps & { | ||
title: string; | ||
title: string, | ||
}; | ||
@@ -62,4 +62,20 @@ | ||
For [Material-UI v5](https://next.material-ui.com/) use `beta={true}` prop on the ModalProvider. | ||
## Compatibility | ||
### See more examples in [example](https://github.com/Quernest/mui-modal-provider/tree/master/example) folder | ||
For [Material-UI v4](https://v4.mui.com/) use `legacy` prop on the ModalProvider. | ||
## Examples | ||
See more examples in [example](https://github.com/Quernest/mui-modal-provider/tree/master/example) folder | ||
## Developing & linking locally | ||
Because this module utilizes react hooks, it must be linked in a special way that is described here in this [react github issue comment](https://github.com/facebook/react/issues/14257#issuecomment-439967377) | ||
1. Update the react and react-dom versions in this module’s package.json devDependencies match the versions in whatever project you’re linking them in. | ||
2. `yarn install` in this module’s root directory | ||
3. Because this module uses hooks, we need to link the module’s react dependency into the project we will be using to test the linked module | ||
4. `cd node_modules/react` then `yarn link` then inside your linked project run `yarn link react` | ||
5. In the linked project’s root directory run `yarn install mui-modal-provider` | ||
6. Then in the module’s root directory run `yarn link` | ||
7. In the linked project’s root directory run `yarn link mui-modal-provider` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83270
784
80
13