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