import { ContextModalProps } from "@mantine/modals"; import { Text } from "@mantine/core"; import { useWindowEvent } from "@mantine/hooks"; import { useState } from "react"; type Props = { label: string; onScan: (value: string) => void; closeOnScan?: boolean; }; const ScanningModal = ({ context, id, innerProps, }: ContextModalProps) => { const [inputValues, setInputValues] = useState(""); const { label, onScan, closeOnScan } = innerProps; useWindowEvent("keydown", (event) => { event.preventDefault(); setInputValues(prevState => prevState + event.key); if (["\n", "\r", "Enter"].includes(event.key)) { onScan(inputValues); setInputValues(""); if (closeOnScan) { context.closeContextModal(id); } } }); return ( {label} ); }; export default ScanningModal;