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.

34 lines
1.1 KiB

  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. settingPath: PropTypes.array.isRequired,
  10. label: PropTypes.node.isRequired,
  11. onChange: PropTypes.func.isRequired,
  12. defaultValue: PropTypes.bool,
  13. disabled: PropTypes.bool,
  14. }
  15. onChange = ({ target }) => {
  16. this.props.onChange(this.props.settingPath, target.checked);
  17. }
  18. render () {
  19. const { prefix, settings, settingPath, label, defaultValue, disabled } = this.props;
  20. const id = ['setting-toggle', prefix, ...settingPath].filter(Boolean).join('-');
  21. return (
  22. <div className='setting-toggle'>
  23. <Toggle disabled={disabled} id={id} checked={settings.getIn(settingPath, defaultValue)} onChange={this.onChange} onKeyDown={this.onKeyDown} />
  24. <label htmlFor={id} className='setting-toggle__label'>{label}</label>
  25. </div>
  26. );
  27. }
  28. }