UNPKG

@nozzlegear/react-win-dialog

Version:

An attempt to recreate the Dialog element from WinJS.

24 lines (23 loc) 8.73 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("react"),ae=require("react-dom"),R=require("classnames");function z(r){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const c in r)if(c!=="default"){const f=Object.getOwnPropertyDescriptor(r,c);Object.defineProperty(l,c,f.get?f:{enumerable:!0,get:()=>r[c]})}}return l.default=r,Object.freeze(l)}const v=z(U),oe=z(ae);var T={exports:{}},g={};/** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var L;function le(){if(L)return g;L=1;var r=Symbol.for("react.transitional.element"),l=Symbol.for("react.fragment");function c(f,i,u){var d=null;if(u!==void 0&&(d=""+u),i.key!==void 0&&(d=""+i.key),"key"in i){u={};for(var m in i)m!=="key"&&(u[m]=i[m])}else u=i;return i=u.ref,{$$typeof:r,type:f,key:d,ref:i!==void 0?i:null,props:u}}return g.Fragment=l,g.jsx=c,g.jsxs=c,g}var _={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var W;function ie(){return W||(W=1,process.env.NODE_ENV!=="production"&&(function(){function r(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===re?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case x:return"Fragment";case G:return"Profiler";case V:return"StrictMode";case Z:return"Suspense";case Q:return"SuspenseList";case ee:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case J:return"Portal";case B:return e.displayName||"Context";case X:return(e._context.displayName||"Context")+".Consumer";case H:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case K:return t=e.displayName||null,t!==null?t:r(e.type)||"Memo";case k:t=e._payload,e=e._init;try{return r(e(t))}catch{}}return null}function l(e){return""+e}function c(e){try{l(e);var t=!1}catch{t=!0}if(t){t=console;var n=t.error,a=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",a),l(e)}}function f(e){if(e===x)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===k)return"<...>";try{var t=r(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function i(){var e=O.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function d(e){if(Y.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function m(e,t){function n(){D||(D=!0,console.error("%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://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function j(){var e=r(this.type);return F[e]||(F[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function w(e,t,n,a,E,h){var o=n.ref;return e={$$typeof:C,type:e,key:t,props:n,_owner:a},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:j}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:E}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:h}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function N(e,t,n,a,E,h){var o=t.children;if(o!==void 0)if(a)if(te(o)){for(a=0;a<o.length;a++)A(o[a]);Object.freeze&&Object.freeze(o)}else console.error("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 A(o);if(Y.call(t,"key")){o=r(e);var b=Object.keys(t).filter(function(ne){return ne!=="key"});a=0<b.length?"{key: someKey, "+b.join(": ..., ")+": ...}":"{key: someKey}",$[o+a]||(b=0<b.length?"{"+b.join(": ..., ")+": ...}":"{}",console.error(`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} />`,a,o,b,o),$[o+a]=!0)}if(o=null,n!==void 0&&(c(n),o=""+n),d(t)&&(c(t.key),o=""+t.key),"key"in t){n={};for(var P in t)P!=="key"&&(n[P]=t[P])}else n=t;return o&&m(n,typeof e=="function"?e.displayName||e.name||"Unknown":e),w(e,o,n,i(),E,h)}function A(e){p(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===k&&(e._payload.status==="fulfilled"?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e=="object"&&e!==null&&e.$$typeof===C}var y=U,C=Symbol.for("react.transitional.element"),J=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),V=Symbol.for("react.strict_mode"),G=Symbol.for("react.profiler"),X=Symbol.for("react.consumer"),B=Symbol.for("react.context"),H=Symbol.for("react.forward_ref"),Z=Symbol.for("react.suspense"),Q=Symbol.for("react.suspense_list"),K=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),ee=Symbol.for("react.activity"),re=Symbol.for("react.client.reference"),O=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=Object.prototype.hasOwnProperty,te=Array.isArray,S=console.createTask?console.createTask:function(){return null};y={react_stack_bottom_frame:function(e){return e()}};var D,F={},I=y.react_stack_bottom_frame.bind(y,u)(),M=S(f(u)),$={};_.Fragment=x,_.jsx=function(e,t,n){var a=1e4>O.recentlyCreatedOwnerStacks++;return N(e,t,n,!1,a?Error("react-stack-top-frame"):I,a?S(f(e)):M)},_.jsxs=function(e,t,n){var a=1e4>O.recentlyCreatedOwnerStacks++;return N(e,t,n,!0,a?Error("react-stack-top-frame"):I,a?S(f(e)):M)}})()),_}var q;function ce(){return q||(q=1,process.env.NODE_ENV==="production"?T.exports=le():T.exports=ie()),T.exports}var s=ce();function se(r){const l=()=>{},c=r.overlayPreventsScrolling!==!1;let f=s.jsx(v.Fragment,{});const i=v.useMemo(()=>document.body.style.overflow,[]);if(v.useEffect(()=>(c&&(r.open?document.body.style.overflow="hidden":document.body.style.overflow=i||""),()=>{c&&(document.body.style.overflow=i||"")}),[r.open,c,i]),r.open){const d=[],m=r.loading??!1,j=r.loadingHidesButtons??!0;(m===!1||j===!1)&&(typeof r.secondaryText=="string"&&d.push(s.jsx("button",{type:"button",className:"btn react-win-dialog-secondary-command",onClick:r.onSecondaryClick||l,children:r.secondaryText},"secondary-button")),typeof r.primaryText=="string"&&d.push(s.jsx("button",{type:"button",className:R("btn react-win-dialog-primary-command primary",{danger:r.danger}),onClick:r.onPrimaryClick||l,children:r.primaryText},"primary-button")));const w=s.jsx("div",{id:r.id,className:R("react-win-dialog-container",r.className),style:r.containerStyle,children:s.jsxs("div",{className:R("react-win-dialog",{danger:r.danger||!1}),style:r.dialogStyle,children:[s.jsx("p",{className:"react-win-dialog-title",children:r.title}),s.jsxs("div",{className:"react-win-dialog-content",children:[r.children,s.jsx(ue,{loading:m,loadingComponent:r.loadingComponent})]}),s.jsx("div",{className:"react-win-dialog-footer",children:d})]})},"react-win-dialog-container");f=s.jsx("div",{children:w})}const u=s.jsx("div",{className:R("react-win-dialog-overlay",{open:r.open}),style:r.overlayStyle,children:f});return oe.createPortal(u,document.body)}const ue=v.memo(r=>{if(r.loading!==!0)return s.jsx(v.Fragment,{});let l;return r.loadingComponent===null||r.loadingComponent===void 0?l=s.jsx("progress",{className:"react-win-dialog-loading-bar"}):typeof r.loadingComponent=="function"?l=v.createElement(r.loadingComponent):l=r.loadingComponent,s.jsx("div",{className:"react-win-dialog-loading-container",children:l})});exports.Dialog=se; //# sourceMappingURL=index.cjs.map