index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import Icon from '../Icon';
  4. import Pagination from '../Pagination';
  5. import SelectBox from '../SelectBox';
  6. import Divider from '../Divider';
  7. import { scaleCheck } from '../../helpers/utility';
  8. import { Container, ToggleButton } from './styled';
  9. import dataset from './data';
  10. type Props = {
  11. totalPage: number;
  12. currentPage: number;
  13. setCurrentPage: (num: number) => void;
  14. changeScale: (num: number | string) => void;
  15. handleClockwiseRotation: () => void;
  16. handleCounterclockwiseRotation: () => void;
  17. handleZoomIn: () => void;
  18. handleZoomOut: () => void;
  19. scale: number;
  20. viewport: ViewportType;
  21. displayMode: string;
  22. toggleDisplayMode: (state: string) => void;
  23. handleHandClick: () => void;
  24. hidden: boolean;
  25. };
  26. const Toolbar: React.FC<Props> = ({
  27. totalPage,
  28. currentPage,
  29. setCurrentPage,
  30. changeScale,
  31. handleClockwiseRotation,
  32. handleCounterclockwiseRotation,
  33. handleZoomIn,
  34. handleZoomOut,
  35. scale,
  36. viewport,
  37. displayMode,
  38. toggleDisplayMode,
  39. handleHandClick,
  40. hidden,
  41. }: Props) => {
  42. const { t } = useTranslation('toolbar');
  43. const data = dataset(t);
  44. const handleScaleSelect = async (
  45. selected: SelectOptionType
  46. ): Promise<any> => {
  47. if (selected.child === 'fit') {
  48. const screenWidth = window.document.body.offsetWidth - 288;
  49. const originPdfWidth = viewport.width / scale;
  50. const rate = screenWidth / originPdfWidth;
  51. changeScale(rate);
  52. } else {
  53. changeScale(scaleCheck(selected.child as number));
  54. }
  55. };
  56. return (
  57. <>
  58. <Container hidden={hidden} displayMode={displayMode}>
  59. <Pagination
  60. totalPage={totalPage}
  61. currentPage={currentPage}
  62. onChange={setCurrentPage}
  63. />
  64. <Divider />
  65. <Icon
  66. glyph="hand"
  67. style={{ width: '30px' }}
  68. onClick={handleHandClick}
  69. />
  70. <Icon
  71. glyph="zoom-in"
  72. style={{ width: '30px' }}
  73. onClick={handleZoomIn}
  74. />
  75. <Icon
  76. glyph="zoom-out"
  77. style={{ width: '30px' }}
  78. onClick={handleZoomOut}
  79. />
  80. <SelectBox
  81. options={data.scaleOptions}
  82. style={{ width: '94px' }}
  83. useInput
  84. isDivide
  85. onChange={handleScaleSelect}
  86. defaultValue={`${Math.round(scale * 100)} %`}
  87. />
  88. <Divider />
  89. <Icon
  90. glyph="rotate-left"
  91. style={{ width: '30px' }}
  92. onClick={handleCounterclockwiseRotation}
  93. />
  94. <Icon
  95. glyph="rotate-right"
  96. style={{ width: '30px' }}
  97. onClick={handleClockwiseRotation}
  98. />
  99. </Container>
  100. <ToggleButton>
  101. {displayMode === 'normal' ? (
  102. <Icon
  103. glyph="tool-close"
  104. onClick={(): void => {
  105. toggleDisplayMode('full');
  106. }}
  107. />
  108. ) : (
  109. <Icon
  110. glyph="tool-open"
  111. onClick={(): void => {
  112. toggleDisplayMode('normal');
  113. }}
  114. />
  115. )}
  116. </ToggleButton>
  117. </>
  118. );
  119. };
  120. export default Toolbar;