ThreeStrandedButton.jsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { useState } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. const ThreeStrandedButton = (props) => {
  5. const { t } = props;
  6. const [btnActive, setBtnActive] = useState('view');
  7. function threeStrandedButtonClickedHandler(viewType) {
  8. if (props.onThreeStrandedButtonClicked != null) {
  9. props.onThreeStrandedButtonClicked(viewType);
  10. }
  11. setBtnActive(viewType);
  12. }
  13. return (
  14. <div className="btn-group grw-three-stranded-button" role="group " aria-label="three-stranded-button">
  15. <button
  16. type="button"
  17. className={`btn btn-outline-primary view-button ${btnActive === 'view' && 'active'}`}
  18. onClick={() => { threeStrandedButtonClickedHandler('view') }}
  19. >
  20. <i className="icon-control-play icon-fw" />
  21. { t('view') }
  22. </button>
  23. <button
  24. type="button"
  25. className={`btn btn-outline-primary edit-button ${btnActive === 'edit' && 'active'}`}
  26. onClick={(e) => { threeStrandedButtonClickedHandler('edit') }}
  27. >
  28. <i className="icon-note icon-fw" />
  29. { t('Edit') }
  30. </button>
  31. <button
  32. type="button"
  33. className={`btn btn-outline-primary hackmd-button ${btnActive === 'hackmd' && 'active'}`}
  34. onClick={() => { threeStrandedButtonClickedHandler('hackmd') }}
  35. >
  36. <i className="fa fa-fw fa-file-text-o" />
  37. { t('hackmd.hack_md') }
  38. </button>
  39. </div>
  40. );
  41. };
  42. ThreeStrandedButton.propTypes = {
  43. t: PropTypes.func.isRequired, // i18next
  44. onThreeStrandedButtonClicked: PropTypes.func,
  45. };
  46. export default withTranslation()(ThreeStrandedButton);