-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
CardModule.vue
176 lines (164 loc) · 6.19 KB
/
CardModule.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
<div class="relative flex flex-col group p-5 nuxt-card-border nuxt-card-bg nuxt-text-default rounded-lg transition-transform duration-150 ease-in-out transform">
<a
:href="mod.website"
:aria-label="mod.website"
target="_blank"
rel="noopener"
class="absolute inset-0"
>
<div
class="transition-opacity duration-200 ease-in-out rounded-full opacity-0 group-hover:opacity-100 absolute top-3 right-3 cursor-pointer"
>
<UnoIcon
class="i-carbon-arrow-up-right text-xl leading-none !block group-hover:text-primary-800 dark:group-hover:text-white"
/>
</div>
</a>
<div class="flex items-start w-full h-20">
<div
class="relative border bg-white border-gray-200 dark:bg-secondary-dark dark:border-secondary-dark w-20 h-20 rounded-lg flex flex-none items-center justify-center"
>
<!-- TODO: use <nuxt-img> -->
<img
v-if="!coverError && iconUrl(mod)"
:src="'https://api.nuxtjs.org/api/ipx/s_80,f_webp/gh/nuxt/modules/main/website/static/' + iconUrl(mod)"
:alt="mod.name"
class="w-10 h-10 object-contain"
width="40px"
height="40px"
@error="coverError = true"
>
<UnoIcon v-else :class="iconPlaceholder(mod)" class="text-4xl opacity-20" />
</div>
<div class="ml-6 w-full h-full">
<h2
class="flex text-lg font-semibold items-center dark:text-white h-9 line-2 leading-tight"
>
<span>{{ mod.name }}</span>
<UnoIcon
v-if="mod.type === 'official'"
v-tooltip="'Official'"
class="i-carbon-badge text-yellow-600 text-lg ml-1 my-auto opacity-85"
/>
</h2>
<div class="flex gap-2 py-3 w-full flex-wrap">
<div
v-for="{ tag, tagText, supportText, color, cssClass } of useModuleComptatibility(mod)"
:key="tag"
v-tooltip="tagText + ': ' + supportText"
:style="{ color: color, background: color + '20' }"
:class="cssClass"
class="flex min-w-12 relative items-center gap-1 text-base rounded-lg px-2 py-1 z-50"
>
<iconNuxt3 v-if="tag === '3.x'" class="h-5 w-5" aria-hidden="true" />
<iconNuxt2 v-if="tag === '2.x'" class="h-5 w-5" aria-hidden="true" />
<iconNuxtBridge v-if="tag === '2.x-bridge'" class="h-5 w-5" aria-hidden="true" />
<div class="-mb-0.5">
{{ tag[0] }}
</div>
</div>
</div>
</div>
</div>
<div class="h-20 mt-4">
<p
class="text-sky-dark dark:text-white dark:opacity-85 text-sm font-normal line-clamp-3 mt-2"
>
{{ mod.description }}
</p>
</div>
<div class="flex w-full z-30 relative">
<div class="flex flex-none">
<a
:href="mod.github"
aria-label="stars"
target=" _blank"
rel="noopener"
class="flex whitespace-nowrap w-full mr-4 text-sky-dark hover:text-gray-400 dark:hover:text-secondary-lighter dark:text-white"
>
<UnoIcon class="mr-2 i-carbon-star" />
<div class="text-sm leading-5 font-medium truncate">
{{ numberFormat(mod.stars) }}
<span
class="hidden md:inline-block"
>star{{ mod.stars !== 1 ? 's' : '' }}</span>
</div>
</a>
<a
:href="npmUrl(mod)"
aria-label="npm"
target=" _blank"
rel="noopener"
class="flex whitespace-nowrap w-full mr-4 text-sky-dark hover:text-gray-400 dark:hover:text-secondary-lighter dark:text-white"
>
<UnoIcon class="mr-2 i-carbon-download" />
<div
class="text-sm leading-5 font-medium truncate"
>{{ numberFormat(mod.downloads) }} installs</div>
</a>
</div>
<div class="flex -space-x-3 hover:space-x-0 absolute right-0 -bottom-1 hover:bg-white dark:hover:bg-sky-darkest">
<a
v-for="contributor of mod.contributors.slice(0, 5).reverse()"
:key="contributor.login"
v-tooltip="contributor.name || contributor.login"
:aria-label="contributor.name || contributor.login"
:href="`https://github.com/${contributor.login}`"
target="_blank"
rel="noopener"
>
<!-- TODO: use <nuxt-img> -->
<img
class="w-7 h-7 flex rounded-full text-white border-4 border-white dark:border-sky-darkest"
:src="'https://api.nuxtjs.org/api/ipx/s_44,f_webp/gh_avatar/' + contributor.login"
:alt="contributor.name|| contributor.login"
format="jpg"
width="28"
height="28"
>
</a>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ModuleInfo, MaintainerInfo } from '~/../lib/types'
import { numberFormatter } from '~/utils/format'
import { CATEGORIES_ICONS } from '~/composables/constants'
defineProps<{ mod: ModuleInfo }>()
const coverError = ref(false)
interface CompatibilityData {
statusText: string
icon: string | null
color: string
class?: string
}
const tagMap = Object.fromEntries(VERSIONS.map(v => [v.key, { tagText: v.label }]))
const supportMap = {
supported: { supportText: 'Supported', supportIcon: 'i-carbon-checkmark', color: '#1aa346', cssClass: '' },
notSupported: { supportText: 'Not supported', supportIcon: 'i-carbon-help', color: '#61626c', cssClass: 'opacity-85' },
wip: { supportText: 'Work in progress', supportIcon: 'i-carbon-time', color: '#c4930a', cssClass: '' }
}
const useModuleComptatibility = (mod: ModuleInfo) => {
return ['2.x', '2.x-bridge', '3.x'].map(tag => ({
tag,
...tagMap[tag],
...(mod.tags.includes(tag) ? supportMap.supported : supportMap.notSupported)
}))
}
function numberFormat (num: number, options = { precision: 1 }) {
return numberFormatter(num, options)
}
function iconUrl ({ icon }: ModuleInfo) {
if (icon) {
return `/icons/${icon}`
}
}
function iconPlaceholder ({ category }: ModuleInfo) {
return CATEGORIES_ICONS[category] || 'i-carbon-circle-dash'
}
function npmUrl ({ npm }: ModuleInfo) {
return `https://npmjs.com/package/${npm}`
}
</script>