import React from "react" import { InnerFormContext } from "../formContext" export interface BarcodeAnswerComponentProps { value?: string onValueChange: any formCtx: InnerFormContext } // Functional? I haven't tried this one yet // Not tested export default class BarcodeAnswerComponent extends React.Component { focus() { // Nothing to focus return null } handleValueChange = () => { return this.props.onValueChange(!this.props.value) } handleScanClick = () => { return this.props.formCtx.scanBarcode!({ success: (text: any) => { return this.props.onValueChange(text) }, error: (err: any) => { console.error(err) } }) } handleClearClick = () => { return this.props.onValueChange(null) } render() { const supported = this.props.formCtx.scanBarcode != null if (this.props.value) { return (

{this.props.value}

) } else { if (supported) { return (
) } else { return (
{this.props.formCtx.T("Barcode scanning not supported on this platform")}
) } } } }