index.tsx 3.2 KB

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