-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathVapiButton.tsx
50 lines (47 loc) · 1.22 KB
/
VapiButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { CALL_STATUS, useVapi } from "./useVapi";
import { Loader2, Mic, Square } from "lucide-react";
const VapiButton = ({
toggleCall,
callStatus,
audioLevel = 0,
}: Partial<ReturnType<typeof useVapi>>) => {
const color =
callStatus === CALL_STATUS.ACTIVE
? "red"
: callStatus === CALL_STATUS.LOADING
? "orange"
: "green";
const buttonStyle = {
borderRadius: "50%",
width: "50px",
height: "50px",
color: "white",
border: "none",
boxShadow: `1px 1px ${10 + audioLevel * 40}px ${
audioLevel * 10
}px ${color}`,
cursor: "pointer",
};
return (
<button
style={buttonStyle}
className={`transition ease-in-out ${
callStatus === CALL_STATUS.ACTIVE
? "bg-red-500 hover:bg-red-700"
: callStatus === CALL_STATUS.LOADING
? "bg-orange-500 hover:bg-orange-700"
: "bg-green-500 hover:bg-green-700"
} flex items-center justify-center`}
onClick={toggleCall}
>
{callStatus === CALL_STATUS.ACTIVE ? (
<Square />
) : callStatus === CALL_STATUS.LOADING ? (
<Loader2 className="animate-spin" />
) : (
<Mic />
)}
</button>
);
};
export { VapiButton };