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.

38 lines
1.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. import React, {useCallback, useContext, useState} from "react";
  2. import {ColorPreset} from "../models/Colors";
  3. import DialogContext from "../contexts/DialogContext";
  4. import {DialogType} from "../models/Dialog";
  5. import {Dialog} from "../primitives/Layout";
  6. import {LuciferIcon} from "../models/Icons";
  7. import {HSColorPicker, Input, KelvinColorPicker} from "../primitives/Forms";
  8. interface ColorDialogProps {
  9. data?: ColorPreset
  10. }
  11. export default function ColorDialog({data}: ColorDialogProps) {
  12. const {setDialog, clearDialog} = useContext(DialogContext);
  13. const [name, setName] = useState(data?.name || "");
  14. const [hue, setHue] = useState(data?.value?.h || 0);
  15. const [sat, setSat] = useState(data?.value?.s || 0);
  16. const [kelvin, setKelvin] = useState(data?.value?.kelvin || 0);
  17. const onClose = useCallback(() => {
  18. setDialog({type: DialogType.None});
  19. }, [setDialog]);
  20. return (
  21. <Dialog title={data ? "Endre farge" : "Ny farge"} buttons={[
  22. {icon: LuciferIcon.Check, text: "Lagre"},
  23. {icon: LuciferIcon.Cross, text: "Avbryt", onClick: clearDialog},
  24. ]}>
  25. <Input label="Navn" value={name} onChange={setName}/>
  26. <HSColorPicker h={hue} s={sat} onChange={(h, s) => {
  27. setHue(h);
  28. setSat(s);
  29. }}/>
  30. <KelvinColorPicker kelvin={kelvin} onChange={setKelvin}/>
  31. </Dialog>
  32. );
  33. }