2 lines
9.7 KiB
JavaScript
2 lines
9.7 KiB
JavaScript
import e,{Component as t}from"react";import{classNames as n,ObjectUtils as i,ZIndexUtils as r,DomHandler as o,ConnectedOverlayScrollHandler as s}from"primereact/utils";import{CSSTransition as a}from"primereact/csstransition";import{OverlayService as l}from"primereact/overlayservice";import{Portal as u}from"primereact/portal";import c from"primereact/api";function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function h(e,t,n){return t&&d(e.prototype,t),n&&d(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function f(e,t){return f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},f(e,t)}function v(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&&f(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 y(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 p(e)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function E(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function w(e){var t=g();return function(){var n,i=k(e);if(t){var r=k(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return y(this,n)}}function g(){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 L=function(r){v(s,t);var o=w(s);function s(e){var t;return m(this,s),(t=o.call(this,e)).state={activeItem:null},t}return h(s,[{key:"onItemClick",value:function(e,t){t.disabled?e.preventDefault():(t.url||e.preventDefault(),t.command&&t.command({originalEvent:e,item:t}),t.items&&(this.setState({activeItem:t}),this.props.onForward()))}},{key:"renderSeparator",value:function(t){return e.createElement("li",{key:"separator_"+t,className:"p-menu-separator"})}},{key:"renderSubmenu",value:function(t){return t.items?e.createElement(s,{model:t.items,index:this.props.index+1,menuWidth:this.props.menuWidth,effectDuration:this.props.effectDuration,onForward:this.props.onForward,parentActive:t===this.state.activeItem}):null}},{key:"renderMenuitem",value:function(t,r){var o=this,s=this.state.activeItem===t,a=n("p-menuitem",{"p-menuitem-active":s,"p-disabled":t.disabled},t.className),l=n("p-menuitem-icon",t.icon),u="p-submenu-icon pi pi-fw pi-angle-right",c=t.icon&&e.createElement("span",{className:l}),p=t.label&&e.createElement("span",{className:"p-menuitem-text"},t.label),m=t.items&&e.createElement("span",{className:u}),d=this.renderSubmenu(t),h=e.createElement("a",{href:t.url||"#",className:"p-menuitem-link",target:t.target,onClick:function(e){return o.onItemClick(e,t,r)},"aria-disabled":t.disabled},c,p,m);t.template&&(h=i.getJSXElement(t.template,t,{onClick:function(e){return o.onItemClick(e,t,r)},className:"p-menuitem-link",labelClassName:"p-menuitem-text",iconClassName:l,submenuIconClassName:u,element:h,props:this.props,active:s}));return e.createElement("li",{key:t.label+"_"+r,className:a,style:t.style},h,d)}},{key:"renderItem",value:function(e,t){return e.separator?this.renderSeparator(t):this.renderMenuitem(e,t)}},{key:"renderItems",value:function(){var e=this;return this.props.model?this.props.model.map((function(t,n){return e.renderItem(t,n)})):null}},{key:"render",value:function(){var t=n({"p-slidemenu-rootlist":this.props.root,"p-submenu-list":!this.props.root,"p-active-submenu":this.props.parentActive}),i={width:this.props.menuWidth+"px",left:this.props.root?-1*this.props.level*this.props.menuWidth+"px":this.props.menuWidth+"px",transitionProperty:this.props.root?"left":"none",transitionDuration:this.props.effectDuration+"ms",transitionTimingFunction:this.props.easing},r=this.renderItems();return e.createElement("ul",{className:t,style:i},r)}}]),s}();E(L,"defaultProps",{model:null,level:0,easing:"ease-out",effectDuration:250,menuWidth:190,parentActive:!1,onForward:null});var x=function(i){v(f,t);var d=w(f);function f(t){var n;return m(this,f),(n=d.call(this,t)).state={level:0,visible:!1},n.navigateBack=n.navigateBack.bind(p(n)),n.navigateForward=n.navigateForward.bind(p(n)),n.onEnter=n.onEnter.bind(p(n)),n.onEntered=n.onEntered.bind(p(n)),n.onExit=n.onExit.bind(p(n)),n.onExited=n.onExited.bind(p(n)),n.onPanelClick=n.onPanelClick.bind(p(n)),n.menuRef=e.createRef(),n}return h(f,[{key:"onPanelClick",value:function(e){this.props.popup&&l.emit("overlay-click",{originalEvent:e,target:this.target})}},{key:"navigateForward",value:function(){this.setState({level:this.state.level+1})}},{key:"navigateBack",value:function(){this.setState({level:this.state.level-1})}},{key:"renderBackward",value:function(){var t=this,i=n("p-slidemenu-backward",{"p-hidden":0===this.state.level});return e.createElement("div",{ref:function(e){return t.backward=e},className:i,onClick:this.navigateBack},e.createElement("span",{className:"p-slidemenu-backward-icon pi pi-fw pi-chevron-left"}),e.createElement("span",null,this.props.backLabel))}},{key:"toggle",value:function(e){this.props.popup&&(this.state.visible?this.hide(e):this.show(e))}},{key:"show",value:function(e){var t=this;this.target=e.currentTarget;var n=e;this.setState({visible:!0},(function(){t.props.onShow&&t.props.onShow(n)}))}},{key:"hide",value:function(e){var t=this,n=e;this.setState({visible:!1},(function(){t.props.onHide&&t.props.onHide(n)}))}},{key:"onEnter",value:function(){this.props.autoZIndex&&r.set("menu",this.menuRef.current,c.autoZIndex,this.props.baseZIndex||c.zIndex.menu),o.absolutePosition(this.menuRef.current,this.target)}},{key:"onEntered",value:function(){this.bindDocumentClickListener(),this.bindDocumentResizeListener(),this.bindScrollListener()}},{key:"onExit",value:function(){this.target=null,this.unbindDocumentClickListener(),this.unbindDocumentResizeListener(),this.unbindScrollListener()}},{key:"onExited",value:function(){r.clear(this.menuRef.current),this.setState({level:0})}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.state.visible&&e.isOutsideClicked(t)&&e.hide(t)},document.addEventListener("click",this.documentClickListener))}},{key:"isOutsideClicked",value:function(e){return this.menuRef&&this.menuRef.current&&!(this.menuRef.current.isSameNode(e.target)||this.menuRef.current.contains(e.target))}},{key:"bindDocumentResizeListener",value:function(){var e=this;this.documentResizeListener||(this.documentResizeListener=function(t){e.state.visible&&!o.isTouchDevice()&&e.hide(t)},window.addEventListener("resize",this.documentResizeListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"unbindDocumentResizeListener",value:function(){this.documentResizeListener&&(window.removeEventListener("resize",this.documentResizeListener),this.documentResizeListener=null)}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new s(this.target,(function(t){e.state.visible&&e.hide(t)}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"componentDidUpdate",value:function(e,t){this.props.model!==e.model&&this.setState({level:0})}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindDocumentResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),r.clear(this.menuRef.current)}},{key:"renderElement",value:function(){var t=this,i=n("p-slidemenu p-component",{"p-slidemenu-overlay":this.props.popup},this.props.className),r=this.renderBackward();return e.createElement(a,{nodeRef:this.menuRef,classNames:"p-connected-overlay",in:!this.props.popup||this.state.visible,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.onEntered,onExit:this.onExit,onExited:this.onExited},e.createElement("div",{ref:this.menuRef,id:this.props.id,className:i,style:this.props.style,onClick:this.onPanelClick},e.createElement("div",{className:"p-slidemenu-wrapper",style:{height:this.props.viewportHeight+"px"}},e.createElement("div",{className:"p-slidemenu-content",ref:function(e){return t.slideMenuContent=e}},e.createElement(L,{model:this.props.model,root:!0,index:0,menuWidth:this.props.menuWidth,effectDuration:this.props.effectDuration,level:this.state.level,parentActive:0===this.state.level,onForward:this.navigateForward})),r)))}},{key:"render",value:function(){var t=this.renderElement();return this.props.popup?e.createElement(u,{element:t,appendTo:this.props.appendTo}):t}}]),f}();E(x,"defaultProps",{id:null,model:null,popup:!1,style:null,className:null,easing:"ease-out",effectDuration:250,backLabel:"Back",menuWidth:190,viewportHeight:175,autoZIndex:!0,baseZIndex:0,appendTo:null,transitionOptions:null,onShow:null,onHide:null});export{x as SlideMenu,L as SlideMenuSub};
|