Download components/feedback-widget.js from iprofitx/helphub-knowledge-base-explorer: direct link, hf CLI and curl.
- Browser
- Download file 3.91 kB
-
https://huggingface.co/spaces/iprofitx/helphub-knowledge-base-explorer/resolve/main/components/feedback-widget.js
- Command line
-
hf download hf://spaces/iprofitx/helphub-knowledge-base-explorer/components/feedback-widget.js
-
curl -L -o feedback-widget.js https://huggingface.co/spaces/iprofitx/helphub-knowledge-base-explorer/resolve/main/components/feedback-widget.js
3.91 kB
| class FeedbackWidget extends HTMLElement { | |
| connectedCallback() { | |
| this.attachShadow({ mode: 'open' }); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| .feedback-container { | |
| margin-top: 2rem; | |
| padding-top: 2rem; | |
| border-top: 1px solid #e5e7eb; | |
| } | |
| .feedback-title { | |
| font-weight: 600; | |
| margin-bottom: 1rem; | |
| color: #374151; | |
| } | |
| .feedback-buttons { | |
| display: flex; | |
| gap: 1rem; | |
| margin-bottom: 1rem; | |
| } | |
| .feedback-button { | |
| padding: 0.5rem 1rem; | |
| border-radius: 0.375rem; | |
| font-weight: 500; | |
| cursor: pointer; | |
| transition: all 0.2s; | |
| display: flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| } | |
| .feedback-yes { | |
| background-color: #f0fdf4; | |
| color: #166534; | |
| border: 1px solid #bbf7d0; | |
| } | |
| .feedback-yes:hover { | |
| background-color: #bbf7d0; | |
| } | |
| .feedback-no { | |
| background-color: #fef2f2; | |
| color: #991b1b; | |
| border: 1px solid #fecaca; | |
| } | |
| .feedback-no:hover { | |
| background-color: #fecaca; | |
| } | |
| .feedback-form { | |
| margin-top: 1rem; | |
| display: none; | |
| } | |
| .feedback-textarea { | |
| width: 100%; | |
| padding: 0.75rem; | |
| border-radius: 0.375rem; | |
| border: 1px solid #d1d5db; | |
| min-height: 100px; | |
| margin-bottom: 0.75rem; | |
| } | |
| .feedback-submit { | |
| background-color: #3b82f6; | |
| color: white; | |
| padding: 0.5rem 1rem; | |
| border-radius: 0.375rem; | |
| font-weight: 500; | |
| cursor: pointer; | |
| border: none; | |
| } | |
| .feedback-submit:hover { | |
| background-color: #2563eb; | |
| } | |
| .feedback-thanks { | |
| color: #166534; | |
| font-weight: 500; | |
| display: none; | |
| } | |
| </style> | |
| <div class="feedback-container"> | |
| <div class="feedback-title">Was this article helpful?</div> | |
| <div class="feedback-buttons"> | |
| <button class="feedback-button feedback-yes" id="helpful-yes"> | |
| <i data-feather="thumbs-up"></i> Yes | |
| </button> | |
| <button class="feedback-button feedback-no" id="helpful-no"> | |
| <i data-feather="thumbs-down"></i> No | |
| </button> | |
| </div> | |
| <form class="feedback-form" id="feedback-form"> | |
| <textarea class="feedback-textarea" placeholder="What can we improve?"></textarea> | |
| <button type="submit" class="feedback-submit">Submit Feedback</button> | |
| </form> | |
| <div class="feedback-thanks" id="feedback-thanks"> | |
| Thank you for your feedback! | |
| </div> | |
| </div> | |
| `; | |
| const yesButton = this.shadowRoot.getElementById('helpful-yes'); | |
| const noButton = this.shadowRoot.getElementById('helpful-no'); | |
| const feedbackForm = this.shadowRoot.getElementById('feedback-form'); | |
| const thanksMessage = this.shadowRoot.getElementById('feedback-thanks'); | |
| yesButton.addEventListener('click', () => { | |
| this.sendFeedback(true); | |
| thanksMessage.style.display = 'block'; | |
| }); | |
| noButton.addEventListener('click', () => { | |
| feedbackForm.style.display = 'block'; | |
| }); | |
| feedbackForm.addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| const textarea = feedbackForm.querySelector('textarea'); | |
| this.sendFeedback(false, textarea.value); | |
| feedbackForm.style.display = 'none'; | |
| thanksMessage.style.display = 'block'; | |
| }); | |
| feather.replace(); | |
| } | |
| sendFeedback(wasHelpful, comment = '') { | |
| console.log('Feedback submitted:', { wasHelpful, comment }); | |
| // In a real implementation, this would send to your analytics/feedback system | |
| } | |
| } | |
| customElements.define('custom-feedback-widget', FeedbackWidget); |