Skip to content

Commit 611cc87

Browse files
fix: use seamless skeleton shift on sparkline (#391)
Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent 814b5cc commit 611cc87

4 files changed

Lines changed: 40 additions & 15 deletions

File tree

app/components/PackageDownloadAnalytics.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ watch(
4949
5050
const isDarkMode = computed(() => resolvedMode.value === 'dark')
5151
52-
// oklh or css variables are not supported by vue-data-ui (for now)
53-
5452
const accentColorValueById = computed<Record<string, string>>(() => {
5553
const map: Record<string, string> = {}
5654
for (const item of accentColors) {

app/components/PackageWeeklyDownloadStats.vue

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,32 @@ const dataset = computed(() =>
116116
117117
const lastDatapoint = computed(() => dataset.value.at(-1)?.period ?? '')
118118
119-
// oklh or css variables are not supported by vue-data-ui (for now)
120119
const config = computed(() => {
121120
return {
122121
theme: 'dark',
122+
/**
123+
* The built-in skeleton loader kicks in when the component is mounted but the data is not yet ready.
124+
* The configuration of the skeleton is customized for a seemless transition with the final state
125+
*/
126+
skeletonConfig: {
127+
style: {
128+
backgroundColor: 'transparent',
129+
dataLabel: {
130+
show: true,
131+
color: 'transparent',
132+
},
133+
area: {
134+
color: colors.value.borderHover,
135+
useGradient: false,
136+
opacity: 10,
137+
},
138+
line: {
139+
color: colors.value.borderHover,
140+
},
141+
},
142+
},
143+
// Same idea: initialize the line at zero, so it nicely transitions to the final dataset
144+
skeletonDataset: Array.from({ length: 52 }, () => 0),
123145
style: {
124146
backgroundColor: 'transparent',
125147
animation: { show: false },
@@ -196,16 +218,21 @@ const config = computed(() => {
196218

197219
<div class="w-full overflow-hidden">
198220
<ClientOnly>
199-
<VueUiSparkline class="w-full max-w-xs" :dataset :config />
221+
<VueUiSparkline class="w-full max-w-xs" :dataset :config>
222+
<template #skeleton>
223+
<!-- This empty div overrides the default built-in scanning animation on load -->
224+
<div />
225+
</template>
226+
</VueUiSparkline>
200227
<template #fallback>
201228
<!-- Skeleton matching sparkline layout: title row + chart with data label -->
202-
<div class="max-w-xs">
203-
<!-- Title row: date range -->
204-
<div class="h-5 flex items-center ps-3">
229+
<div class="min-h-[75.195px]">
230+
<!-- Title row: date range (24px height) -->
231+
<div class="h-6 flex items-center ps-3">
205232
<span class="skeleton h-3 w-36" />
206233
</div>
207-
<!-- Chart area: data label left, sparkline right (h-[51px] matches rendered SVG) -->
208-
<div class="h-[55px] flex items-center">
234+
<!-- Chart area: data label left, sparkline right -->
235+
<div class="aspect-[500/80] flex items-center">
209236
<!-- Data label (covers ~42% width) -->
210237
<div class="w-[42%] flex items-center ps-0.5">
211238
<span class="skeleton h-7 w-24" />

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"validate-npm-package-name": "^7.0.2",
6363
"virtua": "^0.48.3",
6464
"vue": "3.5.27",
65-
"vue-data-ui": "^3.13.6"
65+
"vue-data-ui": "^3.13.7"
6666
},
6767
"devDependencies": {
6868
"@iconify-json/carbon": "1.2.18",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)