2 lines
7.2 KiB
JavaScript
2 lines
7.2 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/csstransition"),s=require("primereact/ripple"),i=require("primereact/portal"),o=require("primereact/api");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=r(e),a=r(o);function c(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 s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(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&&d(e,t)}function m(e){return m="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},m(e)}function b(e,t){if(t&&("object"===m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return p(e)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}function y(){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 v,k,E,S=function(o){f(S,e.Component);var r,d,m,v,k,E=(r=S,d=y(),function(){var e,t=h(r);if(d){var n=h(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return b(this,e)});function S(e){var t;return c(this,S),(t=E.call(this,e)).state={maskVisible:!1,visible:!1},t.onMaskClick=t.onMaskClick.bind(p(t)),t.onClose=t.onClose.bind(p(t)),t.onEntered=t.onEntered.bind(p(t)),t.onExiting=t.onExiting.bind(p(t)),t.onExited=t.onExited.bind(p(t)),t.sidebarRef=l.default.createRef(),t}return m=S,(v=[{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&&t.DomHandler.addClass(this.mask,"p-component-overlay-leave")}},{key:"onExited",value:function(){t.ZIndexUtils.clear(this.mask),this.setState({maskVisible:!1}),this.disableDocumentSettings()}},{key:"enableDocumentSettings",value:function(){this.bindGlobalListeners(),this.props.blockScroll&&t.DomHandler.addClass(document.body,"p-overflow-hidden")}},{key:"disableDocumentSettings",value:function(){this.unbindGlobalListeners(),this.props.blockScroll&&t.DomHandler.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(n){27===n.which&&t.ZIndexUtils.get(e.mask)===t.ZIndexUtils.getCurrent("modal",a.default.autoZIndex)&&e.onClose(n)},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(){t.ZIndexUtils.set("modal",e.mask,a.default.autoZIndex,e.props.baseZIndex||a.default.zIndex.modal)}))}},{key:"componentDidUpdate",value:function(e,n){var s=this;this.props.visible&&!this.state.maskVisible&&this.setState({maskVisible:!0},(function(){t.ZIndexUtils.set("modal",s.mask,a.default.autoZIndex,s.props.baseZIndex||a.default.zIndex.modal)})),this.props.visible!==this.state.visible&&this.state.maskVisible&&this.setState({visible:this.props.visible})}},{key:"componentWillUnmount",value:function(){this.disableDocumentSettings(),t.ZIndexUtils.clear(this.mask)}},{key:"renderCloseIcon",value:function(){var e=this;return this.props.showCloseIcon?l.default.createElement("button",{type:"button",ref:function(t){return e.closeIcon=t},className:"p-sidebar-close p-sidebar-icon p-link",onClick:this.onClose,"aria-label":this.props.ariaCloseLabel},l.default.createElement("span",{className:"p-sidebar-close-icon pi pi-times"}),l.default.createElement(s.Ripple,null)):null}},{key:"renderIcons",value:function(){return this.props.icons?t.ObjectUtils.getJSXElement(this.props.icons,this.props):null}},{key:"renderElement",value:function(){var e=this,s=t.classNames("p-sidebar p-component",this.props.className),i=t.classNames("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()),o=this.renderCloseIcon(),r=this.renderIcons();return l.default.createElement("div",{ref:function(t){return e.mask=t},style:this.props.maskStyle,className:i,onClick:this.onMaskClick},l.default.createElement(n.CSSTransition,{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},l.default.createElement("div",{ref:this.sidebarRef,id:this.props.id,className:s,style:this.props.style,role:"complementary"},l.default.createElement("div",{className:"p-sidebar-header"},r,o),l.default.createElement("div",{className:"p-sidebar-content"},this.props.children))))}},{key:"render",value:function(){if(this.state.maskVisible){var e=this.renderElement();return l.default.createElement(i.Portal,{element:e,appendTo:this.props.appendTo,visible:!0})}return null}}])&&u(m.prototype,v),k&&u(m,k),Object.defineProperty(m,"prototype",{writable:!1}),S}();E={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},(k="defaultProps")in(v=S)?Object.defineProperty(v,k,{value:E,enumerable:!0,configurable:!0,writable:!0}):v[k]=E,exports.Sidebar=S;
|