UNPKG

react-if-render

Version:

Conditional Rendering of React Components.

28 lines (24 loc) 15.4 kB
(function(b,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],h):(b=typeof globalThis<"u"?globalThis:b||self,h(b.index={},b.React))})(this,function(b,h){"use strict";function Ae(u){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const v in u)if(v!=="default"){const f=Object.getOwnPropertyDescriptor(u,v);Object.defineProperty(c,v,f.get?f:{enumerable:!0,get:()=>u[v]})}}return c.default=u,Object.freeze(c)}const Ie=Ae(h);function Ne(u){if(u.__esModule)return u;var c=u.default;if(typeof c=="function"){var v=function f(){return this instanceof f?Reflect.construct(c,arguments,this.constructor):c.apply(this,arguments)};v.prototype=c.prototype}else v={};return Object.defineProperty(v,"__esModule",{value:!0}),Object.keys(u).forEach(function(f){var _=Object.getOwnPropertyDescriptor(u,f);Object.defineProperty(v,f,_.get?_:{enumerable:!0,get:function(){return u[f]}})}),v}var G={exports:{}},A={};const re=Ne(Ie);/** * @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 te;function We(){if(te)return A;te=1;var u=re,c=Symbol.for("react.element"),v=Symbol.for("react.fragment"),f=Object.prototype.hasOwnProperty,_=u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,w={key:!0,ref:!0,__self:!0,__source:!0};function P(R,p,x){var m,T={},j=null,M=null;x!==void 0&&(j=""+x),p.key!==void 0&&(j=""+p.key),p.ref!==void 0&&(M=p.ref);for(m in p)f.call(p,m)&&!w.hasOwnProperty(m)&&(T[m]=p[m]);if(R&&R.defaultProps)for(m in p=R.defaultProps,p)T[m]===void 0&&(T[m]=p[m]);return{$$typeof:c,type:R,key:j,ref:M,props:T,_owner:_.current}}return A.Fragment=v,A.jsx=P,A.jsxs=P,A}var I={};/** * @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 ne;function $e(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&function(){var u=re,c=Symbol.for("react.element"),v=Symbol.for("react.portal"),f=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),P=Symbol.for("react.provider"),R=Symbol.for("react.context"),p=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),T=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),M=Symbol.for("react.offscreen"),fe=Symbol.iterator,Ue="@@iterator";function Ve(e){if(e===null||typeof e!="object")return null;var r=fe&&e[fe]||e[Ue];return typeof r=="function"?r:null}var k=u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];qe("error",e,t)}}function qe(e,r,t){{var n=k.ReactDebugCurrentFrame,o=n.getStackAddendum();o!==""&&(r+="%s",t=t.concat([o]));var s=t.map(function(i){return String(i)});s.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,s)}}var Be=!1,Ge=!1,Je=!1,ze=!1,He=!1,le;le=Symbol.for("react.module.reference");function Ke(e){return!!(typeof e=="string"||typeof e=="function"||e===f||e===w||He||e===_||e===x||e===m||ze||e===M||Be||Ge||Je||typeof e=="object"&&e!==null&&(e.$$typeof===j||e.$$typeof===T||e.$$typeof===P||e.$$typeof===R||e.$$typeof===p||e.$$typeof===le||e.getModuleId!==void 0))}function Xe(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return o!==""?t+"("+o+")":t}function ce(e){return e.displayName||"Context"}function O(e){if(e==null)return null;if(typeof e.tag=="number"&&y("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 f:return"Fragment";case v:return"Portal";case w:return"Profiler";case _:return"StrictMode";case x:return"Suspense";case m:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case R:var r=e;return ce(r)+".Consumer";case P:var t=e;return ce(t._context)+".Provider";case p:return Xe(e,e.render,"ForwardRef");case T:var n=e.displayName||null;return n!==null?n:O(e.type)||"Memo";case j:{var o=e,s=o._payload,i=o._init;try{return O(i(s))}catch{return null}}}return null}var C=Object.assign,W=0,de,ve,pe,ye,ge,me,he;function Ee(){}Ee.__reactDisabledLog=!0;function Ze(){{if(W===0){de=console.log,ve=console.info,pe=console.warn,ye=console.error,ge=console.group,me=console.groupCollapsed,he=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ee,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}W++}}function Qe(){{if(W--,W===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:C({},e,{value:de}),info:C({},e,{value:ve}),warn:C({},e,{value:pe}),error:C({},e,{value:ye}),group:C({},e,{value:ge}),groupCollapsed:C({},e,{value:me}),groupEnd:C({},e,{value:he})})}W<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var J=k.ReactCurrentDispatcher,z;function L(e,r,t){{if(z===void 0)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);z=n&&n[1]||""}return` `+z+e}}var H=!1,U;{var er=typeof WeakMap=="function"?WeakMap:Map;U=new er}function be(e,r){if(!e||H)return"";{var t=U.get(e);if(t!==void 0)return t}var n;H=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var s;s=J.current,J.current=null,Ze();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(S){n=S}Reflect.construct(e,[],i)}else{try{i.call()}catch(S){n=S}e.call(i.prototype)}}else{try{throw Error()}catch(S){n=S}e()}}catch(S){if(S&&n&&typeof S.stack=="string"){for(var a=S.stack.split(` `),g=n.stack.split(` `),l=a.length-1,d=g.length-1;l>=1&&d>=0&&a[l]!==g[d];)d--;for(;l>=1&&d>=0;l--,d--)if(a[l]!==g[d]){if(l!==1||d!==1)do if(l--,d--,d<0||a[l]!==g[d]){var E=` `+a[l].replace(" at new "," at ");return e.displayName&&E.includes("<anonymous>")&&(E=E.replace("<anonymous>",e.displayName)),typeof e=="function"&&U.set(e,E),E}while(l>=1&&d>=0);break}}}finally{H=!1,J.current=s,Qe(),Error.prepareStackTrace=o}var D=e?e.displayName||e.name:"",De=D?L(D):"";return typeof e=="function"&&U.set(e,De),De}function rr(e,r,t){return be(e,!1)}function tr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function V(e,r,t){if(e==null)return"";if(typeof e=="function")return be(e,tr(e));if(typeof e=="string")return L(e);switch(e){case x:return L("Suspense");case m:return L("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case p:return rr(e.render);case T:return V(e.type,r,t);case j:{var n=e,o=n._payload,s=n._init;try{return V(s(o),r,t)}catch{}}}return""}var q=Object.prototype.hasOwnProperty,_e={},Re=k.ReactDebugCurrentFrame;function B(e){if(e){var r=e._owner,t=V(e.type,e._source,r?r.type:null);Re.setExtraStackFrame(t)}else Re.setExtraStackFrame(null)}function nr(e,r,t,n,o){{var s=Function.call.bind(q);for(var i in e)if(s(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var g=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw g.name="Invariant Violation",g}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){a=l}a&&!(a instanceof Error)&&(B(o),y("%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,i,typeof a),B(null)),a instanceof Error&&!(a.message in _e)&&(_e[a.message]=!0,B(o),y("Failed %s type: %s",t,a.message),B(null))}}}var ar=Array.isArray;function K(e){return ar(e)}function ir(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function or(e){try{return Te(e),!1}catch{return!0}}function Te(e){return""+e}function Oe(e){if(or(e))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ir(e)),Te(e)}var $=k.ReactCurrentOwner,ur={key:!0,ref:!0,__self:!0,__source:!0},Se,Pe,X;X={};function sr(e){if(q.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function fr(e){if(q.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function lr(e,r){if(typeof e.ref=="string"&&$.current&&r&&$.current.stateNode!==r){var t=O($.current.type);X[t]||(y('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',O($.current.type),e.ref),X[t]=!0)}}function cr(e,r){{var t=function(){Se||(Se=!0,y("%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 dr(e,r){{var t=function(){Pe||(Pe=!0,y("%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 vr=function(e,r,t,n,o,s,i){var a={$$typeof:c,type:e,key:r,ref:t,props:i,_owner:s};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:o}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function pr(e,r,t,n,o){{var s,i={},a=null,g=null;t!==void 0&&(Oe(t),a=""+t),fr(r)&&(Oe(r.key),a=""+r.key),sr(r)&&(g=r.ref,lr(r,o));for(s in r)q.call(r,s)&&!ur.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps){var l=e.defaultProps;for(s in l)i[s]===void 0&&(i[s]=l[s])}if(a||g){var d=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&cr(i,d),g&&dr(i,d)}return vr(e,a,g,o,n,$.current,i)}}var Z=k.ReactCurrentOwner,je=k.ReactDebugCurrentFrame;function F(e){if(e){var r=e._owner,t=V(e.type,e._source,r?r.type:null);je.setExtraStackFrame(t)}else je.setExtraStackFrame(null)}var Q;Q=!1;function ee(e){return typeof e=="object"&&e!==null&&e.$$typeof===c}function Ce(){{if(Z.current){var e=O(Z.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function yr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return` Check your code at `+r+":"+t+"."}return""}}var we={};function gr(e){{var r=Ce();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 xe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=gr(r);if(we[t])return;we[t]=!0;var n="";e&&e._owner&&e._owner!==Z.current&&(n=" It was passed a child from "+O(e._owner.type)+"."),F(e),y('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),F(null)}}function ke(e,r){{if(typeof e!="object")return;if(K(e))for(var t=0;t<e.length;t++){var n=e[t];ee(n)&&xe(n,r)}else if(ee(e))e._store&&(e._store.validated=!0);else if(e){var o=Ve(e);if(typeof o=="function"&&o!==e.entries)for(var s=o.call(e),i;!(i=s.next()).done;)ee(i.value)&&xe(i.value,r)}}}function mr(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===p||r.$$typeof===T))t=r.propTypes;else return;if(t){var n=O(r);nr(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!Q){Q=!0;var o=O(r);y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",o||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function hr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){F(e),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),F(null);break}}e.ref!==null&&(F(e),y("Invalid attribute `ref` supplied to `React.Fragment`."),F(null))}}function Fe(e,r,t,n,o,s){{var i=Ke(e);if(!i){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 g=yr(o);g?a+=g:a+=Ce();var l;e===null?l="null":K(e)?l="array":e!==void 0&&e.$$typeof===c?(l="<"+(O(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):l=typeof e,y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",l,a)}var d=pr(e,r,t,o,s);if(d==null)return d;if(i){var E=r.children;if(E!==void 0)if(n)if(K(E)){for(var D=0;D<E.length;D++)ke(E[D],e);Object.freeze&&Object.freeze(E)}else y("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(E,e)}return e===f?hr(d):mr(d),d}}function Er(e,r,t){return Fe(e,r,t,!0)}function br(e,r,t){return Fe(e,r,t,!1)}var _r=br,Rr=Er;I.Fragment=f,I.jsx=_r,I.jsxs=Rr}()),I}process.env.NODE_ENV==="production"?G.exports=We():G.exports=$e();var N=G.exports;const ae="Then",ie="Else",oe="If the component's children should be Then and Else";function Ye({condition:u,children:c}){const v=f=>{if(!h.isValidElement(f)||typeof f.type=="string"||!("displayName"in f.type)||typeof f.type.displayName!="string")return Y();const{displayName:_}=f.type,w=u&&_===ae,P=!u&&_===ie,R=![ae,ie].includes(_);return w||P?f:(R&&console.warn(oe),null)};return N.jsx(h.Fragment,{children:h.Children.map(c,v)})}const Y=()=>(console.warn(oe),null);function ue({children:u}){return N.jsx(h.Fragment,{children:u})}ue.displayName="Then";function se({children:u}){return N.jsx(h.Fragment,{children:u})}se.displayName="Else";function Me({condition:u,children:c}){return N.jsx(h.Fragment,{children:u&&c})}function Le({condition:u,children:c}){return N.jsx(h.Fragment,{children:!u&&c})}b.Else=se,b.If=Ye,b.Then=ue,b.Unless=Le,b.When=Me,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});