1- import { useMemo } from 'react' ;
1+ import { ReactNode , useMemo } from 'react' ;
22import { type VariantProps , cva } from 'class-variance-authority' ;
33import { type LocalAudioTrack , type RemoteAudioTrack } from 'livekit-client' ;
44import {
55 type AgentState ,
66 type TrackReferenceOrPlaceholder ,
77 useMultibandTrackVolume ,
88} from '@livekit/components-react' ;
9- import { cn } from '@/lib/utils' ;
9+ import { cloneSingleChild , cn } from '@/lib/utils' ;
1010import { useBarAnimator } from './hooks/useBarAnimator' ;
1111
12- export const audioRadialVisualizerVariants = cva ( [ 'relative flex items-center justify-center' ] , {
13- variants : {
14- size : {
15- icon : 'h-[24px] gap-[2px]' ,
16- sm : 'h-[56px] gap-[4px]' ,
17- md : 'h-[112px] gap-[8px]' ,
18- lg : 'h-[224px] gap-[16px]' ,
19- xl : 'h-[448px] gap-[32px]' ,
20- } ,
21- } ,
22- defaultVariants : {
23- size : 'md' ,
24- } ,
25- } ) ;
26-
27- export const audioRadialVisualizerBarVariants = cva (
12+ export const audioRadialVisualizerVariants = cva (
2813 [
29- 'rounded-full transition-colors duration-250 ease-linear bg-(--audio-visualizer-idle) data-[lk-highlighted=true]:bg-(--audio-visualizer-active)' ,
14+ 'relative flex items-center justify-center' ,
15+ '[&_[data-lk-index]]:absolute [&_[data-lk-index]]:top-1/2 [&_[data-lk-index]]:left-1/2 [&_[data-lk-index]]:origin-bottom [&_[data-lk-index]]:-translate-x-1/2' ,
16+ '[&_[data-lk-index]]:rounded-full [&_[data-lk-index]]:transition-colors [&_[data-lk-index]]:duration-250 [&_[data-lk-index]]:ease-linear [&_[data-lk-index]]:bg-(--audio-visualizer-idle) [&_[data-lk-index]]:data-[lk-highlighted=true]:bg-(--audio-visualizer-active)' ,
3017 ] ,
3118 {
3219 variants : {
3320 size : {
34- icon : 'w-[4px] min-h-[4px]' ,
35- sm : 'w-[8px] min-h-[8px]' ,
36- md : 'w-[16px] min-h-[16px]' ,
37- lg : 'w-[32px] min-h-[32px]' ,
38- xl : 'w-[64px] min-h-[64px]' ,
21+ icon : [ 'h-[24px] gap-[2px]' , '[&_[data-lk-index]]:w-[4px] [&_[data-lk-index]]:min-h-[4px]' ] ,
22+ sm : [ 'h-[56px] gap-[4px]' , '[&_[data-lk-index]]:w-[8px] [&_[data-lk-index]]:min-h-[8px]' ] ,
23+ md : [
24+ 'h-[112px] gap-[8px]' ,
25+ '[&_[data-lk-index]]:w-[16px] [&_[data-lk-index]]:min-h-[16px]' ,
26+ ] ,
27+ lg : [
28+ 'h-[224px] gap-[16px]' ,
29+ '[&_[data-lk-index]]:w-[32px] [&_[data-lk-index]]:min-h-[32px]' ,
30+ ] ,
31+ xl : [
32+ 'h-[448px] gap-[32px]' ,
33+ '[&_[data-lk-index]]:w-[64px] [&_[data-lk-index]]:min-h-[64px]' ,
34+ ] ,
3935 } ,
4036 } ,
4137 defaultVariants : {
@@ -50,7 +46,7 @@ interface AudioRadialVisualizerProps {
5046 barCount ?: number ;
5147 audioTrack ?: LocalAudioTrack | RemoteAudioTrack | TrackReferenceOrPlaceholder ;
5248 className ?: string ;
53- barClassName ?: string ;
49+ children ?: ReactNode ;
5450}
5551
5652export function AudioRadialVisualizer ( {
@@ -60,7 +56,7 @@ export function AudioRadialVisualizer({
6056 barCount,
6157 audioTrack,
6258 className,
63- barClassName ,
59+ children ,
6460} : AudioRadialVisualizerProps & VariantProps < typeof audioRadialVisualizerVariants > ) {
6561 const _barCount = useMemo ( ( ) => {
6662 if ( barCount ) {
@@ -128,22 +124,25 @@ export function AudioRadialVisualizer({
128124 return (
129125 < div
130126 key = { idx }
131- className = { cn ( ' absolute top-1/2 left-1/2 h-1 w-1 -translate-x-1/2 -translate-y-1/2' ) }
127+ className = " absolute top-1/2 left-1/2 h-1 w-1 -translate-x-1/2 -translate-y-1/2"
132128 style = { {
133129 transformOrigin : 'center' ,
134130 transform : `rotate(${ angle } rad) translateY(${ distanceFromCenter } px)` ,
135131 } }
136132 >
137- < div
138- data-lk-index = { idx }
139- data-lk-highlighted = { highlightedIndices . includes ( idx ) }
140- className = { cn (
141- audioRadialVisualizerBarVariants ( { size } ) ,
142- 'absolute top-1/2 left-1/2 origin-bottom -translate-x-1/2' ,
143- barClassName
144- ) }
145- style = { { height : `${ band * distanceFromCenter * 2 } px` } }
146- />
133+ { children ? (
134+ cloneSingleChild ( children , {
135+ key : idx ,
136+ 'data-lk-index' : idx ,
137+ 'data-lk-highlighted' : highlightedIndices . includes ( idx ) ,
138+ } )
139+ ) : (
140+ < div
141+ data-lk-index = { idx }
142+ data-lk-highlighted = { highlightedIndices . includes ( idx ) }
143+ style = { { height : `${ band * distanceFromCenter * 2 } px` } }
144+ />
145+ ) }
147146 </ div >
148147 ) ;
149148 } ) }
0 commit comments