UNPKG

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
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",{"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,k){var E=s(),j=e.useContext(t),I=D.getProps(i,j),P=A(e.useState(!1),2),N=P[0],C=P[1],R=A(e.useState(!1),2),B=R[0],z=R[1],J=D.setMetaData({props:I,state:{containerVisible:N}}),M=J.ptm,X=J.cx,Z=J.sx,H=J.isUnstyled;a(D.css.styles,H,{name:"sidebar"});var L=e.useRef(null),V=e.useRef(null),U=e.useRef(null),_=B&&I.closeOnEscape,F=l("sidebar",_);p({callback:function(e){K(e)},when:_&&F,priority:[c.SIDEBAR,F]});var Y=A(d({type:"click",listener:function(e){0===e.button&&G(e)&&K(e)}}),2),$=Y[0],q=Y[1],G=function(e){return L&&L.current&&!L.current.contains(e.target)},K=function(e){I.onHide(),e.preventDefault()},Q=function(){I.dismissable&&!I.modal&&$(),I.blockScroll&&x.blockBodyScroll()},W=function(){q(),I.blockScroll&&x.unblockBodyScroll()};e.useImperativeHandle(k,(function(){return{props:I,getElement:function(){return L.current},gteMask:function(){return V.current},getCloseIcon:function(){return U.current}}})),b((function(){I.visible&&C(!0)})),u((function(){I.visible&&!N&&C(!0),I.visible!==B&&N&&z(I.visible)})),u((function(){N&&(g.set("modal",V.current,j&&j.autoZIndex||n.autoZIndex,I.baseZIndex||j&&j.zIndex.modal||n.zIndex.modal),z(!0))}),[N]),u((function(){B&&(q(),I.dismissable&&!I.modal&&$())}),[I.dismissable,I.modal,B]),m((function(){W(),V.current&&g.clear(V.current)}));var ee,ne,te,re,ie,ae=function(){var n=I.ariaCloseLabel||r("close"),t=E({type:"button",ref:U,className:X("closeButton"),onClick:function(e){return K(e)},"aria-label":n},M("closeButton")),i=E({className:X("closeIcon")},M("closeIcon")),a=S.getJSXIcon(I.closeIcon||e.createElement(f,i),T({},i),{props:I});return I.showCloseIcon?e.createElement("button",t,a,e.createElement(v,null)):null},oe=E({ref:V,style:Z("mask"),className:X("mask",{maskVisibleState:N}),onMouseDown:function(e){return n=e,void(I.dismissable&&I.modal&&V.current===n.target&&K(n));var n}},M("mask")),se=E({id:I.id,className:y(I.className,X("root",{context:j})),style:I.style,role:"complementary"},D.getOtherProps(I),M("root")),le=E({className:X("header")},M("header")),pe=E({className:X("content")},M("content")),ce=E({className:X("icons")},M("icons")),de={enter:I.fullScreen?150:300,exit:I.fullScreen?150:300},be=E({classNames:X("transition"),in:B,timeout:de,options:I.transitionOptions,unmountOnExit:!0,onEntered:function(){var e;I.onShow&&I.onShow(),!((e=document.activeElement)&&L&&L.current.contains(e))&&I.showCloseIcon&&U.current&&U.current.focus(),Q()},onExiting:function(){I.modal&&!H()&&x.addClass(V.current,"p-component-overlay-leave")},onExited:function(){g.clear(V.current),C(!1),W()}},M("transition"));return N&&(ie=null!=i&&i.content?(re={closeIconRef:U,hide:K},e.createElement("div",oe,e.createElement(o,O({nodeRef:L},be),e.createElement("div",O({ref:L},se),w.getJSXElement(i.content,re))))):(ee=ae(),ne=I.icons?w.getJSXElement(I.icons,I):null,te=I.header?w.getJSXElement(I.header,I):null,e.createElement("div",oe,e.createElement(o,O({nodeRef:L},be),e.createElement("div",O({ref:L},se),e.createElement("div",le,te,e.createElement("div",ce,ne,ee)),e.createElement("div",pe,I.children))))),e.createElement(h,{element:ie,appendTo:I.appendTo,visible:!0}))}));z.displayName="Sidebar";export{z as Sidebar};