forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.tsx
More file actions
98 lines (95 loc) · 2.73 KB
/
Copy pathSidebar.tsx
File metadata and controls
98 lines (95 loc) · 2.73 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* <br/>
* <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotSidebar.gif" width="500" />
*
* A chatbot sidebar component for the CopilotKit framework. Highly customizable through various props and custom CSS.
*
* See [CopilotPopup](/reference/v1/components/chat/CopilotPopup) for a popup version of this component.
*
* ## Install Dependencies
*
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
*
* ```shell npm2yarn \"@copilotkit/react-ui"\
* npm install @copilotkit/react-core @copilotkit/react-ui
* ```
*
* ## Usage
*
* ```tsx
* import { CopilotSidebar } from "@copilotkit/react-ui";
* import "@copilotkit/react-ui/styles.css";
*
* <CopilotSidebar
* labels={{
* title: "Your Assistant",
* initial: "Hi! 👋 How can I assist you today?",
* }}
* >
* <YourApp/>
* </CopilotSidebar>
* ```
*
* ### With Observability Hooks
*
* To monitor user interactions, provide the `observabilityHooks` prop.
* **Note:** This requires a `publicApiKey` in the `<CopilotKit>` provider.
*
* ```tsx
* <CopilotKit publicApiKey="YOUR_PUBLIC_API_KEY">
* <CopilotSidebar
* observabilityHooks={{
* onChatExpanded: () => {
* console.log("Sidebar opened");
* },
* onChatMinimized: () => {
* console.log("Sidebar closed");
* },
* }}
* >
* <YourApp/>
* </CopilotSidebar>
* </CopilotKit>
* ```
*
* ### Look & Feel
*
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
* ```tsx title="YourRootComponent.tsx"
* ...
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
*
* export function YourRootComponent() {
* return (
* <CopilotKit>
* ...
* </CopilotKit>
* );
* }
* ```
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
*/
import React, { useState } from "react";
import { CopilotModal, CopilotModalProps } from "./Modal";
export function CopilotSidebar(props: CopilotModalProps) {
props = {
...props,
className: props.className
? props.className + " copilotKitSidebar"
: "copilotKitSidebar",
};
const [expandedClassName, setExpandedClassName] = useState(
props.defaultOpen ? "sidebarExpanded" : "",
);
const onSetOpen = (open: boolean) => {
props.onSetOpen?.(open);
setExpandedClassName(open ? "sidebarExpanded" : "");
};
return (
<div className={`copilotKitSidebarContentWrapper ${expandedClassName}`}>
<CopilotModal {...props} {...{ onSetOpen }}>
{props.children}
</CopilotModal>
</div>
);
}