| @@ -7,7 +7,7 @@ |
| 7 | 7 | --> |
| 8 | 8 | <script setup lang="ts"> |
| 9 | 9 | import { useRouter, withBase } from 'vitepress' |
| 10 | | import { computed, onMounted, onUnmounted, reactive, ref } from 'vue' |
| 10 | import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue' |
| 11 | 11 | import { |
| 12 | 12 | feedbackOptions, |
| 13 | 13 | type FeedbackType, |
| @@ -130,7 +130,7 @@ const typeOpen = ref<boolean>(false) |
| 130 | 130 | const typeRootRef = ref<HTMLDivElement>() |
| 131 | 131 | const typePlaceholder = { |
| 132 | 132 | label: 'Feedback type', |
| 133 | | icon: 'i-lucide:circle-question-mark', |
| 133 | icon: undefined as string | undefined, |
| 134 | 134 | value: undefined |
| 135 | 135 | } as const |
| 136 | 136 | const selectedType = computed( |
| @@ -148,7 +148,82 @@ function onTypeDocClick(e: MouseEvent) { |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | | onMounted(() => document.addEventListener('click', onTypeDocClick, true)) |
| 151 | // Success celebration: floating twemoji, single ~3s burst with random lanes. |
| 152 | // Pick an icon + depth layer here; size/opacity/timing derive from the layer. |
| 153 | type CelebrateLayer = 'front' | 'mid' | 'back' |
| 154 | |
| 155 | const CELEBRATE_ICONS: { icon: string; layer: CelebrateLayer }[] = [ |
| 156 | { icon: 'i-twemoji-red-heart', layer: 'front' }, |
| 157 | { icon: 'i-twemoji-growing-heart', layer: 'front' }, |
| 158 | { icon: 'i-twemoji-green-heart', layer: 'front' }, |
| 159 | { icon: 'i-twemoji-yellow-heart', layer: 'mid' }, |
| 160 | { icon: 'i-twemoji-folded-hands', layer: 'mid' }, |
| 161 | { icon: 'i-twemoji-purple-heart', layer: 'mid' }, |
| 162 | { icon: 'i-twemoji-beating-heart', layer: 'mid' }, |
| 163 | { icon: 'i-twemoji-orange-heart', layer: 'back' }, |
| 164 | { icon: 'i-twemoji-blue-heart', layer: 'back' }, |
| 165 | { icon: 'i-twemoji-brown-heart', layer: 'back' }, |
| 166 | { icon: 'i-twemoji-white-heart', layer: 'back' }, |
| 167 | { icon: 'i-twemoji-black-heart', layer: 'back' }, |
| 168 | { icon: 'i-twemoji-sparkling-heart', layer: 'back' }, |
| 169 | { icon: 'i-twemoji-glowing-star', layer: 'back' } |
| 170 | ] |
| 171 | |
| 172 | const LAYER_STYLE = { |
| 173 | front: { minSize: 24, maxSize: 30, minOpacity: 0.95, maxOpacity: 1, z: 2, blur: '0px', minDuration: 1.9, maxDuration: 2.1 }, |
| 174 | mid: { minSize: 16, maxSize: 22, minOpacity: 0.8, maxOpacity: 0.9, z: 0, blur: '0px', minDuration: 2, maxDuration: 2.3 }, |
| 175 | back: { minSize: 12, maxSize: 15, minOpacity: 0.4, maxOpacity: 0.55, z: 0, blur: '1px', minDuration: 2.1, maxDuration: 2.3 } |
| 176 | } as const |
| 177 | |
| 178 | interface CelebrationParticle { |
| 179 | icon: string |
| 180 | left: string |
| 181 | delay: string |
| 182 | duration: string |
| 183 | size: string |
| 184 | opacity: string |
| 185 | z: number |
| 186 | blur: string |
| 187 | } |
| 188 | |
| 189 | function makeParticle( |
| 190 | def: (typeof CELEBRATE_ICONS)[number], |
| 191 | index: number, |
| 192 | randomize: boolean |
| 193 | ): CelebrationParticle { |
| 194 | const style = LAYER_STYLE[def.layer] |
| 195 | const pick = (min: number, max: number) => |
| 196 | randomize ? min + Math.random() * (max - min) : (min + max) / 2 |
| 197 | return { |
| 198 | icon: def.icon, |
| 199 | left: randomize |
| 200 | ? `${(2 + Math.random() * 92).toFixed(1)}%` |
| 201 | : `${(((index + 0.5) / CELEBRATE_ICONS.length) * 100).toFixed(1)}%`, |
| 202 | delay: `${pick(0, 0.7).toFixed(2)}s`, |
| 203 | duration: `${pick(style.minDuration, style.maxDuration).toFixed(2)}s`, |
| 204 | size: `${Math.round(pick(style.minSize, style.maxSize))}px`, |
| 205 | opacity: `${pick(style.minOpacity, style.maxOpacity).toFixed(2)}`, |
| 206 | z: style.z, |
| 207 | blur: style.blur |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | const celebrationIcons = ref<CelebrationParticle[]>( |
| 212 | CELEBRATE_ICONS.map((def, i) => makeParticle(def, i, false)) |
| 213 | ) |
| 214 | |
| 215 | function rollCelebration() { |
| 216 | celebrationIcons.value = CELEBRATE_ICONS.map((def, i) => makeParticle(def, i, true)) |
| 217 | } |
| 218 | |
| 219 | watch(success, (v) => { |
| 220 | if (v) rollCelebration() |
| 221 | }) |
| 222 | |
| 223 | onMounted(() => { |
| 224 | document.addEventListener('click', onTypeDocClick, true) |
| 225 | if (success.value) rollCelebration() |
| 226 | }) |
| 152 | 227 | onUnmounted(() => document.removeEventListener('click', onTypeDocClick, true)) |
| 153 | 228 | </script> |
| 154 | 229 | |
| @@ -210,7 +285,7 @@ onUnmounted(() => document.removeEventListener('click', onTypeDocClick, true)) |
| 210 | 285 | :aria-label="`Feedback type: ${selectedType.label}`" |
| 211 | 286 | @click="typeOpen = !typeOpen" |
| 212 | 287 | > |
| 213 | | <span :class="selectedType.icon" class="fb-type-icon" aria-hidden="true" /> |
| 288 | <span v-if="selectedType.icon" :class="selectedType.icon" class="fb-type-icon" aria-hidden="true" /> |
| 214 | 289 | <span class="fb-type-label">{{ selectedType.label }}</span> |
| 215 | 290 | <span |
| 216 | 291 | class="fb-type-chevron i-lucide:chevron-down" |
| @@ -260,8 +335,25 @@ onUnmounted(() => document.removeEventListener('click', onTypeDocClick, true)) |
| 260 | 335 | </p> |
| 261 | 336 | </div> |
| 262 | 337 | </div> |
| 263 | | <div v-else> |
| 338 | <div v-else class="feedback-success"> |
| 264 | 339 | <p class="heading">Thanks for your feedback!</p> |
| 340 | <span |
| 341 | v-for="(item, i) in celebrationIcons" |
| 342 | :key="i" |
| 343 | class="fb-celebrate" |
| 344 | :class="item.icon" |
| 345 | aria-hidden="true" |
| 346 | :style="{ |
| 347 | left: item.left, |
| 348 | width: item.size, |
| 349 | height: item.size, |
| 350 | zIndex: item.z, |
| 351 | filter: `blur(${item.blur})`, |
| 352 | '--fb-peak': item.opacity, |
| 353 | animationDelay: item.delay, |
| 354 | animationDuration: item.duration |
| 355 | }" |
| 356 | /> |
| 265 | 357 | </div> |
| 266 | 358 | </Transition> |
| 267 | 359 | </div> |
| @@ -473,8 +565,10 @@ onUnmounted(() => document.removeEventListener('click', onTypeDocClick, true)) |
| 473 | 565 | transition: background-color 0.15s; |
| 474 | 566 | } |
| 475 | 567 | |
| 476 | | .fb-type-option:hover { |
| 477 | | background-color: var(--vp-c-bg-soft); |
| 568 | .fb-type-option:hover, |
| 569 | .fb-type-option:focus-visible { |
| 570 | background-color: var(--vp-c-brand-soft); |
| 571 | outline: none; |
| 478 | 572 | } |
| 479 | 573 | |
| 480 | 574 | .fb-type-option--selected { |
| @@ -485,10 +579,6 @@ onUnmounted(() => document.removeEventListener('click', onTypeDocClick, true)) |
| 485 | 579 | font-weight: 600; |
| 486 | 580 | } |
| 487 | 581 | |
| 488 | | .fb-type-option--selected:hover { |
| 489 | | background-color: var(--vp-c-brand-soft); |
| 490 | | } |
| 491 | | |
| 492 | 582 | .feedback-send { |
| 493 | 583 | display: inline-flex; |
| 494 | 584 | align-items: center; |
| @@ -520,6 +610,62 @@ onUnmounted(() => document.removeEventListener('click', onTypeDocClick, true)) |
| 520 | 610 | cursor: not-allowed; |
| 521 | 611 | } |
| 522 | 612 | |
| 613 | .feedback-success { |
| 614 | border: 2px solid var(--vp-c-brand-1); |
| 615 | border-radius: 12px; |
| 616 | background-color: var(--vp-c-bg-alt); |
| 617 | color: var(--vp-c-text-1); |
| 618 | display: flex; |
| 619 | align-items: center; |
| 620 | justify-content: center; |
| 621 | text-align: center; |
| 622 | min-height: 120px; |
| 623 | padding: 1rem; |
| 624 | box-shadow: 0 0 0 2px var(--vp-c-brand-soft); |
| 625 | position: relative; |
| 626 | overflow: hidden; |
| 627 | } |
| 628 | |
| 629 | .feedback-success .heading { |
| 630 | margin: 0; |
| 631 | position: relative; |
| 632 | z-index: 1; |
| 633 | } |
| 634 | |
| 635 | .fb-celebrate { |
| 636 | position: absolute; |
| 637 | bottom: -28px; |
| 638 | opacity: 0; |
| 639 | pointer-events: none; |
| 640 | animation-name: fb-float-up; |
| 641 | animation-timing-function: linear; |
| 642 | animation-iteration-count: 1; |
| 643 | } |
| 644 | |
| 645 | @keyframes fb-float-up { |
| 646 | 0% { |
| 647 | transform: translateY(0); |
| 648 | opacity: 0; |
| 649 | } |
| 650 | 15% { |
| 651 | opacity: var(--fb-peak, 0.9); |
| 652 | } |
| 653 | 70% { |
| 654 | opacity: var(--fb-peak, 0.9); |
| 655 | } |
| 656 | 100% { |
| 657 | transform: translateY(-160px); |
| 658 | opacity: 0; |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | @media (prefers-reduced-motion: reduce) { |
| 663 | .fb-celebrate { |
| 664 | animation: none; |
| 665 | display: none; |
| 666 | } |
| 667 | } |
| 668 | |
| 523 | 669 | .fade-enter-active, |
| 524 | 670 | .fade-leave-active { |
| 525 | 671 | transition: opacity 0.25s ease; |