UNPKG

@nuitral/react-ui-suite

Version:
12 lines (11 loc) 11.1 kB
"use strict";var e,r=require("react"),t={exports:{}},n={};var o,a,i={}; /** * @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. */function s(){return o||(o=1,"production"!==process.env.NODE_ENV&&function(){function e(r){if(null==r)return null;if("function"==typeof r)return r.$$typeof===$?null:r.displayName||r.name||null;if("string"==typeof r)return r;switch(r){case m:return"Fragment";case y:return"Profiler";case b:return"StrictMode";case j:return"Suspense";case x:return"SuspenseList";case N:return"Activity"}if("object"==typeof r)switch("number"==typeof r.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),r.$$typeof){case p:return"Portal";case g:return(r.displayName||"Context")+".Provider";case h:return(r._context.displayName||"Context")+".Consumer";case v:var t=r.render;return(r=r.displayName)||(r=""!==(r=t.displayName||t.name||"")?"ForwardRef("+r+")":"ForwardRef"),r;case k:return null!==(t=r.displayName||null)?t:e(r.type)||"Memo";case S:t=r._payload,r=r._init;try{return e(r(t))}catch(e){}}return null}function t(e){return""+e}function n(e){try{t(e);var r=!1}catch(e){r=!0}if(r){var n=(r=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),t(e)}}function o(r){if(r===m)return"<>";if("object"==typeof r&&null!==r&&r.$$typeof===S)return"<...>";try{var t=e(r);return t?"<"+t+">":"<...>"}catch(e){return"<...>"}}function a(){return Error("react-stack-top-frame")}function s(){var r=e(this.type);return M[r]||(M[r]=!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.")),void 0!==(r=this.props.ref)?r:null}function l(r,t,o,a,i,l,d,p){var m,b=t.children;if(void 0!==b)if(a)if(w(b)){for(a=0;a<b.length;a++)c(b[a]);Object.freeze&&Object.freeze(b)}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 c(b);if(_.call(t,"key")){b=e(r);var y=Object.keys(t).filter((function(e){return"key"!==e}));a=0<y.length?"{key: someKey, "+y.join(": ..., ")+": ...}":"{key: someKey}",A[b+a]||(y=0<y.length?"{"+y.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',a,b,y,b),A[b+a]=!0)}if(b=null,void 0!==o&&(n(o),b=""+o),function(e){if(_.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(t)&&(n(t.key),b=""+t.key),"key"in t)for(var h in o={},t)"key"!==h&&(o[h]=t[h]);else o=t;return b&&function(e,r){function t(){u||(u=!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)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(o,"function"==typeof r?r.displayName||r.name||"Unknown":r),function(e,r,t,n,o,a,i,l){return t=a.ref,e={$$typeof:f,type:e,key:r,props:a,_owner:o},null!==(void 0!==t?t:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:s}):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:i}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:l}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(r,b,l,0,null===(m=O.A)?null:m.getOwner(),o,d,p)}function c(e){"object"==typeof e&&null!==e&&e.$$typeof===f&&e._store&&(e._store.validated=1)}var u,d=r,f=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),m=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),y=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),g=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),x=Symbol.for("react.suspense_list"),k=Symbol.for("react.memo"),S=Symbol.for("react.lazy"),N=Symbol.for("react.activity"),$=Symbol.for("react.client.reference"),O=d.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,_=Object.prototype.hasOwnProperty,w=Array.isArray,E=console.createTask?console.createTask:function(){return null},M={},P=(d={"react-stack-bottom-frame":function(e){return e()}})["react-stack-bottom-frame"].bind(d,a)(),T=E(o(a)),A={};i.Fragment=m,i.jsx=function(e,r,t,n,a){var i=1e4>O.recentlyCreatedOwnerStacks++;return l(e,r,t,!1,0,a,i?Error("react-stack-top-frame"):P,i?E(o(e)):T)},i.jsxs=function(e,r,t,n,a){var i=1e4>O.recentlyCreatedOwnerStacks++;return l(e,r,t,!0,0,a,i?Error("react-stack-top-frame"):P,i?E(o(e)):T)}}()),i}var l=(a||(a=1,"production"===process.env.NODE_ENV?t.exports=function(){if(e)return n;e=1;var r=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function o(e,t,n){var o=null;if(void 0!==n&&(o=""+n),void 0!==t.key&&(o=""+t.key),"key"in t)for(var a in n={},t)"key"!==a&&(n[a]=t[a]);else n=t;return t=n.ref,{$$typeof:r,type:e,key:o,ref:void 0!==t?t:null,props:n}}return n.Fragment=t,n.jsx=o,n.jsxs=o,n}():t.exports=s()),t.exports);const c=(e,t=[])=>r.useMemo((()=>{const r={};for(const n in e)if(!t.includes(n)){const t=e[n];r[n]="boolean"==typeof t?t.toString():t}return r}),[e,t]),u=()=>{const e=r.useMemo((()=>["primary","secondary","accent","error","success","warning","info","neutral","background","surface"]),[]),t=r.useMemo((()=>["100","200","300","400","500","600","700","800","900"]),[]),n=[];e.forEach((e=>{n.push(`${e}`),t.forEach((r=>{n.push(`${e}-${r}`)})),n.push(`border-${e}`),t.forEach((r=>{n.push(`border-${e}-${r}`)}))}));return{isValidAttribute:e=>n.includes(e)}},d=({icon:e=""})=>{const t=r.useMemo((()=>`nuitral-icon-${e}`),[e]);return l.jsx("div",{className:`nuitral-icon ${t}`})};exports.NuitralBox=({title:e,description:t,...n})=>{const o=c(n),{isValidAttribute:a}=u(),i=r.useMemo((()=>{const e={};for(const r in o)a(r)&&(e[r]=o[r]);return Object.keys(e).map((e=>`nuitral-box-background-${e}`))}),[o]);return l.jsxs("div",{className:`nuitral-box ${i}`,children:[l.jsx("div",{className:"nuitral-box-title",children:e}),l.jsx("div",{children:t})]})},exports.NuitralButton=({classes:e="",type:t="button",disabled:n=!1,icon:o,iconPosition:a="left",children:i,leftSide:s,rightSide:f,...p})=>{const m=c(p),{isValidAttribute:b}=u(),y=r.useMemo((()=>{const e={};for(const r in m)b(r)&&(e[r]=m[r]);return Object.keys(e).map((e=>`nuitral-button-background-${e}`))}),[m]);return l.jsxs("button",{className:`nuitral-button ${e} ${y} ${n?"disabled":""}`,type:t,disabled:n,...m,children:[s&&l.jsx("div",{className:"left-side",children:s}),o&&"left"===a&&l.jsx(d,{icon:o}),i,o&&"right"===a&&l.jsx(d,{icon:o}),f&&l.jsx("div",{className:"right-side",children:f})]})},exports.NuitralCard=({classes:e="",children:t,header:n,footer:o,hasShadow:a=!1,...i})=>{const s=c(i),{isValidAttribute:d}=u(),f=r.useMemo((()=>{const e={};for(const r in s)d(r)&&!r.startsWith("border-")&&(e[r]=s[r]);return Object.keys(e).length?Object.keys(e).map((e=>`nuitral-card-background-${e}`)):"nuitral-card-background-background"}),[s]),p=r.useMemo((()=>{const e={};for(const r in s)d(r)&&r.startsWith("border-")&&(e[r]=s[r]);return Object.keys(e).length?Object.keys(e).map((e=>`nuitral-card-${e}`)):"nuitral-card-border-primary"}),[s]);return l.jsxs(l.Fragment,{children:[l.jsx("div",{children:f}),l.jsxs("div",{...s,className:`nuitral-card ${e} ${f} ${a?"nuitral-card-shadow":p}`,children:[n&&l.jsx("div",{className:"nuitral-card-header",children:n}),t,o&&l.jsx("div",{className:"nuitral-card-footer",children:o})]})]})},exports.NuitralIcon=d,exports.NuitralInput=({type:e="text",placeholder:r="",icon:t,iconPosition:n="left",disabled:o=!1,classes:a="",value:i,onChange:s})=>l.jsxs("div",{className:`nuitral-input nuitral-input-text-color ${a} ${o?"disabled":""}`,children:[t&&"left"===n&&l.jsx(d,{icon:t}),l.jsx("input",{type:e,disabled:o,placeholder:r,value:i,onChange:r=>{const t="number"===e?Number(r.target.value):r.target.value;s(t)}}),t&&"right"===n&&l.jsx(d,{icon:t})]}),exports.NuitralTab=()=>l.jsx(l.Fragment,{}),exports.NuitralTabs=({items:e=[],children:t=[],classes:n="",selected:o=0,onSelection:a,...i})=>{const[s,f]=r.useState(o),p=c(i),{isValidAttribute:m}=u(),b=r.useMemo((()=>{const e={};for(const r in p)m(r)&&(e[r]=p[r]);return Object.keys(e).map((e=>`nuitral-tab-${e}`)).join(" ")}),[p]),y=e=>{f(e.index),(e=>{a&&a(e)})(e)},h=r.useMemo((()=>{const n={label:"",children:null,component:null,icon:null,iconPosition:"left",classes:"",disabled:!1,leftSide:null,rightSide:null};return e.length>0?e.map((e=>({...n,...e}))):r.Children.map(t,(e=>r.isValidElement(e)?{...n,...e.props}:null))?.filter((e=>null!==e))||[]}),[e,t]);return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:`nuitral-tabs ${b} ${n}`,children:h.map(((e,r)=>l.jsxs("div",{className:`nuitral-tab ${r===s?"nuitral-tab-active":""} ${e.disabled?"disabled":""}`,onClick:()=>!e.disabled&&y({item:e,index:r}),children:[e.leftSide&&l.jsx("div",{className:"left-side",children:e.leftSide}),e.icon&&"left"===e.iconPosition&&l.jsx(d,{icon:e.icon}),e.label,e.icon&&"right"===e.iconPosition&&l.jsx(d,{icon:e.icon}),e.rightSide&&l.jsx("div",{className:"right-side",children:e.rightSide})]},r)))}),l.jsx("div",{className:`nuitral-tab-content ${h[s].classes}`,children:h[s]?.component?r.createElement(h[s].component):h[s]?.children?l.jsx("div",{children:h[s].children}):null})]})},exports.useAttrs=c,exports.useColorsAttributesValidator=u,exports.useNuitralTheming=({theme:e="nuitral",darkMode:t=!1,lightModeName:n="nuitral-light-mode",darkModeName:o="nuitral-dark-mode",rootId:a="nuitral-app",saveSettings:i=!1})=>{const s=(e,r)=>{i&&localStorage.setItem("nuitral",JSON.stringify({darkMode:e,theme:r}))},{theme:l,darkMode:c}=(()=>{if(!i)return{theme:e,darkMode:t};const r=localStorage.getItem("nuitral");return r?JSON.parse(r):{theme:e,darkMode:t}})(),[u,d]=r.useState(c),[f,p]=r.useState(l),m=r.useRef(null),b=()=>{if(m.current){const e=u?o:n;m.current.setAttribute("nuitral-theme",f),m.current.classList.add(e),m.current.classList.remove(u?n:o)}};return r.useEffect((()=>{m.current=document.getElementById(a),b()}),[a]),r.useEffect((()=>{b()}),[u,f]),{manageDarkMode:()=>{d((e=>{const r=!e;return s(r,f),r}))},isDarkMode:u,manageTheme:e=>{p(e),s(u,e)},themeName:f}}; //# sourceMappingURL=react-ui-suite.cjs.js.map