\n );\n }\n}\n\nexport default Checkbox;\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/Checkbox.js\n **/","\"use strict\";\n\nvar _Object$getOwnPropertyDescriptor = require(\"babel-runtime/core-js/object/get-own-property-descriptor\")[\"default\"];\n\nexports[\"default\"] = function get(_x, _x2, _x3) {\n var _again = true;\n\n _function: while (_again) {\n var object = _x,\n property = _x2,\n receiver = _x3;\n _again = false;\n if (object === null) object = Function.prototype;\n\n var desc = _Object$getOwnPropertyDescriptor(object, property);\n\n if (desc === undefined) {\n var parent = Object.getPrototypeOf(object);\n\n if (parent === null) {\n return undefined;\n } else {\n _x = parent;\n _x2 = property;\n _x3 = receiver;\n _again = true;\n desc = parent = undefined;\n continue _function;\n }\n } else if (\"value\" in desc) {\n return desc.value;\n } else {\n var getter = desc.get;\n\n if (getter === undefined) {\n return undefined;\n }\n\n return getter.call(receiver);\n }\n }\n};\n\nexports.__esModule = true;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/helpers/get.js\n ** module id = 3\n ** module chunks = 0\n **/","module.exports = { \"default\": require(\"core-js/library/fn/object/get-own-property-descriptor\"), __esModule: true };\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/core-js/object/get-own-property-descriptor.js\n ** module id = 4\n ** module chunks = 0\n **/","var $ = require('../../modules/$');\nrequire('../../modules/es6.object.get-own-property-descriptor');\nmodule.exports = function getOwnPropertyDescriptor(it, key){\n return $.getDesc(it, key);\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/fn/object/get-own-property-descriptor.js\n ** module id = 5\n ** module chunks = 0\n **/","var $Object = Object;\nmodule.exports = {\n create: $Object.create,\n getProto: $Object.getPrototypeOf,\n isEnum: {}.propertyIsEnumerable,\n getDesc: $Object.getOwnPropertyDescriptor,\n setDesc: $Object.defineProperty,\n setDescs: $Object.defineProperties,\n getKeys: $Object.keys,\n getNames: $Object.getOwnPropertyNames,\n getSymbols: $Object.getOwnPropertySymbols,\n each: [].forEach\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.js\n ** module id = 6\n ** module chunks = 0\n **/","// 19.1.2.6 Object.getOwnPropertyDescriptor(O, P)\nvar toIObject = require('./$.to-iobject');\n\nrequire('./$.object-sap')('getOwnPropertyDescriptor', function($getOwnPropertyDescriptor){\n return function getOwnPropertyDescriptor(it, key){\n return $getOwnPropertyDescriptor(toIObject(it), key);\n };\n});\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/es6.object.get-own-property-descriptor.js\n ** module id = 7\n ** module chunks = 0\n **/","// to indexed object, toObject with fallback for non-array-like ES3 strings\nvar IObject = require('./$.iobject')\n , defined = require('./$.defined');\nmodule.exports = function(it){\n return IObject(defined(it));\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.to-iobject.js\n ** module id = 8\n ** module chunks = 0\n **/","// fallback for non-array-like ES3 and non-enumerable old V8 strings\nvar cof = require('./$.cof');\nmodule.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){\n return cof(it) == 'String' ? it.split('') : Object(it);\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.iobject.js\n ** module id = 9\n ** module chunks = 0\n **/","var toString = {}.toString;\n\nmodule.exports = function(it){\n return toString.call(it).slice(8, -1);\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.cof.js\n ** module id = 10\n ** module chunks = 0\n **/","// 7.2.1 RequireObjectCoercible(argument)\nmodule.exports = function(it){\n if(it == undefined)throw TypeError(\"Can't call method on \" + it);\n return it;\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.defined.js\n ** module id = 11\n ** module chunks = 0\n **/","// most Object methods by ES6 should accept primitives\nvar $export = require('./$.export')\n , core = require('./$.core')\n , fails = require('./$.fails');\nmodule.exports = function(KEY, exec){\n var fn = (core.Object || {})[KEY] || Object[KEY]\n , exp = {};\n exp[KEY] = exec(fn);\n $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp);\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.object-sap.js\n ** module id = 12\n ** module chunks = 0\n **/","var global = require('./$.global')\n , core = require('./$.core')\n , ctx = require('./$.ctx')\n , PROTOTYPE = 'prototype';\n\nvar $export = function(type, name, source){\n var IS_FORCED = type & $export.F\n , IS_GLOBAL = type & $export.G\n , IS_STATIC = type & $export.S\n , IS_PROTO = type & $export.P\n , IS_BIND = type & $export.B\n , IS_WRAP = type & $export.W\n , exports = IS_GLOBAL ? core : core[name] || (core[name] = {})\n , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]\n , key, own, out;\n if(IS_GLOBAL)source = name;\n for(key in source){\n // contains in native\n own = !IS_FORCED && target && key in target;\n if(own && key in exports)continue;\n // export native or passed\n out = own ? target[key] : source[key];\n // prevent global pollution for namespaces\n exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]\n // bind timers to global for call from export context\n : IS_BIND && own ? ctx(out, global)\n // wrap global constructors for prevent change them in library\n : IS_WRAP && target[key] == out ? (function(C){\n var F = function(param){\n return this instanceof C ? new C(param) : C(param);\n };\n F[PROTOTYPE] = C[PROTOTYPE];\n return F;\n // make static versions for prototype methods\n })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;\n if(IS_PROTO)(exports[PROTOTYPE] || (exports[PROTOTYPE] = {}))[key] = out;\n }\n};\n// type bitmap\n$export.F = 1; // forced\n$export.G = 2; // global\n$export.S = 4; // static\n$export.P = 8; // proto\n$export.B = 16; // bind\n$export.W = 32; // wrap\nmodule.exports = $export;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.export.js\n ** module id = 13\n ** module chunks = 0\n **/","// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028\nvar global = module.exports = typeof window != 'undefined' && window.Math == Math\n ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();\nif(typeof __g == 'number')__g = global; // eslint-disable-line no-undef\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.global.js\n ** module id = 14\n ** module chunks = 0\n **/","var core = module.exports = {version: '1.2.6'};\nif(typeof __e == 'number')__e = core; // eslint-disable-line no-undef\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.core.js\n ** module id = 15\n ** module chunks = 0\n **/","// optional / simple context binding\nvar aFunction = require('./$.a-function');\nmodule.exports = function(fn, that, length){\n aFunction(fn);\n if(that === undefined)return fn;\n switch(length){\n case 1: return function(a){\n return fn.call(that, a);\n };\n case 2: return function(a, b){\n return fn.call(that, a, b);\n };\n case 3: return function(a, b, c){\n return fn.call(that, a, b, c);\n };\n }\n return function(/* ...args */){\n return fn.apply(that, arguments);\n };\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.ctx.js\n ** module id = 16\n ** module chunks = 0\n **/","module.exports = function(it){\n if(typeof it != 'function')throw TypeError(it + ' is not a function!');\n return it;\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.a-function.js\n ** module id = 17\n ** module chunks = 0\n **/","module.exports = function(exec){\n try {\n return !!exec();\n } catch(e){\n return true;\n }\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.fails.js\n ** module id = 18\n ** module chunks = 0\n **/","\"use strict\";\n\nvar _Object$create = require(\"babel-runtime/core-js/object/create\")[\"default\"];\n\nvar _Object$setPrototypeOf = require(\"babel-runtime/core-js/object/set-prototype-of\")[\"default\"];\n\nexports[\"default\"] = function (subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass);\n }\n\n subClass.prototype = _Object$create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n if (superClass) _Object$setPrototypeOf ? _Object$setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;\n};\n\nexports.__esModule = true;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/helpers/inherits.js\n ** module id = 19\n ** module chunks = 0\n **/","module.exports = { \"default\": require(\"core-js/library/fn/object/create\"), __esModule: true };\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/core-js/object/create.js\n ** module id = 20\n ** module chunks = 0\n **/","var $ = require('../../modules/$');\nmodule.exports = function create(P, D){\n return $.create(P, D);\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/fn/object/create.js\n ** module id = 21\n ** module chunks = 0\n **/","module.exports = { \"default\": require(\"core-js/library/fn/object/set-prototype-of\"), __esModule: true };\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/core-js/object/set-prototype-of.js\n ** module id = 22\n ** module chunks = 0\n **/","require('../../modules/es6.object.set-prototype-of');\nmodule.exports = require('../../modules/$.core').Object.setPrototypeOf;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/fn/object/set-prototype-of.js\n ** module id = 23\n ** module chunks = 0\n **/","// 19.1.3.19 Object.setPrototypeOf(O, proto)\nvar $export = require('./$.export');\n$export($export.S, 'Object', {setPrototypeOf: require('./$.set-proto').set});\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/es6.object.set-prototype-of.js\n ** module id = 24\n ** module chunks = 0\n **/","// Works with __proto__ only. Old v8 can't work with null proto objects.\n/* eslint-disable no-proto */\nvar getDesc = require('./$').getDesc\n , isObject = require('./$.is-object')\n , anObject = require('./$.an-object');\nvar check = function(O, proto){\n anObject(O);\n if(!isObject(proto) && proto !== null)throw TypeError(proto + \": can't set as prototype!\");\n};\nmodule.exports = {\n set: Object.setPrototypeOf || ('__proto__' in {} ? // eslint-disable-line\n function(test, buggy, set){\n try {\n set = require('./$.ctx')(Function.call, getDesc(Object.prototype, '__proto__').set, 2);\n set(test, []);\n buggy = !(test instanceof Array);\n } catch(e){ buggy = true; }\n return function setPrototypeOf(O, proto){\n check(O, proto);\n if(buggy)O.__proto__ = proto;\n else set(O, proto);\n return O;\n };\n }({}, false) : undefined),\n check: check\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.set-proto.js\n ** module id = 25\n ** module chunks = 0\n **/","module.exports = function(it){\n return typeof it === 'object' ? it !== null : typeof it === 'function';\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.is-object.js\n ** module id = 26\n ** module chunks = 0\n **/","var isObject = require('./$.is-object');\nmodule.exports = function(it){\n if(!isObject(it))throw TypeError(it + ' is not an object!');\n return it;\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.an-object.js\n ** module id = 27\n ** module chunks = 0\n **/","\"use strict\";\n\nvar _Object$defineProperty = require(\"babel-runtime/core-js/object/define-property\")[\"default\"];\n\nexports[\"default\"] = (function () {\n function defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n\n _Object$defineProperty(target, descriptor.key, descriptor);\n }\n }\n\n return function (Constructor, protoProps, staticProps) {\n if (protoProps) defineProperties(Constructor.prototype, protoProps);\n if (staticProps) defineProperties(Constructor, staticProps);\n return Constructor;\n };\n})();\n\nexports.__esModule = true;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/helpers/create-class.js\n ** module id = 28\n ** module chunks = 0\n **/","module.exports = { \"default\": require(\"core-js/library/fn/object/define-property\"), __esModule: true };\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/core-js/object/define-property.js\n ** module id = 29\n ** module chunks = 0\n **/","var $ = require('../../modules/$');\nmodule.exports = function defineProperty(it, key, desc){\n return $.setDesc(it, key, desc);\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/fn/object/define-property.js\n ** module id = 30\n ** module chunks = 0\n **/","\"use strict\";\n\nexports[\"default\"] = function (instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n};\n\nexports.__esModule = true;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/helpers/class-call-check.js\n ** module id = 31\n ** module chunks = 0\n **/","\"use strict\";\n\nvar _Object$assign = require(\"babel-runtime/core-js/object/assign\")[\"default\"];\n\nexports[\"default\"] = _Object$assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n\n return target;\n};\n\nexports.__esModule = true;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/helpers/extends.js\n ** module id = 32\n ** module chunks = 0\n **/","module.exports = { \"default\": require(\"core-js/library/fn/object/assign\"), __esModule: true };\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/core-js/object/assign.js\n ** module id = 33\n ** module chunks = 0\n **/","require('../../modules/es6.object.assign');\nmodule.exports = require('../../modules/$.core').Object.assign;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/fn/object/assign.js\n ** module id = 34\n ** module chunks = 0\n **/","// 19.1.3.1 Object.assign(target, source)\nvar $export = require('./$.export');\n\n$export($export.S + $export.F, 'Object', {assign: require('./$.object-assign')});\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/es6.object.assign.js\n ** module id = 35\n ** module chunks = 0\n **/","// 19.1.2.1 Object.assign(target, source, ...)\nvar $ = require('./$')\n , toObject = require('./$.to-object')\n , IObject = require('./$.iobject');\n\n// should work with symbols and should have deterministic property order (V8 bug)\nmodule.exports = require('./$.fails')(function(){\n var a = Object.assign\n , A = {}\n , B = {}\n , S = Symbol()\n , K = 'abcdefghijklmnopqrst';\n A[S] = 7;\n K.split('').forEach(function(k){ B[k] = k; });\n return a({}, A)[S] != 7 || Object.keys(a({}, B)).join('') != K;\n}) ? function assign(target, source){ // eslint-disable-line no-unused-vars\n var T = toObject(target)\n , $$ = arguments\n , $$len = $$.length\n , index = 1\n , getKeys = $.getKeys\n , getSymbols = $.getSymbols\n , isEnum = $.isEnum;\n while($$len > index){\n var S = IObject($$[index++])\n , keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S)\n , length = keys.length\n , j = 0\n , key;\n while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key];\n }\n return T;\n} : Object.assign;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.object-assign.js\n ** module id = 36\n ** module chunks = 0\n **/","// 7.1.13 ToObject(argument)\nvar defined = require('./$.defined');\nmodule.exports = function(it){\n return Object(defined(it));\n};\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/core-js/library/modules/$.to-object.js\n ** module id = 37\n ** module chunks = 0\n **/","module.exports = __WEBPACK_EXTERNAL_MODULE_38__;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** external \"react\"\n ** module id = 38\n ** module chunks = 0\n **/","import React from 'react';\nimport classnames from 'classnames';\n\nconst _iCheck = 'iCheck';\nconst _iCheckHelper = _iCheck + '-helper';\n\nclass EnhancedSwitch extends React.Component {\n\n static propTypes = {\n inputType: React.PropTypes.string.isRequired,\n\n checked: React.PropTypes.bool,\n defaultChecked: React.PropTypes.bool,\n\n label: React.PropTypes.node,\n\n disabled: React.PropTypes.bool,\n\n indeterminate: React.PropTypes.bool,\n\n onChange: React.PropTypes.func,\n onBlur: React.PropTypes.func,\n onFocus: React.PropTypes.func,\n\n // base class added to customized checkboxes\n checkboxClass: React.PropTypes.string,\n\n // base class added to customized radio buttons\n radioClass: React.PropTypes.string,\n\n // class added on checked state (input.checked = true)\n checkedClass: React.PropTypes.string,\n\n // if not empty, used instead of 'checkedClass' option (input type specific)\n checkedCheckboxClass: React.PropTypes.string,\n checkedRadioClass: React.PropTypes.string,\n\n // if not empty, added as class name on unchecked state (input.checked = false)\n uncheckedClass: React.PropTypes.string,\n\n // if not empty, used instead of 'uncheckedClass' option (input type specific)\n uncheckedCheckboxClass: React.PropTypes.string,\n uncheckedRadioClass: React.PropTypes.string,\n\n // class added on disabled state (input.disabled = true)\n disabledClass: React.PropTypes.string,\n\n // if not empty, used instead of 'disabledClass' option (input type specific)\n disabledCheckboxClass: React.PropTypes.string,\n disabledRadioClass: React.PropTypes.string,\n\n // if not empty, added as class name on enabled state (input.disabled = false)\n enabledClass: React.PropTypes.string,\n\n // if not empty, used instead of 'enabledClass' option (input type specific)\n enabledCheckboxClass: React.PropTypes.string,\n enabledRadioClass: React.PropTypes.string,\n\n // class added on indeterminate state (input.indeterminate = true)\n indeterminateClass: React.PropTypes.string,\n\n // if not empty, used instead of 'indeterminateClass' option (input type specific)\n indeterminateCheckboxClass: React.PropTypes.string,\n indeterminateRadioClass: React.PropTypes.string,\n\n // if not empty, added as class name on determinate state (input.indeterminate = false)\n determinateClass: React.PropTypes.string,\n\n // if not empty, used instead of 'determinateClass' option (input type specific)\n determinateCheckboxClass: React.PropTypes.string,\n determinateRadioClass: React.PropTypes.string,\n\n // class added on hover state (pointer is moved onto input)\n hoverClass: React.PropTypes.string,\n\n // class added on focus state (input has gained focus)\n focusClass: React.PropTypes.string,\n\n // class added on active state (mouse button is pressed on input)\n activeClass: React.PropTypes.string,\n\n // adds hoverClass to customized input on label hover and labelHoverClass to label on input hover\n labelHover: React.PropTypes.bool,\n\n // class added to label if labelHover set to true\n labelHoverClass: React.PropTypes.string,\n\n // increase clickable area by given % (negative number to decrease)\n increaseArea: React.PropTypes.string,\n\n // true to set 'pointer' CSS cursor over enabled inputs and 'default' over disabled\n cursor: React.PropTypes.bool,\n\n // set true to inherit original input's class name\n inheritClass: React.PropTypes.bool,\n\n // if set to true, input's id is prefixed with 'iCheck-' and attached\n inheritID: React.PropTypes.bool,\n\n // set true to activate ARIA support\n aria: React.PropTypes.bool,\n\n // add HTML code or text inside customized input\n insert: React.PropTypes.node,\n\n children: React.PropTypes.node,\n };\n\n static defaultProps = {\n\n checkboxClass: 'icheckbox',\n\n // base class added to customized radio buttons\n radioClass: 'iradio',\n\n // class added on checked state (input.checked = true)\n checkedClass: 'checked',\n\n // class added on disabled state (input.disabled = true)\n disabledClass: 'disabled',\n\n // class added on indeterminate state (input.indeterminate = true)\n indeterminateClass: 'indeterminate',\n\n // class added on hover state (pointer is moved onto input)\n hoverClass: 'hover',\n\n // class added on focus state (input has gained focus)\n focusClass: 'focus',\n\n // class added on active state (mouse button is pressed on input)\n activeClass: 'active',\n\n // adds hoverClass to customized input on label hover and labelHoverClass to label on input hover\n labelHover: true,\n\n // class added to label if labelHover set to true\n labelHoverClass: 'hover',\n\n // increase clickable area by given % (negative number to decrease)\n increaseArea: '',\n\n // true to set 'pointer' CSS cursor over enabled inputs and 'default' over disabled\n cursor: false,\n\n // set true to inherit original input's class name\n inheritClass: false,\n\n // if set to true, input's id is prefixed with 'iCheck-' and attached\n inheritID: false,\n\n // set true to activate ARIA support\n aria: false,\n };\n\n constructor(props) {\n super(props);\n let checked = false;\n if ('checked' in props) {\n checked = props.checked;\n } else {\n checked = props.defaultChecked;\n }\n // Assume we aren't on a mobile for server-side-rendering\n this._mobile = false;\n this.state = {\n checked,\n focused: false,\n hovered: false,\n active: false,\n };\n }\n\n componentDidMount() {\n if (typeof navigator !== 'undefined') {\n this._mobile = /ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);\n }\n this.adjustStyle();\n this.setIndeterminate();\n this.forceUpdate();\n }\n\n componentWillReceiveProps(nextProps) {\n if ('checked' in nextProps) {\n this.setState({\n checked: nextProps.checked,\n });\n }\n }\n\n componentDidUpdate() {\n this.adjustStyle();\n this.setIndeterminate();\n }\n\n getValue() {\n return this.refs.checkbox.value;\n }\n\n setChecked(newCheckedValue) {\n if (!this.props.hasOwnProperty('checked') || this.props.checked === false) {\n // TODO: this.props.onParentShouldUpdate(newSwitchedValue);\n this.refs.checkbox.checked = newCheckedValue;\n } else {\n if (process.env.NODE_ENV !== 'production') {\n let message = 'Cannot call set method while checked is defined as a property.';\n console.error(message); // eslint-disable-line\n }\n }\n }\n\n setIndeterminate() {\n if (this.props.indeterminate) {\n this.refs.checkbox.indeterminate = true;\n }\n }\n\n adjustStyle() {\n const { inputContainer } = this.refs;\n const { position } = window.getComputedStyle(inputContainer);\n\n if (position === 'static') {\n inputContainer.style.position = 'relative';\n }\n }\n\n isChecked() {\n return this.refs.checkbox.checked;\n }\n\n handleChange(e) {\n const checked = e.target.checked;\n if (!('checked' in this.props)) {\n this.setState({\n checked,\n });\n }\n\n if (this.props.onChange) {\n this.props.onChange(e, checked);\n }\n }\n\n handleBlur(e) {\n this.setState({\n focused: false,\n });\n\n if (this.props.onBlur) {\n this.props.onBlur(e);\n }\n }\n\n handleFocus(e) {\n this.setState({\n focused: true,\n });\n\n if (this.props.onFocus) {\n this.props.onFocus(e);\n }\n }\n\n handleHelperClick(event) {\n if (this.props.label) {\n return;\n }\n\n if (this.props.disabled) {\n return;\n }\n\n let newChecked = !this.refs.checkbox.checked;\n\n if (!('checked' in this.props)) {\n this.refs.checkbox.checked = newChecked;\n this.setState({\n checked: newChecked,\n });\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n if (this.props.onChange) {\n // make sure element is not target\n event.target = this.refs.checkbox;\n this.props.onChange(event, newChecked);\n }\n }\n\n render() {\n let props = this.props;\n let { disabled } = props;\n let {\n type,\n name,\n value,\n label,\n onBlur,\n onFocus,\n onMouseUp,\n onMouseDown,\n onMouseLeave,\n onTouchStart,\n onTouchEnd,\n className,\n ...other,\n } = props;\n\n let { checked } = this.state;\n\n // Setup clickable area\n let area = ('' + props.increaseArea).replace('%', '') | 0;\n\n // Clickable area limit\n if (area < -50) {\n area = -50;\n }\n\n let id = props.id;\n\n // Layer styles\n let offset = -area + '%';\n let size = 100 + (area * 2) + '%';\n let layer = {\n position: 'absolute',\n top: offset,\n left: offset,\n display: 'block',\n width: size,\n height: size,\n margin: 0,\n padding: 0,\n background: '#fff',\n border: 0,\n opacity: 0,\n cursor: disabled ? 'default' : 'pointer',\n };\n\n // Choose how to hide input\n let hide;\n if (this._mobile) {\n hide = {\n position: 'absolute',\n visibility: 'hidden',\n };\n } else if (area) {\n hide = layer;\n } else {\n hide = {\n position: 'absolute',\n opacity: 0,\n };\n }\n\n // Check ARIA option\n let aria = !!props.aria;\n\n // TODO: Set ARIA placeholder\n // let ariaID = _iCheck + '-' + Math.random().toString(36).substr(2, 6);\n\n let helper;\n let indeterminateClass = props.indeterminateClass;\n if (props.inputType === 'checkbox' && typeof props.indeterminateCheckboxClass !== 'undefined') {\n indeterminateClass = props.indeterminateCheckboxClass;\n } else if (props.inputType === 'radio' && typeof props.indeterminateRadioClass !== 'undefined') {\n indeterminateClass = props.indeterminateRadioClass;\n }\n\n const wrapProps = {\n className: classnames({\n [props.checkboxClass]: props.inputType === 'checkbox',\n [props.radioClass]: props.inputType === 'radio',\n [indeterminateClass]: props.indeterminate,\n [props.checkedClass]: checked,\n [props.disabledClass]: disabled,\n [props.hoverClass]: this.state.hovered,\n [props.focusClass]: this.state.focused,\n [props.activeClass]: this.state.active,\n }),\n };\n\n if (aria) {\n wrapProps.role = props.inputType;\n // Set ARIA \"labelledby\"\n wrapProps['aria-labelledby'] = '';\n }\n\n if (props.inheritClass) {\n wrapProps.className = classnames(wrapProps.className, props.className);\n }\n\n if (props.inheritID && id) {\n wrapProps.id = _iCheck + '-' + id;\n }\n\n const helperProps = {\n className: _iCheckHelper,\n style: layer,\n onClick: this.handleHelperClick.bind(this),\n };\n\n // Layer addition\n helper = ;\n\n const inputProps = {\n ref: 'checkbox',\n type: props.inputType,\n style: hide,\n name,\n value,\n defaultChecked: props.defaultChecked,\n onChange: this.handleChange.bind(this),\n onBlur: this.handleBlur.bind(this),\n onFocus: this.handleFocus.bind(this),\n };\n\n const inputElement = (\n \n );\n\n let insertElement = props.insert || undefined;\n if (insertElement && !React.isValidElement(insertElement)) {\n insertElement = ;\n }\n\n const inputContainer = (\n \n {inputElement}\n {insertElement}\n {helper}\n
\n );\n\n let labelElement = props.label;\n if (!labelElement) {\n return inputContainer;\n }\n if (!React.isValidElement(labelElement)) {\n labelElement = ;\n }\n\n // Label events\n function handleLabelEvent(event) {\n // Do nothing if input is disabled\n if (disabled) {\n return;\n }\n\n const etype = event.type;\n\n // Click\n if (etype === 'click') {\n // FIXME\n // if ($(event.target).is('a')) {\n // return;\n // }\n // Hover state\n } else if (props.labelHover) {\n // mouseout|touchend false\n this.setState({\n hovered: !/ut|nd/.test(etype),\n });\n }\n\n if (this._mobile) {\n event.stopPropagation();\n }\n // return false;\n }\n\n const labelProps = {\n // onClick: handleLabelEvent.bind(this),\n onMouseOver: handleLabelEvent.bind(this),\n onMouseOut: handleLabelEvent.bind(this),\n onTouchStart: handleLabelEvent.bind(this),\n onTouchEnd: handleLabelEvent.bind(this),\n };\n\n return (\n \n );\n }\n}\n\nexport default EnhancedSwitch;\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/EnhancedSwitch.js\n **/","\"use strict\";\n\nvar _Object$defineProperty = require(\"babel-runtime/core-js/object/define-property\")[\"default\"];\n\nexports[\"default\"] = function (obj, key, value) {\n if (key in obj) {\n _Object$defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n};\n\nexports.__esModule = true;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/helpers/define-property.js\n ** module id = 40\n ** module chunks = 0\n **/","\"use strict\";\n\nexports[\"default\"] = function (obj, keys) {\n var target = {};\n\n for (var i in obj) {\n if (keys.indexOf(i) >= 0) continue;\n if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;\n target[i] = obj[i];\n }\n\n return target;\n};\n\nexports.__esModule = true;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/babel-runtime/helpers/object-without-properties.js\n ** module id = 41\n ** module chunks = 0\n **/","module.exports = __WEBPACK_EXTERNAL_MODULE_42__;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** external \"classnames\"\n ** module id = 42\n ** module chunks = 0\n **/","import React from 'react';\n\nimport EnhancedSwitch from './EnhancedSwitch';\n\nclass Radio extends React.Component {\n\n getValue() {\n return this.refs.enhancedSwitch.getValue();\n }\n\n setChecked(newCheckedValue) {\n this.refs.enhancedSwitch.setSwitched(newCheckedValue);\n }\n\n isChecked() {\n return this.refs.enhancedSwitch.isSwitched();\n }\n\n render() {\n let enhancedSwitchProps = {\n ref: 'enhancedSwitch',\n inputType: 'radio',\n // labelClassName\n };\n\n return (\n \n );\n }\n}\n\nexport default Radio;\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/Radio.js\n **/","import React from 'react';\nimport RadioButton from './Radio';\n\nclass RadioGroup extends React.Component {\n\n static propTypes = {\n /**\n * The name that will be applied to all radio buttons inside it.\n */\n name: React.PropTypes.string.isRequired,\n\n /**\n * Sets the default radio button to be the one whose\n * value matches defaultValue (case-sensitive).\n * This will override any individual radio button with\n * the defaultChecked or checked property stated.\n */\n defaultValue: React.PropTypes.string,\n\n /**\n * The value of the currently selected radio button.\n */\n value: React.PropTypes.string,\n\n /**\n * Callback function that is fired when a radio button has\n * been clicked. Returns the event and the value of the radio\n * button that has been selected.\n */\n onChange: React.PropTypes.func,\n\n /**\n * Should be used to pass `Radio` components.\n */\n children: React.PropTypes.node,\n\n /**\n * The css class name of the root element.\n */\n className: React.PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n this.state = {\n numberCheckedRadioButtons: 0,\n value: this.props.value || this.props.defaultValue || '',\n };\n }\n\n componentWillMount() {\n let cnt = 0;\n\n React.Children.forEach(this.props.children, (option) => {\n if (this.hasCheckAttribute(option)) cnt++;\n }, this);\n\n this.setState({ numberCheckedRadioButtons: cnt });\n }\n\n componentWillReceiveProps(nextProps) {\n if (nextProps.hasOwnProperty('value')) {\n this.setState({\n value: nextProps.value,\n });\n }\n }\n\n getValue() {\n return this.state.value;\n }\n\n setValue(newValue) {\n this.updateRadioButtons(newValue);\n }\n\n clearValue() {\n this.setValue('');\n }\n\n hasCheckAttribute(radioButton) {\n return radioButton.props.hasOwnProperty('checked') && radioButton.props.checked;\n }\n\n updateRadioButtons(newValue) {\n if (this.state.numberCheckedRadioButtons === 0) {\n this.setState({ value: newValue });\n } else {\n if (process.env.NODE_ENV !== 'production') {\n let message = 'Cannot select a different radio button while another radio button ' +\n 'has the \\'checked\\' property set to true.';\n console.error(message); // eslint-disable-line\n }\n }\n }\n\n handleChange(e /* TODO , newValue */) {\n let newValue = e.target.value;\n\n this.updateRadioButtons(newValue);\n\n // Successful update\n if (this.state.numberCheckedRadioButtons === 0) {\n if (this.props.onChange) {\n this.props.onChange(e, newValue);\n }\n }\n }\n\n render() {\n let options = React.Children.map(this.props.children, (option) => {\n let {\n name,\n value,\n label,\n onChange,\n ...other,\n } = option.props;\n\n return (\n \n );\n }, this);\n\n return (\n \n {options}\n
\n );\n }\n}\n\nexport default RadioGroup;\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/RadioGroup.js\n **/"],"sourceRoot":""}
--------------------------------------------------------------------------------
/esdoc.json:
--------------------------------------------------------------------------------
1 | {
2 | "source": "src",
3 | "destination": "./examples/dist/api",
4 | "plugins": [
5 | {
6 | "name": "esdoc-es7-plugin"
7 | }
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/examples/dist/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqin/react-icheck/4b5a3a5b04f5c0ea986d622bb74ac3c7987e3db1/examples/dist/.gitkeep
--------------------------------------------------------------------------------
/examples/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | React-iCheck
7 |
8 |
9 |
10 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/examples/src/js/app.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 |
4 | import { hashHistory, IndexRoute, Router, Route } from 'react-router';
5 |
6 | import App from './components/App';
7 | import GettingStarted from 'react-router!./components/GettingStarted';
8 | import PageNotFound from 'react-router!./components/PageNotFound';
9 | import Basic from 'react-router!./components/examples/Basic';
10 |
11 | const routes = (
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | );
21 |
22 | ReactDOM.render(routes, document.querySelector('#app'));
23 |
--------------------------------------------------------------------------------
/examples/src/js/components/App.js:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.css';
2 | import 'icheck/skins/all.css';
3 |
4 | import React from 'react';
5 | import {
6 | Navbar,
7 | Nav,
8 | NavItem,
9 | Grid,
10 | Row,
11 | Col,
12 | } from 'react-bootstrap';
13 | import { LinkContainer } from 'react-router-bootstrap';
14 |
15 | class App extends React.Component {
16 |
17 | static propTypes = {
18 | children: React.PropTypes.node,
19 | };
20 |
21 | render() {
22 | return (
23 |
24 |
25 |
26 |
27 | React-iCheck
28 |
29 |
30 |
37 |
38 |
39 |
40 |
41 | {this.props.children}
42 |
43 |
44 |
45 |
46 | );
47 | }
48 | }
49 |
50 | export default App;
51 |
--------------------------------------------------------------------------------
/examples/src/js/components/GettingStarted.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class GettingStarted extends React.Component {
4 | render() {
5 | return (
6 |
7 |
Getting started
8 | npm i react-icheck --save
9 |
10 | );
11 | }
12 | }
13 |
14 | export default GettingStarted;
15 |
--------------------------------------------------------------------------------
/examples/src/js/components/Home.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class Home extends React.Component {
4 | render() {
5 | return (
6 |
7 |
React-icheck
8 | icheck components built with React
9 |
10 | );
11 | }
12 | }
13 |
14 | export default Home;
15 |
--------------------------------------------------------------------------------
/examples/src/js/components/PageNotFound.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class PageNotFound extends React.Component {
4 | render() {
5 | return (
6 | Page Not Found
7 | );
8 | }
9 | }
10 |
11 | export default PageNotFound;
12 |
--------------------------------------------------------------------------------
/examples/src/js/components/examples/Basic.js:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 |
3 | import React from 'react';
4 | import { PageHeader } from 'react-bootstrap';
5 | import Demo from './Demo';
6 | import SkinDemo from './SkinDemo';
7 | import LineSkin from './LineSkin';
8 | import PolarisSkin from './PolarisSkin';
9 | import FuturicoSkin from './FuturicoSkin';
10 |
11 | class Basic extends React.Component {
12 |
13 | static propTypes = {};
14 |
15 | static defaultProps = {};
16 |
17 | constructor(props) {
18 | super(props);
19 | this.state = {};
20 | }
21 |
22 | componentDidMount() {
23 | }
24 |
25 | render() {
26 | return (
27 |
28 |
Examples
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | );
40 | }
41 | }
42 |
43 | export default Basic;
44 |
--------------------------------------------------------------------------------
/examples/src/js/components/examples/ColorSchemes.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class ColorSchemes extends React.Component {
4 |
5 | static propTypes = {
6 | color: React.PropTypes.string,
7 | onChange: React.PropTypes.func,
8 | };
9 |
10 | static defaultProps = {
11 | color: '',
12 | };
13 |
14 | constructor(props) {
15 | super(props);
16 | this.state = {
17 | color: props.color,
18 | };
19 | }
20 |
21 | componentWillReceiveProps(nextProps) {
22 | this.setState({ color: nextProps.color });
23 | }
24 |
25 | handleColor(color) {
26 | this.setState({ color });
27 | if (this.props.onChange) {
28 | this.props.onChange(color);
29 | }
30 | }
31 |
32 | render() {
33 | const colors = 'Black Red Green Blue Aero Grey Orange Yellow Pink Purple'.split(' ');
34 |
35 | const lis = colors.map(color => {
36 | let newColor = color.toLowerCase();
37 | if (newColor === 'black') {
38 | newColor = '';
39 | }
40 | return (
41 |
47 | );
48 | });
49 |
50 | return (
51 |
52 |
Color schemes
53 |
56 |
57 | );
58 | }
59 | }
60 |
61 | export default ColorSchemes;
62 |
--------------------------------------------------------------------------------
/examples/src/js/components/examples/Demo.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Panel, Row, Col } from 'react-bootstrap';
3 | import { Checkbox, Radio, RadioGroup } from 'react-icheck';
4 |
5 | class Demo extends React.Component {
6 |
7 | static propTypes = {};
8 |
9 | static defaultProps = {};
10 |
11 | constructor(props) {
12 | super(props);
13 | this.state = {
14 | i1checked: false,
15 | i3checked: false,
16 | i2disabled: false,
17 | i4disabled: false,
18 | radioValue: '3',
19 | };
20 |
21 | this.handle1 = this.handle1.bind(this);
22 | this.handle2 = this.handle2.bind(this);
23 | this.handle3 = this.handle3.bind(this);
24 | this.handle4 = this.handle4.bind(this);
25 | this.handle1Change = this.handle1Change.bind(this);
26 | this.handle3Change = this.handle3Change.bind(this);
27 | this.handleRadioChange = this.handleRadioChange.bind(this);
28 | }
29 |
30 | componentDidMount() {
31 | }
32 |
33 | handle1() {
34 | this.setState({
35 | i1checked: true,
36 | i3checked: true,
37 | radioValue: '3',
38 | });
39 | }
40 |
41 | handle2() {
42 | this.setState({
43 | i1checked: false,
44 | i3checked: false,
45 | radioValue: this.state.radioValue === '3' ? null : this.state.radioValue,
46 | });
47 | }
48 |
49 | handle3() {
50 | this.setState({
51 | i2disabled: true,
52 | i4disabled: true,
53 | });
54 | }
55 |
56 | handle4() {
57 | this.setState({
58 | i2disabled: false,
59 | i4disabled: false,
60 | });
61 | }
62 |
63 | handle1Change(e, checked) {
64 | this.setState({
65 | i1checked: checked,
66 | });
67 | }
68 |
69 | handle3Change(e, checked) {
70 | this.setState({
71 | i3checked: checked,
72 | });
73 | }
74 |
75 | handleRadioChange(event, value) {
76 | this.setState({
77 | radioValue: value,
78 | });
79 | }
80 |
81 | render() {
82 | return (
83 |
84 |
DEMO
85 |
86 |
87 |
88 |
95 |
96 |
103 |
104 |
110 |
111 |
112 |
113 |
119 |
126 |
133 |
134 |
135 |
136 |
137 |
138 | -
139 | Add checked state to 1 and 3 inputs
140 |
141 | -
142 | Remove checked state from 1 and 3 inputs
143 |
144 | -
145 | Add disabled state to 2 and 4 inputs
146 |
147 | -
148 | Remove disabled state from 2 and 4 inputs
149 |
150 |
151 |
152 |
153 | );
154 | }
155 | }
156 |
157 | export default Demo;
158 |
--------------------------------------------------------------------------------
/examples/src/js/components/examples/FuturicoSkin.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Panel, Row, Col } from 'react-bootstrap';
3 | import { Checkbox, Radio } from 'react-icheck';
4 |
5 | class FuturicoSkin extends React.Component {
6 |
7 | static propTypes = {
8 | color: React.PropTypes.string,
9 | };
10 |
11 | constructor(props) {
12 | super(props);
13 | this.state = {
14 | skin: 'futurico',
15 | color: props.color,
16 | };
17 | }
18 |
19 | getCheckboxClass() {
20 | const { skin, color } = this.state;
21 | if (color) {
22 | return `icheckbox_${skin}-${color}`;
23 | }
24 | return `icheckbox_${skin}`;
25 | }
26 |
27 | getRadioClass() {
28 | const { skin, color } = this.state;
29 | if (color) {
30 | return `iradio_${skin}-${color}`;
31 | }
32 | return `iradio_${skin}`;
33 | }
34 |
35 | render() {
36 | return (
37 |
38 |
Futurico skin
39 |
40 |
41 |
42 |
47 |
48 |
54 |
55 |
61 |
62 |
69 |
70 |
71 |
76 |
77 |
83 |
84 |
90 |
91 |
98 |
99 |
100 |
101 |
102 |
103 | );
104 | }
105 | }
106 |
107 | export default FuturicoSkin;
108 |
--------------------------------------------------------------------------------
/examples/src/js/components/examples/LineSkin.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Panel, Row, Col } from 'react-bootstrap';
3 | import { Checkbox, Radio } from 'react-icheck';
4 | import ColorSchemes from './ColorSchemes';
5 |
6 | class LineSkin extends React.Component {
7 |
8 | constructor(props) {
9 | super(props);
10 | this.state = {
11 | skin: 'line',
12 | color: 'blue',
13 | };
14 | }
15 |
16 | componentWillReceiveProps(nextProps) {
17 | this.setState({
18 | color: nextProps.color,
19 | });
20 | }
21 |
22 | getCheckboxClass() {
23 | const { skin, color } = this.state;
24 | if (color) {
25 | return `icheckbox_${skin}-${color}`;
26 | }
27 | return `icheckbox_${skin}`;
28 | }
29 |
30 | getRadioClass() {
31 | const { skin, color } = this.state;
32 | if (color) {
33 | return `iradio_${skin}-${color}`;
34 | }
35 | return `iradio_${skin}`;
36 | }
37 |
38 | handleColor(color) {
39 | this.setState({ color });
40 | }
41 |
42 | render() {
43 | return (
44 |
45 |
Line skin
46 |
47 |
48 |
49 |
Checkbox'}
52 | />
53 |
54 | Checkbox, defaultChecked}
57 | defaultChecked
58 | />
59 |
60 | Checkbox, disabled'}
63 | disabled
64 | />
65 |
66 | Checkbox, defaultChecked disabled'}
69 | defaultChecked
70 | disabled
71 | />
72 |
73 |
74 |
75 | Radio'}
78 | />
79 |
80 | Radio, defaultChecked}
83 | defaultChecked
84 | />
85 |
86 | Radio, disabled'}
89 | disabled
90 | />
91 |
92 | Radio, defaultChecked disabled'}
95 | defaultChecked
96 | disabled
97 | />
98 |
99 |
100 |
101 |
102 |
103 |
104 | );
105 | }
106 | }
107 |
108 | export default LineSkin;
109 |
--------------------------------------------------------------------------------
/examples/src/js/components/examples/PolarisSkin.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Panel, Row, Col } from 'react-bootstrap';
3 | import { Checkbox, Radio } from 'react-icheck';
4 |
5 | class PolarisSkin extends React.Component {
6 |
7 | static propTypes = {
8 | color: React.PropTypes.string,
9 | };
10 |
11 | constructor(props) {
12 | super(props);
13 | this.state = {
14 | skin: 'polaris',
15 | color: props.color,
16 | };
17 | }
18 |
19 | getCheckboxClass() {
20 | const { skin, color } = this.state;
21 | if (color) {
22 | return `icheckbox_${skin}-${color}`;
23 | }
24 | return `icheckbox_${skin}`;
25 | }
26 |
27 | getRadioClass() {
28 | const { skin, color } = this.state;
29 | if (color) {
30 | return `iradio_${skin}-${color}`;
31 | }
32 | return `iradio_${skin}`;
33 | }
34 |
35 | render() {
36 | return (
37 |
38 |
Polaris skin
39 |
40 |
41 |
42 |
47 |
48 |
54 |
55 |
61 |
62 |
69 |
70 |
71 |
76 |
77 |
83 |
84 |
90 |
91 |
98 |
99 |
100 |
101 |
102 |
103 | );
104 | }
105 | }
106 |
107 | export default PolarisSkin;
108 |
--------------------------------------------------------------------------------
/examples/src/js/components/examples/SkinDemo.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Panel, Row, Col } from 'react-bootstrap';
3 | import { Checkbox, Radio } from 'react-icheck';
4 | import ColorSchemes from './ColorSchemes';
5 |
6 | class SkinDemo extends React.Component {
7 |
8 | static propTypes = {
9 | color: React.PropTypes.string,
10 | skin: React.PropTypes.string,
11 | title: React.PropTypes.string,
12 | };
13 |
14 | constructor(props) {
15 | super(props);
16 | this.state = {
17 | skin: props.skin,
18 | color: props.color,
19 | };
20 | }
21 |
22 | componentWillReceiveProps(nextProps) {
23 | this.setState({
24 | skin: nextProps.skin,
25 | color: nextProps.color,
26 | });
27 | }
28 |
29 | getCheckboxClass() {
30 | const { skin, color } = this.state;
31 | if (color) {
32 | return `icheckbox_${skin}-${color}`;
33 | }
34 | return `icheckbox_${skin}`;
35 | }
36 |
37 | getRadioClass() {
38 | const { skin, color } = this.state;
39 | if (color) {
40 | return `iradio_${skin}-${color}`;
41 | }
42 | return `iradio_${skin}`;
43 | }
44 |
45 | handleColor(color) {
46 | this.setState({ color });
47 | }
48 |
49 | render() {
50 | return (
51 |
52 |
{this.props.title}
53 |
54 |
55 |
56 |
61 |
62 |
68 |
69 |
75 |
76 |
83 |
84 |
85 |
90 |
91 |
97 |
98 |
104 |
105 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | );
119 | }
120 | }
121 |
122 | export default SkinDemo;
123 |
--------------------------------------------------------------------------------
/examples/src/js/components/examples/style.scss:
--------------------------------------------------------------------------------
1 | .icheckbox_minimal, .icheckbox_minimal-red, .icheckbox_minimal-green, .icheckbox_minimal-blue, .icheckbox_minimal-aero, .icheckbox_minimal-grey, .icheckbox_minimal-orange, .icheckbox_minimal-yellow, .icheckbox_minimal-pink, .icheckbox_minimal-purple, .iradio_minimal, .iradio_minimal-red, .iradio_minimal-green, .iradio_minimal-blue, .iradio_minimal-aero, .iradio_minimal-grey, .iradio_minimal-orange, .iradio_minimal-yellow, .iradio_minimal-pink, .iradio_minimal-purple {
2 | + span {
3 | padding-left: 18px;
4 | }
5 | }
6 |
7 | .icheckbox_square, .icheckbox_square-red, .icheckbox_square-green, .icheckbox_square-blue, .icheckbox_square-aero, .icheckbox_square-grey, .icheckbox_square-orange, .icheckbox_square-yellow, .icheckbox_square-pink, .icheckbox_square-purple, .iradio_square, .iradio_square-red, .iradio_square-green, .iradio_square-blue, .iradio_square-aero, .iradio_square-grey, .iradio_square-orange, .iradio_square-yellow, .iradio_square-pink, .iradio_square-purple {
8 | + span {
9 | padding-left: 18px;
10 | }
11 | }
12 |
13 | .icheckbox_flat, .icheckbox_flat-red, .icheckbox_flat-green, .icheckbox_flat-blue, .icheckbox_flat-aero, .icheckbox_flat-grey, .icheckbox_flat-orange, .icheckbox_flat-yellow, .icheckbox_flat-pink, .icheckbox_flat-purple, .iradio_flat, .iradio_flat-red, .iradio_flat-green, .iradio_flat-blue, .iradio_flat-aero, .iradio_flat-grey, .iradio_flat-orange, .iradio_flat-yellow, .iradio_flat-pink, .iradio_flat-purple {
14 | + span {
15 | padding-left: 18px;
16 | }
17 | }
18 |
19 | .icheckbox_polaris, .iradio_polaris {
20 | + span {
21 | padding-left: 18px;
22 | }
23 | }
24 |
25 | .icheckbox_futurico, .iradio_futurico {
26 | + span {
27 | padding-left: 18px;
28 | }
29 | }
30 |
31 | .skin.skin-polaris {
32 | .panel {
33 | color: #7a828b;
34 | background: #2c323c;
35 | }
36 | }
37 |
38 | .skin.skin-futurico panel {
39 | color: #888;
40 | background: #2e3035;
41 | }
42 |
43 | .demo {
44 | .label1 {
45 | color:#bbb;
46 | padding-right: 15px;
47 | }
48 | }
49 |
50 | .demo-methods {
51 | padding: 21px 0px 0 0;
52 | }
53 |
54 | .demo-methods .mark {
55 | background: #d3cfc6
56 | }
57 |
58 | .demo-methods dt {
59 | position: relative;
60 | padding: 17px 0px 18px 0;
61 | font: 16px/24px 'MontserratRegular', Helvetica, Arial, sans-serif;
62 | color: #444;
63 | border-bottom: 1px solid #ddd8ce;
64 | }
65 |
66 | .demo-methods dt .self {
67 | cursor: pointer;
68 | }
69 |
70 | .demo-methods dt .self:hover {
71 | color: #222
72 | }
73 |
74 | .demo-methods dt .code {
75 | position: absolute;
76 | right: 0;
77 | bottom: 18px;
78 | color: #777;
79 | }
80 |
81 | .demo-methods dt .code .self:hover {
82 | color: #444
83 | }
84 |
85 | .demo-methods dd {
86 | position: relative;
87 | display: none;
88 | margin: 0;
89 | background: #fff;
90 | border: 1px solid #ddd8ce;
91 | border-top: none;
92 | }
93 |
94 | .demo-methods dd:before {
95 | content: '';
96 | position: absolute;
97 | top: -13px;
98 | left: 0;
99 | width: 0;
100 | height: 0;
101 | border: 1px solid transparent;
102 | border-bottom-color: #ddd8ce;
103 | border-left-color: #ddd8ce
104 | }
105 |
106 | .demo-methods dd .markup {
107 | margin: 0;
108 | color: #888;
109 | background: #f5f3ef;
110 | border: none;
111 | }
112 |
113 | .demo-methods dd .markup .comment {
114 | color: #aaa
115 | }
116 |
117 | .colors {
118 | strong {
119 | float: left;
120 | line-height: 20px;
121 | margin-right: 20px
122 | }
123 |
124 | li {
125 | list-style: none;
126 | }
127 | }
128 |
129 | .colors {
130 | clear: both;
131 | padding: 24px 0 9px;
132 | }
133 |
134 | .colors li {
135 | position: relative;
136 | float: left;
137 | width: 16px;
138 | height: 16px;
139 | margin: 2px 1px 0 0;
140 | background: #000;
141 | cursor: pointer;
142 | filter: alpha(opacity=50);
143 | opacity: .5;
144 | -webkit-transition: opacity .2s;
145 | -moz-transition: opacity .2s;
146 | -ms-transition: opacity .2s;
147 | -o-transition: opacity .2s;
148 | transition: opacity .2s;
149 | }
150 |
151 | .colors li:hover {
152 | filter: alpha(opacity=100);
153 | opacity: 1
154 | }
155 |
156 | .colors li.active {
157 | height: 20px;
158 | margin-top: 0;
159 | filter: alpha(opacity=75);
160 | opacity: .75
161 | }
162 |
163 | .colors li.red {
164 | background: #d54e21
165 | }
166 |
167 | .colors li.green {
168 | background: #78a300
169 | }
170 |
171 | .colors li.blue {
172 | background: #0e76a8
173 | }
174 |
175 | .colors li.aero {
176 | background: #9cc2cb
177 | }
178 |
179 | .colors li.grey {
180 | background: #73716e
181 | }
182 |
183 | .colors li.orange {
184 | background: #f70
185 | }
186 |
187 | .colors li.yellow {
188 | background: #fc0
189 | }
190 |
191 | .colors li.pink {
192 | background: #ff66b5
193 | }
194 |
195 | .colors li.purple {
196 | background: #6a5a8c
197 | }
198 |
--------------------------------------------------------------------------------
/examples/src/scss/index.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqin/react-icheck/4b5a3a5b04f5c0ea986d622bb74ac3c7987e3db1/examples/src/scss/index.scss
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | var gulp = require('gulp');
2 | var initGulpTasks = require('react-component-tools');
3 | var taskConfig = require('./config');
4 |
5 | initGulpTasks(gulp, taskConfig);
6 |
--------------------------------------------------------------------------------
/lib/Checkbox.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _get = require('babel-runtime/helpers/get')['default'];
4 |
5 | var _inherits = require('babel-runtime/helpers/inherits')['default'];
6 |
7 | var _createClass = require('babel-runtime/helpers/create-class')['default'];
8 |
9 | var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
10 |
11 | var _extends = require('babel-runtime/helpers/extends')['default'];
12 |
13 | var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
14 |
15 | Object.defineProperty(exports, '__esModule', {
16 | value: true
17 | });
18 |
19 | var _react = require('react');
20 |
21 | var _react2 = _interopRequireDefault(_react);
22 |
23 | var _EnhancedSwitch = require('./EnhancedSwitch');
24 |
25 | var _EnhancedSwitch2 = _interopRequireDefault(_EnhancedSwitch);
26 |
27 | var Checkbox = (function (_React$Component) {
28 | _inherits(Checkbox, _React$Component);
29 |
30 | function Checkbox(props) {
31 | _classCallCheck(this, Checkbox);
32 |
33 | _get(Object.getPrototypeOf(Checkbox.prototype), 'constructor', this).call(this, props);
34 | this.state = {};
35 | }
36 |
37 | _createClass(Checkbox, [{
38 | key: 'getValue',
39 | value: function getValue() {
40 | return this.refs.enhancedSwitch.getValue();
41 | }
42 | }, {
43 | key: 'setChecked',
44 | value: function setChecked(newCheckedValue) {
45 | this.refs.enhancedSwitch.setChecked(newCheckedValue);
46 | }
47 | }, {
48 | key: 'isChecked',
49 | value: function isChecked() {
50 | return this.refs.enhancedSwitch.isChecked();
51 | }
52 | }, {
53 | key: 'render',
54 | value: function render() {
55 | return _react2['default'].createElement(_EnhancedSwitch2['default'], _extends({ ref: 'enhancedSwitch' }, this.props, { inputType: 'checkbox' }));
56 | }
57 | }]);
58 |
59 | return Checkbox;
60 | })(_react2['default'].Component);
61 |
62 | exports['default'] = Checkbox;
63 | module.exports = exports['default'];
--------------------------------------------------------------------------------
/lib/CheckboxGroup.js:
--------------------------------------------------------------------------------
1 | "use strict";
--------------------------------------------------------------------------------
/lib/EnhancedSwitch.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _get = require('babel-runtime/helpers/get')['default'];
4 |
5 | var _inherits = require('babel-runtime/helpers/inherits')['default'];
6 |
7 | var _createClass = require('babel-runtime/helpers/create-class')['default'];
8 |
9 | var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
10 |
11 | var _defineProperty = require('babel-runtime/helpers/define-property')['default'];
12 |
13 | var _objectWithoutProperties = require('babel-runtime/helpers/object-without-properties')['default'];
14 |
15 | var _extends = require('babel-runtime/helpers/extends')['default'];
16 |
17 | var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
18 |
19 | Object.defineProperty(exports, '__esModule', {
20 | value: true
21 | });
22 |
23 | var _react = require('react');
24 |
25 | var _react2 = _interopRequireDefault(_react);
26 |
27 | var _propTypes = require('prop-types');
28 |
29 | var _propTypes2 = _interopRequireDefault(_propTypes);
30 |
31 | var _classnames2 = require('classnames');
32 |
33 | var _classnames3 = _interopRequireDefault(_classnames2);
34 |
35 | var _iCheck = 'iCheck';
36 | var _iCheckHelper = _iCheck + '-helper';
37 |
38 | var EnhancedSwitch = (function (_React$Component) {
39 | _inherits(EnhancedSwitch, _React$Component);
40 |
41 | _createClass(EnhancedSwitch, null, [{
42 | key: 'propTypes',
43 | value: {
44 | inputType: _propTypes2['default'].string.isRequired,
45 |
46 | checked: _propTypes2['default'].bool,
47 | defaultChecked: _propTypes2['default'].bool,
48 |
49 | label: _propTypes2['default'].node,
50 |
51 | disabled: _propTypes2['default'].bool,
52 |
53 | indeterminate: _propTypes2['default'].bool,
54 |
55 | onChange: _propTypes2['default'].func,
56 | onBlur: _propTypes2['default'].func,
57 | onFocus: _propTypes2['default'].func,
58 |
59 | // base class added to customized checkboxes
60 | checkboxClass: _propTypes2['default'].string,
61 |
62 | // base class added to customized radio buttons
63 | radioClass: _propTypes2['default'].string,
64 |
65 | // class added on checked state (input.checked = true)
66 | checkedClass: _propTypes2['default'].string,
67 |
68 | // if not empty, used instead of 'checkedClass' option (input type specific)
69 | checkedCheckboxClass: _propTypes2['default'].string,
70 | checkedRadioClass: _propTypes2['default'].string,
71 |
72 | // if not empty, added as class name on unchecked state (input.checked = false)
73 | uncheckedClass: _propTypes2['default'].string,
74 |
75 | // if not empty, used instead of 'uncheckedClass' option (input type specific)
76 | uncheckedCheckboxClass: _propTypes2['default'].string,
77 | uncheckedRadioClass: _propTypes2['default'].string,
78 |
79 | // class added on disabled state (input.disabled = true)
80 | disabledClass: _propTypes2['default'].string,
81 |
82 | // if not empty, used instead of 'disabledClass' option (input type specific)
83 | disabledCheckboxClass: _propTypes2['default'].string,
84 | disabledRadioClass: _propTypes2['default'].string,
85 |
86 | // if not empty, added as class name on enabled state (input.disabled = false)
87 | enabledClass: _propTypes2['default'].string,
88 |
89 | // if not empty, used instead of 'enabledClass' option (input type specific)
90 | enabledCheckboxClass: _propTypes2['default'].string,
91 | enabledRadioClass: _propTypes2['default'].string,
92 |
93 | // class added on indeterminate state (input.indeterminate = true)
94 | indeterminateClass: _propTypes2['default'].string,
95 |
96 | // if not empty, used instead of 'indeterminateClass' option (input type specific)
97 | indeterminateCheckboxClass: _propTypes2['default'].string,
98 | indeterminateRadioClass: _propTypes2['default'].string,
99 |
100 | // if not empty, added as class name on determinate state (input.indeterminate = false)
101 | determinateClass: _propTypes2['default'].string,
102 |
103 | // if not empty, used instead of 'determinateClass' option (input type specific)
104 | determinateCheckboxClass: _propTypes2['default'].string,
105 | determinateRadioClass: _propTypes2['default'].string,
106 |
107 | // class added on hover state (pointer is moved onto input)
108 | hoverClass: _propTypes2['default'].string,
109 |
110 | // class added on focus state (input has gained focus)
111 | focusClass: _propTypes2['default'].string,
112 |
113 | // class added on active state (mouse button is pressed on input)
114 | activeClass: _propTypes2['default'].string,
115 |
116 | // adds hoverClass to customized input on label hover and labelHoverClass to label on input hover
117 | labelHover: _propTypes2['default'].bool,
118 |
119 | // class added to label if labelHover set to true
120 | labelHoverClass: _propTypes2['default'].string,
121 |
122 | // increase clickable area by given % (negative number to decrease)
123 | increaseArea: _propTypes2['default'].string,
124 |
125 | // true to set 'pointer' CSS cursor over enabled inputs and 'default' over disabled
126 | cursor: _propTypes2['default'].bool,
127 |
128 | // set true to inherit original input's class name
129 | inheritClass: _propTypes2['default'].bool,
130 |
131 | // if set to true, input's id is prefixed with 'iCheck-' and attached
132 | inheritID: _propTypes2['default'].bool,
133 |
134 | // set true to activate ARIA support
135 | aria: _propTypes2['default'].bool,
136 |
137 | // add HTML code or text inside customized input
138 | insert: _propTypes2['default'].node,
139 |
140 | children: _propTypes2['default'].node,
141 |
142 | // class added for outer label
143 | labelClassName: _propTypes2['default'].string
144 | },
145 | enumerable: true
146 | }, {
147 | key: 'defaultProps',
148 | value: {
149 |
150 | checkboxClass: 'icheckbox',
151 |
152 | // base class added to customized radio buttons
153 | radioClass: 'iradio',
154 |
155 | // class added on checked state (input.checked = true)
156 | checkedClass: 'checked',
157 |
158 | // class added on disabled state (input.disabled = true)
159 | disabledClass: 'disabled',
160 |
161 | // class added on indeterminate state (input.indeterminate = true)
162 | indeterminateClass: 'indeterminate',
163 |
164 | // class added on hover state (pointer is moved onto input)
165 | hoverClass: 'hover',
166 |
167 | // class added on focus state (input has gained focus)
168 | focusClass: 'focus',
169 |
170 | // class added on active state (mouse button is pressed on input)
171 | activeClass: 'active',
172 |
173 | // adds hoverClass to customized input on label hover and labelHoverClass to label on input hover
174 | labelHover: true,
175 |
176 | // class added to label if labelHover set to true
177 | labelHoverClass: 'hover',
178 |
179 | // increase clickable area by given % (negative number to decrease)
180 | increaseArea: '',
181 |
182 | // true to set 'pointer' CSS cursor over enabled inputs and 'default' over disabled
183 | cursor: false,
184 |
185 | // set true to inherit original input's class name
186 | inheritClass: false,
187 |
188 | // if set to true, input's id is prefixed with 'iCheck-' and attached
189 | inheritID: false,
190 |
191 | // set true to activate ARIA support
192 | aria: false
193 | },
194 | enumerable: true
195 | }]);
196 |
197 | function EnhancedSwitch(props) {
198 | _classCallCheck(this, EnhancedSwitch);
199 |
200 | _get(Object.getPrototypeOf(EnhancedSwitch.prototype), 'constructor', this).call(this, props);
201 | var checked = false;
202 | if ('checked' in props) {
203 | checked = props.checked;
204 | } else {
205 | checked = props.defaultChecked;
206 | }
207 | // Assume we aren't on a mobile for server-side-rendering
208 | this._mobile = false;
209 | this.state = {
210 | checked: checked,
211 | focused: false,
212 | hovered: false,
213 | active: false
214 | };
215 | }
216 |
217 | _createClass(EnhancedSwitch, [{
218 | key: 'componentDidMount',
219 | value: function componentDidMount() {
220 | if (typeof navigator !== 'undefined') {
221 | this._mobile = /ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);
222 | }
223 | this.adjustStyle();
224 | this.setIndeterminate();
225 | this.forceUpdate();
226 | }
227 | }, {
228 | key: 'componentWillReceiveProps',
229 | value: function componentWillReceiveProps(nextProps) {
230 | if ('checked' in nextProps) {
231 | this.setState({
232 | checked: nextProps.checked
233 | });
234 | }
235 | }
236 | }, {
237 | key: 'componentDidUpdate',
238 | value: function componentDidUpdate() {
239 | this.adjustStyle();
240 | this.setIndeterminate();
241 | }
242 | }, {
243 | key: 'getValue',
244 | value: function getValue() {
245 | return this.refs.checkbox.value;
246 | }
247 | }, {
248 | key: 'setChecked',
249 | value: function setChecked(newCheckedValue) {
250 | if (!this.props.hasOwnProperty('checked') || this.props.checked === false) {
251 | // TODO: this.props.onParentShouldUpdate(newSwitchedValue);
252 | this.refs.checkbox.checked = newCheckedValue;
253 | } else {
254 | if (process.env.NODE_ENV !== 'production') {
255 | var message = 'Cannot call set method while checked is defined as a property.';
256 | console.error(message); // eslint-disable-line
257 | }
258 | }
259 | }
260 | }, {
261 | key: 'setIndeterminate',
262 | value: function setIndeterminate() {
263 | if (this.props.indeterminate) {
264 | this.refs.checkbox.indeterminate = true;
265 | }
266 | }
267 | }, {
268 | key: 'adjustStyle',
269 | value: function adjustStyle() {
270 | var inputContainer = this.refs.inputContainer;
271 |
272 | var _window$getComputedStyle = window.getComputedStyle(inputContainer);
273 |
274 | var position = _window$getComputedStyle.position;
275 |
276 | if (position === 'static') {
277 | inputContainer.style.position = 'relative';
278 | }
279 | }
280 | }, {
281 | key: 'isChecked',
282 | value: function isChecked() {
283 | return this.refs.checkbox.checked;
284 | }
285 | }, {
286 | key: 'handleChange',
287 | value: function handleChange(e) {
288 | var checked = e.target.checked;
289 | if (!('checked' in this.props)) {
290 | this.setState({
291 | checked: checked
292 | });
293 | }
294 |
295 | if (this.props.onChange) {
296 | this.props.onChange(e, checked);
297 | }
298 | }
299 | }, {
300 | key: 'handleBlur',
301 | value: function handleBlur(e) {
302 | this.setState({
303 | focused: false
304 | });
305 |
306 | if (this.props.onBlur) {
307 | this.props.onBlur(e);
308 | }
309 | }
310 | }, {
311 | key: 'handleFocus',
312 | value: function handleFocus(e) {
313 | this.setState({
314 | focused: true
315 | });
316 |
317 | if (this.props.onFocus) {
318 | this.props.onFocus(e);
319 | }
320 | }
321 | }, {
322 | key: 'handleHelperClick',
323 | value: function handleHelperClick(event) {
324 | if (this.props.label) {
325 | return;
326 | }
327 |
328 | if (this.props.disabled) {
329 | return;
330 | }
331 |
332 | var newChecked = !this.refs.checkbox.checked;
333 |
334 | if (!('checked' in this.props)) {
335 | this.refs.checkbox.checked = newChecked;
336 | this.setState({
337 | checked: newChecked
338 | });
339 | }
340 |
341 | event.preventDefault();
342 | event.stopPropagation();
343 |
344 | if (this.props.onChange) {
345 | // make sure element is not target
346 | event.target = this.refs.checkbox;
347 | this.props.onChange(event, newChecked);
348 | }
349 | }
350 | }, {
351 | key: 'render',
352 | value: function render() {
353 | var _classnames;
354 |
355 | var props = this.props;
356 | var disabled = props.disabled;
357 | var type = props.type;
358 | var name = props.name;
359 | var value = props.value;
360 | var label = props.label;
361 | var onBlur = props.onBlur;
362 | var onFocus = props.onFocus;
363 | var onMouseUp = props.onMouseUp;
364 | var onMouseDown = props.onMouseDown;
365 | var onMouseLeave = props.onMouseLeave;
366 | var onTouchStart = props.onTouchStart;
367 | var onTouchEnd = props.onTouchEnd;
368 | var className = props.className;
369 | var checkboxClass = props.checkboxClass;
370 | var increaseArea = props.increaseArea;
371 | var inputType = props.inputType;
372 | var radioClass = props.radioClass;
373 | var checkedClass = props.checkedClass;
374 | var disabledClass = props.disabledClass;
375 | var indeterminate = props.indeterminate;
376 | var indeterminateClass = props.indeterminateClass;
377 | var hoverClass = props.hoverClass;
378 | var focusClass = props.focusClass;
379 | var activeClass = props.activeClass;
380 | var labelHover = props.labelHover;
381 | var labelHoverClass = props.labelHoverClass;
382 | var labelClassName = props.labelClassName;
383 | var inheritClass = props.inheritClass;
384 | var inheritID = props.inheritID;
385 | var aria = props.aria;
386 | var insert = props.insert;
387 |
388 | var other = _objectWithoutProperties(props, ['type', 'name', 'value', 'label', 'onBlur', 'onFocus', 'onMouseUp', 'onMouseDown', 'onMouseLeave', 'onTouchStart', 'onTouchEnd', 'className', 'checkboxClass', 'increaseArea', 'inputType', 'radioClass', 'checkedClass', 'disabledClass', 'indeterminate', 'indeterminateClass', 'hoverClass', 'focusClass', 'activeClass', 'labelHover', 'labelHoverClass', 'labelClassName', 'inheritClass', 'inheritID', 'aria', 'insert']);
389 |
390 | var checked = this.state.checked;
391 |
392 | // Setup clickable area
393 | var area = ('' + props.increaseArea).replace('%', '') | 0;
394 |
395 | // Clickable area limit
396 | if (area < -50) {
397 | area = -50;
398 | }
399 |
400 | var id = props.id;
401 |
402 | // Layer styles
403 | var offset = -area + '%';
404 | var size = 100 + area * 2 + '%';
405 | var layer = {
406 | position: 'absolute',
407 | top: offset,
408 | left: offset,
409 | display: 'block',
410 | width: size,
411 | height: size,
412 | margin: 0,
413 | padding: 0,
414 | background: '#fff',
415 | border: 0,
416 | opacity: 0,
417 | cursor: disabled ? 'default' : 'pointer'
418 | };
419 |
420 | // Choose how to hide input
421 | var hide = undefined;
422 | if (this._mobile) {
423 | hide = {
424 | position: 'absolute',
425 | visibility: 'hidden'
426 | };
427 | } else if (area) {
428 | hide = layer;
429 | } else {
430 | hide = {
431 | position: 'absolute',
432 | opacity: 0
433 | };
434 | }
435 |
436 | // Check ARIA option
437 | aria = !!props.aria;
438 |
439 | // TODO: Set ARIA placeholder
440 | // let ariaID = _iCheck + '-' + Math.random().toString(36).substr(2, 6);
441 |
442 | var helper = undefined;
443 | if (props.inputType === 'checkbox' && typeof props.indeterminateCheckboxClass !== 'undefined') {
444 | indeterminateClass = props.indeterminateCheckboxClass;
445 | } else if (props.inputType === 'radio' && typeof props.indeterminateRadioClass !== 'undefined') {
446 | indeterminateClass = props.indeterminateRadioClass;
447 | }
448 |
449 | var wrapProps = {
450 | className: (0, _classnames3['default'])((_classnames = {}, _defineProperty(_classnames, props.checkboxClass, props.inputType === 'checkbox'), _defineProperty(_classnames, props.radioClass, props.inputType === 'radio'), _defineProperty(_classnames, indeterminateClass, indeterminate), _defineProperty(_classnames, props.checkedClass, checked), _defineProperty(_classnames, props.disabledClass, disabled), _defineProperty(_classnames, props.hoverClass, this.state.hovered), _defineProperty(_classnames, props.focusClass, this.state.focused), _defineProperty(_classnames, props.activeClass, this.state.active), _classnames))
451 | };
452 |
453 | if (props.inheritClass) {
454 | wrapProps.className = (0, _classnames3['default'])(wrapProps.className, props.className);
455 | }
456 |
457 | if (props.inheritID && id) {
458 | wrapProps.id = _iCheck + '-' + id;
459 | }
460 |
461 | if (aria) {
462 | wrapProps.role = props.inputType;
463 | // Set ARIA "labelledby"
464 | wrapProps['aria-labelledby'] = wrapProps.id;
465 | wrapProps['aria-checked'] = checked;
466 | }
467 |
468 | // Layer addition
469 | helper = _react2['default'].createElement('ins', {
470 | className: _iCheckHelper,
471 | style: layer,
472 | onClick: this.handleHelperClick.bind(this)
473 | });
474 |
475 | var inputElement = _react2['default'].createElement('input', _extends({}, other, {
476 |
477 | ref: 'checkbox',
478 | type: props.inputType,
479 | style: hide,
480 | name: name,
481 | value: value,
482 | defaultChecked: props.defaultChecked,
483 | onChange: this.handleChange.bind(this),
484 | onBlur: this.handleBlur.bind(this),
485 | onFocus: this.handleFocus.bind(this)
486 | }));
487 |
488 | var insertElement = props.insert;
489 | if (insertElement && !_react2['default'].isValidElement(insertElement)) {
490 | insertElement = _react2['default'].createElement('div', { dangerouslySetInnerHTML: { __html: insertElement } });
491 | }
492 |
493 | var inputContainer = _react2['default'].createElement(
494 | 'div',
495 | _extends({ ref: 'inputContainer' }, wrapProps),
496 | inputElement,
497 | insertElement,
498 | helper
499 | );
500 |
501 | var labelElement = props.label;
502 | if (!labelElement) {
503 | return inputContainer;
504 | }
505 | if (!_react2['default'].isValidElement(labelElement)) {
506 | labelElement = _react2['default'].createElement('span', { dangerouslySetInnerHTML: { __html: labelElement } });
507 | }
508 |
509 | // Label events
510 | function handleLabelEvent(event) {
511 | // Do nothing if input is disabled
512 | if (disabled) {
513 | return;
514 | }
515 |
516 | var etype = event.type;
517 |
518 | // Click
519 | if (etype === 'click') {
520 | // FIXME
521 | // if ($(event.target).is('a')) {
522 | // return;
523 | // }
524 | // Hover state
525 | } else if (props.labelHover) {
526 | // mouseout|touchend false
527 | this.setState({
528 | hovered: !/ut|nd/.test(etype)
529 | });
530 | }
531 |
532 | if (this._mobile) {
533 | event.stopPropagation();
534 | }
535 | // return false;
536 | }
537 |
538 | var labelProps = {
539 | // onClick: handleLabelEvent.bind(this),
540 | onMouseOver: handleLabelEvent.bind(this),
541 | onMouseOut: handleLabelEvent.bind(this),
542 | onTouchStart: handleLabelEvent.bind(this),
543 | onTouchEnd: handleLabelEvent.bind(this)
544 | };
545 |
546 | // add className prop for outer label
547 | if (labelClassName) {
548 | labelProps.className = labelClassName;
549 | }
550 |
551 | return _react2['default'].createElement(
552 | 'label',
553 | labelProps,
554 | inputContainer,
555 | labelElement
556 | );
557 | }
558 | }]);
559 |
560 | return EnhancedSwitch;
561 | })(_react2['default'].Component);
562 |
563 | exports['default'] = EnhancedSwitch;
564 | module.exports = exports['default'];
--------------------------------------------------------------------------------
/lib/Radio.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _get = require('babel-runtime/helpers/get')['default'];
4 |
5 | var _inherits = require('babel-runtime/helpers/inherits')['default'];
6 |
7 | var _createClass = require('babel-runtime/helpers/create-class')['default'];
8 |
9 | var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
10 |
11 | var _extends = require('babel-runtime/helpers/extends')['default'];
12 |
13 | var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
14 |
15 | Object.defineProperty(exports, '__esModule', {
16 | value: true
17 | });
18 |
19 | var _react = require('react');
20 |
21 | var _react2 = _interopRequireDefault(_react);
22 |
23 | var _EnhancedSwitch = require('./EnhancedSwitch');
24 |
25 | var _EnhancedSwitch2 = _interopRequireDefault(_EnhancedSwitch);
26 |
27 | var Radio = (function (_React$Component) {
28 | _inherits(Radio, _React$Component);
29 |
30 | function Radio() {
31 | _classCallCheck(this, Radio);
32 |
33 | _get(Object.getPrototypeOf(Radio.prototype), 'constructor', this).apply(this, arguments);
34 | }
35 |
36 | _createClass(Radio, [{
37 | key: 'getValue',
38 | value: function getValue() {
39 | return this.refs.enhancedSwitch.getValue();
40 | }
41 | }, {
42 | key: 'setChecked',
43 | value: function setChecked(newCheckedValue) {
44 | this.refs.enhancedSwitch.setSwitched(newCheckedValue);
45 | }
46 | }, {
47 | key: 'isChecked',
48 | value: function isChecked() {
49 | return this.refs.enhancedSwitch.isSwitched();
50 | }
51 | }, {
52 | key: 'render',
53 | value: function render() {
54 | var enhancedSwitchProps = {
55 | ref: 'enhancedSwitch',
56 | inputType: 'radio'
57 | };
58 |
59 | // labelClassName
60 | return _react2['default'].createElement(_EnhancedSwitch2['default'], _extends({}, this.props, enhancedSwitchProps));
61 | }
62 | }]);
63 |
64 | return Radio;
65 | })(_react2['default'].Component);
66 |
67 | exports['default'] = Radio;
68 | module.exports = exports['default'];
--------------------------------------------------------------------------------
/lib/RadioGroup.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _get = require('babel-runtime/helpers/get')['default'];
4 |
5 | var _inherits = require('babel-runtime/helpers/inherits')['default'];
6 |
7 | var _createClass = require('babel-runtime/helpers/create-class')['default'];
8 |
9 | var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
10 |
11 | var _objectWithoutProperties = require('babel-runtime/helpers/object-without-properties')['default'];
12 |
13 | var _extends = require('babel-runtime/helpers/extends')['default'];
14 |
15 | var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
16 |
17 | Object.defineProperty(exports, '__esModule', {
18 | value: true
19 | });
20 |
21 | var _react = require('react');
22 |
23 | var _react2 = _interopRequireDefault(_react);
24 |
25 | var _propTypes = require('prop-types');
26 |
27 | var _propTypes2 = _interopRequireDefault(_propTypes);
28 |
29 | var _Radio = require('./Radio');
30 |
31 | var _Radio2 = _interopRequireDefault(_Radio);
32 |
33 | var RadioGroup = (function (_React$Component) {
34 | _inherits(RadioGroup, _React$Component);
35 |
36 | _createClass(RadioGroup, null, [{
37 | key: 'propTypes',
38 | value: {
39 | /**
40 | * The name that will be applied to all radio buttons inside it.
41 | */
42 | name: _propTypes2['default'].string.isRequired,
43 |
44 | /**
45 | * Sets the default radio button to be the one whose
46 | * value matches defaultValue (case-sensitive).
47 | * This will override any individual radio button with
48 | * the defaultChecked or checked property stated.
49 | */
50 | defaultValue: _propTypes2['default'].string,
51 |
52 | /**
53 | * The value of the currently selected radio button.
54 | */
55 | value: _propTypes2['default'].string,
56 |
57 | /**
58 | * Callback function that is fired when a radio button has
59 | * been clicked. Returns the event and the value of the radio
60 | * button that has been selected.
61 | */
62 | onChange: _propTypes2['default'].func,
63 |
64 | /**
65 | * Should be used to pass `Radio` components.
66 | */
67 | children: _propTypes2['default'].node,
68 |
69 | /**
70 | * The css class name of the root element.
71 | */
72 | className: _propTypes2['default'].string
73 | },
74 | enumerable: true
75 | }]);
76 |
77 | function RadioGroup(props) {
78 | _classCallCheck(this, RadioGroup);
79 |
80 | _get(Object.getPrototypeOf(RadioGroup.prototype), 'constructor', this).call(this, props);
81 | this.state = {
82 | numberCheckedRadioButtons: 0,
83 | value: this.props.value || this.props.defaultValue || ''
84 | };
85 | }
86 |
87 | _createClass(RadioGroup, [{
88 | key: 'componentWillMount',
89 | value: function componentWillMount() {
90 | var _this = this;
91 |
92 | var cnt = 0;
93 |
94 | _react2['default'].Children.forEach(this.props.children, function (option) {
95 | if (_this.hasCheckAttribute(option)) cnt++;
96 | }, this);
97 |
98 | this.setState({ numberCheckedRadioButtons: cnt });
99 | }
100 | }, {
101 | key: 'componentWillReceiveProps',
102 | value: function componentWillReceiveProps(nextProps) {
103 | if (nextProps.hasOwnProperty('value')) {
104 | this.setState({
105 | value: nextProps.value
106 | });
107 | }
108 | }
109 | }, {
110 | key: 'getValue',
111 | value: function getValue() {
112 | return this.state.value;
113 | }
114 | }, {
115 | key: 'setValue',
116 | value: function setValue(newValue) {
117 | this.updateRadioButtons(newValue);
118 | }
119 | }, {
120 | key: 'clearValue',
121 | value: function clearValue() {
122 | this.setValue('');
123 | }
124 | }, {
125 | key: 'hasCheckAttribute',
126 | value: function hasCheckAttribute(radioButton) {
127 | return radioButton.props.hasOwnProperty('checked') && radioButton.props.checked;
128 | }
129 | }, {
130 | key: 'updateRadioButtons',
131 | value: function updateRadioButtons(newValue) {
132 | if (this.state.numberCheckedRadioButtons === 0) {
133 | this.setState({ value: newValue });
134 | } else {
135 | if (process.env.NODE_ENV !== 'production') {
136 | var message = 'Cannot select a different radio button while another radio button ' + 'has the \'checked\' property set to true.';
137 | console.error(message); // eslint-disable-line
138 | }
139 | }
140 | }
141 | }, {
142 | key: 'handleChange',
143 | value: function handleChange(e /* TODO , newValue */) {
144 | var newValue = e.target.value;
145 |
146 | this.updateRadioButtons(newValue);
147 |
148 | // Successful update
149 | if (this.state.numberCheckedRadioButtons === 0) {
150 | if (this.props.onChange) {
151 | this.props.onChange(e, newValue);
152 | }
153 | }
154 | }
155 | }, {
156 | key: 'render',
157 | value: function render() {
158 | var _this2 = this;
159 |
160 | var options = _react2['default'].Children.map(this.props.children, function (option) {
161 | var _option$props = option.props;
162 | var name = _option$props.name;
163 | var value = _option$props.value;
164 | var label = _option$props.label;
165 | var onChange = _option$props.onChange;
166 |
167 | var other = _objectWithoutProperties(_option$props, ['name', 'value', 'label', 'onChange']);
168 |
169 | return _react2['default'].createElement(_Radio2['default'], _extends({}, other, {
170 | ref: option.props.value,
171 | name: _this2.props.name,
172 | key: option.props.value,
173 | value: option.props.value,
174 | label: option.props.label,
175 | onChange: _this2.handleChange.bind(_this2),
176 | checked: option.props.value === _this2.state.value
177 | }));
178 | }, this);
179 |
180 | return _react2['default'].createElement(
181 | 'div',
182 | { className: this.props.className },
183 | options
184 | );
185 | }
186 | }]);
187 |
188 | return RadioGroup;
189 | })(_react2['default'].Component);
190 |
191 | exports['default'] = RadioGroup;
192 | module.exports = exports['default'];
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
4 |
5 | Object.defineProperty(exports, '__esModule', {
6 | value: true
7 | });
8 |
9 | var _Checkbox = require('./Checkbox');
10 |
11 | var _Checkbox2 = _interopRequireDefault(_Checkbox);
12 |
13 | var _Radio = require('./Radio');
14 |
15 | var _Radio2 = _interopRequireDefault(_Radio);
16 |
17 | var _RadioGroup = require('./RadioGroup');
18 |
19 | var _RadioGroup2 = _interopRequireDefault(_RadioGroup);
20 |
21 | exports['default'] = {
22 | Checkbox: _Checkbox2['default'],
23 | Radio: _Radio2['default'],
24 | RadioGroup: _RadioGroup2['default']
25 | };
26 | module.exports = exports['default'];
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-icheck",
3 | "version": "0.3.8",
4 | "description": "iCheck components built with React. Highly customizable checkboxes and radio buttons",
5 | "main": "lib/index.js",
6 | "scripts": {
7 | "build": "babel ./src -d lib",
8 | "gh-pages": "gulp publish:examples",
9 | "lint": "eslint src examples/src",
10 | "prepublish": "npm run build",
11 | "start": "gulp dev",
12 | "test": "npm run lint && gulp build --p"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/luqin/react-icheck"
17 | },
18 | "license": "ISC",
19 | "files": [
20 | "lib",
21 | "CHANGELOG.md",
22 | "README.md"
23 | ],
24 | "peerDependencies": {
25 | "react": "^15 || ^16"
26 | },
27 | "dependencies": {
28 | "babel-runtime": "^5.8.38",
29 | "classnames": "^2.2.3",
30 | "icheck": "^1.0.2",
31 | "prop-types": "^15.5.8"
32 | },
33 | "devDependencies": {
34 | "babel": "^5.8.38",
35 | "babel-core": "^5.8.38",
36 | "babel-eslint": "^4.1.1",
37 | "babel-plugin-object-assign": "^1.2.1",
38 | "eslint": "^1.10.3",
39 | "bootstrap": "^3.3.7",
40 | "eslint-config-airbnb": "^2.1.1",
41 | "eslint-config-onefe": "^0.2.0",
42 | "eslint-plugin-react": "^3.11.3",
43 | "gulp": "^3.9.1",
44 | "react": "^15.4.2",
45 | "react-dom": "^15.4.2",
46 | "react-bootstrap": "^0.30.3",
47 | "react-component-tools": "^1.0.2",
48 | "react-router": "^2.8.1",
49 | "react-router-bootstrap": "^0.22.1",
50 | "react-router-loader": "^0.5.4",
51 | "webpack": "^1.13.0",
52 | "webpack-dev-server": "^1.14.1"
53 | },
54 | "keywords": [
55 | "react",
56 | "icheck",
57 | "radio",
58 | "checkbox",
59 | "toggle",
60 | "switch",
61 | "radioGroup",
62 | "form",
63 | "input",
64 | "ui",
65 | "react-dom",
66 | "react-icheck",
67 | "react-component"
68 | ]
69 | }
70 |
--------------------------------------------------------------------------------
/src/Checkbox.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import EnhancedSwitch from './EnhancedSwitch';
4 |
5 | class Checkbox extends React.Component {
6 |
7 | constructor(props) {
8 | super(props);
9 | this.state = {};
10 | }
11 |
12 | getValue() {
13 | return this.refs.enhancedSwitch.getValue();
14 | }
15 |
16 | setChecked(newCheckedValue) {
17 | this.refs.enhancedSwitch.setChecked(newCheckedValue);
18 | }
19 |
20 | isChecked() {
21 | return this.refs.enhancedSwitch.isChecked();
22 | }
23 |
24 | render() {
25 | return (
26 |
27 | );
28 | }
29 | }
30 |
31 | export default Checkbox;
32 |
--------------------------------------------------------------------------------
/src/CheckboxGroup.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqin/react-icheck/4b5a3a5b04f5c0ea986d622bb74ac3c7987e3db1/src/CheckboxGroup.js
--------------------------------------------------------------------------------
/src/EnhancedSwitch.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import classnames from 'classnames';
4 |
5 | const _iCheck = 'iCheck';
6 | const _iCheckHelper = _iCheck + '-helper';
7 |
8 | class EnhancedSwitch extends React.Component {
9 |
10 | static propTypes = {
11 | inputType: PropTypes.string.isRequired,
12 |
13 | checked: PropTypes.bool,
14 | defaultChecked: PropTypes.bool,
15 |
16 | label: PropTypes.node,
17 |
18 | disabled: PropTypes.bool,
19 |
20 | indeterminate: PropTypes.bool,
21 |
22 | onChange: PropTypes.func,
23 | onBlur: PropTypes.func,
24 | onFocus: PropTypes.func,
25 |
26 | // base class added to customized checkboxes
27 | checkboxClass: PropTypes.string,
28 |
29 | // base class added to customized radio buttons
30 | radioClass: PropTypes.string,
31 |
32 | // class added on checked state (input.checked = true)
33 | checkedClass: PropTypes.string,
34 |
35 | // if not empty, used instead of 'checkedClass' option (input type specific)
36 | checkedCheckboxClass: PropTypes.string,
37 | checkedRadioClass: PropTypes.string,
38 |
39 | // if not empty, added as class name on unchecked state (input.checked = false)
40 | uncheckedClass: PropTypes.string,
41 |
42 | // if not empty, used instead of 'uncheckedClass' option (input type specific)
43 | uncheckedCheckboxClass: PropTypes.string,
44 | uncheckedRadioClass: PropTypes.string,
45 |
46 | // class added on disabled state (input.disabled = true)
47 | disabledClass: PropTypes.string,
48 |
49 | // if not empty, used instead of 'disabledClass' option (input type specific)
50 | disabledCheckboxClass: PropTypes.string,
51 | disabledRadioClass: PropTypes.string,
52 |
53 | // if not empty, added as class name on enabled state (input.disabled = false)
54 | enabledClass: PropTypes.string,
55 |
56 | // if not empty, used instead of 'enabledClass' option (input type specific)
57 | enabledCheckboxClass: PropTypes.string,
58 | enabledRadioClass: PropTypes.string,
59 |
60 | // class added on indeterminate state (input.indeterminate = true)
61 | indeterminateClass: PropTypes.string,
62 |
63 | // if not empty, used instead of 'indeterminateClass' option (input type specific)
64 | indeterminateCheckboxClass: PropTypes.string,
65 | indeterminateRadioClass: PropTypes.string,
66 |
67 | // if not empty, added as class name on determinate state (input.indeterminate = false)
68 | determinateClass: PropTypes.string,
69 |
70 | // if not empty, used instead of 'determinateClass' option (input type specific)
71 | determinateCheckboxClass: PropTypes.string,
72 | determinateRadioClass: PropTypes.string,
73 |
74 | // class added on hover state (pointer is moved onto input)
75 | hoverClass: PropTypes.string,
76 |
77 | // class added on focus state (input has gained focus)
78 | focusClass: PropTypes.string,
79 |
80 | // class added on active state (mouse button is pressed on input)
81 | activeClass: PropTypes.string,
82 |
83 | // adds hoverClass to customized input on label hover and labelHoverClass to label on input hover
84 | labelHover: PropTypes.bool,
85 |
86 | // class added to label if labelHover set to true
87 | labelHoverClass: PropTypes.string,
88 |
89 | // increase clickable area by given % (negative number to decrease)
90 | increaseArea: PropTypes.string,
91 |
92 | // true to set 'pointer' CSS cursor over enabled inputs and 'default' over disabled
93 | cursor: PropTypes.bool,
94 |
95 | // set true to inherit original input's class name
96 | inheritClass: PropTypes.bool,
97 |
98 | // if set to true, input's id is prefixed with 'iCheck-' and attached
99 | inheritID: PropTypes.bool,
100 |
101 | // set true to activate ARIA support
102 | aria: PropTypes.bool,
103 |
104 | // add HTML code or text inside customized input
105 | insert: PropTypes.node,
106 |
107 | children: PropTypes.node,
108 |
109 | // class added for outer label
110 | labelClassName: PropTypes.string,
111 | };
112 |
113 | static defaultProps = {
114 |
115 | checkboxClass: 'icheckbox',
116 |
117 | // base class added to customized radio buttons
118 | radioClass: 'iradio',
119 |
120 | // class added on checked state (input.checked = true)
121 | checkedClass: 'checked',
122 |
123 | // class added on disabled state (input.disabled = true)
124 | disabledClass: 'disabled',
125 |
126 | // class added on indeterminate state (input.indeterminate = true)
127 | indeterminateClass: 'indeterminate',
128 |
129 | // class added on hover state (pointer is moved onto input)
130 | hoverClass: 'hover',
131 |
132 | // class added on focus state (input has gained focus)
133 | focusClass: 'focus',
134 |
135 | // class added on active state (mouse button is pressed on input)
136 | activeClass: 'active',
137 |
138 | // adds hoverClass to customized input on label hover and labelHoverClass to label on input hover
139 | labelHover: true,
140 |
141 | // class added to label if labelHover set to true
142 | labelHoverClass: 'hover',
143 |
144 | // increase clickable area by given % (negative number to decrease)
145 | increaseArea: '',
146 |
147 | // true to set 'pointer' CSS cursor over enabled inputs and 'default' over disabled
148 | cursor: false,
149 |
150 | // set true to inherit original input's class name
151 | inheritClass: false,
152 |
153 | // if set to true, input's id is prefixed with 'iCheck-' and attached
154 | inheritID: false,
155 |
156 | // set true to activate ARIA support
157 | aria: false,
158 | };
159 |
160 | constructor(props) {
161 | super(props);
162 | let checked = false;
163 | if ('checked' in props) {
164 | checked = props.checked;
165 | } else {
166 | checked = props.defaultChecked;
167 | }
168 | // Assume we aren't on a mobile for server-side-rendering
169 | this._mobile = false;
170 | this.state = {
171 | checked,
172 | focused: false,
173 | hovered: false,
174 | active: false,
175 | };
176 | }
177 |
178 | componentDidMount() {
179 | if (typeof navigator !== 'undefined') {
180 | this._mobile = /ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);
181 | }
182 | this.adjustStyle();
183 | this.setIndeterminate();
184 | this.forceUpdate();
185 | }
186 |
187 | componentWillReceiveProps(nextProps) {
188 | if ('checked' in nextProps) {
189 | this.setState({
190 | checked: nextProps.checked,
191 | });
192 | }
193 | }
194 |
195 | componentDidUpdate() {
196 | this.adjustStyle();
197 | this.setIndeterminate();
198 | }
199 |
200 | getValue() {
201 | return this.refs.checkbox.value;
202 | }
203 |
204 | setChecked(newCheckedValue) {
205 | if (!this.props.hasOwnProperty('checked') || this.props.checked === false) {
206 | // TODO: this.props.onParentShouldUpdate(newSwitchedValue);
207 | this.refs.checkbox.checked = newCheckedValue;
208 | } else {
209 | if (process.env.NODE_ENV !== 'production') {
210 | let message = 'Cannot call set method while checked is defined as a property.';
211 | console.error(message); // eslint-disable-line
212 | }
213 | }
214 | }
215 |
216 | setIndeterminate() {
217 | if (this.props.indeterminate) {
218 | this.refs.checkbox.indeterminate = true;
219 | }
220 | }
221 |
222 | adjustStyle() {
223 | const { inputContainer } = this.refs;
224 | const { position } = window.getComputedStyle(inputContainer);
225 |
226 | if (position === 'static') {
227 | inputContainer.style.position = 'relative';
228 | }
229 | }
230 |
231 | isChecked() {
232 | return this.refs.checkbox.checked;
233 | }
234 |
235 | handleChange(e) {
236 | const checked = e.target.checked;
237 | if (!('checked' in this.props)) {
238 | this.setState({
239 | checked,
240 | });
241 | }
242 |
243 | if (this.props.onChange) {
244 | this.props.onChange(e, checked);
245 | }
246 | }
247 |
248 | handleBlur(e) {
249 | this.setState({
250 | focused: false,
251 | });
252 |
253 | if (this.props.onBlur) {
254 | this.props.onBlur(e);
255 | }
256 | }
257 |
258 | handleFocus(e) {
259 | this.setState({
260 | focused: true,
261 | });
262 |
263 | if (this.props.onFocus) {
264 | this.props.onFocus(e);
265 | }
266 | }
267 |
268 | handleHelperClick(event) {
269 | if (this.props.label) {
270 | return;
271 | }
272 |
273 | if (this.props.disabled) {
274 | return;
275 | }
276 |
277 | let newChecked = !this.refs.checkbox.checked;
278 |
279 | if (!('checked' in this.props)) {
280 | this.refs.checkbox.checked = newChecked;
281 | this.setState({
282 | checked: newChecked,
283 | });
284 | }
285 |
286 | event.preventDefault();
287 | event.stopPropagation();
288 |
289 | if (this.props.onChange) {
290 | // make sure element is not target
291 | event.target = this.refs.checkbox;
292 | this.props.onChange(event, newChecked);
293 | }
294 | }
295 |
296 | render() {
297 | let props = this.props;
298 | let { disabled } = props;
299 | let {
300 | type,
301 | name,
302 | value,
303 | label,
304 | onBlur,
305 | onFocus,
306 | onMouseUp,
307 | onMouseDown,
308 | onMouseLeave,
309 | onTouchStart,
310 | onTouchEnd,
311 | className,
312 |
313 | checkboxClass,
314 | increaseArea,
315 | inputType,
316 | radioClass,
317 | checkedClass,
318 | disabledClass,
319 | indeterminate,
320 | indeterminateClass,
321 | hoverClass,
322 | focusClass,
323 | activeClass,
324 | labelHover,
325 | labelHoverClass,
326 | labelClassName,
327 | inheritClass,
328 | inheritID,
329 | aria,
330 | insert,
331 |
332 | ...other,
333 | } = props;
334 |
335 | let { checked } = this.state;
336 |
337 | // Setup clickable area
338 | let area = ('' + props.increaseArea).replace('%', '') | 0;
339 |
340 | // Clickable area limit
341 | if (area < -50) {
342 | area = -50;
343 | }
344 |
345 | let id = props.id;
346 |
347 | // Layer styles
348 | let offset = -area + '%';
349 | let size = 100 + (area * 2) + '%';
350 | let layer = {
351 | position: 'absolute',
352 | top: offset,
353 | left: offset,
354 | display: 'block',
355 | width: size,
356 | height: size,
357 | margin: 0,
358 | padding: 0,
359 | background: '#fff',
360 | border: 0,
361 | opacity: 0,
362 | cursor: disabled ? 'default' : 'pointer',
363 | };
364 |
365 | // Choose how to hide input
366 | let hide;
367 | if (this._mobile) {
368 | hide = {
369 | position: 'absolute',
370 | visibility: 'hidden',
371 | };
372 | } else if (area) {
373 | hide = layer;
374 | } else {
375 | hide = {
376 | position: 'absolute',
377 | opacity: 0,
378 | };
379 | }
380 |
381 | // Check ARIA option
382 | aria = !!props.aria;
383 |
384 | // TODO: Set ARIA placeholder
385 | // let ariaID = _iCheck + '-' + Math.random().toString(36).substr(2, 6);
386 |
387 | let helper;
388 | if (props.inputType === 'checkbox' && typeof props.indeterminateCheckboxClass !== 'undefined') {
389 | indeterminateClass = props.indeterminateCheckboxClass;
390 | } else if (props.inputType === 'radio' && typeof props.indeterminateRadioClass !== 'undefined') {
391 | indeterminateClass = props.indeterminateRadioClass;
392 | }
393 |
394 | const wrapProps = {
395 | className: classnames({
396 | [props.checkboxClass]: props.inputType === 'checkbox',
397 | [props.radioClass]: props.inputType === 'radio',
398 | [indeterminateClass]: indeterminate,
399 | [props.checkedClass]: checked,
400 | [props.disabledClass]: disabled,
401 | [props.hoverClass]: this.state.hovered,
402 | [props.focusClass]: this.state.focused,
403 | [props.activeClass]: this.state.active,
404 | }),
405 | };
406 |
407 | if (props.inheritClass) {
408 | wrapProps.className = classnames(wrapProps.className, props.className);
409 | }
410 |
411 | if (props.inheritID && id) {
412 | wrapProps.id = _iCheck + '-' + id;
413 | }
414 |
415 | if (aria) {
416 | wrapProps.role = props.inputType;
417 | // Set ARIA "labelledby"
418 | wrapProps['aria-labelledby'] = wrapProps.id;
419 | wrapProps['aria-checked'] = checked;
420 | }
421 |
422 | // Layer addition
423 | helper = (
424 |
429 | );
430 |
431 | const inputElement = (
432 |
445 | );
446 |
447 | let insertElement = props.insert;
448 | if (insertElement && !React.isValidElement(insertElement)) {
449 | insertElement = ;
450 | }
451 |
452 | const inputContainer = (
453 |
454 | {inputElement}
455 | {insertElement}
456 | {helper}
457 |
458 | );
459 |
460 | let labelElement = props.label;
461 | if (!labelElement) {
462 | return inputContainer;
463 | }
464 | if (!React.isValidElement(labelElement)) {
465 | labelElement = ;
466 | }
467 |
468 | // Label events
469 | function handleLabelEvent(event) {
470 | // Do nothing if input is disabled
471 | if (disabled) {
472 | return;
473 | }
474 |
475 | const etype = event.type;
476 |
477 | // Click
478 | if (etype === 'click') {
479 | // FIXME
480 | // if ($(event.target).is('a')) {
481 | // return;
482 | // }
483 | // Hover state
484 | } else if (props.labelHover) {
485 | // mouseout|touchend false
486 | this.setState({
487 | hovered: !/ut|nd/.test(etype),
488 | });
489 | }
490 |
491 | if (this._mobile) {
492 | event.stopPropagation();
493 | }
494 | // return false;
495 | }
496 |
497 | const labelProps = {
498 | // onClick: handleLabelEvent.bind(this),
499 | onMouseOver: handleLabelEvent.bind(this),
500 | onMouseOut: handleLabelEvent.bind(this),
501 | onTouchStart: handleLabelEvent.bind(this),
502 | onTouchEnd: handleLabelEvent.bind(this),
503 | };
504 |
505 | // add className prop for outer label
506 | if (labelClassName) {
507 | labelProps.className = labelClassName;
508 | }
509 |
510 | return (
511 |
515 | );
516 | }
517 | }
518 |
519 | export default EnhancedSwitch;
520 |
--------------------------------------------------------------------------------
/src/Radio.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import EnhancedSwitch from './EnhancedSwitch';
4 |
5 | class Radio extends React.Component {
6 |
7 | getValue() {
8 | return this.refs.enhancedSwitch.getValue();
9 | }
10 |
11 | setChecked(newCheckedValue) {
12 | this.refs.enhancedSwitch.setSwitched(newCheckedValue);
13 | }
14 |
15 | isChecked() {
16 | return this.refs.enhancedSwitch.isSwitched();
17 | }
18 |
19 | render() {
20 | let enhancedSwitchProps = {
21 | ref: 'enhancedSwitch',
22 | inputType: 'radio',
23 | // labelClassName
24 | };
25 |
26 | return (
27 |
28 | );
29 | }
30 | }
31 |
32 | export default Radio;
33 |
--------------------------------------------------------------------------------
/src/RadioGroup.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import RadioButton from './Radio';
4 |
5 | class RadioGroup extends React.Component {
6 |
7 | static propTypes = {
8 | /**
9 | * The name that will be applied to all radio buttons inside it.
10 | */
11 | name: PropTypes.string.isRequired,
12 |
13 | /**
14 | * Sets the default radio button to be the one whose
15 | * value matches defaultValue (case-sensitive).
16 | * This will override any individual radio button with
17 | * the defaultChecked or checked property stated.
18 | */
19 | defaultValue: PropTypes.string,
20 |
21 | /**
22 | * The value of the currently selected radio button.
23 | */
24 | value: PropTypes.string,
25 |
26 | /**
27 | * Callback function that is fired when a radio button has
28 | * been clicked. Returns the event and the value of the radio
29 | * button that has been selected.
30 | */
31 | onChange: PropTypes.func,
32 |
33 | /**
34 | * Should be used to pass `Radio` components.
35 | */
36 | children: PropTypes.node,
37 |
38 | /**
39 | * The css class name of the root element.
40 | */
41 | className: PropTypes.string,
42 | };
43 |
44 | constructor(props) {
45 | super(props);
46 | this.state = {
47 | numberCheckedRadioButtons: 0,
48 | value: this.props.value || this.props.defaultValue || '',
49 | };
50 | }
51 |
52 | componentWillMount() {
53 | let cnt = 0;
54 |
55 | React.Children.forEach(this.props.children, (option) => {
56 | if (this.hasCheckAttribute(option)) cnt++;
57 | }, this);
58 |
59 | this.setState({ numberCheckedRadioButtons: cnt });
60 | }
61 |
62 | componentWillReceiveProps(nextProps) {
63 | if (nextProps.hasOwnProperty('value')) {
64 | this.setState({
65 | value: nextProps.value,
66 | });
67 | }
68 | }
69 |
70 | getValue() {
71 | return this.state.value;
72 | }
73 |
74 | setValue(newValue) {
75 | this.updateRadioButtons(newValue);
76 | }
77 |
78 | clearValue() {
79 | this.setValue('');
80 | }
81 |
82 | hasCheckAttribute(radioButton) {
83 | return radioButton.props.hasOwnProperty('checked') && radioButton.props.checked;
84 | }
85 |
86 | updateRadioButtons(newValue) {
87 | if (this.state.numberCheckedRadioButtons === 0) {
88 | this.setState({ value: newValue });
89 | } else {
90 | if (process.env.NODE_ENV !== 'production') {
91 | let message = 'Cannot select a different radio button while another radio button ' +
92 | 'has the \'checked\' property set to true.';
93 | console.error(message); // eslint-disable-line
94 | }
95 | }
96 | }
97 |
98 | handleChange(e /* TODO , newValue */) {
99 | let newValue = e.target.value;
100 |
101 | this.updateRadioButtons(newValue);
102 |
103 | // Successful update
104 | if (this.state.numberCheckedRadioButtons === 0) {
105 | if (this.props.onChange) {
106 | this.props.onChange(e, newValue);
107 | }
108 | }
109 | }
110 |
111 | render() {
112 | let options = React.Children.map(this.props.children, (option) => {
113 | let {
114 | name,
115 | value,
116 | label,
117 | onChange,
118 | ...other,
119 | } = option.props;
120 |
121 | return (
122 |
132 | );
133 | }, this);
134 |
135 | return (
136 |
137 | {options}
138 |
139 | );
140 | }
141 | }
142 |
143 | export default RadioGroup;
144 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import Checkbox from './Checkbox';
2 | import Radio from './Radio';
3 | import RadioGroup from './RadioGroup';
4 |
5 | export default {
6 | Checkbox,
7 | Radio,
8 | RadioGroup,
9 | };
10 |
--------------------------------------------------------------------------------