pleroma/app/soapbox/features/notifications/components/setting_toggle.js

36 lines
887 B
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import PropTypes from 'prop-types';
import React from 'react';
2020-03-27 13:59:38 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
2020-03-27 13:59:38 -07:00
import Toggle from 'react-toggle';
export default class SettingToggle extends ImmutablePureComponent {
2020-03-27 13:59:38 -07:00
static propTypes = {
2022-03-21 11:09:01 -07:00
id: PropTypes.string,
2020-03-27 13:59:38 -07:00
prefix: PropTypes.string,
settings: ImmutablePropTypes.map.isRequired,
settingPath: PropTypes.array.isRequired,
onChange: PropTypes.func.isRequired,
}
onChange = ({ target }) => {
this.props.onChange(this.props.settingPath, target.checked);
}
render() {
2022-03-21 11:09:01 -07:00
const { id, settings, settingPath } = this.props;
2020-03-27 13:59:38 -07:00
return (
2022-03-21 11:09:01 -07:00
<Toggle
id={id}
checked={settings.getIn(settingPath)}
onChange={this.onChange}
icons={false}
onKeyDown={this.onKeyDown}
/>
2020-03-27 13:59:38 -07:00
);
}
}