UNPKG

react-dynamic-snbar

Version:

Responsive React sidebar with role-based navigation support and easy customization.

12 lines (11 loc) 13.8 kB
"use strict";var e,t=require("react"),r=require("react-router-dom"),n={exports:{}},o={};var a,c,l={}; /** * @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 i(){return a||(a=1,"production"!==process.env.NODE_ENV&&function(){function e(t){if(null==t)return null;if("function"==typeof t)return t.$$typeof===N?null:t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case y:return"Fragment";case m:return"Profiler";case b:return"StrictMode";case j:return"Suspense";case k:return"SuspenseList";case w:return"Activity"}if("object"==typeof t)switch("number"==typeof t.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case p:return"Portal";case g:return(t.displayName||"Context")+".Provider";case v:return(t._context.displayName||"Context")+".Consumer";case h:var r=t.render;return(t=t.displayName)||(t=""!==(t=r.displayName||r.name||"")?"ForwardRef("+t+")":"ForwardRef"),t;case x:return null!==(r=t.displayName||null)?r:e(t.type)||"Memo";case O:r=t._payload,t=t._init;try{return e(t(r))}catch(e){}}return null}function r(e){return""+e}function n(e){try{r(e);var t=!1}catch(e){t=!0}if(t){var n=(t=console).error,o="function"==typeof Symbol&&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.",o),r(e)}}function o(t){if(t===y)return"<>";if("object"==typeof t&&null!==t&&t.$$typeof===O)return"<...>";try{var r=e(t);return r?"<"+r+">":"<...>"}catch(e){return"<...>"}}function a(){return Error("react-stack-top-frame")}function c(){var t=e(this.type);return E[t]||(E[t]=!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!==(t=this.props.ref)?t:null}function i(t,r,o,a,l,i,f,p){var y,b=r.children;if(void 0!==b)if(a)if(P(b)){for(a=0;a<b.length;a++)s(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 s(b);if(C.call(r,"key")){b=e(t);var m=Object.keys(r).filter((function(e){return"key"!==e}));a=0<m.length?"{key: someKey, "+m.join(": ..., ")+": ...}":"{key: someKey}",T[b+a]||(m=0<m.length?"{"+m.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,m,b),T[b+a]=!0)}if(b=null,void 0!==o&&(n(o),b=""+o),function(e){if(C.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(r)&&(n(r.key),b=""+r.key),"key"in r)for(var v in o={},r)"key"!==v&&(o[v]=r[v]);else o=r;return b&&function(e,t){function r(){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)",t))}r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(o,"function"==typeof t?t.displayName||t.name||"Unknown":t),function(e,t,r,n,o,a,l,i){return r=a.ref,e={$$typeof:d,type:e,key:t,props:a,_owner:o},null!==(void 0!==r?r:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:c}):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:l}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(t,b,i,0,null===(y=S.A)?null:y.getOwner(),o,f,p)}function s(e){"object"==typeof e&&null!==e&&e.$$typeof===d&&e._store&&(e._store.validated=1)}var u,f=t,d=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),m=Symbol.for("react.profiler"),v=Symbol.for("react.consumer"),g=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),k=Symbol.for("react.suspense_list"),x=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),w=Symbol.for("react.activity"),N=Symbol.for("react.client.reference"),S=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,C=Object.prototype.hasOwnProperty,P=Array.isArray,_=console.createTask?console.createTask:function(){return null},E={},L=(f={"react-stack-bottom-frame":function(e){return e()}})["react-stack-bottom-frame"].bind(f,a)(),R=_(o(a)),T={};l.Fragment=y,l.jsx=function(e,t,r,n,a){var c=1e4>S.recentlyCreatedOwnerStacks++;return i(e,t,r,!1,0,a,c?Error("react-stack-top-frame"):L,c?_(o(e)):R)},l.jsxs=function(e,t,r,n,a){var c=1e4>S.recentlyCreatedOwnerStacks++;return i(e,t,r,!0,0,a,c?Error("react-stack-top-frame"):L,c?_(o(e)):R)}}()),l}var s=(c||(c=1,"production"===process.env.NODE_ENV?n.exports=function(){if(e)return o;e=1;var t=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(e,r,n){var o=null;if(void 0!==n&&(o=""+n),void 0!==r.key&&(o=""+r.key),"key"in r)for(var a in n={},r)"key"!==a&&(n[a]=r[a]);else n=r;return r=n.ref,{$$typeof:t,type:e,key:o,ref:void 0!==r?r:null,props:n}}return o.Fragment=r,o.jsx=n,o.jsxs=n,o}():n.exports=i()),n.exports),u={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},f=t.createContext&&t.createContext(u),d=["attr","size","title"];function p(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r={};for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){if(t.indexOf(n)>=0)continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function y(){return y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},y.apply(this,arguments)}function b(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function m(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?b(Object(r),!0).forEach((function(t){v(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):b(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function v(e,t,r){var n;return(t="symbol"==typeof(n=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(t,"string"))?n:n+"")in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function g(e){return e&&e.map(((e,r)=>t.createElement(e.tag,m({key:r},e.attr),g(e.child))))}function h(e){return r=>t.createElement(j,y({attr:m({},e.attr)},r),g(e.child))}function j(e){var r=r=>{var n,{attr:o,size:a,title:c}=e,l=p(e,d),i=a||r.size||"1em";return r.className&&(n=r.className),e.className&&(n=(n?n+" ":"")+e.className),t.createElement("svg",y({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},r.attr,o,l,{className:n,style:m(m({color:e.color||r.color},r.style),e.style),height:i,width:i,xmlns:"http://www.w3.org/2000/svg"}),c&&t.createElement("title",null,c),e.children)};return void 0!==f?t.createElement(f.Consumer,null,(e=>r(e))):r(u)}function k(e){return h({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"},child:[]}]})(e)}function x(e){return h({attr:{viewBox:"0 0 320 512"},child:[{tag:"path",attr:{d:"M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z"},child:[]}]})(e)}function O(e){return h({attr:{viewBox:"0 0 320 512"},child:[{tag:"path",attr:{d:"M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"},child:[]}]})(e)}function w(e){return h({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M240.971 130.524l194.343 194.343c9.373 9.373 9.373 24.569 0 33.941l-22.667 22.667c-9.357 9.357-24.522 9.375-33.901.04L224 227.495 69.255 381.516c-9.379 9.335-24.544 9.317-33.901-.04l-22.667-22.667c-9.373-9.373-9.373-24.569 0-33.941L207.03 130.525c9.372-9.373 24.568-9.373 33.941-.001z"},child:[]}]})(e)}exports.Sidebar=function(e){var n=e.activeBg,o=e.activeColor,a=e.navItems,c=e.setMaxWidth,l=e.logo,i=e.title,u=e.role,f=e.fontFamily,d=e.backgroundColor,p=e.color,y=e.categoryColor,b=e.toggleBtn,m=void 0===b||b,v=t.useState({}),g=v[0],h=v[1],j=t.useState(null),N=j[0],S=j[1],C=t.useState(!0),P=C[0],_=C[1],E=t.useState(!1),L=E[0],R=E[1],T=r.useLocation().pathname;t.useEffect((function(){P?null==c||c(!0):null==c||c(!1)}),[P]),t.useEffect((function(){var e,t=u&&a.some((function(e){var t;return null===(t=e.roles)||void 0===t?void 0:t.includes(u)}));if(e=t?a.filter((function(e){return!e.roles||0===e.roles.length||e.roles.includes(u)})):a,a&&0!==a.length){var r=e.reduce((function(e,t){var r=t.category;return e[r]=e[r]||[],e[r].push(t),e}),{});h(r)}}),[a,u]);return t.useEffect((function(){var e=T,t=a.find((function(t){var r;return null===(r=t.children)||void 0===r?void 0:r.some((function(t){return e.startsWith(t.path)}))}));t&&S(t.label)}),[T,a]),s.jsxs(s.Fragment,{children:[s.jsx("button",{className:"mobile-toggle ".concat(L?"mobile-toggle-open":"mobile-toggle-closed"),onClick:function(){return R((function(e){return!e}))},style:{backgroundColor:d||"#1a202c",color:p||"#e2e8f0"},children:L?s.jsx(x,{}):s.jsx(O,{})}),m&&s.jsx("button",{className:"desktop-toggle ".concat(P?"desktop-toggle-expanded":"desktop-toggle-collapsed"),style:{backgroundColor:d||"#1a202c",color:p||"#e2e8f0"},onClick:function(){return _((function(e){return!e}))},children:P?s.jsx(x,{}):s.jsx(O,{})}),s.jsxs("div",{className:"sidebar ".concat(!P&&"sidebar-collapsed"," ").concat(!L&&"sidebar-hidden"),style:{backgroundColor:d||"#1a202c",color:p||"#e2e8f0",fontFamily:f},children:[s.jsx("div",{className:"logo-section",style:{backgroundColor:d||"#1a202c",color:p||"#e2e8f0"},children:s.jsxs("div",{className:"logo-container ".concat(!P&&"logo-container-centered"),children:[s.jsx("img",{src:l,alt:"Logo",className:"logo-image ".concat(P?"logo-image-expanded":"logo-image-collapsed")}),P&&s.jsx("p",{className:"logo-title",style:{opacity:P?1:0},children:i})]})}),Object.entries(g).map((function(e){var t=e[0],a=e[1];return s.jsxs("div",{className:"category-section",children:[s.jsx("h3",{className:"category-title",style:{color:y||"#a0aec0"},children:P&&t}),s.jsx("ul",{className:"nav-list",children:a&&a.map((function(e,t){return s.jsx("li",{children:e.children&&e.children.length>0?s.jsxs("div",{children:[s.jsxs("button",{onClick:function(){return function(e){S((function(t){return t===e?null:e}))}(e.label)},className:"nav-button ".concat(!P&&"nav-button-centered"),style:{backgroundColor:d||"#1a202c",color:p||"#e2e8f0",fontFamily:f},children:[s.jsxs("div",{className:"nav-item-content",children:[e.icon,P&&s.jsx("span",{className:"nav-item-label",children:e.label})]}),P&&s.jsx("span",{className:"dropdown-icon",children:N===e.label?s.jsx(w,{}):s.jsx(k,{})})]}),s.jsx("div",{className:"dropdown-content ".concat(N===e.label?"dropdown-content-open":"dropdown-content-closed"),children:s.jsx("ul",{className:"dropdown-list",children:e.children.map((function(e,t){return s.jsx("li",{children:s.jsxs(r.Link,{to:e.path,style:{color:T===e.path?o||"#3b82f6":p,backgroundColor:T===e.path?n||"#2d3748":"",borderLeft:T===e.path?"2px solid":"none",borderColor:T===e.path?o||"#3b82f6":""},className:"dropdown-link ".concat(T===e.path?"dropdown-link-active":""," ").concat(!P&&"dropdown-link-centered"),onClick:function(){return R((function(e){return!e}))},children:[e.icon,P&&s.jsx("span",{className:"dropdown-label",children:e.label})]})},t)}))})})]}):e.path&&s.jsxs(r.Link,{to:e.path,onClick:function(){S(""),R(!1)},style:{color:T===e.path?o||"#3b82f6":p,backgroundColor:T===e.path?n||"#2d3748":"",borderLeft:T===e.path?"2px solid":"none",borderColor:T===e.path?o||"#3b82f6":""},className:"nav-link ".concat(T===e.path?"nav-link-active":""," ").concat(!P&&"nav-link-centered"),children:[e.icon,P&&s.jsx("span",{className:"nav-item-label",children:e.label})]})},t)}))})]},t)}))]})]})}; //# sourceMappingURL=index.js.map