|
| 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