ColorPicker.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from "react";
  2. import { TwitterPicker } from "react-color";
  3. export function ColorPicker({
  4. color,
  5. onChange
  6. }: {
  7. color: string | null;
  8. onChange: (color: string) => void;
  9. }) {
  10. const [isActive, setActive] = React.useState(false);
  11. return (
  12. <div>
  13. <button
  14. className="swatch"
  15. style={color ? { backgroundColor: color } : undefined}
  16. onClick={() => setActive(!isActive)}
  17. />
  18. {isActive ? (
  19. <div className="popover">
  20. <div className="cover" onClick={() => 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. </div>
  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. }