From 11d739b47384612839f2a7ef7800c77ee5262db0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hauke=20T=C3=B6njes?=
Date: Wed, 28 Jul 2021 14:28:45 +0200
Subject: [PATCH] New color selector - Use headless-ui radio menu for the
selector - Use enum for colors - Design is WIP
---
components/ColorSelector.tsx | 34 ++++++++++++++++++
components/Form.tsx | 42 ++++++++---------------
components/color_selector/ColorOption.tsx | 31 +++++++++++++++++
package.json | 1 +
src/colors.ts | 22 ++++++++++++
src/constants.ts | 11 ------
src/payload.ts | 29 +++++++---------
src/process.ts | 5 +--
tailwind.config.js | 20 +++++------
yarn.lock | 5 +++
10 files changed, 133 insertions(+), 67 deletions(-)
create mode 100644 components/ColorSelector.tsx
create mode 100644 components/color_selector/ColorOption.tsx
create mode 100644 src/colors.ts
diff --git a/components/ColorSelector.tsx b/components/ColorSelector.tsx
new file mode 100644
index 0000000..b850e23
--- /dev/null
+++ b/components/ColorSelector.tsx
@@ -0,0 +1,34 @@
+import React, {useState} from 'react'
+import {RadioGroup} from '@headlessui/react'
+import ColorOption from "./color_selector/ColorOption";
+import {COLORS} from "../src/colors";
+
+interface ColorSelectorProps {
+ initialValue: COLORS,
+
+ onChange(value: COLORS): void;
+
+}
+
+function ColorSelector(props: ColorSelectorProps): JSX.Element {
+ let [color, setColor] = useState(props.initialValue)
+
+ return (
+ className="flex items-center flex-wrap" value={color}
+ onChange={function (value) {
+ setColor(value);
+ props.onChange(value);
+ }}>
+
+
+
+
+
+
+
+
+
+ )
+}
+
+export default ColorSelector
\ No newline at end of file
diff --git a/components/Form.tsx b/components/Form.tsx
index 7cf46e7..7f6a104 100644
--- a/components/Form.tsx
+++ b/components/Form.tsx
@@ -1,6 +1,6 @@
import {saveAs} from 'file-saver';
import React, {FormEvent, useEffect, useRef, useState} from "react";
-import {BrowserQRCodeReader} from "@zxing/browser";
+import {BrowserQRCodeReader, IScannerControls} from "@zxing/browser";
import {Result} from "@zxing/library";
import {useTranslation} from 'next-i18next';
import Link from 'next/link';
@@ -11,15 +11,20 @@ import Check from './Check';
import {PayloadBody} from "../src/payload";
import {getPayloadBodyFromFile, getPayloadBodyFromQR} from "../src/process";
import {PassData} from "../src/pass";
+import ColorSelector from "./ColorSelector";
+import {COLORS} from "../src/colors";
function Form(): JSX.Element {
- const { t } = useTranslation(['index', 'errors', 'common']);
+ const {t} = useTranslation(['index', 'errors', 'common']);
// Whether camera is open or not
const [isCameraOpen, setIsCameraOpen] = useState(false);
+ // Currently selected color
+ const [selectedColor, setSelectedColor] = useState(COLORS.WHITE);
+
// Global camera controls
- const [globalControls, setGlobalControls] = useState(undefined);
+ const [globalControls, setGlobalControls] = useState(undefined);
// Currently selected QR Code / File. Only one of them is set.
const [qrCode, setQrCode] = useState(undefined);
@@ -82,7 +87,7 @@ function Form(): JSX.Element {
setErrorMessage('noCameraAccess');
return;
}
-
+
// Check if camera device is present
if (deviceList.length == 0) {
setErrorMessage("noCameraFound");
@@ -123,7 +128,7 @@ function Form(): JSX.Element {
event.preventDefault();
setLoading(true);
- if(navigator.userAgent.match('CriOS')) {
+ if (navigator.userAgent.match('CriOS')) {
setErrorMessage('safariSupportOnly');
setLoading(false);
return;
@@ -135,7 +140,7 @@ function Form(): JSX.Element {
return;
}
- const color = (document.getElementById('color') as HTMLSelectElement).value;
+ const color = selectedColor;
let payloadBody: PayloadBody;
try {
@@ -208,24 +213,7 @@ function Form(): JSX.Element {
{t('index:pickColorDescription')}
-
-
+
}/>
@@ -241,9 +229,9 @@ function Form(): JSX.Element {