2 lines
6.9 KiB
JavaScript
2 lines
6.9 KiB
JavaScript
import e,{Component as t}from"react";import{DomHandler as n,ZIndexUtils as o,ObjectUtils as i,classNames as s}from"primereact/utils";import{CSSTransition as r}from"primereact/csstransition";import{Ripple as l}from"primereact/ripple";import{Portal as a}from"primereact/portal";import c from"primereact/api";function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e,t){return m=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},m(e,t)}function f(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&m(e,t)}function b(e){return b="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},b(e)}function h(e,t){if(t&&("object"===b(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return d(e)}function y(e){return y=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},y(e)}function v(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var k,E,S,C=function(m){f(g,t);var b,k,E,S,C,w=(b=g,k=v(),function(){var e,t=y(b);if(k){var n=y(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return h(this,e)});function g(t){var n;return p(this,g),(n=w.call(this,t)).state={maskVisible:!1,visible:!1},n.onMaskClick=n.onMaskClick.bind(d(n)),n.onClose=n.onClose.bind(d(n)),n.onEntered=n.onEntered.bind(d(n)),n.onExiting=n.onExiting.bind(d(n)),n.onExited=n.onExited.bind(d(n)),n.sidebarRef=e.createRef(),n}return E=g,(S=[{key:"getPositionClass",value:function(){var e=this,t=["left","right","top","bottom"].find((function(t){return t===e.props.position}));return t?"p-sidebar-".concat(t):""}},{key:"focus",value:function(){var e=document.activeElement;!(e&&this.sidebarRef&&this.sidebarRef.current.contains(e))&&this.props.showCloseIcon&&this.closeIcon.focus()}},{key:"onMaskClick",value:function(e){this.props.dismissable&&this.props.modal&&this.mask===e.target&&this.onClose(e)}},{key:"onClose",value:function(e){this.props.onHide(),e.preventDefault()}},{key:"onEntered",value:function(){this.props.onShow&&this.props.onShow(),this.focus(),this.enableDocumentSettings()}},{key:"onExiting",value:function(){this.props.modal&&n.addClass(this.mask,"p-component-overlay-leave")}},{key:"onExited",value:function(){o.clear(this.mask),this.setState({maskVisible:!1}),this.disableDocumentSettings()}},{key:"enableDocumentSettings",value:function(){this.bindGlobalListeners(),this.props.blockScroll&&n.addClass(document.body,"p-overflow-hidden")}},{key:"disableDocumentSettings",value:function(){this.unbindGlobalListeners(),this.props.blockScroll&&n.removeClass(document.body,"p-overflow-hidden")}},{key:"bindGlobalListeners",value:function(){this.props.closeOnEscape&&this.bindDocumentEscapeListener()}},{key:"unbindGlobalListeners",value:function(){this.unbindDocumentEscapeListener()}},{key:"bindDocumentEscapeListener",value:function(){var e=this;this.documentEscapeListener=function(t){27===t.which&&o.get(e.mask)===o.getCurrent("modal",c.autoZIndex)&&e.onClose(t)},document.addEventListener("keydown",this.documentEscapeListener)}},{key:"unbindDocumentEscapeListener",value:function(){this.documentEscapeListener&&(document.removeEventListener("keydown",this.documentEscapeListener),this.documentEscapeListener=null)}},{key:"componentDidMount",value:function(){var e=this;this.props.visible&&this.setState({maskVisible:!0,visible:!0},(function(){o.set("modal",e.mask,c.autoZIndex,e.props.baseZIndex||c.zIndex.modal)}))}},{key:"componentDidUpdate",value:function(e,t){var n=this;this.props.visible&&!this.state.maskVisible&&this.setState({maskVisible:!0},(function(){o.set("modal",n.mask,c.autoZIndex,n.props.baseZIndex||c.zIndex.modal)})),this.props.visible!==this.state.visible&&this.state.maskVisible&&this.setState({visible:this.props.visible})}},{key:"componentWillUnmount",value:function(){this.disableDocumentSettings(),o.clear(this.mask)}},{key:"renderCloseIcon",value:function(){var t=this;return this.props.showCloseIcon?e.createElement("button",{type:"button",ref:function(e){return t.closeIcon=e},className:"p-sidebar-close p-sidebar-icon p-link",onClick:this.onClose,"aria-label":this.props.ariaCloseLabel},e.createElement("span",{className:"p-sidebar-close-icon pi pi-times"}),e.createElement(l,null)):null}},{key:"renderIcons",value:function(){return this.props.icons?i.getJSXElement(this.props.icons,this.props):null}},{key:"renderElement",value:function(){var t=this,n=s("p-sidebar p-component",this.props.className),o=s("p-sidebar-mask",{"p-component-overlay p-component-overlay-enter":this.props.modal,"p-sidebar-mask-scrollblocker":this.props.blockScroll,"p-sidebar-visible":this.state.maskVisible,"p-sidebar-full":this.props.fullScreen},this.props.maskClassName,this.getPositionClass()),i=this.renderCloseIcon(),l=this.renderIcons();return e.createElement("div",{ref:function(e){return t.mask=e},style:this.props.maskStyle,className:o,onClick:this.onMaskClick},e.createElement(r,{nodeRef:this.sidebarRef,classNames:"p-sidebar",in:this.state.visible,timeout:{enter:this.props.fullScreen?150:300,exit:this.props.fullScreen?150:300},options:this.props.transitionOptions,unmountOnExit:!0,onEntered:this.onEntered,onExiting:this.onExiting,onExited:this.onExited},e.createElement("div",{ref:this.sidebarRef,id:this.props.id,className:n,style:this.props.style,role:"complementary"},e.createElement("div",{className:"p-sidebar-header"},l,i),e.createElement("div",{className:"p-sidebar-content"},this.props.children))))}},{key:"render",value:function(){if(this.state.maskVisible){var t=this.renderElement();return e.createElement(a,{element:t,appendTo:this.props.appendTo,visible:!0})}return null}}])&&u(E.prototype,S),C&&u(E,C),Object.defineProperty(E,"prototype",{writable:!1}),g}();S={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:"close",closeOnEscape:!0,icons:null,modal:!0,appendTo:null,transitionOptions:null,onShow:null,onHide:null},(E="defaultProps")in(k=C)?Object.defineProperty(k,E,{value:S,enumerable:!0,configurable:!0,writable:!0}):k[E]=S;export{C as Sidebar};
|