-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathModuleItem.vue
More file actions
264 lines (242 loc) · 8.35 KB
/
ModuleItem.vue
File metadata and controls
264 lines (242 loc) · 8.35 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<script setup lang="ts">
import type { Module } from '#shared/types'
const emit = defineEmits<{
add: [module: Module]
remove: [module: Module]
}>()
const props = withDefaults(
defineProps<{
module: Module
showBadge?: boolean
isAdded: boolean
showAddButton?: boolean
}>(),
{
showBadge: true,
showAddButton: true
}
)
const { copy } = useClipboard()
const { selectedSort } = useModules()
const { track } = useAnalytics()
const publishedAgo = useTimeAgo(() => props.module.stats.publishedAt)
const createdAgo = useTimeAgo(() => props.module.stats.createdAt)
const relativeDate = computed(() =>
selectedSort.value.key === 'publishedAt' ? publishedAgo.value : createdAgo.value
)
const staticModuleDate = computed(() =>
selectedSort.value.key === 'publishedAt'
? formatDateByLocale('en', props.module.stats.publishedAt)
: formatDateByLocale('en', props.module.stats.createdAt)
)
function copyInstallCommand(moduleName: string) {
track('Module Install Command Copied', { module: moduleName })
const command = `npx nuxt@latest module add ${moduleName}`
copy(command, { title: 'Command copied to clipboard:', description: command })
}
function toggleModule(m: Module) {
const action = props.isAdded ? 'remove' : 'add'
track('Module Toggled', { module: m.name, action })
if (props.isAdded) {
emit('remove', m)
} else {
emit('add', m)
}
}
function handleCardClick(event: MouseEvent) {
if (event.shiftKey) {
event.preventDefault()
toggleModule(props.module)
}
}
const items = computed(() => [
[
{
label: props.isAdded ? 'Remove module' : 'Add module',
icon: props.isAdded ? 'i-lucide-minus' : 'i-lucide-plus',
onSelect: () => toggleModule(props.module)
},
{
label: 'Copy install command',
icon: 'i-lucide-terminal',
onSelect: () => copyInstallCommand(props.module.name)
}
],
[
{
icon: 'i-lucide-book',
label: 'Documentation',
to: `${props.module.website}?utm_source=nuxt.com&utm_medium=aside-module&utm_campaign=nuxt.com`,
target: '_blank'
},
{
label: 'View on GitHub',
icon: 'i-lucide-github',
to: `https://github.com/${props.module.repo}`,
target: '_blank'
},
{
label: 'View on npm',
icon: 'i-lucide-package',
to: `https://npm.chart.dev/${props.module.npm}`,
target: '_blank'
}
]
])
</script>
<template>
<UContextMenu :items="items">
<UPageCard
:to="`/modules/${module.name}`"
:title="module.npm"
:description="module.description"
class="group"
variant="subtle"
:ui="{
root: isAdded ? 'ring-primary hover:ring-primary' : '',
description: 'line-clamp-2 text-muted text-sm',
container: 'flex flex-col',
wrapper: 'flex flex-col min-h-0 items-start',
body: 'flex-none',
footer: 'w-full mt-auto pointer-events-auto pt-4 z-1'
}"
@click="handleCardClick"
>
<template #leading>
<UAvatar
:src="moduleImage(module.icon)"
:icon="moduleIcon(module.category)"
:alt="module.name"
size="md"
class="rounded-md bg-transparent"
/>
</template>
<UBadge
v-show="showBadge && module.type === 'official'"
class="shine absolute top-4 right-4 sm:top-6 sm:right-6"
variant="subtle"
color="primary"
label="Official"
/>
<UBadge
v-show="showBadge && module.sponsor"
class="shine absolute top-4 right-4 sm:top-6 sm:right-6"
variant="subtle"
color="important"
label="Sponsor"
/>
<template #footer>
<USeparator type="dashed" class="mb-4" />
<div class="flex items-center justify-between gap-3 -my-1 text-muted">
<div class="flex items-center gap-3 flex-wrap">
<UTooltip text="Monthly NPM Downloads">
<NuxtLink
class="flex items-center gap-1 hover:text-highlighted"
:to="`https://npm.chart.dev/${module.npm}`"
target="_blank"
>
<UIcon name="i-lucide-circle-arrow-down" class="size-4 shrink-0" />
<span class="text-sm font-medium whitespace-normal">{{ formatNumber(module.stats.downloads) }}</span>
</NuxtLink>
</UTooltip>
<UTooltip text="GitHub Stars">
<NuxtLink
class="flex items-center gap-1 hover:text-highlighted"
:to="`https://github.com/${module.repo}`"
target="_blank"
>
<UIcon name="i-lucide-star" class="size-4 shrink-0" />
<span class="text-sm font-medium whitespace-normal">{{ formatNumber(module.stats.stars || 0) }}</span>
</NuxtLink>
</UTooltip>
<template v-if="module.health">
<UTooltip :text="`Health: ${module.health.status} - ${module.health.score}/100`">
<NuxtLink
:to="`https://nuxt.care/?search=npm:${module.npm}`"
class="flex items-center gap-1 hover:text-highlighted"
target="_blank"
>
<UIcon name="i-lucide-heart-pulse" class="size-4 shrink-0" :style="{ color: module.health.color }" />
<span class="text-sm font-medium whitespace-normal">
{{ module.health.score }}
</span>
</NuxtLink>
</UTooltip>
</template>
<UTooltip v-if="selectedSort.key === 'publishedAt'" :text="`Updated ${formatDateByLocale('en', module.stats.publishedAt)}`">
<NuxtLink
class="flex items-center gap-1 hover:text-highlighted"
:to="`https://github.com/${module.repo}`"
target="_blank"
>
<UIcon name="i-lucide-radio" class="size-4 shrink-0" />
<span class="text-sm font-medium whitespace-normal">
<ClientOnly>
{{ relativeDate }}
<template #fallback>
{{ staticModuleDate }}
</template>
</ClientOnly>
</span>
</NuxtLink>
</UTooltip>
<UTooltip v-if="selectedSort.key === 'createdAt'" :text="`Created ${formatDateByLocale('en', module.stats.createdAt)}`">
<NuxtLink
class="flex items-center gap-1 hover:text-highlighted"
:to="`https://github.com/${module.repo}`"
target="_blank"
>
<UIcon name="i-lucide-package" class="size-4 shrink-0" />
<span class="text-sm font-medium whitespace-normal">
<ClientOnly>
{{ relativeDate }}
<template #fallback>
{{ staticModuleDate }}
</template>
</ClientOnly>
</span>
</NuxtLink>
</UTooltip>
</div>
<div class="flex items-center gap-2">
<UTooltip v-if="showAddButton" :text="isAdded ? 'Remove module' : 'Add module'">
<UButton
:icon="isAdded ? 'i-lucide-check' : 'i-lucide-plus'"
color="neutral"
size="xs"
variant="outline"
@click="toggleModule(module)"
>
<span class="sr-only">{{ isAdded ? 'Remove module' : 'Add module' }}</span>
</UButton>
</UTooltip>
<UTooltip text="Copy install command">
<UButton
icon="i-lucide-terminal"
color="neutral"
size="xs"
variant="outline"
@click="copyInstallCommand(module.name)"
>
<span class="sr-only">Copy command to install {{ module.name }}</span>
</UButton>
</UTooltip>
</div>
</div>
</template>
</UPageCard>
</UContextMenu>
</template>
<style lang="postcss" scoped>
.shine {
text-decoration: none;
display: inline-block;
mask-image: linear-gradient(-75deg, rgba(255,255,255,.8) 30%, #fff 50%, rgba(255,255,255,.8) 70%);
mask-size: 200%;
animation: shine 2s linear infinite;
}
@keyframes shine {
from { -webkit-mask-position: 150%; }
to { -webkit-mask-position: -50%; }
}
</style>