MarkupTools.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React 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 FreehandTool from './FreehandTool';
  8. import TextTool from './FreeTextTool';
  9. import StickyNoteTool from './StickyNoteTool';
  10. import ShapeTool from './ShapeTool';
  11. import useActions from '../actions';
  12. import useStore from '../store';
  13. type Props = {
  14. sidebarState: string;
  15. onClickSidebar: (state: string) => void;
  16. };
  17. const MarkupTools: React.FC<Props> = ({
  18. sidebarState,
  19. onClickSidebar,
  20. }: Props) => {
  21. const { t } = useTranslation('sidebar');
  22. const [{ toolState }, dispatch] = useStore();
  23. const { setTool } = useActions(dispatch);
  24. const onClickTool = (state: string): void => {
  25. if (state === toolState) {
  26. setTool('');
  27. } else {
  28. setTool(state);
  29. }
  30. };
  31. const isActive = sidebarState === 'markup-tools';
  32. const Label = (
  33. <Button
  34. shouldFitContainer
  35. align="left"
  36. onClick={(): void => {
  37. onClickSidebar('markup-tools');
  38. }}
  39. >
  40. <Icon glyph="markup-tools" style={{ marginRight: '10px' }} />
  41. {t('markupTool')}
  42. <Icon
  43. glyph="dropdown-arrow"
  44. style={{
  45. transform: isActive ? 'rotate(180deg)' : 'rotate(0deg)',
  46. marginLeft: '10px',
  47. }}
  48. />
  49. </Button>
  50. );
  51. return (
  52. <ExpansionPanel label={Label} isActive={isActive}>
  53. <HighlightTools
  54. title={t('annotate')}
  55. isActive={toolState === 'highlight'}
  56. onClick={(): void => {
  57. onClickTool('highlight');
  58. }}
  59. />
  60. <FreehandTool
  61. title={t('freehand')}
  62. isActive={toolState === 'freehand'}
  63. onClick={(): void => {
  64. onClickTool('freehand');
  65. }}
  66. />
  67. <TextTool
  68. title={t('textBox')}
  69. isActive={toolState === 'text'}
  70. onClick={(): void => {
  71. onClickTool('text');
  72. }}
  73. />
  74. <StickyNoteTool
  75. title={t('stickyNote')}
  76. isActive={toolState === 'sticky'}
  77. onClick={(): void => {
  78. onClickTool('sticky');
  79. }}
  80. />
  81. <ShapeTool
  82. title={t('shape')}
  83. isActive={toolState === 'shape'}
  84. onClick={(): void => {
  85. onClickTool('shape');
  86. }}
  87. />
  88. </ExpansionPanel>
  89. );
  90. };
  91. export default MarkupTools;