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.75 kB
JavaScript
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"),i=require("primereact/utils");function a(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=a(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,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 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={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 i.ObjectUtils.getMergedProps(e,h.defaultProps)},getOtherProps:function(e){return i.ObjectUtils.getDiffProps(e,h.defaultProps)}},g=c.forwardRef((function(e,a){var s=h.getProps(e),f=y(c.useState(!1),2),p=f[0],m=f[1],b=y(c.useState(!1),2),v=b[0],g=b[1],E=c.useRef(null),S=c.useRef(null),O=c.useRef(null),w=y(r.useEventListener({type:"keydown",listener:function(e){27===e.which&&i.ZIndexUtils.get(S.current)===i.ZIndexUtils.getCurrent("modal",u.default.autoZIndex)&&U(e)}}),2),j=w[0],k=w[1],I=y(r.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(),M()},q=function(){s.modal&&i.DomHandler.addClass(S.current,"p-component-overlay-leave")},D=function(){i.ZIndexUtils.clear(S.current),m(!1),A()},M=function(){s.closeOnEscape&&j(),s.dismissable&&!s.modal&&x(),s.blockScroll&&i.DomHandler.addClass(document.body,"p-overflow-hidden")},A=function(){k(),C(),s.blockScroll&&i.DomHandler.removeClass(document.body,"p-overflow-hidden")};c.useImperativeHandle(a,(function(){return{props:s,getElement:function(){return E.current},gteMask:function(){return S.current},getCloseIcon:function(){return O.current}}})),r.useMountEffect((function(){s.visible&&m(!0)})),r.useUpdateEffect((function(){s.visible&&!p&&m(!0),s.visible!==v&&p&&g(s.visible)})),r.useUpdateEffect((function(){p&&(i.ZIndexUtils.set("modal",S.current,u.default.autoZIndex,s.baseZIndex||u.default.zIndex.modal),g(!0))}),[p]),r.useUpdateEffect((function(){v&&(C(),s.dismissable&&!s.modal&&x())}),[s.dismissable,s.modal,v]),r.useUnmountEffect((function(){A(),S.current&&i.ZIndexUtils.clear(S.current)}));var H,R,T,_,L,z,J,X=function(){if(s.showCloseIcon){var e=s.ariaCloseLabel||t.localeOption("close");return c.createElement("button",{type:"button",ref:O,className:"p-sidebar-close p-sidebar-icon p-link",onClick:U,"aria-label":e},c.createElement("span",{className:"p-sidebar-close-icon pi pi-times","aria-hidden":"true"}),c.createElement(o.Ripple,null))}return null};return p&&(R=h.getOtherProps(s),T=i.classNames("p-sidebar p-component",s.className,{"p-input-filled":"filled"===u.default.inputStyle,"p-ripple-disabled":!1===u.default.ripple}),_=i.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),L=X(),z=s.icons?i.ObjectUtils.getJSXElement(s.icons,s):null,J=c.createElement("div",{ref:S,style:s.maskStyle,className:_,onMouseDown:N},c.createElement(n.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:q,onExited:D},c.createElement("div",d({ref:E,id:s.id,className:T,style:s.style},R,{role:"complementary"}),c.createElement("div",{className:"p-sidebar-header"},z,L),c.createElement("div",{className:"p-sidebar-content"},s.children)))),c.createElement(l.Portal,{element:J,appendTo:s.appendTo,visible:!0}))}));g.displayName="Sidebar",exports.Sidebar=g;
;