Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@trbl/react-modal

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trbl/react-modal - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

dist/build.bundle.js

@@ -1,2 +0,2 @@

module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=7)}([function(e,t){e.exports=require("prop-types")},function(e,t){e.exports=require("react")},function(e,t){e.exports=require("@trbl/react-html-element")},function(e,t){e.exports=require("body-scroll-lock")},function(e,t){e.exports=require("react-transition-group")},function(e,t){e.exports=require("qs")},function(e,t){e.exports=require("react-dom")},function(e,t,n){"use strict";n.r(t),n.d(t,"asModal",(function(){return v})),n.d(t,"Modal",(function(){return P})),n.d(t,"ModalContainer",(function(){return E})),n.d(t,"ModalContext",(function(){return d})),n.d(t,"ModalProvider",(function(){return F})),n.d(t,"ModalToggler",(function(){return G})),n.d(t,"useModal",(function(){return b})),n.d(t,"withModal",(function(){return L}));var r=n(1),o=n.n(r),a=n(6),c=n.n(a),i=n(0),l=n.n(i),u=n(4),s=n(2),f=n.n(s),p=n(3),d=o.a.createContext({}),b=function(){return Object(r.useContext)(d)},m=function(e){return e?{appear:"".concat(e,"--appear"),appearActive:"".concat(e,"--appearActive"),appearDone:"".concat(e,"--appearDone"),enter:"".concat(e,"--enter"),enterActive:"".concat(e,"--enterActive"),enterDone:"".concat(e,"--enterDone"),exit:"".concat(e,"--exit"),exitActive:"".concat(e,"--exitActive"),exitDone:"".concat(e,"--exitDone")}:{}};function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function O(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function g(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?O(Object(n),!0).forEach((function(t){h(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function h(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var v=function(e,t){var n=function(n){var a=b(),i=a.currentModal,l=a.classPrefix,s=a.containerRef,d=a.transTime,O=a.setCloseOnBlur,h=n.id,v=n.className,j=n.style,P=n.htmlElement,S=n.htmlAttributes,w=n.slug,_=n.closeOnBlur,x=n.lockBodyScroll,E=t||w,C=i===E;Object(r.useEffect)((function(){C&&O(_)}),[C,_,O]);var k=Object(r.useRef)(null),D=Object(r.useCallback)((function(e){k.current=e}),[k]);if(Object(r.useEffect)((function(){return k.current&&(C&&x?Object(p.disableBodyScroll)(k.current):Object(p.enableBodyScroll)(k.current)),function(){return Object(p.enableBodyScroll)(k.current)}}),[k,C,x]),s){var M="".concat(l,"__").concat("modal-item"),A=[M,"".concat(M,"--slug-").concat(E),v].filter(Boolean).join(" "),B=g({role:"dialog"!==P?"dialog":void 0,open:C,"aria-modal":!0,"aria-label":S["aria-labelledby"]?void 0:E},S);return c.a.createPortal(o.a.createElement(u.CSSTransition,{timeout:d,in:i===E,classNames:m(M),appear:!0},o.a.createElement(f.a,y({id:h||E,className:A,style:j,htmlElement:P,htmlAttributes:B},{ref:D}),o.a.createElement(e,g({},n,{isOpen:C,modal:a})))),s)}return null};return n.defaultProps={id:void 0,className:void 0,style:{},htmlElement:"dialog",htmlAttributes:{},slug:"",autoFocus:!0,trapFocus:!0,returnFocus:!0,closeOnBlur:!0,lockBodyScroll:!0},n.propTypes={id:l.a.string,className:l.a.string,style:l.a.shape({}),htmlElement:l.a.string,htmlAttributes:l.a.shape({id:l.a.string,className:l.a.string,style:l.a.shape({}),onClick:l.a.func}),slug:l.a.string,autoFocus:l.a.bool,trapFocus:l.a.bool,returnFocus:l.a.bool,closeOnBlur:l.a.bool,lockBodyScroll:l.a.bool},n},j=function(e){var t=e.children,n=e.modal;return t&&"function"==typeof t?t(n):null};j.defaultProps={children:void 0},j.propTypes={children:l.a.func,modal:l.a.shape({}).isRequired};var P=v(j);function S(){return(S=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function w(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var x=function(e){var t=b(),n=t.oneIsOpen,r=t.classPrefix,a=t.transTime,c=t.setContainerRef,i=t.closeAll,l=t.closeOnBlur,s=e.id,p=e.className,d=e.style,y=e.htmlElement,O=e.htmlAttributes,g="".concat(r,"__").concat("modal-container"),h=[g,p].filter(Boolean).join(" "),v=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?w(Object(n),!0).forEach((function(t){_(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},O,{onClick:function(){l&&i(),"function"==typeof O.onClick&&O.onClick()}});return o.a.createElement(u.CSSTransition,{in:n,timeout:a,classNames:m(g),appear:!0},o.a.createElement(f.a,S({id:s,className:h,style:d,htmlElement:y,htmlAttributes:v},{ref:c})))};x.defaultProps={id:void 0,className:void 0,style:{},htmlElement:"div",htmlAttributes:{}},x.propTypes={id:l.a.string,className:l.a.string,style:l.a.shape({}),htmlElement:l.a.string,htmlAttributes:l.a.shape({onClick:l.a.func})};var E=x,C=n(5),k=n.n(C);function D(e){return(D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function M(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function A(e,t){return!t||"object"!==D(t)&&"function"!=typeof t?B(e):t}function B(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function T(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function R(e){return(R=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function N(e,t){return(N=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function q(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var I=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&N(e,t)}(l,e);var t,n,a,c,i=(t=l,function(){var e,n=R(t);if(T()){var r=R(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return A(this,e)});function l(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l),q(B(e=i.call(this)),"closeAll",(function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],n=e.props.handleParamChange;if(t&&("function"==typeof n&&n({key:"modal",value:""}),"boolean"==typeof n&&n)){var r=e.getSearchQuery();delete r.modal;var o=k.a.stringify(r,{addQueryPrefix:!0}),a="".concat(window.location.pathname).concat(o);window.history.pushState({},"",a)}Object(p.clearAllBodyScrollLocks)(),e.setState({currentModal:"",oneIsOpen:!1})})),q(B(e),"open",(function(t){if(t){var n=e.props.handleParamChange;if("function"==typeof n&&n({key:"modal",value:t}),"boolean"==typeof n&&n){var r=e.getSearchQuery();r.modal=t;var o=k.a.stringify(r,{addQueryPrefix:!0}),a="".concat(window.location.pathname).concat(o);window.history.pushState({},"",a)}e.setState({currentModal:t,oneIsOpen:!0})}})),q(B(e),"toggle",(function(t){t===e.state.currentModal?e.closeAll():e.open(t)})),q(B(e),"getModalParam",(function(){return e.getSearchQuery().modal||""})),q(B(e),"getSearchQuery",(function(){return k.a.parse(window.location.search,{ignoreQueryPrefix:!0})})),q(B(e),"setContainerRef",(function(t){e.setState({containerRef:t})})),q(B(e),"setCloseOnBlur",(function(t){e.setState({closeOnBlur:t})})),q(B(e),"bindEsc",(function(t){27===t.keyCode&&e.closeAll()})),q(B(e),"minifyCSSString",(function(e){return e.replace(/\n/g,"").replace(/\s\s+/g," ")})),e.state={containerRef:void 0,currentModal:"",oneIsOpen:!1},e}return n=l,(a=[{key:"componentDidMount",value:function(){var e=this;document.addEventListener("keydown",(function(t){return e.bindEsc(t)}),!1);var t=this.getModalParam();this.setState({currentModal:t,oneIsOpen:Boolean(t)})}},{key:"componentWillUnmount",value:function(){var e=this;document.removeEventListener("keydown",(function(t){return e.bindEsc(t)}),!1)}},{key:"render",value:function(){var e=this.props,t=e.children,n=e.generateCSS,a=e.classPrefix,c=e.minifyCSS,i=e.zIndex,l=e.transTime,u=this.state,s=u.containerRef,f=u.oneIsOpen,p=u.currentModal,b=u.closeOnBlur,m={containerRef:s,oneIsOpen:f,currentModal:p,closeAll:this.closeAll,closeOnBlur:b,setCloseOnBlur:this.setCloseOnBlur,open:this.open,toggle:this.toggle,setContainerRef:this.setContainerRef,classPrefix:a||"trbl",transTime:l},y="";return n&&(y=function(e,t){return"\n .".concat(e,"__").concat("modal-container"," {\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n position: fixed;\n pointer-events: none;\n visibility: hidden;\n z-index: -1;\n }\n\n .").concat(e,"__").concat("modal-container","--appear,\n .").concat(e,"__").concat("modal-container","--appearDone,\n .").concat(e,"__").concat("modal-container","--enter,\n .").concat(e,"__").concat("modal-container","--enterDone,\n .").concat(e,"__").concat("modal-container","--exit {\n pointer-events: all;\n visibility: visible;\n z-index: ").concat(t,";\n }\n\n .").concat(e,"__").concat("modal-item"," {\n position: absolute;\n left: 0;\n top: 0;\n visibility: hidden;\n border: unset;\n background: unset;\n padding: unset;\n }\n\n .").concat(e,"__").concat("modal-item","--appear,\n .").concat(e,"__").concat("modal-item","--appearDone,\n .").concat(e,"__").concat("modal-item","--enter,\n .").concat(e,"__").concat("modal-item","--enterDone,\n .").concat(e,"__").concat("modal-item","--exit {\n visibility: visible;\n }\n")}(a,i),c&&(y=this.minifyCSSString(y))),o.a.createElement(r.Fragment,null,n&&o.a.createElement("style",{dangerouslySetInnerHTML:{__html:y}}),o.a.createElement(d.Provider,{value:m},t&&t))}}])&&M(n.prototype,a),c&&M(n,c),l}(r.Component);I.defaultProps={classPrefix:"",generateCSS:!0,minifyCSS:!0,zIndex:9999,transTime:1e3,handleParamChange:void 0,children:void 0},I.propTypes={classPrefix:l.a.string,generateCSS:l.a.bool,minifyCSS:l.a.bool,zIndex:l.a.number,transTime:l.a.number,handleParamChange:l.a.oneOfType([l.a.func,l.a.bool]),children:l.a.node};var F=I;function Q(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function z(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var L=function(e){return function(t){return o.a.createElement(d.Consumer,null,(function(n){return o.a.createElement(e,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Q(Object(n),!0).forEach((function(t){z(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Q(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},t,{modal:n}))}))}};function H(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function U(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var W=function(e){var t=e.id,n=e.className,r=e.modal,a=r.currentModal,c=r.toggle,i=r.classPrefix,l=e.slug,u=e.style,s=e.htmlElement,p=e.htmlAttributes,d=e.children,b="".concat(i,"__modal-toggler"),m=a===l,y=[b,"".concat(b,"--slug-").concat(l),m&&"".concat(b,"--slug-").concat(l,"--is-open"),n].filter(Boolean).join(" "),O=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?H(Object(n),!0).forEach((function(t){U(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):H(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({role:"button","aria-expanded":m?"true":"false","aria-controls":l},p,{onClick:function(){c(l),"function"==typeof p.onClick&&p.onClick()}});return o.a.createElement(f.a,{id:t,className:y,style:u,htmlElement:s,htmlAttributes:O},d&&d)};W.defaultProps={id:void 0,className:void 0,style:{},htmlElement:"button",htmlAttributes:{},children:void 0},W.propTypes={id:l.a.string,className:l.a.string,style:l.a.shape({}),htmlElement:l.a.string,htmlAttributes:l.a.shape({id:l.a.string,className:l.a.string,style:l.a.shape({}),onClick:l.a.func}),slug:l.a.string.isRequired,modal:l.a.shape({currentModal:l.a.string,toggle:l.a.func,classPrefix:l.a.string}).isRequired,children:l.a.node};var G=L(W)}]);
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=7)}([function(e,t){e.exports=require("prop-types")},function(e,t){e.exports=require("react")},function(e,t){e.exports=require("@trbl/react-html-element")},function(e,t){e.exports=require("react-transition-group")},function(e,t){e.exports=require("qs")},function(e,t){e.exports=require("body-scroll-lock")},function(e,t){e.exports=require("react-dom")},function(e,t,n){"use strict";n.r(t),n.d(t,"asModal",(function(){return h})),n.d(t,"Modal",(function(){return E})),n.d(t,"ModalContainer",(function(){return A})),n.d(t,"ModalContext",(function(){return p})),n.d(t,"ModalProvider",(function(){return Q})),n.d(t,"ModalToggler",(function(){return K})),n.d(t,"useModal",(function(){return b})),n.d(t,"withModal",(function(){return F}));var r=n(1),o=n.n(r),c=n(6),a=n.n(c),i=n(0),l=n.n(i),u=n(3),s=n(2),f=n.n(s),p=o.a.createContext({}),b=function(){return Object(r.useContext)(p)},d=function(e){return e?{appear:"".concat(e,"--appear"),appearActive:"".concat(e,"--appearActive"),appearDone:"".concat(e,"--appearDone"),enter:"".concat(e,"--enter"),enterActive:"".concat(e,"--enterActive"),enterDone:"".concat(e,"--enterDone"),exit:"".concat(e,"--exit"),exitActive:"".concat(e,"--exitActive"),exitDone:"".concat(e,"--exitDone")}:{}};function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function m(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function O(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?m(Object(n),!0).forEach((function(t){v(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function v(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,o=!1,c=void 0;try{for(var a,i=e[Symbol.iterator]();!(r=(a=i.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,c=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw c}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return j(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return j(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function j(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var h=function(e,t){var n=function(n){var c=b(),i=c.currentModal,l=c.classPrefix,s=c.containerRef,p=c.transTime,m=c.setCloseOnBlur,v=c.open,j=c.setBodyScrollLock,h=n.id,P=n.className,w=n.style,S=n.htmlElement,E=n.htmlAttributes,x=n.slug,C=n.closeOnBlur,k=n.lockBodyScroll,D=t||x,A=Object(r.useRef)(!0),T=i===D;Object(r.useEffect)((function(){A&&(T&&v(D),A.current=!1)}),[T,v,A,D]),Object(r.useEffect)((function(){T&&m(C)}),[T,C,m]);var M=Object(r.useRef)(null),B=Object(r.useCallback)((function(e){M.current=e}),[M]);Object(r.useEffect)((function(){M.current&&j(!(!T||!k),M)}),[T,k,j]),Object(r.useEffect)((function(){return function(){return j(!1,M)}}),[j]);var N=g(Object(r.useState)(T),2),_=N[0],I=N[1];if(Object(r.useEffect)((function(){T?I(T):setTimeout((function(){return I(!1)}),p)}),[T,p]),s.current){var q="".concat(l,"__").concat("modal-item"),R=[q,"".concat(q,"--slug-").concat(D),P].filter(Boolean).join(" "),L=O({role:"dialog"!==S?"dialog":void 0,open:"dialog"===S?_||T:void 0,"aria-modal":!0,"aria-label":E["aria-labelledby"]?void 0:D},E);return a.a.createPortal(o.a.createElement(u.CSSTransition,{timeout:p,in:i===D,classNames:d(q),appear:!0},o.a.createElement(f.a,y({id:h||D,className:R,style:w,htmlElement:S,htmlAttributes:L},{ref:B}),o.a.createElement(e,O({},n,{isOpen:T,modal:c})))),s.current)}return null};return n.defaultProps={slug:"",closeOnBlur:!0,lockBodyScroll:!0,id:void 0,className:void 0,style:{},htmlElement:"dialog",htmlAttributes:{}},n.propTypes={slug:l.a.string,closeOnBlur:l.a.bool,lockBodyScroll:l.a.bool,id:l.a.string,className:l.a.string,style:l.a.shape({}),htmlElement:l.a.string,htmlAttributes:l.a.shape({id:l.a.string,className:l.a.string,style:l.a.shape({}),onClick:l.a.func})},n};function P(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function w(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var S=function(e){var t=e.children;return t&&"function"==typeof t?t(function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?P(Object(n),!0).forEach((function(t){w(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):P(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e)):null};S.defaultProps={children:void 0},S.propTypes={children:l.a.func};var E=h(S);function x(){return(x=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function C(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function k(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var D=function(e){var t=b(),n=t.oneIsOpen,r=t.classPrefix,c=t.transTime,a=t.setContainerRef,i=t.closeAll,l=t.closeOnBlur,s=e.id,p=e.className,y=e.style,m=e.htmlElement,O=e.htmlAttributes,v=e.children,g="".concat(r,"__").concat("modal-container"),j=[g,p].filter(Boolean).join(" "),h=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?C(Object(n),!0).forEach((function(t){k(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},O,{onClick:function(){l&&i(),"function"==typeof O.onClick&&O.onClick()}});return o.a.createElement(u.CSSTransition,{in:n,timeout:c,classNames:d(g),appear:!0},o.a.createElement(f.a,x({id:s,className:j,style:y,htmlElement:m,htmlAttributes:h},{ref:a}),v&&v))};D.defaultProps={id:void 0,className:void 0,style:{},htmlElement:"div",htmlAttributes:{},children:void 0},D.propTypes={id:l.a.string,className:l.a.string,style:l.a.shape({}),htmlElement:l.a.string,htmlAttributes:l.a.shape({onClick:l.a.func}),children:l.a.node};var A=D,T=n(4),M=n.n(T),B=n(5);function N(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?N(Object(n),!0).forEach((function(t){I(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):N(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function I(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function q(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,o=!1,c=void 0;try{for(var a,i=e[Symbol.iterator]();!(r=(a=i.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,c=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw c}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return R(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return R(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function R(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var L=function(){return M.a.parse(window.location.search,{ignoreQueryPrefix:!0})},z=function(e){var t=e.classPrefix,n=e.minifyCSS,c=e.generateCSS,a=e.zIndex,i=e.handleParamChange,l=e.children,u=e.transTime,s=Object(r.useRef)(null),f=q(Object(r.useState)(""),2),b=f[0],d=f[1],y=q(Object(r.useState)(!1),2),m=y[0],O=y[1],v=q(Object(r.useState)(!1),2),g=v[0],j=v[1],h=q(Object(r.useState)(!1),2),P=h[0],w=h[1],S=q(Object(r.useState)(""),2),E=S[0],x=S[1],C=q(Object(r.useState)(""),2),k=C[0],D=C[1],A=Object(r.useCallback)((function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(e&&("function"==typeof i&&i({key:"modal",value:""}),"boolean"==typeof i&&i)){var t=L();delete t.modal;var n=M.a.stringify(t,{addQueryPrefix:!0}),r="".concat(window.location.pathname).concat(n);window.history.pushState({},"",r)}Object(B.clearAllBodyScrollLocks)(),d(""),O(!1)}),[i]),T=Object(r.useCallback)((function(e){27===e.keyCode&&A()}),[A]);Object(r.useEffect)((function(){return document.addEventListener("keydown",(function(e){return T(e)}),!1),d(L().modal||""),function(){return document.removeEventListener("keydown",(function(e){return T(e)}),!1)}}),[T]),Object(r.useEffect)((function(){var e="trbl";"string"==typeof t&&t&&(e=t),"boolean"!=typeof t||t||(e=void 0),D(e)}),[t]),Object(r.useEffect)((function(){if(c){var e="";e=function(e,t){var n=e?"".concat(e,"__"):"";return"\n .".concat(n).concat("modal-container"," {\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n position: fixed;\n pointer-events: none;\n visibility: hidden;\n z-index: -1;\n }\n\n .").concat(n).concat("modal-container","--appear,\n .").concat(n).concat("modal-container","--appearDone,\n .").concat(n).concat("modal-container","--enter,\n .").concat(n).concat("modal-container","--enterDone,\n .").concat(n).concat("modal-container","--exit {\n pointer-events: all;\n visibility: visible;\n z-index: ").concat(t,";\n }\n\n .").concat(n).concat("modal-item"," {\n position: absolute;\n left: 0;\n top: 0;\n visibility: hidden;\n }\n\n .").concat(n).concat("modal-item","--appear,\n .").concat(n).concat("modal-item","--appearDone,\n .").concat(n).concat("modal-item","--enter,\n .").concat(n).concat("modal-item","--enterDone,\n .").concat(n).concat("modal-item","--exit {\n visibility: visible;\n }\n ")}(k,a),n&&(e=e.replace(/\n/g,"").replace(/\s\s+/g," ")),x(e)}}),[c,n,a,k]);var N=Object(r.useCallback)((function(e,t){if(!t&&("function"==typeof i&&i({key:"modal",value:e}),"boolean"==typeof i&&i)){var n=L();n.modal=e;var r=M.a.stringify(n,{addQueryPrefix:!0}),o="".concat(window.location.pathname).concat(r);window.history.pushState({},"",o)}d(e),O(!0)}),[i]),I=Object(r.useCallback)((function(e){e===b?A():N(e)}),[A,N,b]),R=Object(r.useCallback)((function(e,t){e?(Object(B.disableBodyScroll)(t.current),w(!0)):(Object(B.enableBodyScroll)(t.current),w(!1))}),[]),z=Object(r.useCallback)((function(e){s.current=e}),[]),Q=_({},e);return delete Q.children,o.a.createElement(r.Fragment,null,c&&o.a.createElement("style",{dangerouslySetInnerHTML:{__html:E}}),o.a.createElement(p.Provider,{value:_({},Q,{transTime:u,containerRef:s,currentModal:b,oneIsOpen:m,closeOnBlur:g,bodyScrollIsLocked:P,classPrefix:k,closeAll:A,setCloseOnBlur:j,open:N,toggle:I,setContainerRef:z,setBodyScrollLock:R})},l&&l))};z.defaultProps={generateCSS:!0,minifyCSS:!0,classPrefix:void 0,handleParamChange:void 0,transTime:1e3,zIndex:9999,children:void 0},z.propTypes={generateCSS:l.a.bool,minifyCSS:l.a.bool,classPrefix:l.a.oneOfType([l.a.string,l.a.bool]),handleParamChange:l.a.oneOfType([l.a.func,l.a.bool]),transTime:l.a.number,zIndex:l.a.number,children:l.a.node};var Q=z;function U(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function $(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var F=function(e){return function(t){return o.a.createElement(p.Consumer,null,(function(n){return o.a.createElement(e,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?U(Object(n),!0).forEach((function(t){$(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):U(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},t,{modal:n}))}))}};function H(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function G(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var J=function(e){var t=e.id,n=e.className,r=e.modal,c=r.currentModal,a=r.toggle,i=r.classPrefix,l=e.slug,u=e.style,s=e.htmlElement,p=e.htmlAttributes,b=e.children,d="".concat(i,"__modal-toggler"),y=c===l,m=[d,"".concat(d,"--slug-").concat(l),y&&"".concat(d,"--slug-").concat(l,"--is-open"),n].filter(Boolean).join(" "),O=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?H(Object(n),!0).forEach((function(t){G(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):H(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({role:"button","aria-expanded":y?"true":"false","aria-controls":l},p,{onClick:function(){a(l),"function"==typeof p.onClick&&p.onClick()}});return o.a.createElement(f.a,{id:t,className:m,style:u,htmlElement:s,htmlAttributes:O},b&&b)};J.defaultProps={id:void 0,className:void 0,style:{},htmlElement:"button",htmlAttributes:{},children:void 0},J.propTypes={id:l.a.string,className:l.a.string,style:l.a.shape({}),htmlElement:l.a.string,htmlAttributes:l.a.shape({id:l.a.string,className:l.a.string,style:l.a.shape({}),onClick:l.a.func}),slug:l.a.string.isRequired,modal:l.a.shape({currentModal:l.a.string,toggle:l.a.func,classPrefix:l.a.string}).isRequired,children:l.a.node};var K=F(J)}]);
//# sourceMappingURL=build.bundle.js.map
{
"name": "@trbl/react-modal",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/build.bundle.js",

@@ -25,2 +25,3 @@ "repository": "git@github.com:trouble/react-modal.git",

"dev": "webpack-dev-server --hot --inline --config webpack.development.config.js",
"netlify": "yarn lint && yarn test && webpack --config webpack.netlify.config.js",
"lint": "eslint .",

@@ -66,3 +67,2 @@ "test": "jest"

"webpack": "^4.41.4",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-cli": "^3.3.10",

@@ -80,4 +80,5 @@ "webpack-dev-server": "^3.10.1"

"files": [
"dist"
"dist/build.bundle.js",
"dist/build.bundle.js.map"
]
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc