1 | !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],e):t.ReactToggled=e(t.React,t.PropTypes)}(this,function(t,e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},r=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},i=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return function(){for(var t=arguments.length,n=Array(t),o=0;o<t;o++)n[o]=arguments[o];return e.forEach(function(t){return t&&t.apply(void 0,n)})}},s=function(){},p=function(t){function e(){var p,g;n(this,e);for(var l=arguments.length,a=Array(l),u=0;u<l;u++)a[u]=arguments[u];return p=g=r(this,t.call.apply(t,[this].concat(a))),g.state={on:g.getOn({on:g.props.defaultOn})},g.getTogglerProps=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return o({"aria-expanded":Boolean(g.getOn()),tabIndex:0},t,{onClick:i(t.onClick,g.toggle)})},g.toggleKeys=["Enter"," "],g.getInputTogglerProps=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return g.getTogglerProps(o({},t,{onKeyUp:i(t.onKeyUp,function(t){"Enter"===t.key&&g.toggle()})}))},g.getElementTogglerProps=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return g.getTogglerProps(o({},t,{onKeyUp:i(t.onKeyUp,function(t){g.toggleKeys.indexOf(t.key)>-1&&g.toggle()})}))},g.setOnState=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:!g.getOn(),e=g.getOn()===t?s:function(){g.props.onToggle(t,g.getTogglerStateAndHelpers())};g.setState({on:t},e)},g.setOn=g.setOnState.bind(g,!0),g.setOff=g.setOnState.bind(g,!1),g.toggle=g.setOnState.bind(g,void 0),r(g,p)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.getOn=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.props;return this.isOnControlled()?e.on:t.on},e.prototype.isOnControlled=function(){return void 0!==this.props.on},e.prototype.getTogglerStateAndHelpers=function(){return{on:this.getOn(),getTogglerProps:this.getTogglerProps,getInputTogglerProps:this.getInputTogglerProps,getElementTogglerProps:this.getElementTogglerProps,setOn:this.setOn,setOff:this.setOff,toggle:this.toggle}},e.prototype.componentWillReceiveProps=function(t){var e=t.on;e!==this.props.on&&e!==this.state.on&&this.setOnState(e)},e.prototype.render=function(){var t;return(t=this.props.children,Array.isArray(t)?t[0]:t)(this.getTogglerStateAndHelpers())},e}(t.Component);return p.defaultProps={defaultOn:!1,onToggle:s},p});
|