docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue

895a3c0227ce8313912df20aedc960d9fb22aeca
wotaku/docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue
Duck updatef93d8411b5 4 months ago

168 lines · 4107 bytes

  1<script setup lang="ts">
  2import { computed } from 'vue'
  3import { langLabel, ratingIcon, ratingTitle } from './helpers'
  4import LazyIcon from './LazyIcon.vue'
  5import type { RepoSite } from './types'
  6import { useTooltip } from './useTooltip'
  7
  8const { show: showTooltip, hide: hideTooltip } = useTooltip()
  9
 10const props = defineProps<{
 11  sites: (RepoSite & { repoName?: string })[]
 12  open: boolean
 13}>()
 14
 15defineEmits<{
 16  toggle: []
 17}>()
 18
 19const primary = computed(() => props.sites[0])
 20const highestRated = computed(() => props.sites.find(site => site.rating === 'nsfw')
 21  ?? props.sites.find(site => site.rating === 'suggestive'))
 22
 23const groupName = computed(() => {
 24  const wordLists = props.sites.map(site => site.name.trim().split(/\s+/))
 25  const minLen = Math.min(...wordLists.map(words => words.length))
 26  const common: string[] = []
 27  for (let i = 0; i < minLen; i++) {
 28    const word = wordLists[0][i]
 29    if (wordLists.every(words => words[i] === word)) common.push(word)
 30    else break
 31  }
 32  if (common.length > 0) return common.join(' ')
 33
 34  const label = langLabel(primary.value.lang)
 35  const stripped = primary.value.name.replace(new RegExp(`\\s*${label}$`, 'i'), '').trim()
 36  return stripped || primary.value.name
 37})
 38</script>
 39
 40<template>
 41  <button
 42    type="button"
 43    class="ext-site-cell ext-site-group"
 44    :class="{ 'ext-site-group-active': open }"
 45    :aria-expanded="open"
 46    :aria-label="`${groupName}, ${sites.length} languages`"
 47    @click="$emit('toggle')"
 48  >
 49    <div class="ext-site-row">
 50      <LazyIcon class="ext-site-icon" :src="primary.icon" :alt="primary.name" />
 51      <span
 52        class="ext-site-name-text"
 53        :aria-label="groupName"
 54        @mouseenter="showTooltip($event, groupName)"
 55        @mouseleave="hideTooltip"
 56      ><span class="ext-site-name-inner">{{ groupName }}</span></span>
 57      <span
 58        v-if="highestRated"
 59        class="ext-site-nsfw"
 60        :class="ratingIcon(highestRated.rating)"
 61        :aria-label="ratingTitle(highestRated.rating)"
 62        @mouseenter="showTooltip($event, ratingTitle(highestRated.rating))"
 63        @mouseleave="hideTooltip"
 64      />
 65      <span
 66        class="ext-site-layers i-lucide:layers"
 67        :aria-label="`${sites.length} versions available`"
 68        @mouseenter="showTooltip($event, `${sites.length} versions available`)"
 69        @mouseleave="hideTooltip"
 70      />
 71    </div>
 72    <span v-if="primary.repoName" class="ext-site-repo">{{ primary.repoName }}</span>
 73  </button>
 74</template>
 75
 76<style scoped>
 77.ext-site-cell {
 78  display: flex;
 79  flex-direction: column;
 80  gap: 0;
 81  padding: 6px 8px;
 82  border-radius: 6px;
 83  border: 1px solid var(--vp-c-divider);
 84  background-color: var(--vp-c-bg-soft);
 85  min-width: 0;
 86  color: var(--vp-c-text-1) !important;
 87  text-decoration: none !important;
 88  transition: border-color 0.2s, background-color 0.2s;
 89}
 90
 91.ext-site-group {
 92  width: 100%;
 93  font: inherit;
 94  text-align: left;
 95  cursor: pointer;
 96}
 97
 98.ext-site-group:hover,
 99.ext-site-group-active {
100  border-color: var(--vp-c-brand-1);
101  background-color: var(--vp-c-bg);
102}
103
104.ext-site-row {
105  display: flex;
106  align-items: center;
107  gap: 6px;
108  min-width: 0;
109}
110
111.ext-site-icon {
112  width: 18px;
113  height: 18px;
114  border-radius: 4px;
115  flex-shrink: 0;
116  object-fit: contain;
117}
118
119.ext-site-icon-fallback {
120  display: flex;
121  align-items: center;
122  justify-content: center;
123  color: var(--vp-c-text-3);
124}
125
126.ext-site-icon-loading {
127  background-color: var(--vp-c-bg-mute, var(--vp-c-bg-soft));
128}
129
130.ext-site-name-text {
131  display: block;
132  flex: 1;
133  min-width: 0;
134}
135
136.ext-site-name-inner {
137  display: block;
138  font-size: 12.5px;
139  font-weight: 600;
140  line-height: 1.2;
141  color: var(--vp-c-text-1);
142  white-space: nowrap;
143  overflow: hidden;
144  text-overflow: ellipsis;
145}
146
147.ext-site-nsfw,
148.ext-site-layers {
149  flex-shrink: 0;
150  font-size: 12px;
151}
152
153.ext-site-layers {
154  color: var(--vp-c-brand-1);
155}
156
157.ext-site-repo {
158  display: block;
159  padding-left: 24px;
160  font-size: 10.5px;
161  font-weight: 400;
162  line-height: 1.1;
163  color: var(--vp-c-text-2);
164  white-space: nowrap;
165  overflow: hidden;
166  text-overflow: ellipsis;
167}
168</style>
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form