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 {

    - - - + + +