Skip to content

Commit aecacb2

Browse files
wojtekmajdanielroe
andauthored
fix(ui): improve MetricsBadges skeleton alignment (#929)
Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent bf0c8f7 commit aecacb2

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

app/components/Package/MetricsBadges.vue

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ const props = defineProps<{
77
version?: string
88
}>()
99
10-
const { data: analysis } = usePackageAnalysis(
10+
const { data: analysis, status } = usePackageAnalysis(
1111
() => props.packageName,
1212
() => props.version,
1313
)
1414
15+
const isLoading = computed(() => status.value !== 'error' && !analysis.value)
16+
1517
// ESM support
1618
const hasEsm = computed(() => {
1719
if (!analysis.value) return false
@@ -52,25 +54,33 @@ const typesHref = computed(() => {
5254
</script>
5355

5456
<template>
55-
<ul v-if="analysis" class="flex items-center gap-1.5 list-none m-0 p-0">
57+
<ul class="flex items-center gap-1.5 list-none m-0 p-0">
5658
<!-- TypeScript types badge -->
57-
<li v-if="!props.isBinary">
59+
<li v-if="!props.isBinary" class="contents">
5860
<TooltipApp :text="typesTooltip">
5961
<component
6062
:is="typesHref ? NuxtLink : 'span'"
6163
:to="typesHref"
6264
:tabindex="!typesHref ? 0 : undefined"
63-
class="inline-flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs rounded transition-colors duration-200 focus-visible:(outline-2 outline-accent)"
65+
class="flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs rounded transition-colors duration-200 focus-visible:(outline-2 outline-accent)"
6466
:class="[
65-
hasTypes
66-
? 'text-fg-muted bg-bg-muted border border-border'
67-
: 'text-fg-subtle bg-bg-subtle border border-border-subtle',
67+
isLoading
68+
? 'text-fg-subtle bg-bg-subtle border border-border-subtle'
69+
: hasTypes
70+
? 'text-fg-muted bg-bg-muted border border-border'
71+
: 'text-fg-subtle bg-bg-subtle border border-border-subtle',
6872
typesHref
6973
? 'hover:text-fg hover:border-border-hover focus-visible:outline-accent/70'
7074
: '',
7175
]"
7276
>
7377
<span
78+
v-if="isLoading"
79+
class="i-carbon-circle-dash w-3 h-3 motion-safe:animate-spin"
80+
aria-hidden="true"
81+
/>
82+
<span
83+
v-else
7484
class="w-3 h-3"
7585
:class="hasTypes ? 'i-carbon-checkmark' : 'i-carbon-close'"
7686
aria-hidden="true"
@@ -81,18 +91,28 @@ const typesHref = computed(() => {
8191
</li>
8292

8393
<!-- ESM badge (show with X if missing) -->
84-
<li>
85-
<TooltipApp :text="hasEsm ? $t('package.metrics.esm') : $t('package.metrics.no_esm')">
94+
<li class="contents">
95+
<TooltipApp
96+
:text="isLoading ? '' : hasEsm ? $t('package.metrics.esm') : $t('package.metrics.no_esm')"
97+
>
8698
<span
8799
tabindex="0"
88-
class="inline-flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs rounded transition-colors duration-200 focus-visible:(outline-2 outline-accent)"
100+
class="flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs rounded transition-colors duration-200 focus-visible:(outline-2 outline-accent)"
89101
:class="
90-
hasEsm
91-
? 'text-fg-muted bg-bg-muted border border-border'
92-
: 'text-fg-subtle bg-bg-subtle border border-border-subtle'
102+
isLoading
103+
? 'text-fg-subtle bg-bg-subtle border border-border-subtle'
104+
: hasEsm
105+
? 'text-fg-muted bg-bg-muted border border-border'
106+
: 'text-fg-subtle bg-bg-subtle border border-border-subtle'
93107
"
94108
>
95109
<span
110+
v-if="isLoading"
111+
class="i-carbon-circle-dash w-3 h-3 motion-safe:animate-spin"
112+
aria-hidden="true"
113+
/>
114+
<span
115+
v-else
96116
class="w-3 h-3"
97117
:class="hasEsm ? 'i-carbon-checkmark' : 'i-carbon-close'"
98118
aria-hidden="true"
@@ -102,14 +122,24 @@ const typesHref = computed(() => {
102122
</TooltipApp>
103123
</li>
104124

105-
<!-- CJS badge (only show if present) -->
106-
<li v-if="hasCjs">
107-
<TooltipApp :text="$t('package.metrics.cjs')">
125+
<!-- CJS badge -->
126+
<li v-if="isLoading || hasCjs" class="contents">
127+
<TooltipApp :text="isLoading ? '' : $t('package.metrics.cjs')">
108128
<span
109129
tabindex="0"
110-
class="inline-flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs text-fg-muted bg-bg-muted border border-border rounded transition-colors duration-200 focus-visible:(outline-2 outline-accent)"
130+
class="flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs rounded transition-colors duration-200 focus-visible:(outline-2 outline-accent)"
131+
:class="
132+
isLoading
133+
? 'text-fg-subtle bg-bg-subtle border border-border-subtle'
134+
: 'text-fg-muted bg-bg-muted border border-border'
135+
"
111136
>
112-
<span class="i-carbon-checkmark w-3 h-3" aria-hidden="true" />
137+
<span
138+
v-if="isLoading"
139+
class="i-carbon-circle-dash w-3 h-3 motion-safe:animate-spin"
140+
aria-hidden="true"
141+
/>
142+
<span v-else class="i-carbon-checkmark w-3 h-3" aria-hidden="true" />
113143
CJS
114144
</span>
115145
</TooltipApp>

app/pages/package/[...package].vue

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ defineOgImageComponent('Package', {
585585
</span>
586586

587587
<!-- Package metrics (module format, types) -->
588-
<ClientOnly>
589-
<div class="flex gap-2 sm:gap-3 flex-wrap">
588+
<div class="flex gap-2 sm:gap-3 flex-wrap">
589+
<ClientOnly>
590590
<PackageMetricsBadges
591591
v-if="resolvedVersion"
592592
:package-name="pkg.name"
@@ -613,16 +613,18 @@ defineOgImageComponent('Package', {
613613
/>
614614
<span>{{ formatCompactNumber(likesData?.totalLikes ?? 0, { decimals: 1 }) }}</span>
615615
</button>
616-
</div>
617-
618-
<template #fallback>
619-
<div class="flex items-center gap-1.5 self-baseline ms-1 sm:ms-2">
620-
<SkeletonBlock class="w-8 h-5 rounded" />
621-
<SkeletonBlock class="w-12 h-5 rounded" />
622-
<SkeletonBlock class="w-5 h-5 rounded" />
623-
</div>
624-
</template>
625-
</ClientOnly>
616+
<template #fallback>
617+
<div
618+
class="flex items-center gap-1.5 list-none m-0 p-0 relative top-[5px] self-baseline ms-1 sm:ms-2"
619+
>
620+
<SkeletonBlock class="w-16 h-5.5 rounded" />
621+
<SkeletonBlock class="w-13 h-5.5 rounded" />
622+
<SkeletonBlock class="w-13 h-5.5 rounded" />
623+
<SkeletonBlock class="w-13 h-5.5 rounded bg-bg-subtle" />
624+
</div>
625+
</template>
626+
</ClientOnly>
627+
</div>
626628

627629
<!-- Internal navigation: Docs + Code + Compare (hidden on mobile, shown in external links instead) -->
628630
<nav

0 commit comments

Comments
 (0)