File size: 3,910 Bytes
799388a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | 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); |