Skip to content

Commit e532f4e

Browse files
authored
Add feedback widget (#217)
Signed-off-by: Dan Barr <[email protected]> Co-authored-by: Dan Barr <[email protected]>
1 parent 1ea85c8 commit e532f4e

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed

docusaurus.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ const config: Config = {
1919
debug: false,
2020
},
2121
],
22+
[
23+
'docusaurus-pushfeedback',
24+
{
25+
project: '8lp399irfx',
26+
buttonStyle: 'dark',
27+
buttonPosition: 'bottom-right',
28+
modalPosition: 'bottom-right',
29+
customFont: true,
30+
},
31+
],
2232
[
2333
'./plugins/mcp-metadata-plugin',
2434
{

package-lock.json

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
"@mdx-js/react": "^3.1.1",
3131
"clsx": "^2.1.1",
3232
"docusaurus-json-schema-plugin": "1.15.0",
33+
"docusaurus-pushfeedback": "^1.0.9",
3334
"glob": "^11.0.3",
3435
"prism-react-renderer": "^2.4.1",
36+
"pushfeedback-react": "^0.1.76",
3537
"react": "^19.1.1",
3638
"react-dom": "^19.1.1",
3739
"redocusaurus": "2.5.0"

src/css/custom.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
--ifm-color-primary-lightest: #340cd7;
4848
--ifm-code-font-size: 95%;
4949
--docusaurus-highlighted-code-line-bg: rgb(0 0 0 / 10%);
50+
51+
--feedback-primary-color: var(--ifm-color-primary) !important;
5052
}
5153

5254
/* Overrides for dark mode. */
@@ -77,6 +79,8 @@ html[data-theme='dark'] {
7779
--ifm-color-primary-lighter: #b3d6ff;
7880
--ifm-color-primary-lightest: #ebf4ff;
7981
--docusaurus-highlighted-code-line-bg: rgb(66 66 66 / 35%);
82+
83+
--feedback-primary-color: var(--ifm-color-primary-darker) !important;
8084
}
8185

8286
thead th {

src/theme/DocItem/Footer/index.tsx

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import React, { type ReactNode, useState } from 'react';
2+
import Footer from '@theme-original/DocItem/Footer';
3+
import type FooterType from '@theme/DocItem/Footer';
4+
import type { WrapperProps } from '@docusaurus/types';
5+
6+
import { FeedbackButton } from 'pushfeedback-react';
7+
import 'pushfeedback/dist/pushfeedback/pushfeedback.css';
8+
9+
type Props = WrapperProps<typeof FooterType>;
10+
11+
function FeedbackWidget(): React.JSX.Element {
12+
const [selected, setSelected] = useState<string | null>(null); // Track the selected button
13+
14+
const buttonThumbsUp = (
15+
<svg
16+
xmlns='http://www.w3.org/2000/svg'
17+
width='20'
18+
height='20'
19+
viewBox='0 0 24 24'
20+
fill='none'
21+
stroke='currentColor'
22+
strokeWidth='2'
23+
strokeLinecap='round'
24+
strokeLinejoin='round'
25+
>
26+
<path d='M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3'></path>
27+
</svg>
28+
);
29+
30+
const buttonThumbsDown = (
31+
<svg
32+
xmlns='http://www.w3.org/2000/svg'
33+
width='20'
34+
height='20'
35+
viewBox='0 0 24 24'
36+
fill='none'
37+
stroke='currentColor'
38+
strokeWidth='2'
39+
strokeLinecap='round'
40+
strokeLinejoin='round'
41+
>
42+
<path d='M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17'></path>
43+
</svg>
44+
);
45+
46+
// Replace with your PROJECT_ID
47+
const projectId: string = '8lp399irfx';
48+
49+
const handleButtonClick = (rating: string): void => {
50+
setSelected(rating);
51+
};
52+
53+
return (
54+
<div className='feedback-widget margin-top--md margin-bottom--md'>
55+
<div className='margin-bottom--sm'>
56+
<b>Was this helpful?</b>
57+
</div>
58+
<span className='feedback-widget-positive'>
59+
<FeedbackButton
60+
project={projectId}
61+
rating={1}
62+
custom-font='True'
63+
button-style='default'
64+
modal-position='center'
65+
submit={true}
66+
>
67+
<button
68+
className={`feedback-button ${selected === '1' ? 'selected' : ''}`}
69+
title='Yes'
70+
onClick={() => handleButtonClick('1')}
71+
>
72+
{buttonThumbsUp}
73+
</button>
74+
</FeedbackButton>
75+
</span>
76+
<span className='feedback-widget-negative margin-left--sm'>
77+
<FeedbackButton
78+
project={projectId}
79+
rating={0}
80+
custom-font='True'
81+
button-style='default'
82+
modal-position='center'
83+
submit={true}
84+
>
85+
<button
86+
className={`feedback-button ${selected === '0' ? 'selected' : ''}`}
87+
title='No'
88+
onClick={() => handleButtonClick('0')}
89+
>
90+
{buttonThumbsDown}
91+
</button>
92+
</FeedbackButton>
93+
</span>
94+
95+
{/* Style Block for Button Hover */}
96+
<style>
97+
{`
98+
.feedback-widget button {
99+
transition: background-color 0.3s, color 0.3s, border-color 0.3s;
100+
border: 2px solid var(--feedback-primary-color);
101+
color: var(--feedback-primary-color);
102+
background-color: transparent;
103+
border-radius: 8px;
104+
padding: 8px 16px;
105+
cursor: pointer;
106+
}
107+
108+
.feedback-widget button.selected {
109+
background-color: var(--feedback-primary-color);
110+
color: white;
111+
border-color: var(--feedback-primary-color);
112+
}
113+
114+
.feedback-widget button:hover {
115+
background-color: var(--feedback-primary-color);
116+
color: white;
117+
border-color: var(--feedback-primary-color);
118+
}
119+
`}
120+
</style>
121+
</div>
122+
);
123+
}
124+
125+
export default function FooterWrapper(props: Props): ReactNode {
126+
return (
127+
<>
128+
<FeedbackWidget />
129+
<Footer {...props} />
130+
</>
131+
);
132+
}

0 commit comments

Comments
 (0)