闭社主体 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.

32 lines
964 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. export default class SettingToggle extends React.PureComponent {
  6. static propTypes = {
  7. prefix: PropTypes.string,
  8. settings: ImmutablePropTypes.map.isRequired,
  9. settingKey: PropTypes.array.isRequired,
  10. label: PropTypes.node.isRequired,
  11. onChange: PropTypes.func.isRequired,
  12. }
  13. onChange = ({ target }) => {
  14. this.props.onChange(this.props.settingKey, target.checked);
  15. }
  16. render () {
  17. const { prefix, settings, settingKey, label } = this.props;
  18. const id = ['setting-toggle', prefix, ...settingKey].filter(Boolean).join('-');
  19. return (
  20. <div className='setting-toggle'>
  21. <Toggle id={id} checked={settings.getIn(settingKey)} onChange={this.onChange} />
  22. <label htmlFor={id} className='setting-toggle__label'>{label}</label>
  23. </div>
  24. );
  25. }
  26. }