@neuphlo/widget-react 0.1.0
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 +54 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +41 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @neuphlo/widget-react
|
|
2
|
+
|
|
3
|
+
React bindings for the [Neuphlo](https://neuphlo.com) support chat widget. Renders a floating launcher; conversations land in your Neuphlo inbox with the same draft-and-approve flow as email.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @neuphlo/widget-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Mount the component anywhere in your tree (it renders nothing):
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { NeuphloWidget } from "@neuphlo/widget-react"
|
|
17
|
+
|
|
18
|
+
export function App() {
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<YourApp />
|
|
22
|
+
<NeuphloWidget widgetKey="your-widget-key" />
|
|
23
|
+
</>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or use the hook:
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { useNeuphloWidget } from "@neuphlo/widget-react"
|
|
32
|
+
|
|
33
|
+
useNeuphloWidget({ widgetKey: "your-widget-key", position: "left", color: "#0f766e" })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Open the panel programmatically (e.g. from a "Contact support" button):
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { openNeuphloWidget } from "@neuphlo/widget-react"
|
|
40
|
+
|
|
41
|
+
<button onClick={openNeuphloWidget}>Contact support</button>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Options
|
|
45
|
+
|
|
46
|
+
| Option | Default | Description |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `widgetKey` | — | Workspace widget key from Inbox settings → Chat widget |
|
|
49
|
+
| `position` | `"right"` | Launcher corner, `"left"` or `"right"` |
|
|
50
|
+
| `color` | `"#171717"` | Launcher accent color |
|
|
51
|
+
| `appUrl` | Neuphlo cloud | Your app origin for self-hosted installs |
|
|
52
|
+
| `scriptUrl` | `https://get.neuphlo.com/widget.js` | Loader script URL |
|
|
53
|
+
|
|
54
|
+
The widget unmounts cleanly — the launcher and panel are removed when the component unmounts.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
__neuphloWidgetLoaded?: boolean;
|
|
4
|
+
NeuphloWidget?: NeuphloWidgetApi;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export interface NeuphloWidgetApi {
|
|
8
|
+
open: () => void;
|
|
9
|
+
close: () => void;
|
|
10
|
+
toggle: () => void;
|
|
11
|
+
destroy: () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface NeuphloWidgetOptions {
|
|
14
|
+
/** Workspace widget key from Inbox settings → Chat widget. */
|
|
15
|
+
widgetKey: string;
|
|
16
|
+
/** Loader script origin. Defaults to the Neuphlo cloud. */
|
|
17
|
+
scriptUrl?: string;
|
|
18
|
+
/** Neuphlo app origin, for self-hosted installs. */
|
|
19
|
+
appUrl?: string;
|
|
20
|
+
/** Launcher corner. Defaults to "right". */
|
|
21
|
+
position?: "left" | "right";
|
|
22
|
+
/** Launcher accent color, any CSS color. */
|
|
23
|
+
color?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function loadNeuphloWidget(options: NeuphloWidgetOptions): () => void;
|
|
26
|
+
export declare function useNeuphloWidget(options: NeuphloWidgetOptions): void;
|
|
27
|
+
export declare function NeuphloWidget(props: NeuphloWidgetOptions): null;
|
|
28
|
+
export declare function openNeuphloWidget(): void;
|
|
29
|
+
export declare function closeNeuphloWidget(): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
const DEFAULT_SCRIPT_URL = "https://get.neuphlo.com/widget.js";
|
|
3
|
+
const SCRIPT_ID = "neuphlo-widget-loader";
|
|
4
|
+
export function loadNeuphloWidget(options) {
|
|
5
|
+
if (typeof document === "undefined")
|
|
6
|
+
return () => { };
|
|
7
|
+
if (document.getElementById(SCRIPT_ID) || window.__neuphloWidgetLoaded) {
|
|
8
|
+
return () => { };
|
|
9
|
+
}
|
|
10
|
+
const script = document.createElement("script");
|
|
11
|
+
script.id = SCRIPT_ID;
|
|
12
|
+
script.src = options.scriptUrl ?? DEFAULT_SCRIPT_URL;
|
|
13
|
+
script.async = true;
|
|
14
|
+
script.dataset.key = options.widgetKey;
|
|
15
|
+
if (options.appUrl)
|
|
16
|
+
script.dataset.app = options.appUrl;
|
|
17
|
+
if (options.position)
|
|
18
|
+
script.dataset.position = options.position;
|
|
19
|
+
if (options.color)
|
|
20
|
+
script.dataset.color = options.color;
|
|
21
|
+
document.body.appendChild(script);
|
|
22
|
+
return () => {
|
|
23
|
+
window.NeuphloWidget?.destroy();
|
|
24
|
+
script.remove();
|
|
25
|
+
window.__neuphloWidgetLoaded = false;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function useNeuphloWidget(options) {
|
|
29
|
+
const { widgetKey, scriptUrl, appUrl, position, color } = options;
|
|
30
|
+
useEffect(() => loadNeuphloWidget({ widgetKey, scriptUrl, appUrl, position, color }), [widgetKey, scriptUrl, appUrl, position, color]);
|
|
31
|
+
}
|
|
32
|
+
export function NeuphloWidget(props) {
|
|
33
|
+
useNeuphloWidget(props);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
export function openNeuphloWidget() {
|
|
37
|
+
window.NeuphloWidget?.open();
|
|
38
|
+
}
|
|
39
|
+
export function closeNeuphloWidget() {
|
|
40
|
+
window.NeuphloWidget?.close();
|
|
41
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neuphlo/widget-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React component for the Neuphlo support chat widget",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/Neuphlo/neuphlo-widget-react.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/react": "^19.0.0",
|
|
29
|
+
"typescript": "^5.9.0"
|
|
30
|
+
},
|
|
31
|
+
"bugs": "https://github.com/Neuphlo/neuphlo-widget-react/issues",
|
|
32
|
+
"homepage": "https://github.com/Neuphlo/neuphlo-widget-react#readme",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json"
|
|
35
|
+
}
|
|
36
|
+
}
|