UNPKG

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