{"dependencies":[{"name":"babel-runtime/helpers/extends","loc":{"line":7,"column":24}},{"name":"babel-runtime/helpers/objectWithoutProperties","loc":{"line":11,"column":40}},{"name":"babel-runtime/core-js/object/get-prototype-of","loc":{"line":15,"column":30}},{"name":"babel-runtime/helpers/classCallCheck","loc":{"line":19,"column":31}},{"name":"babel-runtime/helpers/createClass","loc":{"line":23,"column":28}},{"name":"babel-runtime/helpers/possibleConstructorReturn","loc":{"line":27,"column":42}},{"name":"babel-runtime/helpers/inherits","loc":{"line":31,"column":25}},{"name":"simple-assign","loc":{"line":35,"column":28}},{"name":"react","loc":{"line":39,"column":21}},{"name":"prop-types","loc":{"line":43,"column":25}},{"name":"react-event-listener","loc":{"line":47,"column":34}},{"name":"keycode","loc":{"line":51,"column":23}},{"name":"../styles/transitions","loc":{"line":55,"column":27}},{"name":"./FocusRipple","loc":{"line":59,"column":27}},{"name":"./TouchRipple","loc":{"line":63,"column":27}},{"name":"./../Paper","loc":{"line":67,"column":21}},{"name":"warning","loc":{"line":71,"column":23}}],"generated":{"js":"'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true\n});\n\nvar _extends2 = require('babel-runtime/helpers/extends');\n\nvar _extends3 = _interopRequireDefault(_extends2);\n\nvar _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');\n\nvar _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);\n\nvar _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');\n\nvar _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);\n\nvar _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');\n\nvar _classCallCheck3 = _interopRequireDefault(_classCallCheck2);\n\nvar _createClass2 = require('babel-runtime/helpers/createClass');\n\nvar _createClass3 = _interopRequireDefault(_createClass2);\n\nvar _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');\n\nvar _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);\n\nvar _inherits2 = require('babel-runtime/helpers/inherits');\n\nvar _inherits3 = _interopRequireDefault(_inherits2);\n\nvar _simpleAssign = require('simple-assign');\n\nvar _simpleAssign2 = _interopRequireDefault(_simpleAssign);\n\nvar _react = require('react');\n\nvar _react2 = _interopRequireDefault(_react);\n\nvar _propTypes = require('prop-types');\n\nvar _propTypes2 = _interopRequireDefault(_propTypes);\n\nvar _reactEventListener = require('react-event-listener');\n\nvar _reactEventListener2 = _interopRequireDefault(_reactEventListener);\n\nvar _keycode = require('keycode');\n\nvar _keycode2 = _interopRequireDefault(_keycode);\n\nvar _transitions = require('../styles/transitions');\n\nvar _transitions2 = _interopRequireDefault(_transitions);\n\nvar _FocusRipple = require('./FocusRipple');\n\nvar _FocusRipple2 = _interopRequireDefault(_FocusRipple);\n\nvar _TouchRipple = require('./TouchRipple');\n\nvar _TouchRipple2 = _interopRequireDefault(_TouchRipple);\n\nvar _Paper = require('./../Paper');\n\nvar _Paper2 = _interopRequireDefault(_Paper);\n\nvar _warning = require('warning');\n\nvar _warning2 = _interopRequireDefault(_warning);\n\nfunction _interopRequireDefault(obj) {\n  return obj && obj.__esModule ? obj : { default: obj };\n}\n\nfunction getStyles(props, context) {\n  var baseTheme = context.muiTheme.baseTheme;\n\n  return {\n    root: {\n      cursor: props.disabled ? 'not-allowed' : 'pointer',\n      position: 'relative',\n      overflow: 'visible',\n      display: 'table',\n      height: 'auto',\n      width: '100%'\n    },\n    input: {\n      position: 'absolute',\n      cursor: 'inherit',\n      pointerEvents: 'all',\n      opacity: 0,\n      width: '100%',\n      height: '100%',\n      zIndex: 2,\n      left: 0,\n      boxSizing: 'border-box',\n      padding: 0,\n      margin: 0\n    },\n    controls: {\n      display: 'flex',\n      width: '100%',\n      height: '100%'\n    },\n    label: {\n      float: 'left',\n      position: 'relative',\n      display: 'block',\n      width: 'calc(100% - 60px)',\n      lineHeight: '24px',\n      color: baseTheme.palette.textColor,\n      fontFamily: baseTheme.fontFamily\n    },\n    wrap: {\n      transition: _transitions2.default.easeOut(),\n      float: 'left',\n      position: 'relative',\n      display: 'block',\n      flexShrink: 0,\n      width: 60 - baseTheme.spacing.desktopGutterLess,\n      marginRight: props.labelPosition === 'right' ? baseTheme.spacing.desktopGutterLess : 0,\n      marginLeft: props.labelPosition === 'left' ? baseTheme.spacing.desktopGutterLess : 0\n    },\n    ripple: {\n      color: props.rippleColor || baseTheme.palette.primary1Color,\n      height: '200%',\n      width: '200%',\n      top: -12,\n      left: -12\n    }\n  };\n}\n\nvar EnhancedSwitch = function (_Component) {\n  (0, _inherits3.default)(EnhancedSwitch, _Component);\n\n  function EnhancedSwitch() {\n    var _ref;\n\n    var _temp, _this, _ret;\n\n    (0, _classCallCheck3.default)(this, EnhancedSwitch);\n\n    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {\n      args[_key] = arguments[_key];\n    }\n\n    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = EnhancedSwitch.__proto__ || (0, _getPrototypeOf2.default)(EnhancedSwitch)).call.apply(_ref, [this].concat(args))), _this), _this.state = {\n      isKeyboardFocused: false\n    }, _this.handleChange = function (event) {\n      _this.tabPressed = false;\n      _this.setState({\n        isKeyboardFocused: false\n      });\n\n      var isInputChecked = _this.refs.checkbox.checked;\n\n      if (!_this.props.hasOwnProperty('checked') && _this.props.onParentShouldUpdate) {\n        _this.props.onParentShouldUpdate(isInputChecked);\n      }\n\n      if (_this.props.onSwitch) {\n        _this.props.onSwitch(event, isInputChecked);\n      }\n    }, _this.handleKeyDown = function (event) {\n      var code = (0, _keycode2.default)(event);\n\n      if (code === 'tab') {\n        _this.tabPressed = true;\n      }\n      if (_this.state.isKeyboardFocused && code === 'space') {\n        _this.handleChange(event);\n      }\n    }, _this.handleKeyUp = function (event) {\n      if (_this.state.isKeyboardFocused && (0, _keycode2.default)(event) === 'space') {\n        _this.handleChange(event);\n      }\n    }, _this.handleMouseDown = function (event) {\n      // only listen to left clicks\n      if (event.button === 0) {\n        _this.refs.touchRipple.start(event);\n      }\n    }, _this.handleMouseUp = function () {\n      _this.refs.touchRipple.end();\n    }, _this.handleMouseLeave = function () {\n      _this.refs.touchRipple.end();\n    }, _this.handleTouchStart = function (event) {\n      _this.refs.touchRipple.start(event);\n    }, _this.handleTouchEnd = function () {\n      _this.refs.touchRipple.end();\n    }, _this.handleBlur = function (event) {\n      _this.setState({\n        isKeyboardFocused: false\n      });\n\n      if (_this.props.onBlur) {\n        _this.props.onBlur(event);\n      }\n    }, _this.handleFocus = function (event) {\n      // setTimeout is needed becuase the focus event fires first\n      // Wait so that we can capture if this was a keyboard focus\n      // or touch focus\n      setTimeout(function () {\n        if (_this.tabPressed) {\n          _this.setState({\n            isKeyboardFocused: true\n          });\n        }\n      }, 150);\n\n      if (_this.props.onFocus) {\n        _this.props.onFocus(event);\n      }\n    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);\n  }\n\n  (0, _createClass3.default)(EnhancedSwitch, [{\n    key: 'componentWillMount',\n    value: function componentWillMount() {\n      this.componentWillReceiveProps(this.props);\n    }\n  }, {\n    key: 'componentDidMount',\n    value: function componentDidMount() {\n      var inputNode = this.refs.checkbox;\n      if ((!this.props.switched || inputNode.checked !== this.props.switched) && this.props.onParentShouldUpdate) {\n        this.props.onParentShouldUpdate(inputNode.checked);\n      }\n    }\n  }, {\n    key: 'componentWillReceiveProps',\n    value: function componentWillReceiveProps(nextProps) {\n      var hasCheckedProp = nextProps.hasOwnProperty('checked');\n      var hasNewDefaultProp = nextProps.hasOwnProperty('defaultChecked') && nextProps.defaultChecked !== this.props.defaultChecked;\n\n      if (hasCheckedProp || hasNewDefaultProp) {\n        var switched = nextProps.checked || nextProps.defaultChecked || false;\n\n        this.setState({\n          switched: switched\n        });\n\n        if (this.props.onParentShouldUpdate && switched !== this.props.switched) {\n          this.props.onParentShouldUpdate(switched);\n        }\n      }\n    }\n  }, {\n    key: 'isSwitched',\n    value: function isSwitched() {\n      return this.refs.checkbox.checked;\n    }\n\n    // no callback here because there is no event\n\n  }, {\n    key: 'setSwitched',\n    value: function setSwitched(newSwitchedValue) {\n      if (!this.props.hasOwnProperty('checked') || this.props.checked === false) {\n        if (this.props.onParentShouldUpdate) {\n          this.props.onParentShouldUpdate(newSwitchedValue);\n        }\n        this.refs.checkbox.checked = newSwitchedValue;\n      } else {\n        \"development\" !== \"production\" ? (0, _warning2.default)(false, 'Material-UI: Cannot call set method while checked is defined as a property.') : void 0;\n      }\n    }\n  }, {\n    key: 'getValue',\n    value: function getValue() {\n      return this.refs.checkbox.value;\n    }\n\n    // Checkbox inputs only use SPACE to change their state. Using ENTER will\n    // update the ui but not the input.\n\n\n    /**\n     * Because both the ripples and the checkbox input cannot share pointer\n     * events, the checkbox input takes control of pointer events and calls\n     * ripple animations manually.\n     */\n\n  }, {\n    key: 'render',\n    value: function render() {\n      var _props = this.props,\n          name = _props.name,\n          value = _props.value,\n          checked = _props.checked,\n          iconStyle = _props.iconStyle,\n          inputStyle = _props.inputStyle,\n          inputType = _props.inputType,\n          label = _props.label,\n          labelStyle = _props.labelStyle,\n          labelPosition = _props.labelPosition,\n          onSwitch = _props.onSwitch,\n          onBlur = _props.onBlur,\n          onFocus = _props.onFocus,\n          onMouseUp = _props.onMouseUp,\n          onMouseDown = _props.onMouseDown,\n          onMouseLeave = _props.onMouseLeave,\n          onTouchStart = _props.onTouchStart,\n          onTouchEnd = _props.onTouchEnd,\n          onParentShouldUpdate = _props.onParentShouldUpdate,\n          disabled = _props.disabled,\n          disableTouchRipple = _props.disableTouchRipple,\n          disableFocusRipple = _props.disableFocusRipple,\n          className = _props.className,\n          rippleColor = _props.rippleColor,\n          rippleStyle = _props.rippleStyle,\n          style = _props.style,\n          switched = _props.switched,\n          switchElement = _props.switchElement,\n          thumbStyle = _props.thumbStyle,\n          trackStyle = _props.trackStyle,\n          other = (0, _objectWithoutProperties3.default)(_props, ['name', 'value', 'checked', 'iconStyle', 'inputStyle', 'inputType', 'label', 'labelStyle', 'labelPosition', 'onSwitch', 'onBlur', 'onFocus', 'onMouseUp', 'onMouseDown', 'onMouseLeave', 'onTouchStart', 'onTouchEnd', 'onParentShouldUpdate', 'disabled', 'disableTouchRipple', 'disableFocusRipple', 'className', 'rippleColor', 'rippleStyle', 'style', 'switched', 'switchElement', 'thumbStyle', 'trackStyle']);\n      var prepareStyles = this.context.muiTheme.prepareStyles;\n\n      var styles = getStyles(this.props, this.context);\n      var wrapStyles = (0, _simpleAssign2.default)(styles.wrap, iconStyle);\n      var mergedRippleStyle = (0, _simpleAssign2.default)(styles.ripple, rippleStyle);\n\n      if (thumbStyle) {\n        wrapStyles.marginLeft /= 2;\n        wrapStyles.marginRight /= 2;\n      }\n\n      var labelElement = label && _react2.default.createElement('label', { style: prepareStyles((0, _simpleAssign2.default)(styles.label, labelStyle)) }, label);\n\n      var showTouchRipple = !disabled && !disableTouchRipple;\n      var showFocusRipple = !disabled && !disableFocusRipple;\n\n      var touchRipple = _react2.default.createElement(_TouchRipple2.default, {\n        ref: 'touchRipple',\n        key: 'touchRipple',\n        style: mergedRippleStyle,\n        color: mergedRippleStyle.color,\n        muiTheme: this.context.muiTheme,\n        centerRipple: true\n      });\n\n      var focusRipple = _react2.default.createElement(_FocusRipple2.default, {\n        key: 'focusRipple',\n        innerStyle: mergedRippleStyle,\n        color: mergedRippleStyle.color,\n        muiTheme: this.context.muiTheme,\n        show: this.state.isKeyboardFocused\n      });\n\n      var ripples = [showTouchRipple ? touchRipple : null, showFocusRipple ? focusRipple : null];\n\n      var touchHandlers = showTouchRipple ? {\n        onMouseUp: this.handleMouseUp,\n        onMouseDown: this.handleMouseDown,\n        onMouseLeave: this.handleMouseLeave,\n        onTouchStart: this.handleTouchStart,\n        onTouchEnd: this.handleTouchEnd\n      } : {};\n\n      var inputElement = _react2.default.createElement('input', (0, _extends3.default)({}, other, {\n        ref: 'checkbox',\n        type: inputType,\n        style: prepareStyles((0, _simpleAssign2.default)(styles.input, inputStyle)),\n        name: name,\n        value: value,\n        checked: this.state.switched,\n        disabled: disabled,\n        onBlur: this.handleBlur,\n        onFocus: this.handleFocus,\n        onChange: this.handleChange\n      }, touchHandlers));\n\n      // If toggle component (indicated by whether the style includes thumb) manually lay out\n      // elements in order to nest ripple elements\n      var switchOrThumbElement = !thumbStyle ? _react2.default.createElement('div', { style: prepareStyles(wrapStyles) }, switchElement, ripples) : _react2.default.createElement('div', { style: prepareStyles(wrapStyles) }, _react2.default.createElement('div', { style: prepareStyles((0, _simpleAssign2.default)({}, trackStyle)) }), _react2.default.createElement(_Paper2.default, { style: thumbStyle, zDepth: 1, circle: true }, ' ', ripples, ' '));\n\n      var elementsInOrder = labelPosition === 'right' ? _react2.default.createElement('div', { style: styles.controls }, switchOrThumbElement, labelElement) : _react2.default.createElement('div', { style: styles.controls }, labelElement, switchOrThumbElement);\n\n      return _react2.default.createElement('div', { ref: 'root', className: className, style: prepareStyles((0, _simpleAssign2.default)(styles.root, style)) }, _react2.default.createElement(_reactEventListener2.default, {\n        target: 'window',\n        onKeyDown: this.handleKeyDown,\n        onKeyUp: this.handleKeyUp\n      }), inputElement, elementsInOrder);\n    }\n  }]);\n  return EnhancedSwitch;\n}(_react.Component);\n\nEnhancedSwitch.contextTypes = {\n  muiTheme: _propTypes2.default.object.isRequired\n};\nEnhancedSwitch.propTypes = \"development\" !== \"production\" ? {\n  checked: _propTypes2.default.bool,\n  className: _propTypes2.default.string,\n  defaultChecked: _propTypes2.default.bool,\n  disableFocusRipple: _propTypes2.default.bool,\n  disableTouchRipple: _propTypes2.default.bool,\n  disabled: _propTypes2.default.bool,\n  iconStyle: _propTypes2.default.object,\n  inputStyle: _propTypes2.default.object,\n  inputType: _propTypes2.default.string.isRequired,\n  label: _propTypes2.default.node,\n  labelPosition: _propTypes2.default.oneOf(['left', 'right']),\n  labelStyle: _propTypes2.default.object,\n  name: _propTypes2.default.string,\n  onBlur: _propTypes2.default.func,\n  onFocus: _propTypes2.default.func,\n  onMouseDown: _propTypes2.default.func,\n  onMouseLeave: _propTypes2.default.func,\n  onMouseUp: _propTypes2.default.func,\n  onParentShouldUpdate: _propTypes2.default.func,\n  onSwitch: _propTypes2.default.func,\n  onTouchEnd: _propTypes2.default.func,\n  onTouchStart: _propTypes2.default.func,\n  rippleColor: _propTypes2.default.string,\n  rippleStyle: _propTypes2.default.object,\n  style: _propTypes2.default.object,\n  switchElement: _propTypes2.default.element.isRequired,\n  switched: _propTypes2.default.bool.isRequired,\n  thumbStyle: _propTypes2.default.object,\n  trackStyle: _propTypes2.default.object,\n  value: _propTypes2.default.any\n} : {};\nexports.default = EnhancedSwitch;"},"hash":"b4f9acad0d12ac3d949956bcc88e33e6"}