react-checkbox
Version:
1 lines • 2.5 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("React")):"function"==typeof define&&define.amd?define(["React"],t):"object"==typeof exports?exports.ReactCheckbox=t(require("React")):e.ReactCheckbox=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(){}var o=n(2),a=n(1),i=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};e.exports=o.createClass({displayName:"ReactCheckbox",propTypes:{nextValue:o.PropTypes.func,onChange:o.PropTypes.func,checked:o.PropTypes.any,defaultChecked:o.PropTypes.any,indeterminateValue:o.PropTypes.any,supportIndeterminate:o.PropTypes.bool},getDefaultProps:function(){return{stopPropagation:!0,indeterminateValue:null,supportIndeterminate:!1,nextValue:function(e,t){return e===t.indeterminateValue?!0:e===!0?!1:t.indeterminateValue}}},getInitialState:function(){return{defaultChecked:this.props.defaultChecked}},render:function(){var e=this.prepareProps(this.props,this.state);return o.createElement("input",o.__spread({type:"checkbox"},e,{checked:this.isChecked()}))},componentDidMount:function(){this.checkIndeterminate()},componentDidUpdate:function(){this.checkIndeterminate()},checkIndeterminate:function(){this.props.supportIndeterminate&&(this.getDOMNode().indeterminate=this.isIndeterminate())},isIndeterminate:function(){var e=this.props,t=this.getValue(),n=e.supportIndeterminate&&t===e.indeterminateValue;return n===!0},prepareProps:function(e){var t={};return a(t,e),t.onChange=this.handleChange,t},getValue:function(){var e=this.props;return i(e,"checked")?e.checked:this.state.defaultChecked},isChecked:function(){return this.getValue()||!1},handleChange:function(e){var t=e.target.checked,n=this.props;if(n.supportIndeterminate){var o=this.getValue();"function"==typeof n.nextValue&&(t=n.nextValue(o,this.props))}(n.onChange||r)(t,e),i(n,"checked")||this.setState({defaultChecked:t}),n.stopPropagation&&e.stopPropagation()}})},function(e){"use strict";function t(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=Object.assign||function(e){for(var n,r,o=t(e),a=1;a<arguments.length;a++){n=arguments[a],r=Object.keys(Object(n));for(var i=0;i<r.length;i++)o[r[i]]=n[r[i]]}return o}},function(t){t.exports=e}])});