ColorPicker.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from "react";
  2. import { TwitterPicker } from "react-color";
  3. import { Popover } from "./Popover";
  4. export function ColorPicker({
  5. color,
  6. onChange
  7. }: {
  8. color: string | null;
  9. onChange: (color: string) => void;
  10. }) {
  11. const [isActive, setActive] = React.useState(false);
  12. return (
  13. <div>
  14. <button
  15. className="swatch"
  16. style={color ? { backgroundColor: color } : undefined}
  17. onClick={() => setActive(!isActive)}
  18. />
  19. {isActive ? (
  20. <Popover onCloseRequest={() => setActive(false)}>
  21. <TwitterPicker
  22. colors={[
  23. "#000000",
  24. "#ABB8C3",
  25. "#FFFFFF",
  26. "#FF6900",
  27. "#FCB900",
  28. "#00D084",
  29. "#8ED1FC",
  30. "#0693E3",
  31. "#EB144C",
  32. "#F78DA7",
  33. "#9900EF"
  34. ]}
  35. width="205px"
  36. color={color || undefined}
  37. onChange={changedColor => {
  38. onChange(changedColor.hex);
  39. }}
  40. />
  41. </Popover>
  42. ) : null}
  43. <input
  44. type="text"
  45. className="swatch-input"
  46. value={color || ""}
  47. onPaste={e => onChange(e.clipboardData.getData("text"))}
  48. onChange={e => onChange(e.target.value)}
  49. />
  50. </div>
  51. );
  52. }