|
| 1 | +--- |
| 2 | +import { AstroIcon } from "~/components"; |
| 3 | +--- |
| 4 | + |
| 5 | +<feedback-prompt class="not-content"> |
| 6 | + <div id="feedback-thumbs"> |
| 7 | + <h2>Was this helpful?</h2> |
| 8 | + <div class="not-content"> |
| 9 | + <AstroIcon name="material-symbols:thumb-up-outline-rounded" title="Yes" /> |
| 10 | + <AstroIcon |
| 11 | + name="material-symbols:thumb-down-outline-rounded" |
| 12 | + title="No" |
| 13 | + /> |
| 14 | + </div> |
| 15 | + </div> |
| 16 | + <div id="feedback-yes" class="hidden"> |
| 17 | + <h2>What did you like?</h2> |
| 18 | + <form> |
| 19 | + <fieldset> |
| 20 | + <div> |
| 21 | + <input type="radio" id="accurate" value="accurate" name="reason" /> |
| 22 | + <label for="accurate">Accurate</label> |
| 23 | + </div> |
| 24 | + <div> |
| 25 | + <input |
| 26 | + type="radio" |
| 27 | + id="easy-to-understand" |
| 28 | + value="easy-to-understand" |
| 29 | + name="reason" |
| 30 | + /> |
| 31 | + <label for="easy-to-understand">Easy to understand</label> |
| 32 | + </div> |
| 33 | + <div> |
| 34 | + <input |
| 35 | + type="radio" |
| 36 | + id="solved-my-problem" |
| 37 | + value="solved-my-problem" |
| 38 | + name="reason" |
| 39 | + /> |
| 40 | + <label for="solved-my-problem">Solved my problem</label> |
| 41 | + </div> |
| 42 | + <div> |
| 43 | + <input |
| 44 | + type="radio" |
| 45 | + id="helped-me-decide-to-use-the-product" |
| 46 | + value="solved-my-problem" |
| 47 | + name="reason" |
| 48 | + /> |
| 49 | + <label for="helped-me-decide-to-use-the-product" |
| 50 | + >Helped me decide to use the product</label |
| 51 | + > |
| 52 | + </div> |
| 53 | + <div> |
| 54 | + <input type="radio" id="other" value="other" name="reason" /> |
| 55 | + <label for="other">Other</label> |
| 56 | + <input |
| 57 | + type="text" |
| 58 | + placeholder="Tell us more about your experience." |
| 59 | + id="info" |
| 60 | + name="info" |
| 61 | + /> |
| 62 | + </div> |
| 63 | + <input type="submit" value="Submit" /> |
| 64 | + </fieldset> |
| 65 | + </form> |
| 66 | + </div> |
| 67 | + <div id="feedback-no" class="hidden"> |
| 68 | + <h2>What went wrong?</h2> |
| 69 | + <form> |
| 70 | + <fieldset> |
| 71 | + <div> |
| 72 | + <input |
| 73 | + type="radio" |
| 74 | + id="hard-to-understand" |
| 75 | + value="hard-to-understand" |
| 76 | + name="reason" |
| 77 | + /> |
| 78 | + <label for="hard-to-understand">Hard to understand</label> |
| 79 | + </div> |
| 80 | + <div> |
| 81 | + <input |
| 82 | + type="radio" |
| 83 | + id="incorrect-information" |
| 84 | + value="incorrect-information" |
| 85 | + name="reason" |
| 86 | + /> |
| 87 | + <label for="incorrect-information">Incorrect information</label> |
| 88 | + </div> |
| 89 | + <div> |
| 90 | + <input |
| 91 | + type="radio" |
| 92 | + id="missing-the-information" |
| 93 | + value="missing-the-information" |
| 94 | + name="reason" |
| 95 | + /> |
| 96 | + <label for="missing-the-information">Missing the information</label> |
| 97 | + </div> |
| 98 | + <div> |
| 99 | + <input type="radio" id="other" value="other" name="reason" /> |
| 100 | + <label for="other">Other</label> |
| 101 | + <input |
| 102 | + type="text" |
| 103 | + placeholder="Tell us more about your experience." |
| 104 | + id="info" |
| 105 | + name="info" |
| 106 | + /> |
| 107 | + </div> |
| 108 | + <input type="submit" value="Submit" /> |
| 109 | + </fieldset> |
| 110 | + </form> |
| 111 | + </div> |
| 112 | + |
| 113 | + <div id="feedback-thanks" class="hidden"> |
| 114 | + <h2>Thank you for helping improve Cloudflare's documentation!</h2> |
| 115 | + </div> |
| 116 | +</feedback-prompt> |
| 117 | + |
| 118 | +<style> |
| 119 | + fieldset { |
| 120 | + padding-top: 0; |
| 121 | + padding-left: 0; |
| 122 | + } |
| 123 | + |
| 124 | + label { |
| 125 | + font-size: small; |
| 126 | + color: var(--sl-color-gray-3); |
| 127 | + } |
| 128 | + |
| 129 | + input[type="submit"], |
| 130 | + input::placeholder { |
| 131 | + font-size: x-small; |
| 132 | + } |
| 133 | + |
| 134 | + h2 { |
| 135 | + color: var(--sl-color-white); |
| 136 | + font-size: var(--sl-text-h5); |
| 137 | + font-weight: 600; |
| 138 | + line-height: var(--sl-line-height-headings); |
| 139 | + margin-bottom: 0.5rem; |
| 140 | + } |
| 141 | + |
| 142 | + #info { |
| 143 | + display: none; |
| 144 | + } |
| 145 | + |
| 146 | + #other:checked ~ #info { |
| 147 | + display: flex; |
| 148 | + } |
| 149 | + |
| 150 | + [data-icon] { |
| 151 | + cursor: pointer; |
| 152 | + color: var(--sl-color-gray-3); |
| 153 | + font-size: 1.5rem; |
| 154 | + margin-right: 0.5rem; |
| 155 | + |
| 156 | + &:hover { |
| 157 | + color: var(--sl-color-text-accent); |
| 158 | + border-color: var(--sl-color-text-accent); |
| 159 | + } |
| 160 | + } |
| 161 | +</style> |
| 162 | + |
| 163 | +<script> |
| 164 | + class FeedbackPrompt extends HTMLElement { |
| 165 | + connectedCallback() { |
| 166 | + const icons = { |
| 167 | + '[data-icon="material-symbols:thumb-up-outline-rounded"]': |
| 168 | + "#feedback-yes", |
| 169 | + '[data-icon="material-symbols:thumb-down-outline-rounded"]': |
| 170 | + "#feedback-no", |
| 171 | + }; |
| 172 | + |
| 173 | + const thumbsDiv = this.querySelector("#feedback-thumbs"); |
| 174 | + const thanksDiv = this.querySelector("#feedback-thanks"); |
| 175 | + |
| 176 | + if (!thumbsDiv || !thanksDiv) return; |
| 177 | + |
| 178 | + for (const [button, questions] of Object.entries(icons)) { |
| 179 | + this.querySelector(button)?.addEventListener("click", () => { |
| 180 | + thumbsDiv.classList.add("hidden"); |
| 181 | + |
| 182 | + const questionsDiv = this.querySelector(questions); |
| 183 | + |
| 184 | + if (!questionsDiv) return; |
| 185 | + |
| 186 | + questionsDiv.classList.remove("hidden"); |
| 187 | + |
| 188 | + const form = questionsDiv.querySelector("form"); |
| 189 | + |
| 190 | + if (!form) return; |
| 191 | + |
| 192 | + form.addEventListener("submit", async (e) => { |
| 193 | + e.preventDefault(); |
| 194 | + |
| 195 | + const formData = new FormData(e.target as HTMLFormElement); |
| 196 | + formData.set("page", window.location.pathname); |
| 197 | + formData.set("option", questions.split("-")[1]); |
| 198 | + |
| 199 | + fetch("https://feedback.developers.cloudflare.com", { |
| 200 | + method: "POST", |
| 201 | + body: formData, |
| 202 | + }); |
| 203 | + |
| 204 | + questionsDiv.classList.add("hidden"); |
| 205 | + thanksDiv.classList.remove("hidden"); |
| 206 | + }); |
| 207 | + }); |
| 208 | + } |
| 209 | + } |
| 210 | + } |
| 211 | + |
| 212 | + customElements.define("feedback-prompt", FeedbackPrompt); |
| 213 | +</script> |
0 commit comments