2 lines
4.3 KiB
JavaScript
2 lines
4.3 KiB
JavaScript
import e,{Component as t}from"react";import{classNames as n}from"primereact/utils";import{Button as r}from"primereact/button";function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(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 s(e,t,n){return t&&l(e.prototype,t),n&&l(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(e,t){return a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},a(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&&a(e,t)}function p(e){return p="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},p(e)}function u(e,t){if(t&&("object"===p(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return o(e)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function y(e){var t=h();return function(){var n,r=f(e);if(t){var o=f(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return u(this,n)}}function h(){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 b,d,v,m=function(e){c(r,t);var n=y(r);function r(){return i(this,r),n.apply(this,arguments)}return s(r,[{key:"render",value:function(){return this.props.children}}]),r}(),g=function(e){c(r,t);var n=y(r);function r(){return i(this,r),n.apply(this,arguments)}return s(r,[{key:"render",value:function(){return this.props.children}}]),r}(),w=function(l){c(p,t);var a=y(p);function p(e){var t;return i(this,p),(t=a.call(this,e)).props.onToggle||(t.state={active:!1}),t.open=t.open.bind(o(t)),t.close=t.close.bind(o(t)),t.onDisplayKeyDown=t.onDisplayKeyDown.bind(o(t)),t}return s(p,[{key:"open",value:function(e){this.props.disabled||(this.props.onOpen&&this.props.onOpen(e),this.props.onToggle?this.props.onToggle({originalEvent:e,value:!0}):this.setState({active:!0}))}},{key:"close",value:function(e){this.props.onClose&&this.props.onClose(e),this.props.onToggle?this.props.onToggle({originalEvent:e,value:!1}):this.setState({active:!1})}},{key:"onDisplayKeyDown",value:function(e){"Enter"===e.key&&(this.open(e),e.preventDefault())}},{key:"isActive",value:function(){return this.props.onToggle?this.props.active:this.state.active}},{key:"renderDisplay",value:function(t){var r=n("p-inplace-display",{"p-disabled":this.props.disabled});return e.createElement("div",{className:r,onClick:this.open,onKeyDown:this.onDisplayKeyDown,tabIndex:this.props.tabIndex,"aria-label":this.props.ariaLabel},t)}},{key:"renderCloseButton",value:function(){return this.props.closable?e.createElement(r,{type:"button",className:"p-inplace-content-close",icon:"pi pi-times",onClick:this.close}):null}},{key:"renderContent",value:function(t){var n=this.renderCloseButton();return e.createElement("div",{className:"p-inplace-content"},t,n)}},{key:"renderChildren",value:function(){var t=this,n=this.isActive();return e.Children.map(this.props.children,(function(e,r){return n&&e.type===g?t.renderContent(e):n||e.type!==m?void 0:t.renderDisplay(e)}))}},{key:"render",value:function(){var t=n("p-inplace p-component",{"p-inplace-closable":this.props.closable},this.props.className);return e.createElement("div",{className:t},this.renderChildren())}}]),p}();v={style:null,className:null,active:!1,closable:!1,disabled:!1,tabIndex:0,ariaLabel:null,onOpen:null,onClose:null,onToggle:null},(d="defaultProps")in(b=w)?Object.defineProperty(b,d,{value:v,enumerable:!0,configurable:!0,writable:!0}):b[d]=v;export{w as Inplace,g as InplaceContent,m as InplaceDisplay};
|