Skip to content

Commit

Permalink
Improved feedback (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
fantkolja and oliverhowell authored Feb 12, 2025
1 parent fca52b8 commit c4d39d3
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 27 deletions.
Binary file modified build/ui-bundle.zip
Binary file not shown.
130 changes: 129 additions & 1 deletion src/css/feedback.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/* Feedback question and buttons */
@keyframes vertical-shaking {
0% { transform: translateY(0); }
25% { transform: translateY(5px); }
50% { transform: translateY(-5px); }
75% { transform: translateY(5px); }
100% { transform: translateY(0); }
}

.feedback-prompt {
width: var(--toc-width);
Expand Down Expand Up @@ -138,3 +144,125 @@ a.feedback-button:hover {
.mail {
background: transparent url(../img/mail.svg) center left / contain no-repeat;
}

.feedback-form-submit-container {
display: none;
}

.feedback-form-container {
display: flex;
flex-direction: column;
gap: 1rem;
}

.feedback-form-container:has(> .feedback-radio-button-label > input[name="feedback"]:checked) ~ .feedback-form-submit-container {
display: block;
}

.feedback-radio-button-label:has(input[name="feedback"]:checked) + .additional-textual-feedback {
display: block;
}

input[name="feedback"] {
appearance: none;
border-radius: 50%;
width: 16px;
height: 16px;
border: 1px solid var(--neutral-light);
transition: 0.2s border-width linear;
margin: 0;
position: relative;
top: 4px;
padding: 0;
}

input[name="feedback"]:checked {
border: 4px solid var(--success-light);
}

.feedback-radio-button-label {
display: flex;
align-items: flex-start;
gap: 1rem;
font-family: var(--heading-font-family);
font-size: 14px;
cursor: pointer;
color: var(--secondary-text);
transition: transform 300ms;
}

.feedback-radio-button-label:hover {
transform: translateY(-3px);
}

.radio-btn-title {
font-weight: 600;
padding: 2px 0;
}

input[name="feedback"]:checked ~ .feedback-description .radio-btn-title {
color: var(--body-font-color);
}

.feedback-description {
display: flex;
flex-direction: column;
}

.feedback-form-submit-btn {
display: block;
margin: 0 0 0 auto;
color: var(--primary-light);
border: 1px solid var(--primary-light);
border-radius: 20px;
background-color: var(--neutral-white);
padding: 6px 20px;
transition: transform 300ms;
}

.feedback-form-submit-btn:hover {
transform: translateY(-3px);
}

.feedback-form-submit-btn:disabled {
color: var(--neutral-light);
border: 1px solid var(--neutral-light);
cursor: wait;
}

.additional-textual-feedback {
border: 1px solid var(--neutral-light);
color: var(--secondary-text);
border-radius: 10px;
padding: 10px;
width: 100%;
display: none;
}

.additional-textual-feedback::placeholder {
color: var(--neutral-light);
}

.overlay-content.feedback-overlay-content {
padding: 30px 60px;
}

.feedback-overlay-title {
margin: 0;
}

.feedback-overlay-description {
margin: 0.5rem 0 2rem;
}

.feedback-submit-success {
background-color: var(--accent4-light);
border: 1px solid var(--accent4);
font-size: 14px;
padding: 10px 20px;
border-radius: 10px;
animation-name: vertical-shaking;
animation-delay: 0.3s;
animation-duration: 0.5s;
animation-iteration-count: 1;
}
71 changes: 71 additions & 0 deletions src/css/overlay.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@keyframes animatetop {
from {
top: -300px;
opacity: 0;
}

to {
top: 0;
opacity: 1;
}
}

@keyframes fadeIn {
from {
opacity: 0;
}

to {
opacity: 1;
}
}

.overlay {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
animation-name: fadeIn;
animation-duration: 0.4s;
}

.overlay.open {
display: block;
}

.overlay-content {
background-color: #fefefe;
margin: 15vh auto 0;
padding: 20px;
border: 1px solid #888;
border-radius: 10px;
width: fit-content;
max-width: 1000px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
animation-name: animatetop;
animation-duration: 0.4s;
position: relative;
}

.close-overlay {
position: absolute;
top: 1rem;
right: 1rem;
color: var(--neutral-light);
font-size: 28px;
line-height: 0.5;
font-weight: bold;
transition: color 300ms;
}

.close-overlay:hover,
.close-overlay:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
1 change: 1 addition & 0 deletions src/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import "tutorials.css";
@import "expanded-image.css";
@import "feedback.css";
@import "overlay.css";
@import "home.css";
@import "swagger.css";
@import "main.css";
Expand Down
3 changes: 2 additions & 1 deletion src/css/toc.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
flex: 0 0 var(--toc-width);
min-width: 222px;
overflow-y: auto;
height: var(--toc-height);
height: max-content;
max-height: var(--toc-height);
overflow-x: hidden;
}

Expand Down
73 changes: 73 additions & 0 deletions src/js/05-feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const feedbackForm = document.getElementById('feedback-form')
const additionalTextualFeedback = document.getElementById('additional-textual-feedback')
const overlay = document.getElementById('feedback-overlay')
const helpfulFeedbackWidget = document.getElementById('helpful-feedback-widget')
const feedbackSubmitSuccess = document.getElementById('feedback-submit-success')
const submitBtn = document.getElementById('feedback-form-submit-btn')

const handleSubmit = (event) => {
event.preventDefault()
submitBtn.setAttribute('disabled', '')

// eslint-disable-next-line no-undef
const formData = new FormData(feedbackForm)

// eslint-disable-next-line no-undef
fetch('/', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams(formData).toString(),
})
.then(() => console.debug('Thank you for your feedback'))
.catch((error) => console.error(error))
submitBtn.removeAttribute('disabled')
overlay.classList.remove('open')
feedbackSubmitSuccess.classList.remove('hidden')
helpfulFeedbackWidget.classList.add('hidden')
}

const openFormContainer = (containerToOpen, containerToClose, radioToCheck, radioToUncheck) => {
feedbackForm.reset()
document.getElementById(containerToOpen).classList.remove('hidden')
document.getElementById(containerToClose).classList.add('hidden')
document.getElementById(radioToCheck).setAttribute('checked', '')
document.getElementById(radioToUncheck).removeAttribute('checked')
overlay.classList.add('open')
}

const showPositiveFeedbackForm = () => {
openFormContainer(
'positive-feedback-form-container',
'negative-feedback-form-container',
'yes',
'no'
)
}

const showNegativeFeedbackForm = () => {
openFormContainer(
'negative-feedback-form-container',
'positive-feedback-form-container',
'no',
'yes'
)
}

const changeFeedbackAdditionalTextPlacement = (event) => {
// eslint-disable-next-line no-undef
const formData = new FormData(feedbackForm)
const feedbackValue = formData.get('feedback')
const selectedRadioButton = document.querySelector(`[value="${feedbackValue}"]`)
selectedRadioButton.parentNode.insertAdjacentElement('afterend', additionalTextualFeedback)
}

const closeOverlay = () => {
feedbackForm.reset()
overlay.classList.remove('open')
}

feedbackForm.addEventListener('submit', handleSubmit)
feedbackForm.addEventListener('change', changeFeedbackAdditionalTextPlacement)
document.getElementById('close-feedback-overlay').addEventListener('click', closeOverlay)
document.getElementById('positive-feedback-starter').addEventListener('click', showPositiveFeedbackForm)
document.getElementById('negative-feedback-starter').addEventListener('click', showNegativeFeedbackForm)
3 changes: 0 additions & 3 deletions src/partials/feedback-footer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<img class="card-img" src="{{{uiRootPath}}}/img/lifebuoy.svg" alt="lifebuoy" />
<h4 class="card-title">Help and support</h4>
</div>
{{#if (not-eq page.layout 'home')}}
{{> was-this-helpful-feedback }}
{{/if}}
{{#with (get-page-info)}}
<a class="additional-feedback feedback-button" href="{{this.src.origin.webUrl}}/issues/new?title=Docs: Feedback for {{{this.title}}}&body=Hi, I have some feedback about [this page]({{{this.src.editUrl}}})%0D%0A" target="_blank">
<span class="feedback-button-text git">
Expand Down
12 changes: 1 addition & 11 deletions src/partials/feedback.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,5 @@
</a>
{{/with}}
{{/if}}
<form name="docs-feedback" id="feedback-form" netlify-honeypot="bot-field" method="POST" data-netlify="true">
<p class="hidden">
<label>Don’t fill this out if you’re human: <input name="bot-field" /></label>
</p>
{{> was-this-helpful-feedback }}
</form>
{{> was-this-helpful-feedback }}
</div>
<script>
function submitForm() {
document.getElementById("feedback-form").submit();
}
</script>
Loading

0 comments on commit c4d39d3

Please sign in to comment.