2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.checkbox=function(e,t,o,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=r(t);function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function p(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 l(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 a(e){return a="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},a(e)}function f(e,t){if(t&&("object"===a(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 d(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function y(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function b(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?y(Object(o),!0).forEach((function(t){d(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):y(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function k(){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(e){l(v,e);var r,u,a,d,y,m=(r=v,u=k(),function(){var e,t=h(r);if(u){var o=h(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return f(this,e)});function v(e){var o;return s(this,v),(o=m.call(this,e)).state={focused:!1},o.onClick=o.onClick.bind(p(o)),o.onFocus=o.onFocus.bind(p(o)),o.onBlur=o.onBlur.bind(p(o)),o.onKeyDown=o.onKeyDown.bind(p(o)),o.inputRef=t.createRef(o.props.inputRef),o}return a=v,(d=[{key:"onClick",value:function(e){if(!this.props.disabled&&!this.props.readOnly&&this.props.onChange){var t=this.isChecked()?this.props.falseValue:this.props.trueValue;this.props.onChange({originalEvent:e,value:this.props.value,checked:t,stopPropagation:function(){},preventDefault:function(){},target:{type:"checkbox",name:this.props.name,id:this.props.id,value:this.props.value,checked:t}}),this.inputRef.current.checked=!this.isChecked(),this.inputRef.current.focus(),e.preventDefault()}}},{key:"updateInputRef",value:function(){var e=this.props.inputRef;e&&("function"==typeof e?e(this.inputRef.current):e.current=this.inputRef.current)}},{key:"componentDidMount",value:function(){this.updateInputRef(),this.props.tooltip&&this.renderTooltip()}},{key:"componentWillUnmount",value:function(){this.tooltip&&(this.tooltip.destroy(),this.tooltip=null)}},{key:"componentDidUpdate",value:function(e){this.inputRef.current.checked=this.isChecked(),e.tooltip===this.props.tooltip&&e.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(b({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip())}},{key:"onFocus",value:function(){this.setState({focused:!0})}},{key:"onBlur",value:function(){this.setState({focused:!1})}},{key:"onKeyDown",value:function(e){"Enter"===e.key&&(this.onClick(e),e.preventDefault())}},{key:"renderTooltip",value:function(){this.tooltip=n.tip({target:this.element,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"isChecked",value:function(){return this.props.checked===this.props.trueValue}},{key:"render",value:function(){var e=this,t=this.isChecked(),n=o.classNames("p-checkbox p-component",{"p-checkbox-checked":t,"p-checkbox-disabled":this.props.disabled,"p-checkbox-focused":this.state.focused},this.props.className),r=o.classNames("p-checkbox-box",{"p-highlight":t,"p-disabled":this.props.disabled,"p-focus":this.state.focused}),s=t&&this.props.icon;return i.default.createElement("div",{ref:function(t){return e.element=t},id:this.props.id,className:n,style:this.props.style,onClick:this.onClick,onContextMenu:this.props.onContextMenu,onMouseDown:this.props.onMouseDown},i.default.createElement("div",{className:"p-hidden-accessible"},i.default.createElement("input",{ref:this.inputRef,type:"checkbox","aria-labelledby":this.props.ariaLabelledBy,id:this.props.inputId,name:this.props.name,tabIndex:this.props.tabIndex,defaultChecked:t,onKeyDown:this.onKeyDown,onFocus:this.onFocus,onBlur:this.onBlur,disabled:this.props.disabled,readOnly:this.props.readOnly,required:this.props.required})),i.default.createElement("div",{className:r,ref:function(t){return e.box=t},role:"checkbox","aria-checked":t},o.IconUtils.getJSXIcon(s,{className:"p-checkbox-icon p-c"},{props:this.props,checked:t})))}}])&&c(a.prototype,d),y&&c(a,y),Object.defineProperty(a,"prototype",{writable:!1}),v}(t.Component);return d(m,"defaultProps",{id:null,inputRef:null,inputId:null,value:null,name:null,checked:!1,trueValue:!0,falseValue:!1,style:null,className:null,disabled:!1,required:!1,readOnly:!1,tabIndex:null,icon:"pi pi-check",tooltip:null,tooltipOptions:null,ariaLabelledBy:null,onChange:null,onMouseDown:null,onContextMenu:null}),e.Checkbox=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.tooltip);
|