@openk9ui/openk9-chatbot 3.0.1
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 +50 -0
- package/dist/SingleMessage-Dyc7W2JZ.js +13738 -0
- package/dist/assets/Chatbot.css +107 -0
- package/dist/components/Chatbot.js +399 -0
- package/dist/components/LanguageContext.js +53 -0
- package/dist/components/Search.js +91 -0
- package/dist/components/SingleMessage.js +9 -0
- package/dist/components/Translate.js +69 -0
- package/dist/components/client.js +119 -0
- package/dist/components/styled.js +21 -0
- package/dist/components/useFocusTrap.js +95 -0
- package/dist/components/useGenerateResponse.js +271 -0
- package/dist/components/useLanguage.js +12 -0
- package/dist/lib/components/Chatbot.js +168 -0
- package/dist/lib/components/LanguageContext.js +63 -0
- package/dist/lib/components/Search.js +56 -0
- package/dist/lib/components/SingleMessage.js +385 -0
- package/dist/lib/components/Translate.js +71 -0
- package/dist/lib/components/client.js +170 -0
- package/dist/lib/components/styled.js +14 -0
- package/dist/lib/components/useFocusTrap.js +85 -0
- package/dist/lib/components/useGenerateResponse.js +310 -0
- package/dist/lib/components/useLanguage.js +16 -0
- package/dist/lib/main.js +8 -0
- package/dist/main.js +4 -0
- package/dist/src/theme.js +52 -0
- package/dist/types/lib/components/Chatbot.d.ts +26 -0
- package/dist/types/lib/components/LanguageContext.d.ts +12 -0
- package/dist/types/lib/components/Search.d.ts +9 -0
- package/dist/types/lib/components/SingleMessage.d.ts +19 -0
- package/dist/types/lib/components/Translate.d.ts +5 -0
- package/dist/types/lib/components/client.d.ts +91 -0
- package/dist/types/lib/components/styled.d.ts +13 -0
- package/dist/types/lib/components/useFocusTrap.d.ts +5 -0
- package/dist/types/lib/components/useGenerateResponse.d.ts +33 -0
- package/dist/types/lib/components/useLanguage.d.ts +4 -0
- package/dist/types/lib/main.d.ts +2 -0
- package/dist/types/src/theme.d.ts +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ThemeProvider, useTheme, Box, Button, IconButton } from "@mui/material";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import Search from "./Search.js";
|
|
5
|
+
import useGenerateResponse from "./useGenerateResponse.js";
|
|
6
|
+
import { c as createTheme, S as SingleMessage } from "../SingleMessage-Dyc7W2JZ.js";
|
|
7
|
+
import { useFocusTrap } from "./useFocusTrap.js";
|
|
8
|
+
import { Translate } from "./Translate.js";
|
|
9
|
+
import { LanguageProvider } from "./LanguageContext.js";
|
|
10
|
+
import '../assets/Chatbot.css';const defaultThemeK9 = createTheme({
|
|
11
|
+
breakpoints: {
|
|
12
|
+
values: {
|
|
13
|
+
xs: 0,
|
|
14
|
+
sm: 576,
|
|
15
|
+
md: 768,
|
|
16
|
+
lg: 992,
|
|
17
|
+
xl: 1200
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
palette: {
|
|
21
|
+
primary: {
|
|
22
|
+
main: "#C0272B",
|
|
23
|
+
contrastText: "#FFF",
|
|
24
|
+
dark: "#b10707",
|
|
25
|
+
light: "#e77979"
|
|
26
|
+
},
|
|
27
|
+
text: {
|
|
28
|
+
primary: "#000000",
|
|
29
|
+
secondary: "#666666"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
typography: {
|
|
33
|
+
allVariants: {
|
|
34
|
+
fontFamily: "Titillium Web"
|
|
35
|
+
},
|
|
36
|
+
fontFamily: "Titillium Web",
|
|
37
|
+
body1: {
|
|
38
|
+
fontWeight: 400,
|
|
39
|
+
fontSize: "12px",
|
|
40
|
+
lineHeight: "19px"
|
|
41
|
+
},
|
|
42
|
+
body2: {
|
|
43
|
+
fontFamily: "Roboto",
|
|
44
|
+
font: "Roboto",
|
|
45
|
+
fontWeight: 500,
|
|
46
|
+
fontSize: "10px",
|
|
47
|
+
lineHeight: "12px"
|
|
48
|
+
},
|
|
49
|
+
h5: {
|
|
50
|
+
fontWeight: 400,
|
|
51
|
+
fontSize: "12px",
|
|
52
|
+
lineHeight: "22px"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
spacing: 2,
|
|
56
|
+
shape: { borderRadius: 2 }
|
|
57
|
+
});
|
|
58
|
+
const Chatbot = ({
|
|
59
|
+
icon,
|
|
60
|
+
title,
|
|
61
|
+
initialMessage = "Benvenuti su Openk9, hai dei dubbi? non esitare a chiedere",
|
|
62
|
+
nameChatbot,
|
|
63
|
+
themeCustom,
|
|
64
|
+
language,
|
|
65
|
+
tenant,
|
|
66
|
+
callbackAuthorization
|
|
67
|
+
}) => {
|
|
68
|
+
return /* @__PURE__ */ jsx(React__default.Fragment, { children: /* @__PURE__ */ jsx(ThemeProvider, { theme: themeCustom || defaultThemeK9, children: /* @__PURE__ */ jsx(LanguageProvider, { initialLanguage: language, children: /* @__PURE__ */ jsx(
|
|
69
|
+
StructureChatbot,
|
|
70
|
+
{
|
|
71
|
+
icon,
|
|
72
|
+
title,
|
|
73
|
+
initialMessage,
|
|
74
|
+
nameChatbot,
|
|
75
|
+
tenant,
|
|
76
|
+
callbackAuthorization
|
|
77
|
+
}
|
|
78
|
+
) }) }) });
|
|
79
|
+
};
|
|
80
|
+
const StructureChatbot = ({
|
|
81
|
+
icon,
|
|
82
|
+
title,
|
|
83
|
+
initialMessage = "Benvenuti su Openk9, hai dei dubbi? non esitare a chiedere",
|
|
84
|
+
nameChatbot,
|
|
85
|
+
tenant = "",
|
|
86
|
+
callbackAuthorization
|
|
87
|
+
}) => {
|
|
88
|
+
const [isView, setIsView] = React__default.useState(false);
|
|
89
|
+
const [welcomeMessageTime, setWelcomeMessageTime] = React__default.useState("");
|
|
90
|
+
const chatbotSearchRef = React__default.useRef(null);
|
|
91
|
+
const theme = useTheme();
|
|
92
|
+
const {
|
|
93
|
+
messages,
|
|
94
|
+
generateResponse,
|
|
95
|
+
cancelAllResponses,
|
|
96
|
+
isChatting,
|
|
97
|
+
isLoading: isGenerateMessage,
|
|
98
|
+
resetMessage
|
|
99
|
+
} = useGenerateResponse({
|
|
100
|
+
initialMessages: [],
|
|
101
|
+
tenant,
|
|
102
|
+
callbackAuthorization
|
|
103
|
+
});
|
|
104
|
+
const [trapRef] = useFocusTrap(isView);
|
|
105
|
+
const messagesEndRef = React__default.useRef(null);
|
|
106
|
+
React__default.useEffect(() => {
|
|
107
|
+
if (messages && messagesEndRef.current) {
|
|
108
|
+
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
109
|
+
}
|
|
110
|
+
}, [messages]);
|
|
111
|
+
React__default.useEffect(() => {
|
|
112
|
+
const currentTime = /* @__PURE__ */ new Date();
|
|
113
|
+
setWelcomeMessageTime(
|
|
114
|
+
currentTime.toLocaleTimeString([], {
|
|
115
|
+
hour: "2-digit",
|
|
116
|
+
minute: "2-digit"
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
}, []);
|
|
120
|
+
React__default.useEffect(() => {
|
|
121
|
+
if (isView && chatbotSearchRef.current) {
|
|
122
|
+
chatbotSearchRef.current.focus();
|
|
123
|
+
}
|
|
124
|
+
}, [isView]);
|
|
125
|
+
return /* @__PURE__ */ jsxs(
|
|
126
|
+
Box,
|
|
127
|
+
{
|
|
128
|
+
className: "openk9-chatbot-structure",
|
|
129
|
+
ref: trapRef,
|
|
130
|
+
sx: {
|
|
131
|
+
display: "flex",
|
|
132
|
+
justifyContent: "flex-start",
|
|
133
|
+
alignItems: "flex-end",
|
|
134
|
+
bgcolor: "trasparent",
|
|
135
|
+
flexDirection: "column",
|
|
136
|
+
gap: "12px"
|
|
137
|
+
},
|
|
138
|
+
children: [
|
|
139
|
+
isView && /* @__PURE__ */ jsxs(
|
|
140
|
+
Box,
|
|
141
|
+
{
|
|
142
|
+
className: "openk9-chatbot-container",
|
|
143
|
+
sx: {
|
|
144
|
+
position: { xs: "fixed", sm: "unset" },
|
|
145
|
+
top: { xs: "0", sm: "unset" },
|
|
146
|
+
left: { xs: "0", sm: "unset" },
|
|
147
|
+
display: "flex",
|
|
148
|
+
flexDirection: "column",
|
|
149
|
+
border: {
|
|
150
|
+
xs: "unset",
|
|
151
|
+
sm: `1px solid ${theme.palette.divider}`
|
|
152
|
+
},
|
|
153
|
+
borderRadius: { xs: "unset", sm: theme.shape.borderRadius * 2 },
|
|
154
|
+
backgroundColor: theme.palette.primary.contrastText,
|
|
155
|
+
height: { xs: "100vh", sm: "460px" },
|
|
156
|
+
width: { xs: "100vw", sm: "365px" },
|
|
157
|
+
boxShadow: theme.shadows[3],
|
|
158
|
+
zIndex: 2
|
|
159
|
+
},
|
|
160
|
+
children: [
|
|
161
|
+
/* @__PURE__ */ jsx(
|
|
162
|
+
ChatbotHeader,
|
|
163
|
+
{
|
|
164
|
+
title,
|
|
165
|
+
icon,
|
|
166
|
+
isChatting,
|
|
167
|
+
resetMessage,
|
|
168
|
+
setIsView
|
|
169
|
+
}
|
|
170
|
+
),
|
|
171
|
+
/* @__PURE__ */ jsx(
|
|
172
|
+
MessageList,
|
|
173
|
+
{
|
|
174
|
+
messages,
|
|
175
|
+
icon,
|
|
176
|
+
welcomeMessageTime,
|
|
177
|
+
initialMessage,
|
|
178
|
+
isGenerateMessage,
|
|
179
|
+
messagesEndRef,
|
|
180
|
+
nameChatbot
|
|
181
|
+
}
|
|
182
|
+
),
|
|
183
|
+
/* @__PURE__ */ jsx(
|
|
184
|
+
Search,
|
|
185
|
+
{
|
|
186
|
+
handleSearch: generateResponse,
|
|
187
|
+
cancelAllResponses,
|
|
188
|
+
isChatting,
|
|
189
|
+
icon,
|
|
190
|
+
chatbotSearchRef
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
),
|
|
196
|
+
/* @__PURE__ */ jsx(
|
|
197
|
+
Button,
|
|
198
|
+
{
|
|
199
|
+
className: "openk9-toggle-chatbot-button",
|
|
200
|
+
"aria-label": isView ? Translate({ label: "closeChatbot" }) : Translate({ label: "openChatbot" }),
|
|
201
|
+
sx: {
|
|
202
|
+
borderRadius: "50%",
|
|
203
|
+
color: "white",
|
|
204
|
+
display: { xs: isView ? "none" : "unset", sm: "flex" },
|
|
205
|
+
minWidth: "56px",
|
|
206
|
+
width: "56px",
|
|
207
|
+
height: "56px",
|
|
208
|
+
boxShadow: theme.shadows[3],
|
|
209
|
+
background: theme.palette.primary.main,
|
|
210
|
+
padding: 0,
|
|
211
|
+
"&:hover": {
|
|
212
|
+
background: theme.palette.primary.light,
|
|
213
|
+
boxShadow: theme.shadows[3]
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
onClick: () => setIsView(!isView),
|
|
217
|
+
children: /* @__PURE__ */ jsx(
|
|
218
|
+
Box,
|
|
219
|
+
{
|
|
220
|
+
className: "openk9-toggle-icon-wrapper",
|
|
221
|
+
sx: {
|
|
222
|
+
justifyContent: "center",
|
|
223
|
+
display: "flex",
|
|
224
|
+
height: "100%",
|
|
225
|
+
width: "100%",
|
|
226
|
+
alignItems: "center"
|
|
227
|
+
},
|
|
228
|
+
children: isView ? icon.closeIcon : icon.buttonIcon
|
|
229
|
+
}
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
};
|
|
237
|
+
const ChatbotHeader = ({ title, icon, isChatting, resetMessage, setIsView }) => {
|
|
238
|
+
const theme = useTheme();
|
|
239
|
+
return /* @__PURE__ */ jsxs(
|
|
240
|
+
Box,
|
|
241
|
+
{
|
|
242
|
+
className: "openk9-chatbot-header",
|
|
243
|
+
sx: {
|
|
244
|
+
display: "flex",
|
|
245
|
+
alignItems: "center",
|
|
246
|
+
borderBottom: `1px solid ${theme.palette.divider}`,
|
|
247
|
+
pb: theme.spacing(2),
|
|
248
|
+
mb: theme.spacing(2),
|
|
249
|
+
gap: theme.spacing(2),
|
|
250
|
+
padding: "12px",
|
|
251
|
+
paddingBottom: "0px",
|
|
252
|
+
marginBottom: "12px",
|
|
253
|
+
justifyContent: "space-between"
|
|
254
|
+
},
|
|
255
|
+
children: [
|
|
256
|
+
/* @__PURE__ */ jsx(
|
|
257
|
+
Box,
|
|
258
|
+
{
|
|
259
|
+
className: "openk9-logo-icon",
|
|
260
|
+
sx: {
|
|
261
|
+
minWidth: 0,
|
|
262
|
+
padding: 0
|
|
263
|
+
},
|
|
264
|
+
children: icon.logoIcon
|
|
265
|
+
}
|
|
266
|
+
),
|
|
267
|
+
/* @__PURE__ */ jsx("div", { children: title }),
|
|
268
|
+
/* @__PURE__ */ jsxs(
|
|
269
|
+
Box,
|
|
270
|
+
{
|
|
271
|
+
className: "openk9-header-buttons",
|
|
272
|
+
display: "flex",
|
|
273
|
+
gap: "5px",
|
|
274
|
+
alignItems: "center",
|
|
275
|
+
children: [
|
|
276
|
+
/* @__PURE__ */ jsx(
|
|
277
|
+
Button,
|
|
278
|
+
{
|
|
279
|
+
className: "openk9-refresh-button",
|
|
280
|
+
disabled: isChatting,
|
|
281
|
+
onClick: resetMessage,
|
|
282
|
+
"aria-label": Translate({ label: "clearChat" }),
|
|
283
|
+
sx: {
|
|
284
|
+
minWidth: 0,
|
|
285
|
+
padding: 0,
|
|
286
|
+
height: "24px",
|
|
287
|
+
width: "24px"
|
|
288
|
+
},
|
|
289
|
+
children: icon.refreshChatIcon
|
|
290
|
+
}
|
|
291
|
+
),
|
|
292
|
+
/* @__PURE__ */ jsx(
|
|
293
|
+
IconButton,
|
|
294
|
+
{
|
|
295
|
+
className: "openk9-close-button",
|
|
296
|
+
onClick: () => setIsView(false),
|
|
297
|
+
role: "button",
|
|
298
|
+
size: "small",
|
|
299
|
+
sx: { display: { xs: "block", sm: "none" } },
|
|
300
|
+
"aria-label": Translate({ label: "closeChatbot" }),
|
|
301
|
+
children: icon.closeModal
|
|
302
|
+
}
|
|
303
|
+
)
|
|
304
|
+
]
|
|
305
|
+
}
|
|
306
|
+
)
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
};
|
|
311
|
+
const MessageList = ({
|
|
312
|
+
messages,
|
|
313
|
+
icon,
|
|
314
|
+
initialMessage,
|
|
315
|
+
isGenerateMessage,
|
|
316
|
+
messagesEndRef,
|
|
317
|
+
nameChatbot,
|
|
318
|
+
welcomeMessageTime = ""
|
|
319
|
+
}) => /* @__PURE__ */ jsx(
|
|
320
|
+
Box,
|
|
321
|
+
{
|
|
322
|
+
className: "openk9-message-list-container",
|
|
323
|
+
component: "section",
|
|
324
|
+
sx: {
|
|
325
|
+
flex: 1,
|
|
326
|
+
display: "flex",
|
|
327
|
+
flexDirection: "column",
|
|
328
|
+
overflow: "hidden"
|
|
329
|
+
},
|
|
330
|
+
children: /* @__PURE__ */ jsxs(
|
|
331
|
+
Box,
|
|
332
|
+
{
|
|
333
|
+
className: "openk9-message-list",
|
|
334
|
+
sx: {
|
|
335
|
+
flex: 1,
|
|
336
|
+
overflowY: "auto",
|
|
337
|
+
paddingInline: "16px",
|
|
338
|
+
gap: "12px",
|
|
339
|
+
display: "flex",
|
|
340
|
+
flexDirection: "column",
|
|
341
|
+
alignItems: "flex-start",
|
|
342
|
+
bgcolor: "transparent"
|
|
343
|
+
},
|
|
344
|
+
children: [
|
|
345
|
+
/* @__PURE__ */ jsx(
|
|
346
|
+
SingleMessage,
|
|
347
|
+
{
|
|
348
|
+
contentMessage: initialMessage,
|
|
349
|
+
isChatbot: true,
|
|
350
|
+
timeMessage: welcomeMessageTime,
|
|
351
|
+
icon: icon.chatbotIcon,
|
|
352
|
+
isLoading: false,
|
|
353
|
+
nameChatbot
|
|
354
|
+
}
|
|
355
|
+
),
|
|
356
|
+
messages.length > 0 && messages.map((message, index) => {
|
|
357
|
+
const sendTime = (message == null ? void 0 : message.sendTime) ? new Date(message == null ? void 0 : message.sendTime).toLocaleTimeString([], {
|
|
358
|
+
hour: "2-digit",
|
|
359
|
+
minute: "2-digit"
|
|
360
|
+
}) : "";
|
|
361
|
+
const responseTime = (message == null ? void 0 : message.responseTime) ? new Date(message == null ? void 0 : message.responseTime).toLocaleTimeString([], {
|
|
362
|
+
hour: "2-digit",
|
|
363
|
+
minute: "2-digit"
|
|
364
|
+
}) : (message == null ? void 0 : message.responseTime) || "";
|
|
365
|
+
return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
366
|
+
/* @__PURE__ */ jsx(
|
|
367
|
+
SingleMessage,
|
|
368
|
+
{
|
|
369
|
+
contentMessage: message.question,
|
|
370
|
+
isChatbot: false,
|
|
371
|
+
timeMessage: sendTime,
|
|
372
|
+
icon: icon.userIcon,
|
|
373
|
+
isLoading: false
|
|
374
|
+
}
|
|
375
|
+
),
|
|
376
|
+
/* @__PURE__ */ jsx(
|
|
377
|
+
SingleMessage,
|
|
378
|
+
{
|
|
379
|
+
contentMessage: message.answer,
|
|
380
|
+
status: message.status,
|
|
381
|
+
sources: message == null ? void 0 : message.sources,
|
|
382
|
+
isChatbot: true,
|
|
383
|
+
timeMessage: responseTime,
|
|
384
|
+
icon: icon.chatbotIcon,
|
|
385
|
+
isLoading: (isGenerateMessage == null ? void 0 : isGenerateMessage.id) === message.id && (isGenerateMessage == null ? void 0 : isGenerateMessage.isLoading),
|
|
386
|
+
nameChatbot
|
|
387
|
+
}
|
|
388
|
+
),
|
|
389
|
+
index === messages.length - 1 && /* @__PURE__ */ jsx("div", { ref: messagesEndRef })
|
|
390
|
+
] }, index);
|
|
391
|
+
})
|
|
392
|
+
]
|
|
393
|
+
}
|
|
394
|
+
)
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
export {
|
|
398
|
+
Chatbot as default
|
|
399
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useState, useEffect } from "react";
|
|
3
|
+
const LanguageContext = createContext(
|
|
4
|
+
void 0
|
|
5
|
+
);
|
|
6
|
+
function remappingLanguage(language) {
|
|
7
|
+
switch (language) {
|
|
8
|
+
case "en":
|
|
9
|
+
return "en_US";
|
|
10
|
+
case "it":
|
|
11
|
+
return "it_IT";
|
|
12
|
+
case "es":
|
|
13
|
+
return "es_ES";
|
|
14
|
+
case "de":
|
|
15
|
+
return "de_DE";
|
|
16
|
+
case "fr":
|
|
17
|
+
return "fr_FR";
|
|
18
|
+
default:
|
|
19
|
+
return language;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const LanguageProvider = ({
|
|
23
|
+
children,
|
|
24
|
+
initialLanguage
|
|
25
|
+
}) => {
|
|
26
|
+
const [language, setLanguage] = useState(
|
|
27
|
+
initialLanguage ? remappingLanguage(initialLanguage) : remappingLanguage(document.documentElement.lang || "en")
|
|
28
|
+
);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (initialLanguage) {
|
|
31
|
+
setLanguage(remappingLanguage(initialLanguage));
|
|
32
|
+
}
|
|
33
|
+
}, [initialLanguage]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const handleLangChange = () => {
|
|
36
|
+
setLanguage(remappingLanguage(document.documentElement.lang || "en"));
|
|
37
|
+
};
|
|
38
|
+
const observer = new MutationObserver((mutationsList) => {
|
|
39
|
+
for (const mutation of mutationsList) {
|
|
40
|
+
if (mutation.type === "attributes" && mutation.attributeName === "lang") {
|
|
41
|
+
handleLangChange();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
observer.observe(document.documentElement, { attributes: true });
|
|
46
|
+
return () => observer.disconnect();
|
|
47
|
+
}, []);
|
|
48
|
+
return /* @__PURE__ */ jsx(LanguageContext.Provider, { value: { language, setLanguage }, children });
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
LanguageProvider,
|
|
52
|
+
LanguageContext as default
|
|
53
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme, Box, TextField, Button } from "@mui/material";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import { Translate } from "./Translate.js";
|
|
5
|
+
function Search({
|
|
6
|
+
handleSearch,
|
|
7
|
+
isChatting,
|
|
8
|
+
icon,
|
|
9
|
+
chatbotSearchRef
|
|
10
|
+
}) {
|
|
11
|
+
const [search, setSearch] = React__default.useState("");
|
|
12
|
+
const theme = useTheme();
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
"form",
|
|
15
|
+
{
|
|
16
|
+
className: "openk9-search-form",
|
|
17
|
+
onSubmit: (event) => {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
handleSearch(search);
|
|
20
|
+
setSearch("");
|
|
21
|
+
},
|
|
22
|
+
style: {
|
|
23
|
+
display: "flex",
|
|
24
|
+
gap: "15px",
|
|
25
|
+
padding: "12px",
|
|
26
|
+
borderTop: "1px solid #C7C7C7C7"
|
|
27
|
+
},
|
|
28
|
+
children: /* @__PURE__ */ jsxs(
|
|
29
|
+
Box,
|
|
30
|
+
{
|
|
31
|
+
className: "openk9-search-box",
|
|
32
|
+
display: "flex",
|
|
33
|
+
width: "100%",
|
|
34
|
+
gap: 1,
|
|
35
|
+
children: [
|
|
36
|
+
/* @__PURE__ */ jsx(
|
|
37
|
+
TextField,
|
|
38
|
+
{
|
|
39
|
+
className: "openk9-search-input",
|
|
40
|
+
fullWidth: true,
|
|
41
|
+
inputRef: chatbotSearchRef,
|
|
42
|
+
variant: "outlined",
|
|
43
|
+
value: search,
|
|
44
|
+
onChange: (event) => setSearch(event.currentTarget.value),
|
|
45
|
+
placeholder: Translate({ label: "customPlaceholder" }),
|
|
46
|
+
sx: { width: "100%", background: "white" },
|
|
47
|
+
inputProps: {
|
|
48
|
+
style: {
|
|
49
|
+
padding: 0,
|
|
50
|
+
paddingInline: "6px",
|
|
51
|
+
height: "29px",
|
|
52
|
+
fontSize: "12px",
|
|
53
|
+
fontWeight: "400",
|
|
54
|
+
lineHeight: "18.25px",
|
|
55
|
+
textAlign: "left",
|
|
56
|
+
borderRadius: theme.shape.borderRadius * 2
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
/* @__PURE__ */ jsx(
|
|
62
|
+
Button,
|
|
63
|
+
{
|
|
64
|
+
className: "openk9-search-button",
|
|
65
|
+
type: "submit",
|
|
66
|
+
variant: "contained",
|
|
67
|
+
"aria-label": Translate({ label: "startQuestion" }),
|
|
68
|
+
color: "primary",
|
|
69
|
+
sx: {
|
|
70
|
+
backgroundColor: theme.palette.primary.main,
|
|
71
|
+
color: theme.palette.primary.contrastText,
|
|
72
|
+
stroke: "white",
|
|
73
|
+
fill: "transparent",
|
|
74
|
+
minWidth: "29px",
|
|
75
|
+
height: "29px",
|
|
76
|
+
padding: 0,
|
|
77
|
+
borderRadius: theme.shape.borderRadius
|
|
78
|
+
},
|
|
79
|
+
disabled: search === "" || isChatting,
|
|
80
|
+
children: icon.searchIcon
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
Search as default
|
|
91
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useLanguage } from "./useLanguage.js";
|
|
2
|
+
function Translate({ label }) {
|
|
3
|
+
var _a;
|
|
4
|
+
const { language } = useLanguage();
|
|
5
|
+
const htmlLang = language;
|
|
6
|
+
const translation = (_a = translations[label]) == null ? void 0 : _a[htmlLang];
|
|
7
|
+
return translation || label;
|
|
8
|
+
}
|
|
9
|
+
const translations = {
|
|
10
|
+
closeChatbot: {
|
|
11
|
+
it_IT: "Chiudi il chatbot",
|
|
12
|
+
en_US: "Close the chatbot",
|
|
13
|
+
fr_FR: "Fermez le chatbot",
|
|
14
|
+
es_ES: "Cerrar el chatbot",
|
|
15
|
+
de_DE: "Schließen Sie den Chatbot"
|
|
16
|
+
},
|
|
17
|
+
openChatbot: {
|
|
18
|
+
it_IT: "Apri il chatbot",
|
|
19
|
+
en_US: "Open the chatbot",
|
|
20
|
+
fr_FR: "Ouvrir le chatbot",
|
|
21
|
+
es_ES: "Abrir el chatbot",
|
|
22
|
+
de_DE: "Öffnen Sie den Chatbot"
|
|
23
|
+
},
|
|
24
|
+
clearChat: {
|
|
25
|
+
it_IT: "Svuota la chat",
|
|
26
|
+
en_US: "Clear the chat",
|
|
27
|
+
fr_FR: "Effacer le chat",
|
|
28
|
+
es_ES: "Borrar el chat",
|
|
29
|
+
de_DE: "Leeren Sie den Chat"
|
|
30
|
+
},
|
|
31
|
+
startQuestion: {
|
|
32
|
+
it_IT: "Fai partire una domanda",
|
|
33
|
+
en_US: "Start a question",
|
|
34
|
+
fr_FR: "Commencez une question",
|
|
35
|
+
es_ES: "Iniciar una pregunta",
|
|
36
|
+
de_DE: "Starten Sie eine Frage"
|
|
37
|
+
},
|
|
38
|
+
youSendMessage: {
|
|
39
|
+
it_IT: "tu hai mandato un messaggio alle ",
|
|
40
|
+
en_US: "you sent a message at ",
|
|
41
|
+
fr_FR: "vous avez envoyé un message à ",
|
|
42
|
+
es_ES: "tú enviaste un mensaje a las ",
|
|
43
|
+
de_DE: "du hast eine Nachricht um "
|
|
44
|
+
},
|
|
45
|
+
sendMessage: {
|
|
46
|
+
it_IT: "ha mandato un messaggio alle ",
|
|
47
|
+
en_US: "sent a message at ",
|
|
48
|
+
fr_FR: "a envoyé un message à ",
|
|
49
|
+
es_ES: "envió un mensaje a las ",
|
|
50
|
+
de_DE: "hat eine Nachricht um "
|
|
51
|
+
},
|
|
52
|
+
customPlaceholder: {
|
|
53
|
+
it_IT: "scrivi il tuo messaggio...",
|
|
54
|
+
en_US: "write your message...",
|
|
55
|
+
fr_FR: "écris ton message...",
|
|
56
|
+
es_ES: "escribe tu mensaje...",
|
|
57
|
+
de_DE: "Schreiben Sie Ihre Nachricht..."
|
|
58
|
+
},
|
|
59
|
+
searchLabel: {
|
|
60
|
+
it_IT: "Cerca nel chatbot",
|
|
61
|
+
en_US: "Search in the chatbot",
|
|
62
|
+
fr_FR: "Rechercher dans le chatbot",
|
|
63
|
+
es_ES: "Buscar en el chatbot",
|
|
64
|
+
de_DE: "Im Chatbot suchen"
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
Translate
|
|
69
|
+
};
|