primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime
2 lines (1 loc) • 13.1 kB
JavaScript
import*as e from"react";import n,{PrimeReactContext as t,localeOption as r}from"primereact/api";import{ComponentBase as i,useHandleStyle as a}from"primereact/componentbase";import{CSSTransition as o}from"primereact/csstransition";import{useMergeProps as s,useDisplayOrder as l,useGlobalOnEscapeKey as p,ESC_KEY_HANDLING_PRIORITIES as c,useEventListener as d,useMountEffect as b,useUpdateEffect as u,useUnmountEffect as m}from"primereact/hooks";import{TimesIcon as f}from"primereact/icons/times";import{Portal as h}from"primereact/portal";import{Ripple as v}from"primereact/ripple";import{classNames as y,ZIndexUtils as g,DomHandler as x,ObjectUtils as w,IconUtils as S}from"primereact/utils";function O(){return O=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},O.apply(this,arguments)}function k(e){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},k(e)}function E(e,n){if("object"!==k(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!==k(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}function j(e){var n=E(e,"string");return"symbol"===k(n)?n:String(n)}function I(e){if(Array.isArray(e))return e}function P(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,i,a,o,s=[],l=!0,p=!1;try{if(a=(t=t.call(e)).next,0===n){if(Object(t)!==t)return;l=!1}else for(;!(l=(r=a.call(t)).done)&&(s.push(r.value),s.length!==n);l=!0);}catch(e){p=!0,i=e}finally{try{if(!l&&null!=t.return&&(o=t.return(),Object(o)!==o))return}finally{if(p)throw i}}return s}}function N(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function C(e,n){if(e){if("string"==typeof e)return N(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?N(e,n):void 0}}function R(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function A(e,n){return I(e)||P(e,n)||C(e,n)||R()}var D=i.extend({defaultProps:{__TYPE:"Sidebar",appendTo:null,ariaCloseLabel:null,baseZIndex:0,blockScroll:!1,children:void 0,className:null,closeIcon:null,closeOnEscape:!0,content:null,dismissable:!0,fullScreen:!1,header:null,icons:null,id:null,maskClassName:null,maskStyle:null,modal:!0,onHide:null,onShow:null,position:"left",showCloseIcon:!0,style:null,transitionOptions:null,visible:!1},css:{classes:{closeButton:"p-sidebar-close p-sidebar-icon p-link",closeIcon:"p-sidebar-close-icon",mask:function(e){var n=e.props,t=e.maskVisibleState,r=["left","right","top","bottom"].find((function(e){return e===n.position}));return y("p-sidebar-mask",r&&!n.fullScreen?"p-sidebar-".concat(r):"",{"p-component-overlay p-component-overlay-enter":n.modal,"p-sidebar-mask-scrollblocker":n.blockScroll,"p-sidebar-visible":t,"p-sidebar-full":n.fullScreen},n.maskClassName)},header:function(e){return y("p-sidebar-header",{"p-sidebar-custom-header":e.props.header})},content:"p-sidebar-content",icons:"p-sidebar-icons",root:function(e){var t=e.context;return y("p-sidebar p-component",e.props.className,{"p-input-filled":t&&"filled"===t.inputStyle||"filled"===n.inputStyle,"p-ripple-disabled":t&&!1===t.ripple||!1===n.ripple})},transition:"p-sidebar"},styles:"\n@layer primereact {\n .p-sidebar-mask {\n display: none;\n justify-content: center;\n align-items: center;\n pointer-events: none;\n background-color: transparent;\n transition-property: background-color;\n }\n \n .p-sidebar-visible {\n display: flex;\n }\n \n .p-sidebar-mask.p-component-overlay {\n pointer-events: auto;\n }\n \n .p-sidebar {\n display: flex;\n flex-direction: column;\n pointer-events: auto;\n transform: translate3d(0px, 0px, 0px);\n position: relative;\n }\n \n .p-sidebar-content {\n overflow-y: auto;\n flex-grow: 1;\n }\n \n .p-sidebar-header {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n }\n \n .p-sidebar-custom-header {\n justify-content: space-between;\n }\n \n .p-sidebar-icons {\n display: flex;\n align-items: center;\n flex-shrink: 0;\n }\n \n .p-sidebar-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n overflow: hidden;\n position: relative;\n }\n \n .p-sidebar-full .p-sidebar {\n transition: none;\n transform: none;\n width: 100vw;\n height: 100vh;\n max-height: 100%;\n top: 0px;\n left: 0px;\n }\n \n /* Animation */\n /* Top, Bottom, Left and Right */\n .p-sidebar-top .p-sidebar-enter,\n .p-sidebar-top .p-sidebar-exit-active {\n transform: translate3d(0px, -100%, 0px);\n }\n \n .p-sidebar-bottom .p-sidebar-enter,\n .p-sidebar-bottom .p-sidebar-exit-active {\n transform: translate3d(0px, 100%, 0px);\n }\n \n .p-sidebar-left .p-sidebar-enter,\n .p-sidebar-left .p-sidebar-exit-active {\n transform: translate3d(-100%, 0px, 0px);\n }\n \n .p-sidebar-right .p-sidebar-enter,\n .p-sidebar-right .p-sidebar-exit-active {\n transform: translate3d(100%, 0px, 0px);\n }\n \n .p-sidebar-top .p-sidebar-enter-active,\n .p-sidebar-bottom .p-sidebar-enter-active,\n .p-sidebar-left .p-sidebar-enter-active,\n .p-sidebar-right .p-sidebar-enter-active {\n transform: translate3d(0px, 0px, 0px);\n transition: all 0.3s;\n }\n \n .p-sidebar-top .p-sidebar-enter-done,\n .p-sidebar-bottom .p-sidebar-enter-done,\n .p-sidebar-left .p-sidebar-enter-done,\n .p-sidebar-right .p-sidebar-enter-done {\n transform: none;\n }\n \n .p-sidebar-top .p-sidebar-exit-active,\n .p-sidebar-bottom .p-sidebar-exit-active,\n .p-sidebar-left .p-sidebar-exit-active,\n .p-sidebar-right .p-sidebar-exit-active {\n transition: all 0.3s;\n }\n \n /* Full */\n .p-sidebar-full .p-sidebar-enter {\n opacity: 0;\n transform: scale(0.5);\n }\n \n .p-sidebar-full .p-sidebar-enter-active {\n opacity: 1;\n transform: scale(1);\n transition: all 0.15s cubic-bezier(0, 0, 0.2, 1);\n }\n \n .p-sidebar-full .p-sidebar-enter-done {\n transform: none;\n }\n \n .p-sidebar-full .p-sidebar-exit-active {\n opacity: 0;\n transform: scale(0.5);\n transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);\n }\n \n /* Size */\n .p-sidebar-left .p-sidebar {\n width: 20rem;\n height: 100%;\n }\n \n .p-sidebar-right .p-sidebar {\n width: 20rem;\n height: 100%;\n }\n \n .p-sidebar-top .p-sidebar {\n height: 10rem;\n width: 100%;\n }\n \n .p-sidebar-bottom .p-sidebar {\n height: 10rem;\n width: 100%;\n }\n \n .p-sidebar-left .p-sidebar-sm,\n .p-sidebar-right .p-sidebar-sm {\n width: 20rem;\n }\n \n .p-sidebar-left .p-sidebar-md,\n .p-sidebar-right .p-sidebar-md {\n width: 40rem;\n }\n \n .p-sidebar-left .p-sidebar-lg,\n .p-sidebar-right .p-sidebar-lg {\n width: 60rem;\n }\n \n .p-sidebar-top .p-sidebar-sm,\n .p-sidebar-bottom .p-sidebar-sm {\n height: 10rem;\n }\n \n .p-sidebar-top .p-sidebar-md,\n .p-sidebar-bottom .p-sidebar-md {\n height: 20rem;\n }\n \n .p-sidebar-top .p-sidebar-lg,\n .p-sidebar-bottom .p-sidebar-lg {\n height: 30rem;\n }\n \n .p-sidebar-left .p-sidebar-view,\n .p-sidebar-right .p-sidebar-view,\n .p-sidebar-top .p-sidebar-view,\n .p-sidebar-bottom .p-sidebar-view {\n width: 100%;\n height: 100%;\n }\n \n .p-sidebar-left .p-sidebar-content,\n .p-sidebar-right .p-sidebar-content,\n .p-sidebar-top .p-sidebar-content,\n .p-sidebar-bottom .p-sidebar-content {\n width: 100%;\n height: 100%;\n }\n \n @media screen and (max-width: 64em) {\n .p-sidebar-left .p-sidebar-lg,\n .p-sidebar-left .p-sidebar-md,\n .p-sidebar-right .p-sidebar-lg,\n .p-sidebar-right .p-sidebar-md {\n width: 20rem;\n }\n } \n}\n",inlineStyles:{mask:function(e){var n=e.props;return{position:"fixed",height:"100%",width:"100%",left:0,top:0,display:"flex",justifyContent:"left"===n.position?"flex-start":"right"===n.position?"flex-end":"center",alignItems:"top"===n.position?"flex-start":"bottom"===n.position?"flex-end":"center"}}}}});function B(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function T(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?B(Object(t),!0).forEach((function(n){var r,i,a;r=e,a=t[n],(i=j(i=n))in r?Object.defineProperty(r,i,{value:a,enumerable:!0,configurable:!0,writable:!0}):r[i]=a})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):B(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}var z=e.forwardRef((function(i,y){var k=s(),E=e.useContext(t),j=D.getProps(i,E),I=A(e.useState(!1),2),P=I[0],N=I[1],C=A(e.useState(!1),2),R=C[0],B=C[1],z=D.setMetaData({props:j,state:{containerVisible:P}}),J=z.ptm,M=z.cx,X=z.sx,Z=z.isUnstyled;a(D.css.styles,Z,{name:"sidebar"});var H=e.useRef(null),L=e.useRef(null),V=e.useRef(null),U=R&&j.closeOnEscape,_=l("sidebar",U);p({callback:function(e){G(e)},when:U&&_,priority:[c.SIDEBAR,_]});var F=A(d({type:"click",listener:function(e){0===e.button&&q(e)&&G(e)}}),2),Y=F[0],$=F[1],q=function(e){return H&&H.current&&!H.current.contains(e.target)},G=function(e){j.onHide(),e.preventDefault()},K=function(){j.dismissable&&!j.modal&&Y(),j.blockScroll&&x.blockBodyScroll()},Q=function(){$(),j.blockScroll&&x.unblockBodyScroll()};e.useImperativeHandle(y,(function(){return{props:j,getElement:function(){return H.current},gteMask:function(){return L.current},getCloseIcon:function(){return V.current}}})),b((function(){j.visible&&N(!0)})),u((function(){j.visible&&!P&&N(!0),j.visible!==R&&P&&B(j.visible)})),u((function(){P&&(g.set("modal",L.current,E&&E.autoZIndex||n.autoZIndex,j.baseZIndex||E&&E.zIndex.modal||n.zIndex.modal),B(!0))}),[P]),u((function(){R&&($(),j.dismissable&&!j.modal&&Y())}),[j.dismissable,j.modal,R]),m((function(){Q(),L.current&&g.clear(L.current)}));var W,ee,ne,te,re,ie=function(){var n=j.ariaCloseLabel||r("close"),t=k({type:"button",ref:V,className:M("closeButton"),onClick:function(e){return G(e)},"aria-label":n},J("closeButton")),i=k({className:M("closeIcon")},J("closeIcon")),a=S.getJSXIcon(j.closeIcon||e.createElement(f,i),T({},i),{props:j});return j.showCloseIcon?e.createElement("button",t,a,e.createElement(v,null)):null},ae=k({ref:L,style:X("mask"),className:M("mask",{maskVisibleState:P}),onMouseDown:function(e){return n=e,void(j.dismissable&&j.modal&&L.current===n.target&&G(n));var n}},J("mask")),oe=k({id:j.id,className:M("root",{context:E}),style:j.style,role:"complementary"},D.getOtherProps(j),J("root")),se=k({className:M("header")},J("header")),le=k({className:M("content")},J("content")),pe=k({className:M("icons")},J("icons")),ce={enter:j.fullScreen?150:300,exit:j.fullScreen?150:300},de=k({classNames:M("transition"),in:R,timeout:ce,options:j.transitionOptions,unmountOnExit:!0,onEntered:function(){var e;j.onShow&&j.onShow(),!((e=document.activeElement)&&H&&H.current.contains(e))&&j.showCloseIcon&&V.current&&V.current.focus(),K()},onExiting:function(){j.modal&&!Z()&&x.addClass(L.current,"p-component-overlay-leave")},onExited:function(){g.clear(L.current),N(!1),Q()}},J("transition"));return P&&(re=null!=i&&i.content?(te={closeIconRef:V,hide:G},e.createElement("div",ae,e.createElement(o,O({nodeRef:H},de),e.createElement("div",O({ref:H},oe),w.getJSXElement(i.content,te))))):(W=ie(),ee=j.icons?w.getJSXElement(j.icons,j):null,ne=j.header?w.getJSXElement(j.header,j):null,e.createElement("div",ae,e.createElement(o,O({nodeRef:H},de),e.createElement("div",O({ref:H},oe),e.createElement("div",se,ne,e.createElement("div",pe,ee,W)),e.createElement("div",le,j.children))))),e.createElement(h,{element:re,appendTo:j.appendTo,visible:!0}))}));z.displayName="Sidebar";export{z as Sidebar};