index.tsx 3.5 KB

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