|
1 | | -import React from 'react'; |
| 1 | +import React, { useState } from 'react'; |
2 | 2 | import Footer from '@theme-original/DocItem/Footer'; |
3 | 3 |
|
| 4 | +function FeedbackWidget() { |
| 5 | + const [selected, setSelected] = useState(null); // Track the selected button |
4 | 6 |
|
| 7 | + const buttonThumbsUp = ( |
| 8 | + <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> |
| 9 | + <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> |
| 10 | + </svg> |
| 11 | + ); |
| 12 | + |
| 13 | + const buttonThumbsDown = ( |
| 14 | + <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> |
| 15 | + <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> |
| 16 | + </svg> |
| 17 | + ); |
5 | 18 |
|
6 | | -function FeedbackWidget() { |
7 | | - const buttonThumbsUp = <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><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></svg>; |
8 | | - const buttonThumbsDown = <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><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></svg>; |
9 | | - // Replace with your <PROJECT_ID> |
10 | 19 | const projectId = 'wlkz1eomrs'; |
11 | 20 |
|
12 | | - return( |
13 | | - <div className="feedback-widget margin-top--md margin-bottom--md"> |
14 | | - <div className="margin-bottom--sm"> |
15 | | - <b>Was this helpful?</b> |
16 | | - </div> |
17 | | - <span className="feedback-widget-positive"> |
18 | | - <feedback-button project={projectId} rating="1" custom-font="True" button-style="default" modal-position="center" success-message="Your input helps us improve every day."> |
19 | | - <button className="button button--outline button--primary button--sm" title="Yes"> |
20 | | - {buttonThumbsUp} |
21 | | - </button> |
22 | | - </feedback-button> |
23 | | - </span> |
24 | | - <span className="feedback-widget-negative margin-left--sm"> |
25 | | - <feedback-button project={projectId} rating="0" custom-font="True" button-style="default" modal-position="center" success-message="Your input helps us improve every day."> |
26 | | - <button className="button button--outline button--primary button--sm" title="No"> |
27 | | - {buttonThumbsDown} |
28 | | - </button> |
29 | | - </feedback-button> |
30 | | - </span> |
| 21 | + const handleButtonClick = (rating) => { |
| 22 | + setSelected(rating); |
| 23 | + }; |
| 24 | + |
| 25 | + return ( |
| 26 | + <div className="feedback-widget margin-top--md margin-bottom--md"> |
| 27 | + <div className="margin-bottom--sm"> |
| 28 | + <b>Was this helpful?</b> |
31 | 29 | </div> |
| 30 | + <span className="feedback-widget-positive"> |
| 31 | + <feedback-button |
| 32 | + project={projectId} |
| 33 | + rating="1" |
| 34 | + custom-font="True" |
| 35 | + button-style="default" |
| 36 | + modal-position="center" |
| 37 | + success-message="Your input helps us improve every day." |
| 38 | + submit="true" |
| 39 | + > |
| 40 | + <button |
| 41 | + className={`feedback-button ${selected === '1' ? 'selected' : ''}`} |
| 42 | + title="Yes" |
| 43 | + onClick={() => handleButtonClick('1')} |
| 44 | + > |
| 45 | + {buttonThumbsUp} |
| 46 | + </button> |
| 47 | + </feedback-button> |
| 48 | + </span> |
| 49 | + <span className="feedback-widget-negative margin-left--sm"> |
| 50 | + <feedback-button |
| 51 | + project={projectId} |
| 52 | + rating="0" |
| 53 | + custom-font="True" |
| 54 | + button-style="default" |
| 55 | + modal-position="center" |
| 56 | + success-message="Your input helps us improve every day." |
| 57 | + submit="true" |
| 58 | + > |
| 59 | + <button |
| 60 | + className={`feedback-button ${selected === '0' ? 'selected' : ''}`} |
| 61 | + title="No" |
| 62 | + onClick={() => handleButtonClick('0')} |
| 63 | + > |
| 64 | + {buttonThumbsDown} |
| 65 | + </button> |
| 66 | + </feedback-button> |
| 67 | + </span> |
| 68 | + |
| 69 | + {/* Style Block for Button Hover */} |
| 70 | + <style> |
| 71 | + {` |
| 72 | + .feedback-widget button { |
| 73 | + transition: background-color 0.3s, color 0.3s, border-color 0.3s; |
| 74 | + border: 2px solid var(--feedback-primary-color); |
| 75 | + color: var(--feedback-primary-color); |
| 76 | + background-color: transparent; |
| 77 | + border-radius: 8px; |
| 78 | + padding: 8px 16px; |
| 79 | + cursor: pointer; |
| 80 | + } |
| 81 | +
|
| 82 | + .feedback-widget button.selected { |
| 83 | + background-color: var(--feedback-primary-color); |
| 84 | + color: white; |
| 85 | + border-color: var(--feedback-primary-color); |
| 86 | + } |
| 87 | +
|
| 88 | + .feedback-widget button:hover { |
| 89 | + background-color: var(--feedback-primary-color); |
| 90 | + color: white; |
| 91 | + border-color: var(--feedback-primary-color); |
| 92 | + } |
| 93 | + `} |
| 94 | + </style> |
| 95 | + </div> |
32 | 96 | ); |
33 | 97 | } |
34 | 98 |
|
35 | 99 | export default function FooterWrapper(props) { |
36 | 100 | return ( |
37 | 101 | <> |
38 | | - |
39 | | - <FeedbackWidget/> |
| 102 | + <FeedbackWidget /> |
40 | 103 | <Footer {...props} /> |
41 | 104 | </> |
42 | 105 | ); |
|
0 commit comments