Skip to content

Commit 776dd1d

Browse files
fix(shadcn): fix agent track control audio visualizer (#1267)
1 parent 378b3d8 commit 776dd1d

6 files changed

Lines changed: 31 additions & 17 deletions

File tree

packages/shadcn/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@
55
module.exports = {
66
root: true,
77
extends: ['lk-custom'],
8+
settings: {
9+
react: {
10+
version: '19',
11+
},
12+
},
813
};

packages/shadcn/components/agents-ui/agent-chat-indicator.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { type Ref } from 'react';
12
import { cva, type VariantProps } from 'class-variance-authority';
2-
import { motion, type HTMLMotionProps } from 'motion/react';
3+
import { motion, type MotionProps } from 'motion/react';
34

45
import { cn } from '@/lib/utils';
56

@@ -46,7 +47,7 @@ const agentChatIndicatorVariants = cva('bg-muted-foreground inline-block size-2.
4647
/**
4748
* Props for the AgentChatIndicator component.
4849
*/
49-
export interface AgentChatIndicatorProps {
50+
export interface AgentChatIndicatorProps extends MotionProps {
5051
/**
5152
* The size of the indicator dot.
5253
* @defaultValue 'md'
@@ -56,6 +57,10 @@ export interface AgentChatIndicatorProps {
5657
* Additional CSS class names to apply to the indicator.
5758
*/
5859
className?: string;
60+
/**
61+
* Allows getting a ref to the component instance.\nOnce the component unmounts, React will set `ref.current` to `null`\n(or call the ref with `null` if you passed a callback ref).\n@see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
62+
*/
63+
ref?: Ref<HTMLSpanElement>;
5964
}
6065

6166
/**
@@ -73,9 +78,7 @@ export function AgentChatIndicator({
7378
size = 'md',
7479
className,
7580
...props
76-
}: AgentChatIndicatorProps &
77-
HTMLMotionProps<'span'> &
78-
VariantProps<typeof agentChatIndicatorVariants>) {
81+
}: AgentChatIndicatorProps & VariantProps<typeof agentChatIndicatorVariants>) {
7982
return (
8083
<motion.span
8184
{...motionAnimationProps}

packages/shadcn/components/agents-ui/agent-control-bar.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ export function AgentControlBar({
282282
>
283283
<motion.div
284284
{...MOTION_PROPS}
285-
// @ts-ignore
286285
inert={!(isChatOpen || isChatOpenUncontrolled)}
287286
animate={isChatOpen || isChatOpenUncontrolled ? 'visible' : 'hidden'}
288287
className="border-input/50 flex w-full items-start overflow-hidden border-b"

packages/shadcn/components/agents-ui/agent-track-control.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ export function AgentTrackControl({
290290
<AgentAudioVisualizerBar
291291
size="icon"
292292
barCount={3}
293-
audioTrack={audioTrack}
293+
state={pressed ? 'speaking' : 'disconnected'}
294+
audioTrack={pressed ? audioTrack : undefined}
294295
className="audiovisualizer flex h-6 w-auto items-center justify-center gap-0.5"
295296
>
296297
<span

packages/shadcn/hooks/agents-ui/use-agent-control-bar.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface UseInputControlsProps {
5555
}
5656

5757
export interface UseInputControlsReturn {
58-
micTrackRef: TrackReferenceOrPlaceholder;
58+
micTrackRef?: TrackReferenceOrPlaceholder;
5959
microphoneToggle: ReturnType<typeof useTrackToggle<Track.Source.Microphone>>;
6060
cameraToggle: ReturnType<typeof useTrackToggle<Track.Source.Camera>>;
6161
screenShareToggle: ReturnType<typeof useTrackToggle<Track.Source.ScreenShare>>;
@@ -69,8 +69,6 @@ export function useInputControls({
6969
saveUserChoices = true,
7070
onDeviceError,
7171
}: UseInputControlsProps = {}): UseInputControlsReturn {
72-
const { microphoneTrack, localParticipant } = useLocalParticipant();
73-
7472
const microphoneToggle = useTrackToggle({
7573
source: Track.Source.Microphone,
7674
onDeviceError: (error) => onDeviceError?.({ source: Track.Source.Microphone, error }),
@@ -86,12 +84,15 @@ export function useInputControls({
8684
onDeviceError: (error) => onDeviceError?.({ source: Track.Source.ScreenShare, error }),
8785
});
8886

87+
const { microphoneTrack, localParticipant } = useLocalParticipant();
8988
const micTrackRef = useMemo(() => {
90-
return {
91-
participant: localParticipant,
92-
source: Track.Source.Microphone,
93-
publication: microphoneTrack,
94-
};
89+
return localParticipant && microphoneTrack
90+
? {
91+
participant: localParticipant,
92+
source: Track.Source.Microphone,
93+
publication: microphoneTrack,
94+
}
95+
: undefined;
9596
}, [localParticipant, microphoneTrack]);
9697

9798
const {

packages/shadcn/scripts/doc-gen.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ const parser = withDefaultConfig({
2222
if (prop.declarations !== undefined && prop.declarations.length > 0) {
2323
return prop.declarations.some((declaration) => {
2424
return (
25+
declaration.name !== 'MotionProps' &&
2526
declaration.name !== 'DOMAttributes' &&
2627
declaration.name !== 'AriaAttributes' &&
2728
!declaration.name.endsWith('HTMLAttributes') &&
28-
!declaration.fileName.includes('class-variance-authority')
29+
!declaration.fileName.includes('/motion-dom') &&
30+
!declaration.fileName.includes('/class-variance-authority')
2931
);
3032
});
3133
}
@@ -56,6 +58,9 @@ for (const file of files) {
5658
console.log('--------------------------------');
5759
console.log(`Writing prop-types.json to ${path.join(__dirname, '../dist', 'prop-types.json')}`);
5860

59-
fs.writeFileSync(path.join(__dirname, '../dist', 'prop-types.json'), JSON.stringify(docs, null, 2));
61+
fs.writeFileSync(
62+
path.join(__dirname, '../dist', 'prop-types.json'),
63+
JSON.stringify(docs, null, 2) + '\n',
64+
);
6065
console.log('--------------------------------');
6166
console.log('Done');

0 commit comments

Comments
 (0)