index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 } 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. handleMouseOver: () => void;
  20. scale: number;
  21. viewport: ViewportType;
  22. displayMode: string;
  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. handleMouseOver,
  36. scale,
  37. viewport,
  38. displayMode,
  39. handleHandClick,
  40. hidden,
  41. }: Props) => {
  42. const { t } = useTranslation('toolbar');
  43. const data = dataset(t);
  44. const handleScaleSelect = (selected: SelectOptionType) => {
  45. if (selected.child === 'fit') {
  46. const screenWidth = window.document.body.offsetWidth - 288;
  47. const originPdfWidth = viewport.width / scale;
  48. const rate = screenWidth / originPdfWidth;
  49. changeScale(rate);
  50. } else {
  51. changeScale(scaleCheck(selected.child as number));
  52. }
  53. };
  54. return (
  55. <Container
  56. onMouseOver={handleMouseOver}
  57. hidden={hidden}
  58. displayMode={displayMode}
  59. >
  60. <Pagination
  61. totalPage={totalPage}
  62. currentPage={currentPage}
  63. onChange={setCurrentPage}
  64. />
  65. <Divider />
  66. <Icon glyph="hand" style={{ width: '30px' }} onClick={handleHandClick} />
  67. <Icon glyph="zoom-in" style={{ width: '30px' }} onClick={handleZoomIn} />
  68. <Icon
  69. glyph="zoom-out"
  70. style={{ width: '30px' }}
  71. onClick={handleZoomOut}
  72. />
  73. <SelectBox
  74. options={data.scaleOptions}
  75. style={{ width: '94px' }}
  76. useInput
  77. isDivide
  78. onChange={handleScaleSelect}
  79. defaultValue={`${Math.round(scale * 100)} %`}
  80. />
  81. <Divider />
  82. <Icon
  83. glyph="rotate-left"
  84. style={{ width: '30px' }}
  85. onClick={handleCounterclockwiseRotation}
  86. />
  87. <Icon
  88. glyph="rotate-right"
  89. style={{ width: '30px' }}
  90. onClick={handleClockwiseRotation}
  91. />
  92. </Container>
  93. );
  94. };
  95. export default Toolbar;