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.

42 lines
940 B

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 {randId} from "../../Helpers/random";
  3. import iro from "@jaames/iro";
  4. function BrightnessSlider({brightness, onChange}) {
  5. const [random] = useState(randId());
  6. useLayoutEffect(() => {
  7. const colorPicker = new iro.ColorPicker("#brightness-picker-" + random, {
  8. color: `rgb(${brightness}, ${brightness}, ${brightness})`,
  9. layout: [
  10. {
  11. component: iro.ui.Slider,
  12. options: {
  13. borderColor: '#888'
  14. }
  15. }
  16. ],
  17. });
  18. colorPicker.on("input:end", color => {
  19. onChange(color.rgb.r);
  20. });
  21. return () => {
  22. const elem = document.getElementById(`brightness-picker-${random}`);
  23. if (elem === null) {
  24. return;
  25. }
  26. elem.innerHTML = "";
  27. };
  28. }, [brightness]);
  29. return (
  30. <div id={`brightness-picker-${random}`}>
  31. </div>
  32. );
  33. }
  34. export default BrightnessSlider;