@@ -3,7 +3,7 @@ import { useBarAnimator } from './animators/useBarAnimator';
33import { useMultibandTrackVolume , type VoiceAssistantState } from '../../hooks' ;
44import type { TrackReferenceOrPlaceholder } from '@livekit/components-core' ;
55import { useMaybeTrackRefContext } from '../../context' ;
6- import { mergeProps } from '../../utils' ;
6+ import { cloneSingleChild , mergeProps } from '../../utils' ;
77
88/**
99 * @beta
@@ -25,6 +25,8 @@ export interface BarVisualizerProps extends React.HTMLProps<HTMLDivElement> {
2525 barCount ?: number ;
2626 trackRef ?: TrackReferenceOrPlaceholder ;
2727 options ?: BarVisualizerOptions ;
28+ /** The template component to be used in the visualizer. */
29+ children ?: React . ReactNode ;
2830}
2931
3032const sequencerIntervals = new Map < VoiceAssistantState , number > ( [
@@ -76,7 +78,7 @@ const getSequencerInterval = (
7678 */
7779export const BarVisualizer = /* @__PURE__ */ React . forwardRef < HTMLDivElement , BarVisualizerProps > (
7880 function BarVisualizer (
79- { state, options, barCount = 15 , trackRef, ...props } : BarVisualizerProps ,
81+ { state, options, barCount = 15 , trackRef, children , ...props } : BarVisualizerProps ,
8082 ref ,
8183 ) {
8284 const elementProps = mergeProps ( props , { className : 'lk-audio-bar-visualizer' } ) ;
@@ -102,17 +104,28 @@ export const BarVisualizer = /* @__PURE__ */ React.forwardRef<HTMLDivElement, Ba
102104
103105 return (
104106 < 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+ ) }
116129 </ div >
117130 ) ;
118131 } ,
0 commit comments