|
1 | | -<script> |
| 1 | +<!-- <script> |
2 | 2 |
|
3 | 3 | import {Inkeep} from "@inkeep/uikit-js" |
4 | 4 |
|
@@ -115,8 +115,147 @@ document.addEventListener("keydown", function (event) { |
115 | 115 | handleOpen(); |
116 | 116 | } |
117 | 117 | }); |
| 118 | +</script> --> |
| 119 | + |
| 120 | +<script> |
| 121 | + // Get the button element |
| 122 | + const inkeepTriggers = document.querySelectorAll("[kui-trigger='search']"); |
| 123 | + |
| 124 | + // Create a new div element to hold the Inkeep modal and set its id and position |
| 125 | + const inkeepDiv = document.createElement("div"); |
| 126 | + inkeepDiv.id = "inkeepModal"; |
| 127 | + inkeepDiv.style.position = "absolute"; |
| 128 | + document.body.appendChild(inkeepDiv); |
| 129 | + |
| 130 | + const handleClose = () => { |
| 131 | + inkeepWidget.render({ |
| 132 | + ...config, |
| 133 | + isOpen: false, |
| 134 | + baseSettings: undefined |
| 135 | + }); |
| 136 | + }; |
| 137 | + |
| 138 | + const handleOpen = () => { |
| 139 | + const theme = document.documentElement.getAttribute("data-theme"); |
| 140 | + const isInkeepActive = document.body.classList.contains("inkeep-active"); |
| 141 | + |
| 142 | + if (isInkeepActive) { |
| 143 | + inkeepWidget.render({ |
| 144 | + ...config, |
| 145 | + isOpen: true, |
| 146 | + baseSettings: { |
| 147 | + colorMode: { |
| 148 | + forcedColorMode: theme |
| 149 | + } |
| 150 | + } |
| 151 | + }); |
| 152 | + } else { |
| 153 | + initializeInkeep(); |
| 154 | + } |
| 155 | + }; |
| 156 | + |
| 157 | + const config = { |
| 158 | + componentType: "CustomTrigger", // required |
| 159 | + targetElement: inkeepDiv, // required |
| 160 | + properties: { |
| 161 | + isOpen: false, // required |
| 162 | + onClose: handleClose, // required |
| 163 | + onOpen: undefined, |
| 164 | + baseSettings: { |
| 165 | + apiKey: import.meta.env.PUBLIC_INKEEP_API_KEY!, // required |
| 166 | + integrationId: import.meta.env.PUBLIC_INKEEP_INTEGRATION_ID!, // required |
| 167 | + organizationId: import.meta.env.PUBLIC_INKEEP_ORGANIZATION_ID!, // required |
| 168 | + primaryBrandColor: "#0f0f0f", |
| 169 | + organizationDisplayName: "Kinde", |
| 170 | + colorMode: { |
| 171 | + enableSystem: true |
| 172 | + }, |
| 173 | + theme: { |
| 174 | + stylesheetUrls: ["/vendors/inkeep.css"] |
| 175 | + } |
| 176 | + }, |
| 177 | + aiChatSettings: { |
| 178 | + chatSubjectName: "Kinde", |
| 179 | + botAvatarSrcUrl: |
| 180 | + "https://storage.googleapis.com/organization-image-assets/kinde-botAvatarSrcUrl-1720166731622.png", |
| 181 | + botAvatarDarkSrcUrl: |
| 182 | + "https://storage.googleapis.com/organization-image-assets/kinde-botAvatarDarkSrcUrl-1720676197273.png", |
| 183 | + getHelpCallToActions: [ |
| 184 | + { |
| 185 | + name: "Slack", |
| 186 | + url: "https://join.slack.com/t/thekindecommunity/shared_invite/zt-2k5i0aeet-d6Z_2qYphcNCpj0bFa4oCg", |
| 187 | + icon: { |
| 188 | + builtIn: "FaSlack" |
| 189 | + } |
| 190 | + }, |
| 191 | + { |
| 192 | + name: "Discord", |
| 193 | + url: "https://discord.gg/wHX6j7wG5d", |
| 194 | + icon: { |
| 195 | + builtIn: "FaDiscord" |
| 196 | + } |
| 197 | + }, |
| 198 | + { |
| 199 | + name: "Github", |
| 200 | + url: "https://github.com/kinde-oss", |
| 201 | + icon: { |
| 202 | + builtIn: "FaGithub" |
| 203 | + } |
| 204 | + } |
| 205 | + ], |
| 206 | + quickQuestions: [ |
| 207 | + "Where do I set up my authentication methods?", |
| 208 | + "How can I be notified when certain events happen?", |
| 209 | + "What's the quickest way to get started with Kinde?" |
| 210 | + ] |
| 211 | + } |
| 212 | + } |
| 213 | + }; |
| 214 | + |
| 215 | + // Embed the widget using the `Inkeep.embed()` function. |
| 216 | + let inkeepWidget: any; |
| 217 | + // Add event listener to open the Inkeep modal when the button is clicked |
| 218 | + inkeepTriggers.forEach((trigger) => trigger.addEventListener("click", handleOpen)); |
| 219 | + |
| 220 | + function initializeInkeep() { |
| 221 | + import("@inkeep/uikit-js/dist/embed.js") |
| 222 | + .then((lib) => { |
| 223 | + inkeepWidget = lib.Inkeep(config.properties.baseSettings).embed(config as any); // |
| 224 | + |
| 225 | + document.body.classList.add("inkeep-active"); |
| 226 | + }) |
| 227 | + .then(() => { |
| 228 | + const theme = document.documentElement.getAttribute("data-theme"); |
| 229 | + |
| 230 | + inkeepWidget.render({ |
| 231 | + ...config, |
| 232 | + isOpen: true, |
| 233 | + baseSettings: { |
| 234 | + colorMode: { |
| 235 | + forcedColorMode: theme |
| 236 | + } |
| 237 | + } |
| 238 | + }); |
| 239 | + }) |
| 240 | + .catch((error) => console.log(error)); |
| 241 | + } |
| 242 | + |
| 243 | + document.addEventListener("keydown", function (event) { |
| 244 | + // Check if the `/` key is pressed |
| 245 | + if (event.key === "/" && !event.metaKey && !event.ctrlKey) { |
| 246 | + event.preventDefault(); |
| 247 | + handleOpen(); |
| 248 | + } |
| 249 | + |
| 250 | + // Check if Cmd (Meta) + K or Ctrl + K is pressed |
| 251 | + if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") { |
| 252 | + event.preventDefault(); |
| 253 | + handleOpen(); |
| 254 | + } |
| 255 | + }); |
118 | 256 | </script> |
119 | 257 |
|
| 258 | + |
120 | 259 | <style is:inline> |
121 | 260 | [data-theme="dark"] .ikp-modal__container { |
122 | 261 | filter: invert(0); |
|
0 commit comments