闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
918 B

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import Toggle from 'react-toggle';
  5. class SettingToggle extends React.PureComponent {
  6. static propTypes = {
  7. settings: ImmutablePropTypes.map.isRequired,
  8. settingKey: PropTypes.array.isRequired,
  9. label: PropTypes.node.isRequired,
  10. onChange: PropTypes.func.isRequired,
  11. }
  12. onChange = (e) => {
  13. this.props.onChange(this.props.settingKey, e.target.checked);
  14. }
  15. render () {
  16. const { settings, settingKey, label, onChange } = this.props;
  17. const id = `setting-toggle-${settingKey.join('-')}`;
  18. return (
  19. <div className='setting-toggle'>
  20. <Toggle id={id} checked={settings.getIn(settingKey)} onChange={this.onChange} />
  21. <label htmlFor={id} className='setting-toggle__label'>{label}</label>
  22. </div>
  23. );
  24. }
  25. }
  26. export default SettingToggle;