Browse Source
Merge branch 'asmodeus' of git.aiterp.net:lucifer/new-server into asmodeus
pull/1/head
Merge branch 'asmodeus' of git.aiterp.net:lucifer/new-server into asmodeus
pull/1/head
Gisle Aune
3 years ago
8 changed files with 211 additions and 20 deletions
-
14app/api/presets.go
-
10webui/src/actions/ColorPresets.ts
-
13webui/src/contexts/DialogContext.tsx
-
54webui/src/dialogs/ColorDialog.tsx
-
5webui/src/pages/SettingsPage.tsx
-
20webui/src/primitives/Forms.sass
-
111webui/src/primitives/Forms.tsx
-
4webui/src/primitives/Layout.tsx
@ -1,23 +1,71 @@ |
|||||
import React, {useCallback, useContext, useState} from "react"; |
|
||||
|
import React, {useCallback, useContext, useEffect, useState} from "react"; |
||||
import {ColorPreset} from "../models/Colors"; |
import {ColorPreset} from "../models/Colors"; |
||||
import DialogContext from "../contexts/DialogContext"; |
import DialogContext from "../contexts/DialogContext"; |
||||
import {DialogType} from "../models/Dialog"; |
import {DialogType} from "../models/Dialog"; |
||||
|
import {Dialog} from "../primitives/Layout"; |
||||
|
import {LuciferIcon} from "../models/Icons"; |
||||
|
import {HSColorPicker, Input, KelvinColorPicker} from "../primitives/Forms"; |
||||
|
|
||||
interface ColorDialogProps { |
interface ColorDialogProps { |
||||
data?: ColorPreset |
data?: ColorPreset |
||||
} |
} |
||||
|
|
||||
|
enum ColorType { |
||||
|
HueSat, |
||||
|
Kelvin, |
||||
|
HueSatKelvin, |
||||
|
} |
||||
|
|
||||
|
const COLOR_TYPE_OPTIONS = [ |
||||
|
{value: ColorType.HueSat, name: "Bare Nyanse (H) og metning (S)"}, |
||||
|
{value: ColorType.Kelvin, name: "Bare temperatur (K)"}, |
||||
|
{value: ColorType.HueSatKelvin, name: "Nyanse (H), metning (K) og kelvin (S)"}, |
||||
|
]; |
||||
|
|
||||
export default function ColorDialog({data}: ColorDialogProps) { |
export default function ColorDialog({data}: ColorDialogProps) { |
||||
const {setDialog} = useContext(DialogContext); |
|
||||
|
const {setDialog, clearDialog} = useContext(DialogContext); |
||||
|
|
||||
const [name, setName] = useState(data?.name || ""); |
const [name, setName] = useState(data?.name || ""); |
||||
const [hue, setHue] = useState(data?.value?.h || 0); |
const [hue, setHue] = useState(data?.value?.h || 0); |
||||
const [sat, setSat] = useState(data?.value?.s || 0); |
const [sat, setSat] = useState(data?.value?.s || 0); |
||||
const [kelvin, setKelvin] = useState(data?.value?.kelvin || 0); |
const [kelvin, setKelvin] = useState(data?.value?.kelvin || 0); |
||||
|
|
||||
const onClose = useCallback(() => { |
|
||||
|
const [colorType, setColorType] = useState(COLOR_TYPE_OPTIONS[0].value); |
||||
|
const [isInit, setIsInit] = useState(false); |
||||
|
|
||||
|
const onSave = useCallback(() => { |
||||
setDialog({type: DialogType.None}); |
setDialog({type: DialogType.None}); |
||||
}, [setDialog]); |
}, [setDialog]); |
||||
|
|
||||
|
useEffect(() => { |
||||
|
if (!isInit && data) { |
||||
|
const v = data.value; |
||||
|
|
||||
|
if (v.kelvin !== undefined && v.kelvin > 0) { |
||||
|
setColorType((v.h || v.s) ? ColorType.HueSatKelvin : ColorType.Kelvin); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!isInit) { |
||||
|
setIsInit(true); |
||||
|
} |
||||
|
}, [isInit, data, colorType]); |
||||
|
|
||||
|
return ( |
||||
|
<Dialog title={data ? "Endre farge" : "Ny farge"} buttons={[ |
||||
|
{icon: LuciferIcon.Check, text: "Lagre", onClick: onSave}, |
||||
|
{icon: LuciferIcon.Cross, text: "Avbryt", onClick: clearDialog}, |
||||
|
]}> |
||||
|
<Input label="Navn" value={name} onChange={setName}/> |
||||
|
{colorType !== ColorType.Kelvin && ( |
||||
|
<HSColorPicker h={hue} s={sat} onChange={(h, s) => { |
||||
|
setHue(h); |
||||
|
setSat(s); |
||||
|
}}/> |
||||
|
)} |
||||
|
{colorType !== ColorType.HueSat && ( |
||||
|
<KelvinColorPicker kelvin={kelvin} onChange={setKelvin}/> |
||||
|
)} |
||||
|
</Dialog> |
||||
|
); |
||||
} |
} |
@ -0,0 +1,20 @@ |
|||||
|
@import "../res/colors" |
||||
|
|
||||
|
.FormLine |
||||
|
padding: 0.5em 1ch |
||||
|
width: 100% |
||||
|
|
||||
|
&:first-of-type |
||||
|
margin-top: 0 |
||||
|
|
||||
|
input, select |
||||
|
display: block |
||||
|
width: 100% |
||||
|
font: inherit |
||||
|
background-color: $color-background-elevated |
||||
|
color: $color-foreground |
||||
|
border: none |
||||
|
padding: 0.25em 0.5ch |
||||
|
|
||||
|
&:focus, &:active |
||||
|
outline: 1px solid $color-foreground-elevated |
Write
Preview
Loading…
Cancel
Save
Reference in new issue