Skip to content

Commit 096a7b5

Browse files
fix: add auto theme switch to the Canny widget (#8846)
Co-authored-by: sebastienlorber <[email protected]>
1 parent 829a218 commit 096a7b5

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

website/src/css/custom.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
--site-color-tooltip-background: #353738;
2020
--site-color-svg-icon-favorite: #e9669e;
2121
--site-color-checkbox-checked-bg: hsl(167deg 56% 73% / 25%);
22-
--site-color-feedback-background: #fff;
22+
--site-color-feedback-background: #f0f8ff;
2323
--docusaurus-highlighted-code-line-bg: rgb(0 0 0 / 10%);
2424
/* Use a darker color to ensure contrast, ideally we don't need important */
2525
--ifm-breadcrumb-color-active: var(--ifm-color-primary-darker) !important;
2626
--ifm-menu-color-active: var(--ifm-color-primary-darker) !important;
2727
}
2828

2929
html[data-theme='dark'] {
30-
--site-color-feedback-background: #f0f8ff;
30+
--site-color-feedback-background: #2a2929;
3131
--site-color-favorite-background: #1d1e1e;
3232
--site-color-checkbox-checked-bg: hsl(167deg 56% 73% / 10%);
3333
--docusaurus-highlighted-code-line-bg: rgb(66 66 66 / 35%);

website/src/plugins/featureRequests/FeatureRequestsPage.tsx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,51 @@
77

88
import React, {useEffect} from 'react';
99
import clsx from 'clsx';
10+
import {useColorMode} from '@docusaurus/theme-common';
1011
import Layout from '@theme/Layout';
1112

1213
import cannyScript from './cannyScript';
1314
import styles from './styles.module.css';
1415

1516
const BOARD_TOKEN = '054e0e53-d951-b14c-7e74-9eb8f9ed2f91';
1617

17-
export default function FeatureRequests({
18-
basePath,
19-
}: {
20-
basePath: string;
21-
}): JSX.Element {
18+
function useCannyTheme() {
19+
const {colorMode} = useColorMode();
20+
return colorMode === 'light' ? 'light' : 'dark';
21+
}
22+
23+
function CannyWidget({basePath}: {basePath: string}) {
2224
useEffect(() => {
2325
cannyScript();
26+
}, []);
27+
28+
const theme = useCannyTheme();
29+
useEffect(() => {
2430
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2531
const {Canny} = window as any;
2632
Canny('render', {
2733
boardToken: BOARD_TOKEN,
2834
basePath,
35+
theme,
2936
});
30-
}, [basePath]);
37+
}, [basePath, theme]);
38+
return (
39+
<main
40+
key={theme} // widget needs a full reset: unable to update the theme
41+
className={clsx('container', 'margin-vert--lg', styles.main)}
42+
data-canny
43+
/>
44+
);
45+
}
3146

47+
export default function FeatureRequests({
48+
basePath,
49+
}: {
50+
basePath: string;
51+
}): JSX.Element {
3252
return (
3353
<Layout title="Feedback" description="Docusaurus 2 Feature Requests page">
34-
<main
35-
className={clsx('container', 'margin-vert--lg', styles.main)}
36-
data-canny
37-
/>
54+
<CannyWidget basePath={basePath} />
3855
</Layout>
3956
);
4057
}

0 commit comments

Comments
 (0)