diff --git a/components/Colors.tsx b/components/Colors.tsx new file mode 100644 index 0000000..8fd1e1a --- /dev/null +++ b/components/Colors.tsx @@ -0,0 +1,45 @@ +import React, {useState} from 'react' +import {RadioGroup} from '@headlessui/react' +import {COLORS, rgbToHex} from "../src/colors"; + +interface ColorsProps { + initialValue: COLORS, + onChange(value: COLORS): void; +} + +function Colors(props: ColorsProps): JSX.Element { + let [color, setColor] = useState(props.initialValue) + + return ( + + className="flex flex-wrap" value={color} + onChange={function (value) { + setColor(value); + props.onChange(value); + } + }> + {Object.values(COLORS).map((color) => { + return ( + + {({checked}) => ( +
+ {checked && + + + + } +
+ )} +
+ ) + })} + + ) +} + +export default Colors; \ No newline at end of file diff --git a/components/Form.tsx b/components/Form.tsx index 7cf46e7..be9206b 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 {COLORS} from "../src/colors"; +import Colors from './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,13 +229,13 @@ function Form(): JSX.Element {

    - - - + + +
-