From 9232a9a0d611ace62d8870f3dc15566b81dbbb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Z=C3=ADpek?= Date: Mon, 1 Apr 2024 19:13:54 +0200 Subject: [PATCH] Color inputs --- client/package.json | 1 + client/src/assets/components/_input.scss | 55 ++++++++++--- client/src/components/CssColorInput.tsx | 55 +++++++++++++ .../components/MQTTButtonSettings.tsx | 25 +++++- .../components/BoxMQTTButtonContent.tsx | 12 ++- .../DashboardGrid/components/EditableBox.tsx | 10 ++- client/src/utils/dashboard/parseDashboard.ts | 3 + client/tsconfig.json | 4 +- client/yarn.lock | 79 +++++++++++++++++++ 9 files changed, 226 insertions(+), 18 deletions(-) create mode 100644 client/src/components/CssColorInput.tsx diff --git a/client/package.json b/client/package.json index 7deae7e..a465958 100644 --- a/client/package.json +++ b/client/package.json @@ -26,6 +26,7 @@ "vite-plugin-svgr": "^2.2.1" }, "dependencies": { + "@uiw/react-color-colorful": "^2.1.1", "preact": "^10.10.6", "react-query": "^3.39.2", "wouter": "^2.8.0-alpha.2" diff --git a/client/src/assets/components/_input.scss b/client/src/assets/components/_input.scss index a3f6bc2..7b26986 100644 --- a/client/src/assets/components/_input.scss +++ b/client/src/assets/components/_input.scss @@ -39,48 +39,83 @@ textarea { color: var(--input-appendix-fg-color); background-color: var(--input-appendix-bg-color); - >span { + > span { display: flex; align-items: center; padding: 0 0.3rem; height: 100%; } - >button { + > button { height: 100%; } } } +.color-input { + display: flex; + align-items: center; + + .current-color { + width: 2rem; + height: 1.5rem; + border: 1px solid var(--input-border-color); + margin-right: 0.5rem; + } + + .color-picker { + margin-top: -280px; + + > .title { + display: flex; + justify-content: space-between; + align-items: center; + + .close { + display: inline-flex; + padding: 0.5rem; + cursor: pointer; + font-size: 125%; + } + } + + position: absolute; + background-color: var(--box-bg-color); + padding: 0.5rem; + border: 1px solid var(--input-border-color); + } +} + .checkbox-label { display: inline-flex; align-items: center; } -.checkbox-label input[type="checkbox"] { - margin-top: 6px; +.checkbox-label input[type='checkbox'] { + margin-top: 3px; + margin-right: 5px; } .input.buttons { .button-picker { - >button { + > button { margin: 0.1rem; } } } .input.date-time { - >div { + > div { display: flex; align-items: center; } - input[type="date"] { + input[type='date'] { margin-right: 0.25rem; flex: 1; } - input[type="time"] { + input[type='time'] { flex-grow: 0; flex-shrink: 0; } @@ -109,7 +144,7 @@ textarea { color: var(--input-hint-color); font-size: 90%; margin-top: 0rem; - margin-bottom: 0.50rem; + margin-bottom: 0.5rem; } .control { @@ -149,4 +184,4 @@ textarea { } } } -} \ No newline at end of file +} diff --git a/client/src/components/CssColorInput.tsx b/client/src/components/CssColorInput.tsx new file mode 100644 index 0000000..c98caa0 --- /dev/null +++ b/client/src/components/CssColorInput.tsx @@ -0,0 +1,55 @@ +import { forwardRef, useState } from 'preact/compat' +import Colorful from '@uiw/react-color-colorful' +import { CancelIcon } from '@/icons' + +type Props = { + value: string + onChange: (e: Event) => void + name: string + ref: (el: HTMLInputElement | null) => void +} + +export const CssColorInput = forwardRef( + ({ name, value, ref, onChange }: Props) => { + const [showPicker, setShowPicker] = useState(false) + + const handleChange = (e: Event) => { + onChange(e) + } + + return ( +
+ {showPicker && ( +
+
+
{value}
+
setShowPicker(false)}> + +
+
+ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + onChange({ target: { name, value: color.hex } } as any) + } + disableAlpha + /> +
+ )} +
setShowPicker(true)} + /> + +
+ ) + } +) diff --git a/client/src/pages/dashboard/components/BoxSettings/components/MQTTButtonSettings.tsx b/client/src/pages/dashboard/components/BoxSettings/components/MQTTButtonSettings.tsx index 66cd703..306ca4f 100644 --- a/client/src/pages/dashboard/components/BoxSettings/components/MQTTButtonSettings.tsx +++ b/client/src/pages/dashboard/components/BoxSettings/components/MQTTButtonSettings.tsx @@ -1,3 +1,4 @@ +import { CssColorInput } from '@/components/CssColorInput' import { FormCheckboxField } from '@/components/FormCheckboxField' import { FormField } from '@/components/FormField' import { DashboardMQTTButtonData } from '@/utils/dashboard/parseDashboard' @@ -46,7 +47,7 @@ export const MQTTButtonSettings = ({ value, onChange }: Props) => { - + @@ -56,12 +57,32 @@ export const MQTTButtonSettings = ({ value, onChange }: Props) => {