ColorSelector.tsx 969 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React, { useState, useEffect } from 'react';
  2. import ColorSelectorComp from '../components/ColorSelector';
  3. import useStore from '../store';
  4. type Props = {
  5. title?: string;
  6. selectedColor?: string;
  7. onClick: (color: string) => void;
  8. mode?: 'normal' | 'shape' | 'freehand' | 'watermark';
  9. throughPortal?: boolean;
  10. };
  11. const ColorSelector: React.FC<Props> = ({
  12. title,
  13. onClick,
  14. selectedColor,
  15. mode,
  16. throughPortal = false,
  17. }: Props) => {
  18. const [isCollapse, setCollapse] = useState(true);
  19. const [{ sidebarState }] = useStore();
  20. const pickerToggle = (): void => {
  21. setCollapse(!isCollapse);
  22. };
  23. useEffect(() => {
  24. setCollapse(true);
  25. }, [sidebarState]);
  26. return (
  27. <ColorSelectorComp
  28. title={title}
  29. onClick={onClick}
  30. selectedColor={selectedColor}
  31. mode={mode}
  32. pickerToggle={pickerToggle}
  33. isCollapse={isCollapse}
  34. throughPortal={throughPortal}
  35. />
  36. );
  37. };
  38. export default ColorSelector;