UNPKG

react-flash-modal

Version:

A lightweight and flexible React modal component with smooth animations and easy customization. Perfect for modern web applications. Can be easily integrated into any project.

31 lines (28 loc) 15.5 kB
(function(_,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],g):(_=typeof globalThis<"u"?globalThis:_||self,g(_["react-flash-modal"]={},_.React,_.ReactDOM))})(this,function(_,g,Ae){"use strict";var Z={exports:{}},I={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ue;function Le(){if(ue)return I;ue=1;var M=g,w=Symbol.for("react.element"),j=Symbol.for("react.fragment"),R=Object.prototype.hasOwnProperty,k=M.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,D={key:!0,ref:!0,__self:!0,__source:!0};function C(h,c,T){var d,y={},b=null,F=null;T!==void 0&&(b=""+T),c.key!==void 0&&(b=""+c.key),c.ref!==void 0&&(F=c.ref);for(d in c)R.call(c,d)&&!D.hasOwnProperty(d)&&(y[d]=c[d]);if(h&&h.defaultProps)for(d in c=h.defaultProps,c)y[d]===void 0&&(y[d]=c[d]);return{$$typeof:w,type:h,key:b,ref:F,props:y,_owner:k.current}}return I.Fragment=j,I.jsx=C,I.jsxs=C,I}var W={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var se;function Ie(){return se||(se=1,process.env.NODE_ENV!=="production"&&function(){var M=g,w=Symbol.for("react.element"),j=Symbol.for("react.portal"),R=Symbol.for("react.fragment"),k=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),C=Symbol.for("react.provider"),h=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),F=Symbol.for("react.offscreen"),$=Symbol.iterator,U="@@iterator";function B(e){if(e===null||typeof e!="object")return null;var r=$&&e[$]||e[U];return typeof r=="function"?r:null}var O=M.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function f(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Y("error",e,t)}}function Y(e,r,t){{var n=O.ReactDebugCurrentFrame,i=n.getStackAddendum();i!==""&&(r+="%s",t=t.concat([i]));var u=t.map(function(o){return String(o)});u.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,u)}}var z=!1,J=!1,K=!1,Ye=!1,Ne=!1,le;le=Symbol.for("react.module.reference");function Ve(e){return!!(typeof e=="string"||typeof e=="function"||e===R||e===D||Ne||e===k||e===T||e===d||Ye||e===F||z||J||K||typeof e=="object"&&e!==null&&(e.$$typeof===b||e.$$typeof===y||e.$$typeof===C||e.$$typeof===h||e.$$typeof===c||e.$$typeof===le||e.getModuleId!==void 0))}function $e(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function ce(e){return e.displayName||"Context"}function x(e){if(e==null)return null;if(typeof e.tag=="number"&&f("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case R:return"Fragment";case j:return"Portal";case D:return"Profiler";case k:return"StrictMode";case T:return"Suspense";case d:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case h:var r=e;return ce(r)+".Consumer";case C:var t=e;return ce(t._context)+".Provider";case c:return $e(e,e.render,"ForwardRef");case y:var n=e.displayName||null;return n!==null?n:x(e.type)||"Memo";case b:{var i=e,u=i._payload,o=i._init;try{return x(o(u))}catch{return null}}}return null}var P=Object.assign,N=0,fe,de,ve,pe,me,he,ye;function ge(){}ge.__reactDisabledLog=!0;function Ue(){{if(N===0){fe=console.log,de=console.info,ve=console.warn,pe=console.error,me=console.group,he=console.groupCollapsed,ye=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ge,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}N++}}function Be(){{if(N--,N===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},e,{value:fe}),info:P({},e,{value:de}),warn:P({},e,{value:ve}),error:P({},e,{value:pe}),group:P({},e,{value:me}),groupCollapsed:P({},e,{value:he}),groupEnd:P({},e,{value:ye})})}N<0&&f("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Q=O.ReactCurrentDispatcher,ee;function G(e,r,t){{if(ee===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);ee=n&&n[1]||""}return` `+ee+e}}var re=!1,X;{var ze=typeof WeakMap=="function"?WeakMap:Map;X=new ze}function be(e,r){if(!e||re)return"";{var t=X.get(e);if(t!==void 0)return t}var n;re=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=Q.current,Q.current=null,Ue();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(p){n=p}Reflect.construct(e,[],o)}else{try{o.call()}catch(p){n=p}e.call(o.prototype)}}else{try{throw Error()}catch(p){n=p}e()}}catch(p){if(p&&n&&typeof p.stack=="string"){for(var a=p.stack.split(` `),v=n.stack.split(` `),s=a.length-1,l=v.length-1;s>=1&&l>=0&&a[s]!==v[l];)l--;for(;s>=1&&l>=0;s--,l--)if(a[s]!==v[l]){if(s!==1||l!==1)do if(s--,l--,l<0||a[s]!==v[l]){var m=` `+a[s].replace(" at new "," at ");return e.displayName&&m.includes("<anonymous>")&&(m=m.replace("<anonymous>",e.displayName)),typeof e=="function"&&X.set(e,m),m}while(s>=1&&l>=0);break}}}finally{re=!1,Q.current=u,Be(),Error.prepareStackTrace=i}var L=e?e.displayName||e.name:"",S=L?G(L):"";return typeof e=="function"&&X.set(e,S),S}function Je(e,r,t){return be(e,!1)}function Ke(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function q(e,r,t){if(e==null)return"";if(typeof e=="function")return be(e,Ke(e));if(typeof e=="string")return G(e);switch(e){case T:return G("Suspense");case d:return G("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case c:return Je(e.render);case y:return q(e.type,r,t);case b:{var n=e,i=n._payload,u=n._init;try{return q(u(i),r,t)}catch{}}}return""}var V=Object.prototype.hasOwnProperty,_e={},Ee=O.ReactDebugCurrentFrame;function H(e){if(e){var r=e._owner,t=q(e.type,e._source,r?r.type:null);Ee.setExtraStackFrame(t)}else Ee.setExtraStackFrame(null)}function Ge(e,r,t,n,i){{var u=Function.call.bind(V);for(var o in e)if(u(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var v=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw v.name="Invariant Violation",v}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(s){a=s}a&&!(a instanceof Error)&&(H(i),f("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,o,typeof a),H(null)),a instanceof Error&&!(a.message in _e)&&(_e[a.message]=!0,H(i),f("Failed %s type: %s",t,a.message),H(null))}}}var Xe=Array.isArray;function te(e){return Xe(e)}function qe(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function He(e){try{return Re(e),!1}catch{return!0}}function Re(e){return""+e}function Te(e){if(He(e))return f("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qe(e)),Re(e)}var Oe=O.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0},xe,we;function Qe(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function er(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function rr(e,r){typeof e.ref=="string"&&Oe.current}function tr(e,r){{var t=function(){xe||(xe=!0,f("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function nr(e,r){{var t=function(){we||(we=!0,f("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var ar=function(e,r,t,n,i,u,o){var a={$$typeof:w,type:e,key:r,ref:t,props:o,_owner:u};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function or(e,r,t,n,i){{var u,o={},a=null,v=null;t!==void 0&&(Te(t),a=""+t),er(r)&&(Te(r.key),a=""+r.key),Qe(r)&&(v=r.ref,rr(r,i));for(u in r)V.call(r,u)&&!Ze.hasOwnProperty(u)&&(o[u]=r[u]);if(e&&e.defaultProps){var s=e.defaultProps;for(u in s)o[u]===void 0&&(o[u]=s[u])}if(a||v){var l=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&tr(o,l),v&&nr(o,l)}return ar(e,a,v,i,n,Oe.current,o)}}var ne=O.ReactCurrentOwner,Ce=O.ReactDebugCurrentFrame;function A(e){if(e){var r=e._owner,t=q(e.type,e._source,r?r.type:null);Ce.setExtraStackFrame(t)}else Ce.setExtraStackFrame(null)}var ae;ae=!1;function oe(e){return typeof e=="object"&&e!==null&&e.$$typeof===w}function Pe(){{if(ne.current){var e=x(ne.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function ir(e){return""}var Se={};function ur(e){{var r=Pe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=` Check the top-level render call using <`+t+">.")}return r}}function je(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=ur(r);if(Se[t])return;Se[t]=!0;var n="";e&&e._owner&&e._owner!==ne.current&&(n=" It was passed a child from "+x(e._owner.type)+"."),A(e),f('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),A(null)}}function ke(e,r){{if(typeof e!="object")return;if(te(e))for(var t=0;t<e.length;t++){var n=e[t];oe(n)&&je(n,r)}else if(oe(e))e._store&&(e._store.validated=!0);else if(e){var i=B(e);if(typeof i=="function"&&i!==e.entries)for(var u=i.call(e),o;!(o=u.next()).done;)oe(o.value)&&je(o.value,r)}}}function sr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===c||r.$$typeof===y))t=r.propTypes;else return;if(t){var n=x(r);Ge(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ae){ae=!0;var i=x(r);f("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&f("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function lr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){A(e),f("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),A(null);break}}e.ref!==null&&(A(e),f("Invalid attribute `ref` supplied to `React.Fragment`."),A(null))}}var De={};function Fe(e,r,t,n,i,u){{var o=Ve(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var v=ir();v?a+=v:a+=Pe();var s;e===null?s="null":te(e)?s="array":e!==void 0&&e.$$typeof===w?(s="<"+(x(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):s=typeof e,f("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",s,a)}var l=or(e,r,t,i,u);if(l==null)return l;if(o){var m=r.children;if(m!==void 0)if(n)if(te(m)){for(var L=0;L<m.length;L++)ke(m[L],e);Object.freeze&&Object.freeze(m)}else f("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ke(m,e)}if(V.call(r,"key")){var S=x(e),p=Object.keys(r).filter(function(mr){return mr!=="key"}),ie=p.length>0?"{key: someKey, "+p.join(": ..., ")+": ...}":"{key: someKey}";if(!De[S+ie]){var pr=p.length>0?"{"+p.join(": ..., ")+": ...}":"{}";f(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,ie,S,pr,S),De[S+ie]=!0}}return e===R?lr(l):sr(l),l}}function cr(e,r,t){return Fe(e,r,t,!0)}function fr(e,r,t){return Fe(e,r,t,!1)}var dr=fr,vr=cr;W.Fragment=R,W.jsx=dr,W.jsxs=vr}()),W}process.env.NODE_ENV==="production"?Z.exports=Le():Z.exports=Ie();var E=Z.exports;const We=M=>{const{isOpen:w=!1,onClose:j,background:R,modalContent:k,children:D=""}=M,{color:C="#00000050",blur:h,maxWidth:c,zIndex:T=2}=R,{width:d="60%",isModalTop:y}=k,{visible:b=!0,bgColor:F="blue",name:$="",textColor:U="white",radiusTopX:B="12px",fontSize:O="18px",padding:f="15px 20px"}=y,Y=g.useRef(),z=J=>{Y.current&&!Y.current.contains(J.target)&&j()};return g.useEffect(()=>{if(!document.getElementById("root_modal_overlay_element")){let K=document.createElement("div");K.id="root_modal_overlay_element",document.body.appendChild(K)}return document.addEventListener("mousedown",z),()=>{document.removeEventListener("mousedown",z)}},[]),w?Ae.createPortal(E.jsx("div",{className:"modal-overlay-container",style:{backgroundColor:C,backdropFilter:`blur(${h==null?void 0:h.size})`,maxWidth:c,zIndex:T},children:E.jsxs("div",{className:"modal-overlay-block",ref:Y,style:{width:d},children:[b&&E.jsxs("div",{className:"modal-overlay-top",style:{backgroundColor:F,color:U,borderTopRightRadius:B,borderTopLeftRadius:B,padding:f},children:[E.jsx("div",{children:E.jsx("span",{style:{fontSize:O},children:$})}),E.jsx("span",{onClick:j,className:"modal-overlay-close",children:E.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:U,viewBox:"0 0 24 24",width:"19px",height:"19px",children:E.jsx("path",{d:"M 4.7070312 3.2929688 L 3.2929688 4.7070312 L 10.585938 12 L 3.2929688 19.292969 L 4.7070312 20.707031 L 12 13.414062 L 19.292969 20.707031 L 20.707031 19.292969 L 13.414062 12 L 20.707031 4.7070312 L 19.292969 3.2929688 L 12 10.585938 L 4.7070312 3.2929688 z"})})})]}),D]})}),document.getElementById("root_modal_overlay_element")):null},Me=g.memo(We);_.ModalPortal=Me,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});