index.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import React, { useState } from 'react';
  2. import Button from '../Button';
  3. import Icon from '../Icon';
  4. import Divider from '../Divider';
  5. import Box from '../Box';
  6. import Sliders from '../Sliders';
  7. import ColorSelector from '../../containers/ColorSelector';
  8. import { Container, Subtitle, SliderWrapper } from './styled';
  9. type Props = {
  10. onUpdate: OnUpdateType;
  11. onDelete: () => void;
  12. colorProps?: string;
  13. opacityProps?: number;
  14. };
  15. const AnnotationOptions: React.FC<Props> = ({
  16. onUpdate,
  17. onDelete,
  18. colorProps,
  19. opacityProps,
  20. }: Props) => {
  21. const [openSlider, setSlider] = useState(false);
  22. const [opacity, setOpacity] = useState(opacityProps);
  23. const handleClick = (color: string): void => {
  24. onUpdate({ bdcolor: color });
  25. };
  26. const handleChange = (value: number): void => {
  27. setOpacity(value);
  28. onUpdate({ transparency: value * 0.01 });
  29. };
  30. const sliderToggle = (e: React.MouseEvent<HTMLElement>): void => {
  31. e.preventDefault();
  32. setSlider(!openSlider);
  33. };
  34. return (
  35. <Container>
  36. {openSlider && (
  37. <>
  38. <Box w="40px" h="36px" d="flex" j="center">
  39. <Icon glyph="right-arrow" onClick={sliderToggle} />
  40. </Box>
  41. <Divider style={{ margin: '0 10px 0 10px' }} />
  42. <SliderWrapper>
  43. <Sliders value={opacity} onChange={handleChange} />
  44. </SliderWrapper>
  45. <Subtitle>{`${opacity} %`}</Subtitle>
  46. </>
  47. )}
  48. {!openSlider && (
  49. <>
  50. <ColorSelector selectedColor={colorProps} onClick={handleClick} />
  51. <Subtitle>opacity</Subtitle>
  52. <Button
  53. appearance="dark"
  54. style={{ height: '34px', width: '80px', fontSize: '12px' }}
  55. onClick={sliderToggle}
  56. >
  57. {`${opacity} %`}
  58. </Button>
  59. <Divider style={{ height: '44px', margin: '0 6px 0 15px' }} />
  60. <Box w="48px" h="36px" d="flex" j="center">
  61. <Icon glyph="trash" onClick={onDelete} />
  62. </Box>
  63. </>
  64. )}
  65. </Container>
  66. );
  67. };
  68. export default AnnotationOptions;