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) 5.74 kB
this.primereact=this.primereact||{},this.primereact.sidebar=function(e,t,n,r,l,o,i,a){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var u=c(t),d=s(n);function f(){return f=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},f.apply(this,arguments)}function p(e){if(Array.isArray(e))return e}function m(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,l,o,i,a=[],s=!0,c=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(r=o.call(n)).done)&&(a.push(r.value),a.length!==t);s=!0);}catch(e){c=!0,l=e}finally{try{if(!s&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw l}}return a}}function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function v(e,t){if(e){if("string"==typeof e)return b(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?b(e,t):void 0}}function y(){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 h(e,t){return p(e)||m(e,t)||v(e,t)||y()}var 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,children:void 0},getProps:function(e){return a.ObjectUtils.getMergedProps(e,g.defaultProps)},getOtherProps:function(e){return a.ObjectUtils.getDiffProps(e,g.defaultProps)}},E=u.forwardRef((function(e,t){var s=g.getProps(e),c=h(u.useState(!1),2),p=c[0],m=c[1],b=h(u.useState(!1),2),v=b[0],y=b[1],E=u.useRef(null),S=u.useRef(null),O=u.useRef(null),w=h(l.useEventListener({type:"keydown",listener:function(e){27===e.which&&a.ZIndexUtils.get(S.current)===a.ZIndexUtils.getCurrent("modal",d.default.autoZIndex)&&U(e)}}),2),j=w[0],k=w[1],I=h(l.useEventListener({type:"click",listener:function(e){2!==e.which&&P(e)&&U(e)}}),2),x=I[0],C=I[1],P=function(e){return E&&E.current&&!E.current.contains(e.target)},N=function(e){s.dismissable&&s.modal&&S.current===e.target&&U(e)},U=function(e){s.onHide(),e.preventDefault()},Z=function(){var e;s.onShow&&s.onShow(),!((e=document.activeElement)&&E&&E.current.contains(e))&&s.showCloseIcon&&O.current.focus(),R()},D=function(){s.modal&&a.DomHandler.addClass(S.current,"p-component-overlay-leave")},M=function(){a.ZIndexUtils.clear(S.current),m(!1),A()},R=function(){s.closeOnEscape&&j(),s.dismissable&&!s.modal&&x(),s.blockScroll&&a.DomHandler.addClass(document.body,"p-overflow-hidden")},A=function(){k(),C(),s.blockScroll&&a.DomHandler.removeClass(document.body,"p-overflow-hidden")};u.useImperativeHandle(t,(function(){return{props:s,getElement:function(){return E.current},gteMask:function(){return S.current},getCloseIcon:function(){return O.current}}})),l.useMountEffect((function(){s.visible&&m(!0)})),l.useUpdateEffect((function(){s.visible&&!p&&m(!0),s.visible!==v&&p&&y(s.visible)})),l.useUpdateEffect((function(){p&&(a.ZIndexUtils.set("modal",S.current,d.default.autoZIndex,s.baseZIndex||d.default.zIndex.modal),y(!0))}),[p]),l.useUpdateEffect((function(){v&&(C(),s.dismissable&&!s.modal&&x())}),[s.dismissable,s.modal,v]),l.useUnmountEffect((function(){A(),S.current&&a.ZIndexUtils.clear(S.current)}));var H,T,_,L,z,J,X,Y=function(){if(s.showCloseIcon){var e=s.ariaCloseLabel||n.localeOption("close");return u.createElement("button",{type:"button",ref:O,className:"p-sidebar-close p-sidebar-icon p-link",onClick:U,"aria-label":e},u.createElement("span",{className:"p-sidebar-close-icon pi pi-times","aria-hidden":"true"}),u.createElement(i.Ripple,null))}return null};return p&&(T=g.getOtherProps(s),_=a.classNames("p-sidebar p-component",s.className,{"p-input-filled":"filled"===d.default.inputStyle,"p-ripple-disabled":!1===d.default.ripple}),L=a.classNames("p-sidebar-mask",{"p-component-overlay p-component-overlay-enter":s.modal,"p-sidebar-mask-scrollblocker":s.blockScroll,"p-sidebar-visible":p,"p-sidebar-full":s.fullScreen},(H=["left","right","top","bottom"].find((function(e){return e===s.position})))?"p-sidebar-".concat(H):"",s.maskClassName),z=Y(),J=s.icons?a.ObjectUtils.getJSXElement(s.icons,s):null,X=u.createElement("div",{ref:S,style:s.maskStyle,className:L,onMouseDown:N},u.createElement(r.CSSTransition,{nodeRef:E,classNames:"p-sidebar",in:v,timeout:{enter:s.fullScreen?150:300,exit:s.fullScreen?150:300},options:s.transitionOptions,unmountOnExit:!0,onEntered:Z,onExiting:D,onExited:M},u.createElement("div",f({ref:E,id:s.id,className:_,style:s.style},T,{role:"complementary"}),u.createElement("div",{className:"p-sidebar-header"},J,z),u.createElement("div",{className:"p-sidebar-content"},s.children)))),u.createElement(o.Portal,{element:X,appendTo:s.appendTo,visible:!0}))}));return E.displayName="Sidebar",e.Sidebar=E,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.api,primereact.csstransition,primereact.hooks,primereact.portal,primereact.ripple,primereact.utils);