2 lines
5.8 KiB
JavaScript
2 lines
5.8 KiB
JavaScript
import e,{Component as t}from"react";import{CSSTransition as n}from"primereact/csstransition";import{UniqueComponentId as o,IconUtils as r,ObjectUtils as l,classNames as s}from"primereact/utils";import{Ripple as i}from"primereact/ripple";function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(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 c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){return u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},u(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&&u(e,t)}function h(e){return h="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},h(e)}function d(e,t){if(t&&("object"===h(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return c(e)}function g(e){return g=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},g(e)}function m(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?y(Object(n),!0).forEach((function(t){m(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return 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 O=function(u){f(w,t);var h,m,y,O,E,j=(h=w,m=v(),function(){var e,t=g(h);if(m){var n=g(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return d(this,e)});function w(t){var n;p(this,w);var o={id:(n=j.call(this,t)).props.id};return n.props.onToggle||(o=b(b({},o),{},{collapsed:n.props.collapsed})),n.state=o,n.toggle=n.toggle.bind(c(n)),n.contentRef=e.createRef(),n}return y=w,(O=[{key:"toggle",value:function(e){if(this.props.toggleable){var t=this.props.onToggle?this.props.collapsed:this.state.collapsed;t?this.expand(e):this.collapse(e),this.props.onToggle&&this.props.onToggle({originalEvent:e,value:!t})}e.preventDefault()}},{key:"expand",value:function(e){this.props.onToggle||this.setState({collapsed:!1}),this.props.onExpand&&this.props.onExpand(e)}},{key:"collapse",value:function(e){this.props.onToggle||this.setState({collapsed:!0}),this.props.onCollapse&&this.props.onCollapse(e)}},{key:"isCollapsed",value:function(){return!!this.props.toggleable&&(this.props.onToggle?this.props.collapsed:this.state.collapsed)}},{key:"componentDidMount",value:function(){this.state.id||this.setState({id:o()})}},{key:"renderToggleIcon",value:function(t){return this.props.toggleable?e.createElement("button",{className:"p-panel-header-icon p-panel-toggler p-link",onClick:this.toggle,id:this.state.id+"_label","aria-controls":this.state.id+"_content","aria-expanded":!t,role:"tab"},r.getJSXIcon(t?this.props.expandIcon:this.props.collapseIcon,{props:this.props,collapsed:t}),e.createElement(i,null)):null}},{key:"renderHeader",value:function(t){var n=l.getJSXElement(this.props.header,this.props),o=l.getJSXElement(this.props.icons,this.props),r=this.renderToggleIcon(t),s=e.createElement("span",{className:"p-panel-title",id:this.state.id+"_header"},n),i=e.createElement("div",{className:"p-panel-icons"},o,r),p=e.createElement("div",{className:"p-panel-header"},s,i);return this.props.headerTemplate?l.getJSXElement(this.props.headerTemplate,{className:"p-panel-header",titleClassName:"p-panel-title",iconsClassName:"p-panel-icons",togglerClassName:"p-panel-header-icon p-panel-toggler p-link",togglerIconClassName:t?this.props.expandIcon:this.props.collapseIcon,onTogglerClick:this.toggle,titleElement:s,iconsElement:i,togglerElement:r,element:p,props:this.props,collapsed:t}):this.props.header||this.props.toggleable?p:null}},{key:"renderContent",value:function(t){return e.createElement(n,{nodeRef:this.contentRef,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:!t,unmountOnExit:!0,options:this.props.transitionOptions},e.createElement("div",{ref:this.contentRef,className:"p-toggleable-content","aria-hidden":t,role:"region",id:this.state.id+"_content","aria-labelledby":this.state.id+"_header"},e.createElement("div",{className:"p-panel-content"},this.props.children)))}},{key:"render",value:function(){var t=s("p-panel p-component",{"p-panel-toggleable":this.props.toggleable},this.props.className),n=this.isCollapsed(),o=this.renderHeader(n),r=this.renderContent(n);return e.createElement("div",{id:this.props.id,className:t,style:this.props.style},o,r)}}])&&a(y.prototype,O),E&&a(y,E),Object.defineProperty(y,"prototype",{writable:!1}),w}();m(O,"defaultProps",{id:null,header:null,headerTemplate:null,toggleable:null,style:null,className:null,collapsed:null,expandIcon:"pi pi-plus",collapseIcon:"pi pi-minus",icons:null,transitionOptions:null,onExpand:null,onCollapse:null,onToggle:null});export{O as Panel};
|