2019-07-02 08:10:25 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2019-08-09 17:06:27 +01:00
|
|
|
import ToggleSwitch from '../toggle_switch';
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2019-08-07 06:02:36 +01:00
|
|
|
import './setting_toggle.scss';
|
|
|
|
|
2019-07-29 20:20:00 +01:00
|
|
|
export default class SettingToggle extends PureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
prefix: PropTypes.string,
|
|
|
|
settings: ImmutablePropTypes.map.isRequired,
|
|
|
|
settingPath: PropTypes.array.isRequired,
|
|
|
|
label: PropTypes.node.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
onChange = ({ target }) => {
|
|
|
|
this.props.onChange(this.props.settingPath, target.checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { prefix, settings, settingPath, label } = this.props;
|
|
|
|
const id = ['setting-toggle', prefix, ...settingPath].filter(Boolean).join('-');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='setting-toggle'>
|
2019-08-09 17:06:27 +01:00
|
|
|
<ToggleSwitch id={id} checked={settings.getIn(settingPath)} onChange={this.onChange} onKeyDown={this.onKeyDown} />
|
2019-07-02 08:10:25 +01:00
|
|
|
<label htmlFor={id} className='setting-toggle__label'>{label}</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|