index.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react';
  2. import { WithTranslation } from 'next-i18next';
  3. import { withTranslation } from '../../i18n';
  4. import { OptionPropsType } from '../../constants/type';
  5. import Typography from '../Typography';
  6. import SelectBox from '../SelectBox';
  7. import SliderWithTitle from '../SliderWithTitle';
  8. import ColorSelector from '../ColorSelector';
  9. import {
  10. Wrapper,
  11. } from '../../global/toolStyled';
  12. import {
  13. shapeOptions, typeOptions,
  14. } from './data';
  15. type i18nProps = {
  16. t: (key: string) => string;
  17. }
  18. type Props = i18nProps & OptionPropsType;
  19. const ShapeOption: React.SFC<Props> = ({
  20. t,
  21. shape,
  22. color,
  23. opacity,
  24. width,
  25. setDataState = (): void => {
  26. // do nothing
  27. },
  28. }: Props) => (
  29. <>
  30. <Wrapper>
  31. <Typography
  32. variant="subtitle"
  33. style={{ marginTop: '8px' }}
  34. align="left"
  35. >
  36. {t('style')}
  37. </Typography>
  38. <SelectBox
  39. options={shapeOptions}
  40. style={{ marginRight: '10px' }}
  41. onChange={(item: Record<string, any>): void => { setDataState({ shape: item.key }); }}
  42. />
  43. {
  44. shape !== 'line' && shape !== 'arrow' && (
  45. <SelectBox
  46. options={typeOptions}
  47. onChange={(item: Record<string, any>): void => { setDataState({ type: item.key }); }}
  48. />
  49. )
  50. }
  51. </Wrapper>
  52. <Wrapper>
  53. <ColorSelector
  54. title={t('color')}
  55. mode="shape"
  56. selectedColor={color}
  57. onClick={(selected: string): void => { setDataState({ color: selected }); }}
  58. />
  59. </Wrapper>
  60. <Wrapper>
  61. <SliderWithTitle
  62. title={t('opacity')}
  63. value={opacity}
  64. tips={`${opacity}%`}
  65. onSlide={(val: number): void => { setDataState({ opacity: val }); }}
  66. />
  67. </Wrapper>
  68. <Wrapper>
  69. <SliderWithTitle
  70. title={t('width')}
  71. value={width}
  72. tips={`${width}pt`}
  73. onSlide={(val: number): void => { setDataState({ width: val }); }}
  74. maximum={40}
  75. />
  76. </Wrapper>
  77. </>
  78. );
  79. const translator = withTranslation('sidebar');
  80. type TransProps = WithTranslation & OptionPropsType;
  81. export default translator<TransProps>(ShapeOption);