The main server, and probably only repository in this org.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
836 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import React, {useLayoutEffect, useState} from "react";
  2. import iro from '@jaames/iro';
  3. import {randId} from "../../Helpers/random";
  4. function ColorPicker({color, onChange}) {
  5. const [random] = useState(randId());
  6. useLayoutEffect(() => {
  7. const colorPicker = new iro.ColorPicker("#color-picker-" + random, {
  8. color: `#${color}`,
  9. layout: [
  10. {
  11. component: iro.ui.Wheel,
  12. options: {}
  13. }
  14. ],
  15. });
  16. colorPicker.on("input:end", color => {
  17. onChange(color.hexString.substr(1));
  18. });
  19. return () => {
  20. const elem = document.getElementById(`color-picker-${random}`);
  21. if (elem === null) {
  22. return;
  23. }
  24. elem.innerHTML = "";
  25. };
  26. }, [color]);
  27. return (
  28. <div id={`color-picker-${random}`}>
  29. </div>
  30. );
  31. }
  32. export default ColorPicker;