MarkupTools.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React, { useEffect } from 'react';
  2. import Button from '../components/Button';
  3. import ExpansionPanel from '../components/ExpansionPanel';
  4. import Icon from '../components/Icon';
  5. import HighlightTools from './HighlightTools';
  6. import Freehand from '../components/Freehand';
  7. import TextTools from '../components/TextTools';
  8. import Shape from '../components/Shape';
  9. import useActions from '../actions';
  10. import useStore from '../store';
  11. import { BtnWrapper } from '../global/toolStyled';
  12. const MarkupTools: React.FunctionComponent = () => {
  13. const [{ sidebarState, markupToolState }, dispatch] = useStore();
  14. const { setSidebar, setMarkupTool } = useActions(dispatch);
  15. const onClickSidebar = (state: string): void => {
  16. if (state === sidebarState) {
  17. setSidebar('');
  18. } else {
  19. setSidebar(state);
  20. }
  21. };
  22. const onClickTool = (state: string): void => {
  23. if (state === markupToolState) {
  24. setMarkupTool('');
  25. } else {
  26. setMarkupTool(state);
  27. }
  28. };
  29. useEffect(() => {
  30. if (sidebarState !== 'markup-tools') {
  31. setMarkupTool('');
  32. }
  33. }, []);
  34. return (
  35. <ExpansionPanel
  36. label={(
  37. <Button
  38. shouldFitContainer
  39. align="left"
  40. onClick={(): void => { onClickSidebar('markup-tools'); }}
  41. >
  42. <Icon glyph="markup-tools" style={{ marginRight: '10px' }} />
  43. Markup Tools
  44. </Button>
  45. )}
  46. isActive={sidebarState === 'markup-tools'}
  47. >
  48. <HighlightTools
  49. isActive={markupToolState === 'highlight'}
  50. onClick={(): void => { onClickTool('highlight'); }}
  51. />
  52. <Freehand
  53. isActive={markupToolState === 'freehand'}
  54. onClick={(): void => { onClickTool('freehand'); }}
  55. />
  56. <TextTools
  57. isActive={markupToolState === 'text'}
  58. onClick={(): void => { onClickTool('text'); }}
  59. />
  60. <BtnWrapper>
  61. <Button shouldFitContainer align="left" onClick={(): void => { onClickTool('sticky'); }} isActive={markupToolState === 'sticky'}>
  62. <Icon glyph="sticky-note" style={{ marginRight: '10px' }} />
  63. Sticky Note
  64. </Button>
  65. </BtnWrapper>
  66. <Shape
  67. isActive={markupToolState === 'shape'}
  68. onClick={(): void => { onClickTool('shape'); }}
  69. />
  70. </ExpansionPanel>
  71. );
  72. };
  73. export default MarkupTools;