-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
236 lines (219 loc) · 7.67 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html lang="en" class="">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="stylesheet" href="/sandbox-styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- import any custom fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600&family=Space+Mono&display=swap"
rel="stylesheet"
/>
<title>Sandbox widget embed</title>
<!-- widget script (required) -->
<script
type="module"
src="https://unpkg.com/@inkeep/uikit-js@latest/dist/embed.js"
defer
></script>
</head>
<body>
<div id="root">
<div id="app">
<div class="toolbar">
<button id="color-mode-toggle">🌞</button>
<button id="custom-trigger-button">toggle custom widget</button>
<div id="search-bar"></div>
</div>
<div class="inkeep-widget-root">
<label for="component-type">select a filter</label>
<select name="environment" id="environment-select">
<option value="">--Please choose an option--</option>
<option value="Narnia">Narnia</option>
<option value="Atlantis">Atlantis</option>
<option value="Neverland">Neverland</option>
</select>
<div id="embedded-chat"></div>
<div id="custom-trigger"></div>
</div>
</div>
</div>
<!-- script to toggle color mode in parent ui (for example purposes only) -->
<script src="./color-mode.js"></script>
<script type="module">
const envConfig = {
INTEGRATION_ID: import.meta.env.VITE_INKEEP_INTEGRATION_ID ?? "",
API_KEY: import.meta.env.VITE_INKEEP_API_KEY ?? "",
ORGANIZATION_ID: import.meta.env.VITE_INKEEP_ORGANIZATION_ID ?? "",
};
// initialize with baseSettings
const inkeep = Inkeep({
// baseSettings here
integrationId: envConfig.INTEGRATION_ID || "", // required
apiKey: envConfig.API_KEY || "", // required
organizationId: envConfig.ORGANIZATION_ID || "", // required
organizationDisplayName: "Inkeep",
primaryBrandColor: "black",
userId: "",
userEmail: "dev@inkeep.com",
userName: "Inkeep",
optOutAllAnalytics: true,
optOutAnalyticalCookies: true,
optOutFunctionalCookies: true,
});
// optional used to sync widget color mode with UI
const colorModeSync = {
observedElement: document.documentElement, // element to observe for color mode changes
// Function that return true if dark mode otherwise false
isDarkModeCallback: (el) => {
return el.classList.contains("dark");
},
colorModeAttribute: "class", // attribute that changes on the observedElement when colorMode changes (ex. `"class"` or `"data-theme"`)
// another common example: if using data attributes instead of classes for dark mode
// isDarkModeCallback: (el) => {
// return el.dataset.theme === 'dark';
// },
// colorModeAttribute: 'data-theme',
};
// EmbeddedChat
const embeddedChat = inkeep.embed({
componentType: "EmbeddedChat", // required, options: 'ChatButton', 'EmbeddedChat', 'SearchBar', 'CustomTrigger'
targetElement: document.getElementById("embedded-chat"), // required (optional for CustomTrigger or ChatButton)
colorModeSync, // optional
properties: {
// optional component specific settings here
baseSettings: {
theme: {
stylesheetUrls: [
"/widget-overrides.css", // example of how to override styles via a stylesheet
],
tokens: {
fonts: {
heading: "'Space Grotesk'",
body: "'Space Grotesk'", // set custom font here
mono: "'Space Mono', monospace",
},
},
},
},
aiChatSettings: {
placeholder: "Ask me anything...",
isChatSharingEnabled: true,
shareChatUrlBasePath: "http://localhost:5175/shared-chat",
disclaimerSettings: {
isDisclaimerEnabled: true,
},
},
},
});
// ------------------------------
// SearchBar
const searchBar = inkeep.embed({
componentType: "SearchBar",
targetElement: document.getElementById("search-bar"),
colorModeSync,
properties: {
baseSettings: {
theme: {
components: {
SearchBarTrigger: {
defaultProps: {
size: "expand",
// variant: 'emphasized',
style: {
width: "100%",
},
},
},
},
},
},
aiChatSettings: {
placeholder: "Type your message here...",
isChatSharingEnabled: true,
shareChatUrlBasePath: "http://localhost:5175/shared-chat",
disclaimerSettings: {
isDisclaimerEnabled: true,
disclaimerText: "This is a disclaimer",
},
},
searchSettings: {
placeholder: "Search...",
tabSettings: {
isAllTabEnabled: true,
tabOrderByLabel: ["Resources", "Blog", "Solutions"],
rootBreadcrumbsToUseAsTabs: ["Blog"],
alwaysDisplayedTabs: ["Blog"],
},
shouldOpenLinksInNewTab: true,
},
},
});
// ------------------------------
// ChatButton
const chatButton = inkeep.embed({
componentType: "ChatButton",
colorModeSync,
properties: {
baseSettings: {
// ...additional baseSettings here
},
aiChatSettings: {
// ...additional aiChatSettings here
},
searchSettings: {
// ...additional searchSettings here
},
},
});
// ------------------------------
// CustomTrigger
const triggerButton = document.getElementById("custom-trigger-button");
triggerButton.addEventListener("click", () => {
customTrigger.render({
isOpen: true,
});
});
const onClose = () => {
customTrigger.render({
isOpen: false,
});
};
const customTrigger = inkeep.embed({
componentType: "CustomTrigger",
targetElement: document.getElementById("custom-trigger"),
colorModeSync, // optional
properties: {
// ... additional properties here
isOpen: false,
onClose,
},
});
// ------------------------------
// example of how to change a prop and re-render the component so that it updates
const environmentSelect = document.getElementById("environment-select");
// for a visual demonstration
const colorMap = {
Narnia: "#ff9463",
Atlantis: "#04e5de6",
Neverland: "#83e290",
};
environmentSelect.addEventListener("change", (e) => {
const environment = e.target.value;
embeddedChat.render({
baseSettings: {
primaryBrandColor: colorMap[environment] ?? "black",
filters: {
attributes: {
env: environment,
},
},
},
});
});
</script>
</body>
</html>