import React, { useRef } from 'react'; import { Loader2, Mic, MicOff } from 'lucide-react'; import { useVoiceInput } from '../lib/useVoiceInput'; import { triggerHaptic } from '../lib/api'; import { VoiceWave } from './VoiceWave'; interface VoiceInputButtonProps { // The field's text; dictated words are appended to what was there when the recording started value: string; onChange: (text: string) => void; onError?: (message: string) => void; // Field to focus once the text is final focusRef?: React.RefObject; className?: string; } // Microphone inside an input row, like the one in Quick Dump (Doku/ui-patterns.md). Hidden when voice // input is off or the browser cannot do it (e.g. Firefox without an own Whisper server). export const VoiceInputButton: React.FC = ({ value, onChange, onError, focusRef, className = '' }) => { const baseRef = useRef(''); const voice = useVoiceInput({ onText: (text, final) => { const base = baseRef.current; if (text) onChange(base ? `${base} ${text}` : text); if (final) focusRef?.current?.focus(); }, onError, }); if (!voice.available) return null; const listening = voice.state === 'listening'; const transcribing = voice.state === 'transcribing'; return ( {listening && voice.mode === 'server' && } ); };