闭社主体 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
905 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. htmlFor: PropTypes.string,
  12. }
  13. onChange = (e) => {
  14. this.props.onChange(this.props.settingKey, e.target.checked);
  15. }
  16. render () {
  17. const { settings, settingKey, label, onChange, htmlFor = '' } = this.props;
  18. return (
  19. <label htmlFor={htmlFor} className='setting-toggle__label'>
  20. <Toggle checked={settings.getIn(settingKey)} onChange={this.onChange} />
  21. <span className='setting-toggle'>{label}</span>
  22. </label>
  23. );
  24. }
  25. }
  26. export default SettingToggle;