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.

103 lines
2.3 KiB

  1. /*
  2. `<ComposeAdvancedOptionsToggle>`
  3. ================================
  4. > For more information on the contents of this file, please contact:
  5. >
  6. > - surinna [@srn@dev.glitch.social]
  7. This creates the toggle used by `<ComposeAdvancedOptions>`.
  8. __Props:__
  9. - __`onChange` (`PropTypes.func`) :__
  10. This provides the function to call when the toggle is
  11. (de-?)activated.
  12. - __`active` (`PropTypes.bool`) :__
  13. This prop controls whether the toggle is currently active or not.
  14. - __`name` (`PropTypes.string`) :__
  15. This identifies the toggle, and is sent to `onChange()` when it is
  16. called.
  17. - __`shortText` (`PropTypes.string`) :__
  18. This is a short string used as the title of the toggle.
  19. - __`longText` (`PropTypes.string`) :__
  20. This is a longer string used as a subtitle for the toggle.
  21. */
  22. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  23. /*
  24. Imports:
  25. --------
  26. */
  27. // Package imports //
  28. import React from 'react';
  29. import PropTypes from 'prop-types';
  30. import Toggle from 'react-toggle';
  31. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  32. /*
  33. Implementation:
  34. ---------------
  35. */
  36. export default class ComposeAdvancedOptionsToggle extends React.PureComponent {
  37. static propTypes = {
  38. onChange: PropTypes.func.isRequired,
  39. active: PropTypes.bool.isRequired,
  40. name: PropTypes.string.isRequired,
  41. shortText: PropTypes.string.isRequired,
  42. longText: PropTypes.string.isRequired,
  43. }
  44. /*
  45. ### `onToggle()`
  46. The `onToggle()` function simply calls the `onChange()` prop with the
  47. toggle's `name`.
  48. */
  49. onToggle = () => {
  50. this.props.onChange(this.props.name);
  51. }
  52. /*
  53. ### `render()`
  54. The `render()` function is used to render our component. We just render
  55. a `<Toggle>` and place next to it our text.
  56. */
  57. render() {
  58. const { active, shortText, longText } = this.props;
  59. return (
  60. <div role='button' tabIndex='0' className='advanced-options-dropdown__option' onClick={this.onToggle}>
  61. <div className='advanced-options-dropdown__option__toggle'>
  62. <Toggle checked={active} onChange={this.onToggle} />
  63. </div>
  64. <div className='advanced-options-dropdown__option__content'>
  65. <strong>{shortText}</strong>
  66. {longText}
  67. </div>
  68. </div>
  69. );
  70. }
  71. }