index.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import Icon from '../Icon';
  4. import Typography from '../Typography';
  5. import SliderWithTitle from '../SliderWithTitle';
  6. import SelectBox from '../SelectBox';
  7. import ColorSelector from '../../containers/ColorSelector';
  8. import { OptionPropsType, SelectOptionType } from '../../constants/type';
  9. import { Wrapper, Group, Item } from '../../global/toolStyled';
  10. import { fontOptions, sizeOptions, alignOptions, styleOptions } from './data';
  11. const TextOption: React.SFC<OptionPropsType> = ({
  12. fontName,
  13. fontSize,
  14. align,
  15. fontStyle,
  16. color,
  17. opacity,
  18. setDataState = (): void => {
  19. // do nothing
  20. },
  21. }: OptionPropsType) => {
  22. const { t } = useTranslation('sidebar');
  23. return (
  24. <>
  25. <Wrapper>
  26. <Typography
  27. variant="subtitle"
  28. style={{ marginTop: '8px' }}
  29. align="left"
  30. >
  31. {t('font')}
  32. </Typography>
  33. <Group>
  34. <SelectBox
  35. style={{ width: '100px' }}
  36. defaultValue={fontName}
  37. options={fontOptions}
  38. onChange={(option: SelectOptionType): void => {
  39. setDataState({ fontName: option.child });
  40. }}
  41. />
  42. {styleOptions.map(ele => (
  43. <Item
  44. key={ele.key}
  45. size="small"
  46. selected={fontStyle === ele.child}
  47. onClick={(): void => {
  48. setDataState({
  49. fontStyle: ele.child === fontStyle ? '' : ele.child,
  50. });
  51. }}
  52. >
  53. <Icon glyph={ele.key} />
  54. </Item>
  55. ))}
  56. </Group>
  57. </Wrapper>
  58. <Wrapper width="40%">
  59. <Typography
  60. variant="subtitle"
  61. style={{ marginTop: '8px' }}
  62. align="left"
  63. >
  64. {t('size')}
  65. </Typography>
  66. <Group>
  67. <SelectBox
  68. defaultValue={fontSize}
  69. options={sizeOptions}
  70. onChange={(option: SelectOptionType): void => {
  71. setDataState({ fontSize: option.child });
  72. }}
  73. />
  74. </Group>
  75. </Wrapper>
  76. <Wrapper width="60%">
  77. <Typography
  78. variant="subtitle"
  79. style={{ marginTop: '8px' }}
  80. align="left"
  81. >
  82. {t('align')}
  83. </Typography>
  84. <Group>
  85. {alignOptions.map(ele => (
  86. <Item
  87. key={ele.key}
  88. size="small"
  89. selected={align === ele.child}
  90. onClick={(): void => {
  91. setDataState({ align: ele.child });
  92. }}
  93. >
  94. <Icon glyph={ele.key} />
  95. </Item>
  96. ))}
  97. </Group>
  98. </Wrapper>
  99. <Wrapper>
  100. <ColorSelector
  101. title={t('color')}
  102. selectedColor={color}
  103. onClick={(selected: string): void => {
  104. setDataState({ color: selected });
  105. }}
  106. />
  107. </Wrapper>
  108. <Wrapper>
  109. <SliderWithTitle
  110. title={t('opacity')}
  111. value={opacity}
  112. tips={`${opacity}%`}
  113. onSlide={(val: number): void => {
  114. setDataState({ opacity: val });
  115. }}
  116. />
  117. </Wrapper>
  118. </>
  119. );
  120. };
  121. export default TextOption;