index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from 'react';
  2. import { useTranslation } from '../../i18n';
  3. import { WatermarkType, SelectOptionType } from '../../constants/type';
  4. import Button from '../Button';
  5. import Box from '../Box';
  6. import Icon from '../Icon';
  7. import Typography from '../Typography';
  8. import Tabs from '../Tabs';
  9. import Divider from '../Divider';
  10. import ColorSelect from '../ColorSelector';
  11. import SliderWithTitle from '../SliderWithTitle';
  12. import TextBox from '../WatermarkTextBox';
  13. import {
  14. Container, Head, Body, Footer, IconWrapper,
  15. } from '../../global/sidebarStyled';
  16. type Props = WatermarkType & {
  17. onClick: () => void;
  18. isActive: boolean;
  19. onSave: () => void;
  20. onDelete: () => void;
  21. setDataState: (arg: Record<string, any>) => void;
  22. };
  23. const WatermarkOption: React.SFC<Props> = ({
  24. onClick,
  25. type,
  26. opacity = 0,
  27. scale = 1,
  28. rotation,
  29. textcolor,
  30. text,
  31. onSave,
  32. onDelete,
  33. setDataState = (): void => {
  34. // do nothing
  35. },
  36. }: Props) => {
  37. const { t } = useTranslation('sidebar');
  38. return (
  39. <Container>
  40. <Head>
  41. <IconWrapper>
  42. <Icon glyph="left-back" onClick={onClick} />
  43. </IconWrapper>
  44. <Typography light>
  45. {t('watermark')}
  46. </Typography>
  47. </Head>
  48. <Body>
  49. <Typography variant="subtitle" align="left">
  50. {t('type')}
  51. </Typography>
  52. <Tabs
  53. options={[
  54. {
  55. key: 'text',
  56. content: t('text'),
  57. child: (
  58. <TextBox
  59. t={t}
  60. value={text}
  61. onChange={(value: string): void => { setDataState({ text: value }); }}
  62. />
  63. ),
  64. },
  65. ]}
  66. onChange={(option: SelectOptionType): void => { setDataState({ type: option.key }); }}
  67. />
  68. {
  69. type === 'text' ? (
  70. <>
  71. <Divider orientation="horizontal" style={{ margin: '20px 0' }} />
  72. <ColorSelect
  73. title={t('color')}
  74. mode="watermark"
  75. selectedColor={textcolor}
  76. onClick={(val: string): void => { setDataState({ textcolor: val }); }}
  77. />
  78. </>
  79. ) : null
  80. }
  81. <Box mt="20">
  82. <SliderWithTitle
  83. title={t('opacity')}
  84. value={opacity * 100}
  85. tips={`${(opacity * 100).toFixed(0)}%`}
  86. onSlide={(val: number): void => { setDataState({ opacity: val * 0.01 }); }}
  87. />
  88. </Box>
  89. <Box mt="20">
  90. <SliderWithTitle
  91. title={t('rotate')}
  92. value={rotation}
  93. maximum={360}
  94. tips={`${rotation}°`}
  95. onSlide={(val: number): void => { setDataState({ rotation: val }); }}
  96. />
  97. </Box>
  98. <Box mt="20">
  99. <SliderWithTitle
  100. title={t('scale')}
  101. value={scale * 100}
  102. tips={`${Math.round(scale * 100)}%`}
  103. minimum={50}
  104. maximum={250}
  105. onSlide={(val: number): void => { setDataState({ scale: val / 100 }); }}
  106. />
  107. </Box>
  108. <Divider orientation="horizontal" style={{ margin: '20px 0' }} />
  109. </Body>
  110. <Footer>
  111. <Button appearance="primary" onClick={onSave}>
  112. {t('save')}
  113. </Button>
  114. <Button appearance="danger-link" onClick={onDelete}>
  115. {t('removeWatermark')}
  116. </Button>
  117. </Footer>
  118. </Container>
  119. );
  120. };
  121. export default WatermarkOption;