@customerhero/react 2.1.1 → 2.3.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.
@@ -0,0 +1,32 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CSSProperties } from 'react';
3
+ import { CustomerHeroChatConfig, IncidentBanner } from '@customerhero/js';
4
+
5
+ interface PreviewWidgetProps extends CustomerHeroChatConfig {
6
+ /**
7
+ * Optional wrapper styles. The component already wraps its children in a
8
+ * `position: relative` block; this lets the host control width/height/
9
+ * background of the preview canvas.
10
+ */
11
+ style?: CSSProperties;
12
+ /** Optional className on the outer wrapper. */
13
+ className?: string;
14
+ /**
15
+ * Render the chatbot's incident banner inside the preview chat window.
16
+ * `null` (or omitted) hides the banner. The banner is sanitized client-side
17
+ * so dashboard-side typos in fields like `link.url` don't crash the preview.
18
+ */
19
+ banner?: IncidentBanner | null;
20
+ }
21
+ /**
22
+ * Render the chat widget for visual preview only — no API calls, no SSE,
23
+ * no localStorage writes, input disabled. The window auto-opens. The bubble
24
+ * and window are positioned `absolute` inside the wrapper element.
25
+ *
26
+ * The host passes the same config shape as `<ChatWidget>`, plus an optional
27
+ * `colorScheme` (`light` / `dark` / `auto`) to drive the visitor-side dark
28
+ * mode toggle independently of the chatbot's own light/dark palettes.
29
+ */
30
+ declare function PreviewWidget({ style, className, banner, ...config }: PreviewWidgetProps): react_jsx_runtime.JSX.Element;
31
+
32
+ export { PreviewWidget, type PreviewWidgetProps };
@@ -0,0 +1,32 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CSSProperties } from 'react';
3
+ import { CustomerHeroChatConfig, IncidentBanner } from '@customerhero/js';
4
+
5
+ interface PreviewWidgetProps extends CustomerHeroChatConfig {
6
+ /**
7
+ * Optional wrapper styles. The component already wraps its children in a
8
+ * `position: relative` block; this lets the host control width/height/
9
+ * background of the preview canvas.
10
+ */
11
+ style?: CSSProperties;
12
+ /** Optional className on the outer wrapper. */
13
+ className?: string;
14
+ /**
15
+ * Render the chatbot's incident banner inside the preview chat window.
16
+ * `null` (or omitted) hides the banner. The banner is sanitized client-side
17
+ * so dashboard-side typos in fields like `link.url` don't crash the preview.
18
+ */
19
+ banner?: IncidentBanner | null;
20
+ }
21
+ /**
22
+ * Render the chat widget for visual preview only — no API calls, no SSE,
23
+ * no localStorage writes, input disabled. The window auto-opens. The bubble
24
+ * and window are positioned `absolute` inside the wrapper element.
25
+ *
26
+ * The host passes the same config shape as `<ChatWidget>`, plus an optional
27
+ * `colorScheme` (`light` / `dark` / `auto`) to drive the visitor-side dark
28
+ * mode toggle independently of the chatbot's own light/dark palettes.
29
+ */
30
+ declare function PreviewWidget({ style, className, banner, ...config }: PreviewWidgetProps): react_jsx_runtime.JSX.Element;
31
+
32
+ export { PreviewWidget, type PreviewWidgetProps };
@@ -0,0 +1,53 @@
1
+ import {
2
+ ChatBubble,
3
+ ChatWindow,
4
+ CustomerHeroProvider,
5
+ useCustomerHeroClient
6
+ } from "./chunk-BB2DI7WR.js";
7
+
8
+ // src/preview.tsx
9
+ import { useEffect, useMemo } from "react";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ function PreviewBootstrap({
12
+ config,
13
+ banner
14
+ }) {
15
+ const client = useCustomerHeroClient();
16
+ useEffect(() => {
17
+ client.__seedForPreview(config, { banner: banner ?? null });
18
+ }, [client]);
19
+ const configKey = JSON.stringify(config);
20
+ const bannerKey = JSON.stringify(banner ?? null);
21
+ useEffect(() => {
22
+ client.__seedForPreview(config, { banner: banner ?? null });
23
+ }, [client, configKey, bannerKey]);
24
+ return null;
25
+ }
26
+ var wrapperStyleBase = {
27
+ position: "relative",
28
+ overflow: "hidden"
29
+ };
30
+ function PreviewWidget({
31
+ style,
32
+ className,
33
+ banner,
34
+ ...config
35
+ }) {
36
+ const initialConfig = useMemo(() => config, []);
37
+ return /* @__PURE__ */ jsx(
38
+ "div",
39
+ {
40
+ className,
41
+ style: { ...wrapperStyleBase, ...style },
42
+ "data-customerhero-preview": "true",
43
+ children: /* @__PURE__ */ jsxs(CustomerHeroProvider, { disableAutoFetch: true, ...initialConfig, children: [
44
+ /* @__PURE__ */ jsx(PreviewBootstrap, { config, banner }),
45
+ /* @__PURE__ */ jsx(ChatBubble, { embedded: true }),
46
+ /* @__PURE__ */ jsx(ChatWindow, { embedded: true })
47
+ ] })
48
+ }
49
+ );
50
+ }
51
+ export {
52
+ PreviewWidget
53
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@customerhero/react",
3
- "version": "2.1.1",
3
+ "version": "2.3.0",
4
4
  "private": false,
5
5
  "description": "React components for embedding the CustomerHero chat widget.",
6
6
  "keywords": [
@@ -34,6 +34,16 @@
34
34
  "types": "./dist/index.d.cts",
35
35
  "default": "./dist/index.cjs"
36
36
  }
37
+ },
38
+ "./preview": {
39
+ "import": {
40
+ "types": "./dist/preview.d.ts",
41
+ "default": "./dist/preview.js"
42
+ },
43
+ "require": {
44
+ "types": "./dist/preview.d.cts",
45
+ "default": "./dist/preview.cjs"
46
+ }
37
47
  }
38
48
  },
39
49
  "main": "./dist/index.cjs",
@@ -58,7 +68,7 @@
58
68
  "react": ">=18"
59
69
  },
60
70
  "devDependencies": {
61
- "@customerhero/js": "^2.1.1",
71
+ "@customerhero/js": "^2.3.0",
62
72
  "@testing-library/react": "^16.1.0",
63
73
  "@types/react": "^19.0.0",
64
74
  "@types/react-dom": "^19.0.0",