-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathKapaWidget.tsx
More file actions
42 lines (36 loc) · 1.2 KB
/
KapaWidget.tsx
File metadata and controls
42 lines (36 loc) · 1.2 KB
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
"use client";
import { useComputedColorScheme } from "@mantine/core";
import Script from "next/script";
import { useEffect } from "react";
import docsConfig from "../../docs-config";
export default function KapaWidget() {
const colorScheme = useComputedColorScheme("light");
// Sync the resolved Mantine color scheme to a data-theme attribute on <html>
// so that the Kapa widget can detect theme changes. Kapa only watches
// class, data-theme, data-color-mode, and data-bs-theme.
useEffect(() => {
document.documentElement.setAttribute("data-theme", colorScheme);
}, [colorScheme]);
if (!docsConfig.kapa) {
return null;
}
const { websiteId, projectName, projectColor, projectLogoPath } =
docsConfig.kapa;
const projectLogoUrl = new URL(
projectLogoPath,
docsConfig.siteUrl,
).toString();
return (
<Script
id="kapa-widget"
strategy="afterInteractive"
src="https://widget.kapa.ai/kapa-widget.bundle.js"
data-website-id={websiteId}
data-project-name={projectName}
data-project-color={projectColor}
data-project-logo={projectLogoUrl}
data-button-hide="true"
data-color-scheme-selector="[data-theme='dark']"
/>
);
}