33 * Replaces the chat textarea when voice input is active.
44 */
55
6- import React from "react" ;
6+ import React , { useRef , useState , useLayoutEffect } from "react" ;
77import { LiveAudioVisualizer } from "react-audio-visualize" ;
88import { Loader2 } from "lucide-react" ;
99import { cn } from "@/common/lib/utils" ;
@@ -27,12 +27,26 @@ interface RecordingOverlayProps {
2727export const RecordingOverlay : React . FC < RecordingOverlayProps > = ( props ) => {
2828 const isRecording = props . state === "recording" ;
2929 const isTranscribing = props . state === "transcribing" ;
30+ const containerRef = useRef < HTMLDivElement > ( null ) ;
31+ const [ containerWidth , setContainerWidth ] = useState ( 400 ) ;
32+
33+ // Measure container width for the canvas
34+ useLayoutEffect ( ( ) => {
35+ const measure = ( ) => {
36+ if ( containerRef . current ) {
37+ setContainerWidth ( containerRef . current . offsetWidth ) ;
38+ }
39+ } ;
40+ measure ( ) ;
41+ window . addEventListener ( "resize" , measure ) ;
42+ return ( ) => window . removeEventListener ( "resize" , measure ) ;
43+ } , [ ] ) ;
3044
3145 const modeColor = MODE_COLORS [ props . mode ] ;
3246
3347 // Border and background classes based on state
3448 const containerClasses = cn (
35- "mb-1 flex min-h-[72px] w-full flex-col items-center justify-center gap-2 rounded-md border px-4 py-3 transition-all focus:outline-none" ,
49+ "mb-1 flex w-full flex-col items-center justify-center gap-1 rounded-md border px-3 py-2 transition-all focus:outline-none" ,
3650 isRecording
3751 ? props . mode === "plan"
3852 ? "cursor-pointer border-plan-mode bg-plan-mode/10"
@@ -49,14 +63,14 @@ export const RecordingOverlay: React.FC<RecordingOverlayProps> = (props) => {
4963 aria-label = { isRecording ? "Stop recording" : "Transcribing..." }
5064 >
5165 { /* Visualizer / Animation Area */ }
52- < div className = "flex h-10 w-full items-center justify-center" >
66+ < div ref = { containerRef } className = "flex h-8 w-full items-center justify-center" >
5367 { isRecording && props . mediaRecorder ? (
5468 < LiveAudioVisualizer
5569 mediaRecorder = { props . mediaRecorder }
56- width = "100%"
57- height = { 40 }
58- barWidth = { 3 }
59- gap = { 2 }
70+ width = { containerWidth }
71+ height = { 32 }
72+ barWidth = { 2 }
73+ gap = { 1 }
6074 barColor = { modeColor }
6175 smoothingTimeConstant = { 0.5 }
6276 fftSize = { 256 }
0 commit comments