|
| 1 | +<script setup lang="ts"> |
| 2 | +const props = defineProps<{ |
| 3 | + packageName: string |
| 4 | +}>() |
| 5 | +
|
| 6 | +const { data: score, status } = usePackageScore(() => props.packageName) |
| 7 | +
|
| 8 | +const scoreMetrics = computed(() => { |
| 9 | + if (!score.value) return [] |
| 10 | + return [ |
| 11 | + { |
| 12 | + key: 'quality', |
| 13 | + value: score.value.detail.quality * 100, |
| 14 | + label: $t('package.scores.quality'), |
| 15 | + }, |
| 16 | + { |
| 17 | + key: 'popularity', |
| 18 | + value: score.value.detail.popularity * 100, |
| 19 | + label: $t('package.scores.popularity'), |
| 20 | + }, |
| 21 | + { |
| 22 | + key: 'maintenance', |
| 23 | + value: score.value.detail.maintenance * 100, |
| 24 | + label: $t('package.scores.maintenance'), |
| 25 | + }, |
| 26 | + ] |
| 27 | +}) |
| 28 | +
|
| 29 | +function getScoreColor(percentage: number): string { |
| 30 | + if (percentage < 40) return 'oklch(0.55 0.12 25)' |
| 31 | + if (percentage < 70) return 'oklch(0.6 0.1 85)' |
| 32 | + return 'oklch(0.55 0.1 145)' |
| 33 | +} |
| 34 | +</script> |
| 35 | + |
| 36 | +<template> |
| 37 | + <CollapsibleSection id="scores" :title="$t('package.scores.title')"> |
| 38 | + <template #actions> |
| 39 | + <TooltipApp :text="$t('package.scores.source')"> |
| 40 | + <span class="i-carbon:information w-3.5 h-3.5 text-fg-subtle" aria-hidden="true" /> |
| 41 | + </TooltipApp> |
| 42 | + </template> |
| 43 | + <div v-if="status === 'pending'" class="flex flex-col gap-2"> |
| 44 | + <div v-for="i in 3" :key="i" class="flex items-center gap-3"> |
| 45 | + <SkeletonInline class="w-24 h-3" /> |
| 46 | + <SkeletonInline class="flex-1 h-3 rounded-full" /> |
| 47 | + <SkeletonInline class="w-8 h-3" /> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + <div v-else-if="score" class="flex flex-col gap-2"> |
| 51 | + <div v-for="metric in scoreMetrics" :key="metric.key" class="flex items-center gap-3"> |
| 52 | + <span class="w-24 text-xs text-fg-subtle">{{ metric.label }}</span> |
| 53 | + <div class="flex-1 h-1.5 bg-border-subtle rounded-full overflow-hidden"> |
| 54 | + <div |
| 55 | + class="h-full rounded-full" |
| 56 | + :style="{ width: `${metric.value}%`, background: getScoreColor(metric.value) }" |
| 57 | + /> |
| 58 | + </div> |
| 59 | + <span class="w-8 text-xs font-mono text-fg-muted text-right"> |
| 60 | + {{ Math.round(metric.value) }}% |
| 61 | + </span> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + <p v-else class="text-fg-subtle text-sm">{{ $t('package.scores.unavailable') }}</p> |
| 65 | + </CollapsibleSection> |
| 66 | +</template> |
0 commit comments