@@ -3,7 +3,7 @@ import { useBarAnimator } from './animators/useBarAnimator';
3
3
import { useMultibandTrackVolume , type VoiceAssistantState } from '../../hooks' ;
4
4
import type { TrackReferenceOrPlaceholder } from '@livekit/components-core' ;
5
5
import { useMaybeTrackRefContext } from '../../context' ;
6
- import { mergeProps } from '../../utils' ;
6
+ import { cloneSingleChild , mergeProps } from '../../utils' ;
7
7
8
8
/**
9
9
* @beta
@@ -25,6 +25,8 @@ export interface BarVisualizerProps extends React.HTMLProps<HTMLDivElement> {
25
25
barCount ?: number ;
26
26
trackRef ?: TrackReferenceOrPlaceholder ;
27
27
options ?: BarVisualizerOptions ;
28
+ /** The template component to be used in the visualizer. */
29
+ children ?: React . ReactNode ;
28
30
}
29
31
30
32
const sequencerIntervals = new Map < VoiceAssistantState , number > ( [
@@ -76,7 +78,7 @@ const getSequencerInterval = (
76
78
*/
77
79
export const BarVisualizer = /* @__PURE__ */ React . forwardRef < HTMLDivElement , BarVisualizerProps > (
78
80
function BarVisualizer (
79
- { state, options, barCount = 15 , trackRef, ...props } : BarVisualizerProps ,
81
+ { state, options, barCount = 15 , trackRef, children , ...props } : BarVisualizerProps ,
80
82
ref ,
81
83
) {
82
84
const elementProps = mergeProps ( props , { className : 'lk-audio-bar-visualizer' } ) ;
@@ -102,17 +104,28 @@ export const BarVisualizer = /* @__PURE__ */ React.forwardRef<HTMLDivElement, Ba
102
104
103
105
return (
104
106
< div ref = { ref } { ...elementProps } data-lk-va-state = { state } >
105
- { volumeBands . map ( ( volume , idx ) => (
106
- < span
107
- key = { idx }
108
- className = { `lk-audio-bar ${ highlightedIndices . includes ( idx ) && 'lk-highlighted' } ` }
109
- style = { {
110
- // TODO transform animations would be more performant, however the border-radius gets distorted when using scale transforms. a 9-slice approach (or 3 in this case) could work
111
- // transform: `scale(1, ${Math.min(maxHeight, Math.max(minHeight, volume))}`,
112
- height : `${ Math . min ( maxHeight , Math . max ( minHeight , volume * 100 + 5 ) ) } %` ,
113
- } }
114
- > </ span >
115
- ) ) }
107
+ { volumeBands . map ( ( volume , idx ) =>
108
+ children ? (
109
+ cloneSingleChild ( children , {
110
+ 'data-lk-highlighted' : highlightedIndices . includes ( idx ) ,
111
+ 'data-lk-bar-index' : idx ,
112
+ class : 'lk-audio-bar' ,
113
+ style : { height : `${ Math . min ( maxHeight , Math . max ( minHeight , volume * 100 + 5 ) ) } %` } ,
114
+ } )
115
+ ) : (
116
+ < span
117
+ key = { idx }
118
+ data-lk-highlighted = { highlightedIndices . includes ( idx ) }
119
+ data-lk-bar-index = { idx }
120
+ className = { `lk-audio-bar ${ highlightedIndices . includes ( idx ) && 'lk-highlighted' } ` }
121
+ style = { {
122
+ // TODO transform animations would be more performant, however the border-radius gets distorted when using scale transforms. a 9-slice approach (or 3 in this case) could work
123
+ // transform: `scale(1, ${Math.min(maxHeight, Math.max(minHeight, volume))}`,
124
+ height : `${ Math . min ( maxHeight , Math . max ( minHeight , volume * 100 + 5 ) ) } %` ,
125
+ } }
126
+ > </ span >
127
+ ) ,
128
+ ) }
116
129
</ div >
117
130
) ;
118
131
} ,
0 commit comments