MarkupTools.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React, { useEffect } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import Button from '../components/Button';
  4. import ExpansionPanel from '../components/ExpansionPanel';
  5. import Icon from '../components/Icon';
  6. import HighlightTools from './HighlightTools';
  7. import FreehandTools from './FreehandTools';
  8. import TextTools from './FreeTextTools';
  9. import StickyNoteTools from './StickyNoteTools';
  10. import ShapeTools from './ShapeTools';
  11. import useActions from '../actions';
  12. import useStore from '../store';
  13. const MarkupTools: React.FC = () => {
  14. const { t } = useTranslation('sidebar');
  15. const [{ sidebarState, markupToolState }, dispatch] = useStore();
  16. const { setSidebar, setMarkupTool } = useActions(dispatch);
  17. const onClickSidebar = (state: string): void => {
  18. if (state === sidebarState) {
  19. setSidebar('');
  20. } else {
  21. setSidebar(state);
  22. }
  23. };
  24. const onClickTool = (state: string): void => {
  25. if (state === markupToolState) {
  26. setMarkupTool('');
  27. } else {
  28. setMarkupTool(state);
  29. }
  30. };
  31. useEffect(() => {
  32. if (sidebarState !== 'markup-tools') {
  33. setMarkupTool('');
  34. }
  35. }, []);
  36. const Label = (
  37. <Button
  38. shouldFitContainer
  39. align="left"
  40. onClick={(): void => {
  41. onClickSidebar('markup-tools');
  42. }}
  43. >
  44. <Icon glyph="markup-tools" style={{ marginRight: '10px' }} />
  45. {t('markupTool')}
  46. </Button>
  47. );
  48. return (
  49. <ExpansionPanel label={Label} isActive={sidebarState === 'markup-tools'}>
  50. <HighlightTools
  51. title={t('annotate')}
  52. isActive={markupToolState === 'highlight'}
  53. onClick={(): void => {
  54. onClickTool('highlight');
  55. }}
  56. />
  57. <FreehandTools
  58. title={t('freehand')}
  59. isActive={markupToolState === 'freehand'}
  60. onClick={(): void => {
  61. onClickTool('freehand');
  62. }}
  63. />
  64. <TextTools
  65. title={t('textBox')}
  66. isActive={markupToolState === 'text'}
  67. onClick={(): void => {
  68. onClickTool('text');
  69. }}
  70. />
  71. <StickyNoteTools
  72. title={t('stickyNote')}
  73. isActive={markupToolState === 'sticky'}
  74. onClick={(): void => {
  75. onClickTool('sticky');
  76. }}
  77. />
  78. <ShapeTools
  79. title={t('shape')}
  80. isActive={markupToolState === 'shape'}
  81. onClick={(): void => {
  82. onClickTool('shape');
  83. }}
  84. />
  85. </ExpansionPanel>
  86. );
  87. };
  88. export default MarkupTools;