Skip to content

Commit 6e1f18a

Browse files
committed
feat: integrate NumberFlow for animated stats
Replaces static number displays with NumberFlow component to provide smooth animated transitions when stats update. Refactors stats composable to expose raw numeric values alongside formatted strings, enabling NumberFlow to handle number animations while maintaining formatted displays where needed. Improves user experience by adding visual feedback when GitHub statistics change.
1 parent aa60c57 commit 6e1f18a

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

app/components/home/Stats.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<script setup lang="ts">
2-
const { stats } = useGithubStats()
2+
import NumberFlow from '@number-flow/vue'
3+
4+
const { rawStats } = useGithubStats()
35
</script>
46

57
<template>
@@ -42,9 +44,7 @@ const { stats } = useGithubStats()
4244
<template #fallback>
4345
<Skeleton class="mx-auto h-12 w-24" />
4446
</template>
45-
<div class="text-5xl font-bold tabular-nums">
46-
{{ stats.stars }}
47-
</div>
47+
<NumberFlow class="text-5xl font-bold tabular-nums" :value="rawStats.stars" />
4848
</ClientOnly>
4949
<p class="text-muted-foreground">
5050
{{ $t('home.stats.stars') }}
@@ -60,9 +60,7 @@ const { stats } = useGithubStats()
6060
<template #fallback>
6161
<Skeleton class="mx-auto h-12 w-24" />
6262
</template>
63-
<div class="text-5xl font-bold tabular-nums">
64-
{{ stats.forks }}
65-
</div>
63+
<NumberFlow class="text-5xl font-bold tabular-nums" :value="rawStats.forks" />
6664
</ClientOnly>
6765
<p class="text-muted-foreground">
6866
{{ $t('home.stats.forks') }}

app/composables/useGithubStats.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ export function useGithubStats() {
2424
},
2525
)
2626

27+
const rawStats = computed(() => ({
28+
stars: data.value?.stars ?? 6000,
29+
forks: data.value?.forks ?? 4000,
30+
}))
31+
2732
const formattedStats = computed(() => ({
28-
stars: data.value?.stars?.toLocaleString() ?? '6,000',
29-
forks: data.value?.forks?.toLocaleString() ?? '4,000',
33+
stars: rawStats.value.stars.toLocaleString(),
34+
forks: rawStats.value.forks.toLocaleString(),
3035
}))
3136

32-
return { stats: formattedStats, status }
37+
return { stats: formattedStats, rawStats, status }
3338
}

app/layouts/default.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script setup lang="ts">
2+
import NumberFlow from '@number-flow/vue'
23
import { Menu, Star, X } from 'lucide-vue-next'
34
import { GitHubIcon, TelegramIcon, XIcon } from 'vue3-simple-icons'
45
56
const showMenu = ref(false)
67
const { title, telegram, twitter, github } = useAppConfig()
7-
const { stats } = useGithubStats()
8+
const { rawStats } = useGithubStats()
89
</script>
910

1011
<template>
@@ -105,7 +106,7 @@ const { stats } = useGithubStats()
105106
>
106107
<GitHubIcon class="size-4" />
107108
<Star class="size-3" />
108-
<span class="tabular-nums">{{ stats.stars }}</span>
109+
<NumberFlow class="tabular-nums" :value="rawStats.stars" />
109110
</a>
110111
</Button>
111112

0 commit comments

Comments
 (0)