Skip to content

Commit ba87a55

Browse files
feat: add animation toggle for sparkline chart (#1578)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 6b3d50c commit ba87a55

File tree

8 files changed

+41
-6
lines changed

8 files changed

+41
-6
lines changed

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const props = defineProps<{
1313
1414
const router = useRouter()
1515
const route = useRoute()
16+
const { settings } = useSettings()
1617
1718
const chartModal = useModal('chart-modal')
1819
const hasChartModalTransitioned = shallowRef(false)
@@ -87,6 +88,12 @@ const { colors } = useCssVariables(
8788
},
8889
)
8990
91+
function toggleSparklineAnimation() {
92+
settings.value.sidebar.animateSparkline = !settings.value.sidebar.animateSparkline
93+
}
94+
95+
const hasSparklineAnimation = computed(() => settings.value.sidebar.animateSparkline)
96+
9097
const isDarkMode = computed(() => resolvedMode.value === 'dark')
9198
9299
const accentColorValueById = computed<Record<string, string>>(() => {
@@ -224,7 +231,7 @@ const config = computed(() => {
224231
line: {
225232
color: colors.value.borderHover,
226233
pulse: {
227-
show: true, // the pulse will not show if prefers-reduced-motion (enforced by vue-data-ui)
234+
show: hasSparklineAnimation.value, // the pulse will not show if prefers-reduced-motion (enforced by vue-data-ui)
228235
loop: true, // runs only once if false
229236
radius: 1.5,
230237
color: pulseColor.value,
@@ -302,6 +309,16 @@ const config = computed(() => {
302309
</div>
303310
</template>
304311
</ClientOnly>
312+
313+
<div v-if="hasWeeklyDownloads" class="hidden motion-safe:flex justify-end">
314+
<ButtonBase size="small" @click="toggleSparklineAnimation">
315+
{{
316+
hasSparklineAnimation
317+
? $t('package.trends.pause_animation')
318+
: $t('package.trends.play_animation')
319+
}}
320+
</ButtonBase>
321+
</div>
305322
</template>
306323
<p v-else class="py-2 text-sm font-mono text-fg-subtle">
307324
{{ $t('package.trends.no_data') }}

app/composables/useSettings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface AppSettings {
3636
}
3737
sidebar: {
3838
collapsed: string[]
39+
animateSparkline: boolean
3940
}
4041
}
4142

@@ -52,6 +53,7 @@ const DEFAULT_SETTINGS: AppSettings = {
5253
},
5354
sidebar: {
5455
collapsed: [],
56+
animateSparkline: true,
5557
},
5658
}
5759

i18n/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@
367367
"downloads": "Downloads",
368368
"likes": "Likes",
369369
"contributors": "Contributors"
370-
}
370+
},
371+
"play_animation": "Play animation",
372+
"pause_animation": "Pause animation"
371373
},
372374
"downloads": {
373375
"title": "Weekly Downloads",

i18n/locales/fr-FR.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@
367367
"downloads": "Téléchargements",
368368
"likes": "J'aime",
369369
"contributors": "Contributeurs"
370-
}
370+
},
371+
"play_animation": "Lancer l'animation",
372+
"pause_animation": "Mettre l'animation en pause"
371373
},
372374
"downloads": {
373375
"title": "Téléchargements hebdo.",

i18n/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,12 @@
11071107
}
11081108
},
11091109
"additionalProperties": false
1110+
},
1111+
"play_animation": {
1112+
"type": "string"
1113+
},
1114+
"pause_animation": {
1115+
"type": "string"
11101116
}
11111117
},
11121118
"additionalProperties": false

lunaria/files/en-GB.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@
366366
"downloads": "Downloads",
367367
"likes": "Likes",
368368
"contributors": "Contributors"
369-
}
369+
},
370+
"play_animation": "Play animation",
371+
"pause_animation": "Pause animation"
370372
},
371373
"downloads": {
372374
"title": "Weekly Downloads",

lunaria/files/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@
366366
"downloads": "Downloads",
367367
"likes": "Likes",
368368
"contributors": "Contributors"
369-
}
369+
},
370+
"play_animation": "Play animation",
371+
"pause_animation": "Pause animation"
370372
},
371373
"downloads": {
372374
"title": "Weekly Downloads",

lunaria/files/fr-FR.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@
366366
"downloads": "Téléchargements",
367367
"likes": "J'aime",
368368
"contributors": "Contributeurs"
369-
}
369+
},
370+
"play_animation": "Lancer l'animation",
371+
"pause_animation": "Mettre l'animation en pause"
370372
},
371373
"downloads": {
372374
"title": "Téléchargements hebdo.",

0 commit comments

Comments
 (0)