primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 80+ 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) • 4.78 kB
JavaScript
import*as e from"react";import n,{localeOption as t}from"primereact/api";import{CSSTransition as r}from"primereact/csstransition";import{useEventListener as o,useMountEffect as l,useUpdateEffect as a,useUnmountEffect as i}from"primereact/hooks";import{Portal as s}from"primereact/portal";import{Ripple as c}from"primereact/ripple";import{ZIndexUtils as u,DomHandler as m,ObjectUtils as p,classNames as d}from"primereact/utils";function f(){return f=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},f.apply(this,arguments)}function b(e){if(Array.isArray(e))return e}function y(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,o,l=[],a=!0,i=!1;try{for(t=t.call(e);!(a=(r=t.next()).done)&&(l.push(r.value),!n||l.length!==n);a=!0);}catch(e){i=!0,o=e}finally{try{a||null==t.return||t.return()}finally{if(i)throw o}}return l}}function v(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 h(e,n){if(e){if("string"==typeof e)return v(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)?v(e,n):void 0}}function S(){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 E(e,n){return b(e)||y(e,n)||h(e,n)||S()}var g=e.forwardRef((function(b,y){var v=E(e.useState(!1),2),h=v[0],S=v[1],w=E(e.useState(!1),2),k=w[0],C=w[1],I=e.useRef(null),N=e.useRef(null),x=e.useRef(null),O=E(o({type:"keydown",listener:function(e){27===e.which&&u.get(N.current)===u.getCurrent("modal",n.autoZIndex)&&H(e)}}),2),j=O[0],A=O[1],R=E(o({type:"click",listener:function(e){2!==e.which&&Z(e)&&H(e)}}),2),T=R[0],P=R[1],Z=function(e){return I&&I.current&&!I.current.contains(e.target)},D=function(e){b.dismissable&&b.modal&&N.current===e.target&&H(e)},H=function(e){b.onHide(),e.preventDefault()},M=function(){var e;b.onShow&&b.onShow(),!((e=document.activeElement)&&I&&I.current.contains(e))&&b.showCloseIcon&&x.current.focus(),z()},L=function(){b.modal&&m.addClass(N.current,"p-component-overlay-leave")},_=function(){u.clear(N.current),S(!1),J()},z=function(){b.closeOnEscape&&j(),b.dismissable&&!b.modal&&T(),b.blockScroll&&m.addClass(document.body,"p-overflow-hidden")},J=function(){A(),P(),b.blockScroll&&m.removeClass(document.body,"p-overflow-hidden")};e.useImperativeHandle(y,(function(){return{props:b,getElement:function(){return I.current},gteMask:function(){return N.current},getCloseIcon:function(){return x.current}}})),l((function(){b.visible&&S(!0)})),a((function(){b.visible&&!h&&S(!0),b.visible!==k&&h&&C(b.visible)})),a((function(){h&&(u.set("modal",N.current,n.autoZIndex,b.baseZIndex||n.zIndex.modal),C(!0))}),[h]),i((function(){J(),N.current&&u.clear(N.current)}));var K,U,X,Y,$,q,B,F=function(){if(b.showCloseIcon){var n=b.ariaCloseLabel||t("close");return e.createElement("button",{type:"button",ref:x,className:"p-sidebar-close p-sidebar-icon p-link",onClick:H,"aria-label":n},e.createElement("span",{className:"p-sidebar-close-icon pi pi-times","aria-hidden":"true"}),e.createElement(c,null))}return null};return h&&(U=p.findDiffKeys(b,g.defaultProps),X=d("p-sidebar p-component",b.className),Y=d("p-sidebar-mask",{"p-component-overlay p-component-overlay-enter":b.modal,"p-sidebar-mask-scrollblocker":b.blockScroll,"p-sidebar-visible":h,"p-sidebar-full":b.fullScreen},(K=["left","right","top","bottom"].find((function(e){return e===b.position})))?"p-sidebar-".concat(K):"",b.maskClassName),$=F(),q=b.icons?p.getJSXElement(b.icons,b):null,B=e.createElement("div",{ref:N,style:b.maskStyle,className:Y,onMouseDown:D},e.createElement(r,{nodeRef:I,classNames:"p-sidebar",in:k,timeout:{enter:b.fullScreen?150:300,exit:b.fullScreen?150:300},options:b.transitionOptions,unmountOnExit:!0,onEntered:M,onExiting:L,onExited:_},e.createElement("div",f({ref:I,id:b.id,className:X,style:b.style},U,{role:"complementary"}),e.createElement("div",{className:"p-sidebar-header"},q,$),e.createElement("div",{className:"p-sidebar-content"},b.children)))),e.createElement(s,{element:B,appendTo:b.appendTo,visible:!0}))}));g.displayName="Sidebar",g.defaultProps={__TYPE:"Sidebar",id:null,style:null,className:null,maskStyle:null,maskClassName:null,visible:!1,position:"left",fullScreen:!1,blockScroll:!1,baseZIndex:0,dismissable:!0,showCloseIcon:!0,ariaCloseLabel:null,closeOnEscape:!0,icons:null,modal:!0,appendTo:null,transitionOptions:null,onShow:null,onHide:null};export{g as Sidebar};