index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 onClick={onClick}>
  45. <Icon glyph="left-back" />
  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. throughPortal
  84. />
  85. </>
  86. ) : null}
  87. <Box mt="20">
  88. <SliderWithTitle
  89. title={t('opacity')}
  90. value={opacity * 100}
  91. tips={`${(opacity * 100).toFixed(0)}%`}
  92. onSlide={(val: number): void => {
  93. setDataState({ opacity: val * 0.01 });
  94. }}
  95. />
  96. </Box>
  97. <Box mt="20">
  98. <SliderWithTitle
  99. title={t('rotate')}
  100. value={rotation}
  101. maximum={360}
  102. tips={`${rotation}°`}
  103. onSlide={(val: number): void => {
  104. setDataState({ rotation: val });
  105. }}
  106. />
  107. </Box>
  108. <Box mt="20">
  109. <SliderWithTitle
  110. title={t('scale')}
  111. value={scale * 100}
  112. tips={`${Math.round(scale * 100)}%`}
  113. minimum={50}
  114. maximum={250}
  115. onSlide={(val: number): void => {
  116. setDataState({ scale: val / 100 });
  117. }}
  118. />
  119. </Box>
  120. <Divider orientation="horizontal" style={{ margin: '20px 0' }} />
  121. </Body>
  122. <Footer>
  123. <Button appearance="primary" onClick={onSave}>
  124. {t('save')}
  125. </Button>
  126. <Button appearance="danger-link" onClick={onDelete}>
  127. {t('removeWatermark')}
  128. </Button>
  129. </Footer>
  130. </Container>
  131. );
  132. };
  133. export default WatermarkOption;