@snipet/react-widget 0.0.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @snipet/react-widget
|
|
2
|
+
|
|
3
|
+
React bindings for the [Snipet chat widget](https://github.com/usesnipet/snipet/tree/main/apps/widget).
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @snipet/react-widget
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Render `<SnipetWidget />` once, anywhere in your app. It draws the widget in the page corner and
|
|
12
|
+
renders nothing in place.
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { SnipetWidget, useSnipet } from "@snipet/react-widget";
|
|
16
|
+
|
|
17
|
+
export function App() {
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
<SnipetWidget
|
|
21
|
+
apiUrl="https://snipet.example.com"
|
|
22
|
+
appId="<your app id>"
|
|
23
|
+
agentId="<your agent id>"
|
|
24
|
+
theme="auto"
|
|
25
|
+
onMessage={(message) => console.log(message.role, message.text)}
|
|
26
|
+
/>
|
|
27
|
+
<HelpButton />
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function HelpButton() {
|
|
33
|
+
const snipet = useSnipet();
|
|
34
|
+
return <button onClick={() => snipet.open()}>Help</button>;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- Props are the widget's [options](https://github.com/usesnipet/snipet/tree/main/apps/widget#options); changing one updates the widget.
|
|
39
|
+
- Events: `onOpen`, `onClose`, `onMessage`, `onError` (see [events](https://github.com/usesnipet/snipet/tree/main/apps/widget#events)).
|
|
40
|
+
- `src` overrides where the widget script loads from (default: unpkg, same version as this package).
|
|
41
|
+
- Unmounting `<SnipetWidget />` removes the widget.
|
|
42
|
+
|
|
43
|
+
`useSnipet()` returns the widget API: `open`, `close`, `toggle`, `enable`, `disable`, `configure`,
|
|
44
|
+
`setToken`, `on`. Calls made before the script loads are queued.
|
|
45
|
+
|
|
46
|
+
### Signed-in users
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
<SnipetWidget apiUrl={apiUrl} agentId={agentId} token={user?.snipetToken} getToken={refreshSnipetToken} />
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Issue tokens from your backend; see [signing in end users](https://github.com/usesnipet/snipet/tree/main/apps/widget#signing-in-end-users).
|
|
53
|
+
Keep `getToken` stable (`useCallback` or a module function) so the widget isn't reconfigured on every render.
|
|
54
|
+
|
|
55
|
+
Works with SSR frameworks (Next.js, Remix): the component is a client component and only touches the
|
|
56
|
+
DOM in effects.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snipet/react-widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "React bindings for the Snipet chat widget.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@snipet/widget": "0.
|
|
25
|
+
"@snipet/widget": "0.2.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=18"
|