ThreeStrandedButton.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { UncontrolledTooltip } from 'reactstrap';
  5. const ThreeStrandedButton = (props) => {
  6. const { t, isBtnDisabled, editorMode } = props;
  7. function threeStrandedButtonClickedHandler(viewType) {
  8. if (isBtnDisabled) {
  9. return;
  10. }
  11. if (props.onThreeStrandedButtonClicked != null) {
  12. props.onThreeStrandedButtonClicked(viewType);
  13. }
  14. }
  15. return (
  16. <>
  17. <div
  18. className="btn-group grw-three-stranded-button"
  19. role="group"
  20. aria-label="three-stranded-button"
  21. id="grw-three-stranded-button"
  22. >
  23. <button
  24. type="button"
  25. className={`btn btn-outline-primary view-button ${editorMode === 'view' && 'active'} ${isBtnDisabled && 'disabled'}`}
  26. onClick={() => { threeStrandedButtonClickedHandler('view') }}
  27. >
  28. <i className="icon-control-play icon-fw grw-three-stranded-button-icon" />
  29. { t('view') }
  30. </button>
  31. <button
  32. type="button"
  33. className={`btn btn-outline-primary edit-button ${editorMode === 'edit' && 'active'} ${isBtnDisabled && 'disabled'}`}
  34. onClick={() => { threeStrandedButtonClickedHandler('edit') }}
  35. >
  36. <i className="icon-note icon-fw grw-three-stranded-button-icon" />
  37. { t('Edit') }
  38. </button>
  39. <button
  40. type="button"
  41. className={`btn btn-outline-primary hackmd-button ${editorMode === 'hackmd' && 'active'} ${isBtnDisabled && 'disabled'}`}
  42. onClick={() => { threeStrandedButtonClickedHandler('hackmd') }}
  43. >
  44. <i className="fa fa-fw fa-file-text-o grw-three-stranded-button-icon" />
  45. { t('hackmd.hack_md') }
  46. </button>
  47. </div>
  48. {isBtnDisabled && (
  49. <UncontrolledTooltip placement="top" target="grw-three-stranded-button" fade={false}>
  50. {t('Not available for guest')}
  51. </UncontrolledTooltip>
  52. )}
  53. </>
  54. );
  55. };
  56. ThreeStrandedButton.propTypes = {
  57. t: PropTypes.func.isRequired, // i18next
  58. onThreeStrandedButtonClicked: PropTypes.func,
  59. isBtnDisabled: PropTypes.bool,
  60. editorMode: PropTypes.string,
  61. };
  62. ThreeStrandedButton.defaultProps = {
  63. isBtnDisabled: false,
  64. };
  65. // export const Huga = withTranslation()(ThreeStrandedButton);
  66. export const TwoStrandedButton = withTranslation()((props) => {
  67. // const TwoStrandedButton = (props) => {
  68. const { t, isBtnDisabled, editorMode } = props;
  69. function threeStrandedButtonClickedHandler(viewType) {
  70. if (isBtnDisabled) {
  71. return;
  72. }
  73. if (props.onThreeStrandedButtonClicked != null) {
  74. props.onThreeStrandedButtonClicked(viewType);
  75. }
  76. }
  77. return (
  78. <>
  79. <div
  80. className="btn-group grw-three-stranded-button"
  81. role="group"
  82. aria-label="three-stranded-button"
  83. id="grw-three-stranded-button"
  84. >
  85. <button
  86. type="button"
  87. className={`btn btn-outline-primary view-button ${editorMode === 'view' && 'active'} ${isBtnDisabled && 'disabled'}`}
  88. onClick={() => { threeStrandedButtonClickedHandler('view') }}
  89. >
  90. <i className="icon-control-play icon-fw grw-three-stranded-button-icon" />
  91. { t('view') }
  92. </button>
  93. <button
  94. type="button"
  95. className={`btn btn-outline-primary edit-button ${editorMode === 'edit' && 'active'} ${isBtnDisabled && 'disabled'}`}
  96. onClick={() => { threeStrandedButtonClickedHandler('edit') }}
  97. >
  98. <i className="icon-note icon-fw grw-three-stranded-button-icon" />
  99. { t('Edit') }
  100. </button>
  101. <button
  102. type="button"
  103. className={`btn btn-outline-primary hackmd-button ${editorMode === 'hackmd' && 'active'} ${isBtnDisabled && 'disabled'}`}
  104. onClick={() => { threeStrandedButtonClickedHandler('hackmd') }}
  105. >
  106. <i className="fa fa-fw fa-file-text-o grw-three-stranded-button-icon" />
  107. { t('hackmd.hack_md') }
  108. </button>
  109. </div>
  110. {isBtnDisabled && (
  111. <UncontrolledTooltip placement="top" target="grw-three-stranded-button" fade={false}>
  112. {t('Not available for guest')}
  113. </UncontrolledTooltip>
  114. )}
  115. </>
  116. );
  117. });
  118. TwoStrandedButton.propTypes = {
  119. t: PropTypes.func.isRequired, // i18next
  120. onThreeStrandedButtonClicked: PropTypes.func,
  121. isBtnDisabled: PropTypes.bool,
  122. editorMode: PropTypes.string,
  123. };
  124. TwoStrandedButton.defaultProps = {
  125. isBtnDisabled: false,
  126. };
  127. export const Hoge = withTranslation()(ThreeStrandedButton);
  128. // export default withTranslation()(ThreeStrandedButton);