2022-10-08 03:32:59 +02:00
|
|
|
/** @jsx React.DOM */
|
|
|
|
|
2022-10-08 20:37:38 +02:00
|
|
|
var Slider = createReactClass({
|
2022-10-13 04:23:57 +02:00
|
|
|
key: function(e) {
|
|
|
|
if (e.keyCode == 32) {
|
|
|
|
// Toggle on space.
|
|
|
|
if (this.props.onChange) {
|
|
|
|
this.props.onChange(!this.props.value);
|
|
|
|
}
|
|
|
|
} else if (e.keyCode == 39) {
|
|
|
|
// Slide with cursor keys.
|
|
|
|
if (this.props.onChange && this.props.value) {
|
|
|
|
this.props.onChange(!this.props.value);
|
|
|
|
}
|
|
|
|
} else if (e.keyCode == 37) {
|
|
|
|
// Slide with cursor keys.
|
|
|
|
if (this.props.onChange && !this.props.value) {
|
|
|
|
this.props.onChange(!this.props.value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Don't handle, so don't hit the default prevent below.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
},
|
|
|
|
|
2022-10-08 03:32:59 +02:00
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<div
|
2022-10-08 21:29:14 +02:00
|
|
|
className={classNames("slider", this.props.value ? "on" : "off", this.props.className)}
|
2022-10-08 03:32:59 +02:00
|
|
|
onClick={function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
if (this.props.onChange) {
|
|
|
|
this.props.onChange(!this.props.value);
|
|
|
|
}
|
|
|
|
}.bind(this)}
|
2022-10-13 04:23:57 +02:00
|
|
|
tabindex={0}
|
|
|
|
onKeyDown={this.key}
|
2022-10-08 03:32:59 +02:00
|
|
|
>{ this.props.value ?
|
2022-10-08 23:26:48 +02:00
|
|
|
<>
|
2022-10-08 03:32:59 +02:00
|
|
|
<span className="ball on"></span>
|
|
|
|
<span className="label on">{this.props.on}</span>
|
2022-10-08 23:26:48 +02:00
|
|
|
</> :
|
|
|
|
<>
|
2022-10-08 03:32:59 +02:00
|
|
|
<span className="label off">{this.props.off}</span>
|
|
|
|
<span className="ball off"></span>
|
2022-10-08 23:26:48 +02:00
|
|
|
</>
|
2022-10-08 03:32:59 +02:00
|
|
|
}</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|