index.tsx 3.2 KB

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