@tugitark/react-widget 1.0.0 → 1.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/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { Props } from '@tugitark/declarative-widget';
2
+ declare function Widget(p: Props): null;
3
+ export default Widget;
package/index.js CHANGED
@@ -1,7 +1,35 @@
1
1
  // Copyright (c) 2026, TugiTark. All rights reserved.
2
2
 
3
- /// <reference types="Widget" />
3
+ import { useState } from 'react';
4
+
5
+ import render from '@tugitark/declarative-widget';
6
+
7
+ function Widget(props) {
8
+ // Is this the first time this component has been rendered ever?
9
+ const [firstTime, setFirstTime] = useState(true);
10
+
11
+ function onNotification(hasNotification: boolean) {
12
+ if (props.jwtFn == null && props.user == null) {
13
+ if (firstTime) {
14
+ // Replicate FAQ internal behaviour at a per-component level.
15
+ props.onNotification?.(hasNotification);
16
+ }
17
+ } else {
18
+ props.onNotification?.(hasNotification);
19
+ }
20
+ }
21
+
22
+ function onReady() {
23
+ if (firstTime) {
24
+ setFirstTime(false);
25
+ props.onReady?.();
26
+ }
27
+ }
28
+
29
+ render({ ...props, onReady, onNotification });
30
+
31
+ return null;
32
+ }
4
33
 
5
- import Widget from './Widget.tsx';
6
34
  export default Widget;
7
35
 
package/index.md CHANGED
@@ -145,4 +145,43 @@ The following optional properties are shared with the full version:
145
145
  * `open`
146
146
  * `visible`
147
147
 
148
+ Notes
149
+ -------
150
+
151
+ While there can be only one widget on the page there can be multiple `<TugiWidget>` components at once. Which one will be used is non-deterministic - even if you have one `<TugiWidget>` with `visible={true}` and another one with `visible={false}` this will not guarantee that the visible one is the one that gets shown, the invisible one may be "shown", resulting in neither being seen. The one selected is based on internal render and update orders. Further, having two at once may result in the widget being constantly unloaded and reloaded even when nothing has changed as the underlying code flips repeatedly between them. If you have two versions of the widget shown in different circumstances then make sure that the whole component is conditional:
152
+
153
+
154
+ ```javascript
155
+ return (
156
+ disabled
157
+ ? <TugiWidget
158
+ chatDisabledReason="You are not signed in."
159
+ title="FAQ"
160
+ body="Let us help you get started."
161
+ sections={[
162
+ { title: 'Who are we?', content: 'We are Tugi Tark.' },
163
+ { title: 'What do we do?', content: 'Make awesome customer support solutions.' },
164
+ { title: 'How?', content: 'Smart AI agents who know all about your customers and services.' },
165
+ { title: 'How do I join?', content: 'Click the sign-up botton at the top-right of the page.' },
166
+ ]}
167
+ />
168
+ : <TugiWidget
169
+ jwtFn={jwtFn}
170
+ brandId="a040050697fc4b2db16acfbbad1d0da4"
171
+ brandName="Super Casino"
172
+ tenantId="gb-casinos-ltd"
173
+ httpUrl="https://app.tugi.ai/tugi.widget"
174
+ wsUrl="wss://ws.tugi.ai"
175
+ customize={{
176
+ title: 'Tugi Casino Help',
177
+ showTitle: true,
178
+ fontColor: '#2c3e50',
179
+ primaryColor: '#2c3e50',
180
+ secondaryColor: 'hsla(36, 100%, 50%, 1)',
181
+ homePageBackgroundColor: 'hsla(36, 100%, 37%, 0.2)',
182
+ homePageTextColor: '#2c3e50',
183
+ }}
184
+ />
185
+ );
186
+ ```
148
187
 
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@tugitark/react-widget",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Wraps the tugitark widget in a React component.",
5
5
  "scripts": {
6
6
  "release": "npm publish --access public"
7
7
  },
8
8
  "files": [
9
- "Widget.tsx",
9
+ "index.d.ts",
10
10
  "index.js",
11
11
  "index.md"
12
12
  ],
13
13
  "dependencies": {
14
- "@tugitark/declarative-widget": "^1.0.0",
15
- "react": ">=16.3.0"
14
+ "@tugitark/declarative-widget": "^1.0.2"
15
+ },
16
+ "peerDependencies": {
17
+ "react": ">=0.0.0"
16
18
  },
17
19
  "keywords": [
18
20
  "Typescript",
package/Widget.tsx DELETED
@@ -1,38 +0,0 @@
1
- // Copyright (c) 2026, TugiTark. All rights reserved.
2
-
3
- import * as React from 'react';
4
- import { useState } from 'react';
5
-
6
- import render, { Props } from '@tugitark/declarative-widget';
7
-
8
- function Widget(props: Props) {
9
- // Is this the first time this component has been rendered ever?
10
- const [firstTime, setFirstTime] = useState(true);
11
-
12
- function onNotification(hasNotification: boolean) {
13
- if (props.jwtFn == null && props.user == null) {
14
- if (firstTime) {
15
- // Replicate FAQ internal behaviour at a per-component level.
16
- props.onNotification?.(hasNotification);
17
- }
18
- } else {
19
- props.onNotification?.(hasNotification);
20
- }
21
- }
22
-
23
- function onReady() {
24
- if (firstTime) {
25
- setFirstTime(false);
26
- props.onReady?.();
27
- }
28
- }
29
-
30
- render({ ...props, onReady, onNotification });
31
-
32
- return (
33
- <></>
34
- );
35
- }
36
-
37
- export default Widget;
38
-