2 lines
5.4 KiB
JavaScript
2 lines
5.4 KiB
JavaScript
import e,{Component as t}from"react";import{UniqueComponentId as n,classNames as r}from"primereact/utils";import{CSSTransition as o}from"primereact/csstransition";import{Ripple as l}from"primereact/ripple";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){return p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},p(e,t)}function c(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&&p(e,t)}function u(e){return u="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},u(e)}function f(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return a(e)}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},d(e)}function g(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?h(Object(n),!0).forEach((function(t){g(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):h(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function b(){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 m=function(p){c(j,t);var u,g,h,m,v,O=(u=j,g=b(),function(){var e,t=d(u);if(g){var n=d(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return f(this,e)});function j(t){var n;i(this,j),n=O.call(this,t);var r={id:t.id};return n.props.onToggle||(r=y(y({},r),{},{collapsed:t.collapsed})),n.state=r,n.toggle=n.toggle.bind(a(n)),n.contentRef=e.createRef(),n}return h=j,(m=[{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:n()})}},{key:"renderContent",value:function(t){return e.createElement(o,{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,id:this.state.id+"_content",className:"p-toggleable-content","aria-hidden":t,role:"region","aria-labelledby":this.state.id+"_header"},e.createElement("div",{className:"p-fieldset-content"},this.props.children)))}},{key:"renderToggleIcon",value:function(t){if(this.props.toggleable){var n=r("p-fieldset-toggler pi",{"pi-plus":t,"pi-minus":!t});return e.createElement("span",{className:n})}return null}},{key:"renderLegendContent",value:function(t){if(this.props.toggleable){var n=this.renderToggleIcon(t),r=this.state.id+"_content";return e.createElement("a",{href:"#"+r,"aria-controls":r,id:this.state.id+"_header","aria-expanded":!t,tabIndex:this.props.toggleable?null:-1},n,e.createElement("span",{className:"p-fieldset-legend-text"},this.props.legend),e.createElement(l,null))}return e.createElement("span",{className:"p-fieldset-legend-text",id:this.state.id+"_header"},this.props.legend)}},{key:"renderLegend",value:function(t){var n=this.renderLegendContent(t);if(null!=this.props.legend||this.props.toggleable)return e.createElement("legend",{className:"p-fieldset-legend p-unselectable-text",onClick:this.toggle},n)}},{key:"render",value:function(){var t=r("p-fieldset p-component",this.props.className,{"p-fieldset-toggleable":this.props.toggleable}),n=this.isCollapsed(),o=this.renderLegend(n),l=this.renderContent(n);return e.createElement("fieldset",{id:this.props.id,className:t,style:this.props.style,onClick:this.props.onClick},o,l)}}])&&s(h.prototype,m),v&&s(h,v),Object.defineProperty(h,"prototype",{writable:!1}),j}();g(m,"defaultProps",{id:null,legend:null,className:null,style:null,toggleable:null,collapsed:null,transitionOptions:null,onExpand:null,onCollapse:null,onToggle:null,onClick:null});export{m as Fieldset};
|