|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref } from 'vue'; |
| 3 | +import { useSponsorsGrid } from 'vitepress/dist/client/theme-default/composables/sponsor-grid'; |
| 4 | +import type { Sponsor } from '../sponsors'; |
| 5 | +
|
| 6 | +interface Props { |
| 7 | + size?: 'xmini' | 'mini' | 'small' | 'medium' | 'big'; |
| 8 | + data: Sponsor[]; |
| 9 | +} |
| 10 | +
|
| 11 | +const props = withDefaults(defineProps<Props>(), { |
| 12 | + size: 'medium' |
| 13 | +}); |
| 14 | +
|
| 15 | +const el = ref(null); |
| 16 | +
|
| 17 | +useSponsorsGrid({ el, size: props.size }); |
| 18 | +</script> |
| 19 | + |
| 20 | +<template> |
| 21 | + <div class="VPSponsorsGrid vp-sponsor-grid" :class="[size]" ref="el"> |
| 22 | + <div |
| 23 | + v-for="sponsor in data" |
| 24 | + :key="sponsor.name" |
| 25 | + class="vp-sponsor-grid-item" |
| 26 | + :class="{ 'has-dark-logo': sponsor.imgDark }" |
| 27 | + > |
| 28 | + <a |
| 29 | + class="vp-sponsor-grid-link" |
| 30 | + :href="sponsor.url" |
| 31 | + target="_blank" |
| 32 | + rel="sponsored noopener" |
| 33 | + > |
| 34 | + <article class="vp-sponsor-grid-box"> |
| 35 | + <h4 class="visually-hidden">{{ sponsor.name }}</h4> |
| 36 | + <!-- Both logos are rendered and one is hidden in CSS, so the right |
| 37 | + one is already in place before hydration. --> |
| 38 | + <img |
| 39 | + class="vp-sponsor-grid-image logo-light" |
| 40 | + :src="sponsor.img" |
| 41 | + :alt="sponsor.name" |
| 42 | + /> |
| 43 | + <img |
| 44 | + v-if="sponsor.imgDark" |
| 45 | + class="vp-sponsor-grid-image logo-dark" |
| 46 | + :src="sponsor.imgDark" |
| 47 | + :alt="sponsor.name" |
| 48 | + /> |
| 49 | + </article> |
| 50 | + </a> |
| 51 | + <!-- Sits inside the tile: the grid clips anything that overflows it. --> |
| 52 | + <span v-if="sponsor.description" class="tooltip"> |
| 53 | + {{ sponsor.description }} |
| 54 | + </span> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | +</template> |
| 58 | + |
| 59 | +<style scoped> |
| 60 | +.vp-sponsor-grid-item { |
| 61 | + position: relative; |
| 62 | +} |
| 63 | +
|
| 64 | +.tooltip { |
| 65 | + position: absolute; |
| 66 | + bottom: 14px; |
| 67 | + left: 50%; |
| 68 | + transform: translate(-50%, 6px); |
| 69 | + max-width: calc(100% - 28px); |
| 70 | + padding: 7px 12px; |
| 71 | + border: 1px solid var(--vp-c-divider); |
| 72 | + border-radius: 10px; |
| 73 | + background-color: var(--vp-c-bg-elv); |
| 74 | + box-shadow: var(--vp-shadow-2); |
| 75 | + color: var(--vp-c-text-1); |
| 76 | + font-size: 13px; |
| 77 | + font-weight: 500; |
| 78 | + line-height: 18px; |
| 79 | + text-align: center; |
| 80 | + text-wrap: balance; |
| 81 | + opacity: 0; |
| 82 | + transition: |
| 83 | + opacity 0.2s, |
| 84 | + transform 0.2s; |
| 85 | + pointer-events: none; |
| 86 | +} |
| 87 | +
|
| 88 | +.vp-sponsor-grid-item:hover .tooltip, |
| 89 | +.vp-sponsor-grid-item:focus-within .tooltip { |
| 90 | + opacity: 1; |
| 91 | + transform: translate(-50%, 0); |
| 92 | +} |
| 93 | +
|
| 94 | +@media (prefers-reduced-motion: reduce) { |
| 95 | + .tooltip { |
| 96 | + transition: none; |
| 97 | + } |
| 98 | +} |
| 99 | +</style> |
0 commit comments