mirror of
https://github.com/opensupports/opensupports.git
synced 2025-04-08 18:35:06 +02:00
43 lines
982 B
JavaScript
43 lines
982 B
JavaScript
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
import i18n from 'lib-app/i18n';
|
|
|
|
class ToggleButton extends React.Component {
|
|
|
|
static propTypes = {
|
|
value: React.PropTypes.bool,
|
|
onChange: React.PropTypes.func
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<div className={this.getClass()} onClick={this.onClick.bind(this)}>
|
|
{this.props.value ? i18n('ON') : i18n('OFF')}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
getClass() {
|
|
let classes = {
|
|
'toggle-button': true,
|
|
'toggle-button_disabled': (this.props.disabled),
|
|
[this.props.className]: (this.props.className)
|
|
};
|
|
|
|
return classNames(classes);
|
|
}
|
|
|
|
|
|
onClick() {
|
|
if (this.props.onChange && !this.props.disabled) {
|
|
this.props.onChange({
|
|
target: {
|
|
value: !this.props.value
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
export default ToggleButton; |