Skip to content

Commit 96fe24c

Browse files
add AgentDisconnectButton
1 parent 8b3fd89 commit 96fe24c

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as React from 'react';
2+
import { StoryObj } from '@storybook/react-vite';
3+
import { AgentSessionProvider } from '../../.storybook/lk-decorators/AgentSessionProvider';
4+
import { AgentDisconnectButton, type AgentDisconnectButtonProps } from '@agents-ui';
5+
6+
export default {
7+
component: AgentDisconnectButton,
8+
decorators: [AgentSessionProvider],
9+
render: (args: AgentDisconnectButtonProps) => (
10+
<AgentDisconnectButton {...args}></AgentDisconnectButton>
11+
),
12+
argTypes: {
13+
size: {
14+
options: ['default', 'sm', 'lg', 'icon', 'icon-sm', 'icon-lg'],
15+
control: { type: 'select' },
16+
},
17+
onClick: { action: 'onClick' },
18+
className: { control: { type: 'text' } },
19+
},
20+
parameters: {
21+
layout: 'centered',
22+
actions: {
23+
handles: [],
24+
},
25+
},
26+
};
27+
28+
export const Default: StoryObj<AgentDisconnectButtonProps> = {
29+
args: {},
30+
};
31+
32+
export const Icon: StoryObj<AgentDisconnectButtonProps> = {
33+
args: {
34+
size: 'icon',
35+
},
36+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use client';
2+
3+
import { Button, buttonVariants } from '@/components/ui/button';
4+
import { cn } from '@/lib/utils';
5+
import { useSessionContext } from '@livekit/components-react';
6+
import { type VariantProps } from 'class-variance-authority';
7+
import { PhoneOffIcon } from 'lucide-react';
8+
9+
export interface AgentDisconnectButtonProps
10+
extends React.ComponentProps<'button'>,
11+
VariantProps<typeof buttonVariants> {
12+
icon?: React.ReactNode;
13+
children?: React.ReactNode;
14+
}
15+
16+
export function AgentDisconnectButton({
17+
icon,
18+
size = 'default',
19+
children,
20+
onClick,
21+
...props
22+
}: AgentDisconnectButtonProps) {
23+
const { end } = useSessionContext();
24+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
25+
onClick?.(event);
26+
end();
27+
};
28+
29+
return (
30+
<Button variant="destructive" size={size} onClick={handleClick} {...props}>
31+
{icon ?? <PhoneOffIcon />}
32+
{children ?? <span className={cn(size?.includes('icon') && 'sr-only')}>END CALL</span>}
33+
</Button>
34+
);
35+
}

packages/shadcn/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './components/agents-ui/audio-visualizer-bar/audio-visualizer-bar';
22
export * from './components/agents-ui/agent-track-toggle';
33
export * from './components/agents-ui/agent-track-control';
4+
export * from './components/agents-ui/agent-disconnect-button';

0 commit comments

Comments
 (0)