MarkupTools.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. return (
  37. <ExpansionPanel
  38. label={(
  39. <Button
  40. shouldFitContainer
  41. align="left"
  42. onClick={(): void => { onClickSidebar('markup-tools'); }}
  43. >
  44. <Icon glyph="markup-tools" style={{ marginRight: '10px' }} />
  45. {t('markupTool')}
  46. </Button>
  47. )}
  48. isActive={sidebarState === 'markup-tools'}
  49. >
  50. <HighlightTools
  51. title={t('annotate')}
  52. isActive={markupToolState === 'highlight'}
  53. onClick={(): void => { onClickTool('highlight'); }}
  54. />
  55. <FreehandTools
  56. title={t('freehand')}
  57. isActive={markupToolState === 'freehand'}
  58. onClick={(): void => { onClickTool('freehand'); }}
  59. />
  60. <TextTools
  61. title={t('textBox')}
  62. isActive={markupToolState === 'text'}
  63. onClick={(): void => { onClickTool('text'); }}
  64. />
  65. <StickyNoteTools
  66. title={t('stickyNote')}
  67. isActive={markupToolState === 'sticky'}
  68. onClick={(): void => { onClickTool('sticky'); }}
  69. />
  70. <ShapeTools
  71. title={t('shape')}
  72. isActive={markupToolState === 'shape'}
  73. onClick={(): void => { onClickTool('shape'); }}
  74. />
  75. </ExpansionPanel>
  76. );
  77. };
  78. export default MarkupTools;