logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

setting_toggle.js (1098B)


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