Skip to content

Commit 6228002

Browse files
committed
improve npm download count animation
1 parent b59555c commit 6228002

File tree

3 files changed

+77
-64
lines changed

3 files changed

+77
-64
lines changed

app/components/OpenSourceStats.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import { FaDownload } from 'react-icons/fa'
88
import convexImageWhite from '~/images/convex-white.svg'
99
import convexImageDark from '~/images/convex-dark.svg'
1010

11-
const counterIntervalMs = 500
12-
13-
const StableCounter = ({ value }: { value?: number }) => {
11+
const StableCounter = ({
12+
value,
13+
intervalMs,
14+
}: {
15+
value?: number
16+
intervalMs?: number
17+
}) => {
1418
const dummyString = Number(
1519
Array(value?.toString().length ?? 1)
1620
.fill('8')
@@ -23,14 +27,19 @@ const StableCounter = ({ value }: { value?: number }) => {
2327
<span className="opacity-0">{dummyString}</span>
2428
<span className="absolute -top-0.5 left-0">
2529
<NumberFlow
30+
// Defer to counter hook calculated interval
31+
spinTiming={{
32+
duration: intervalMs,
33+
easing: 'linear',
34+
}}
35+
// Slow horizontal shift animation (due to differing number widths)
2636
transformTiming={{
27-
duration: counterIntervalMs,
37+
duration: 1000,
2838
easing: 'linear',
2939
}}
3040
value={value}
3141
trend={1}
3242
continuous
33-
isolate
3443
willChange
3544
/>
3645
</span>
@@ -43,10 +52,8 @@ const NpmDownloadCounter = ({
4352
}: {
4453
npmData: Parameters<typeof useNpmDownloadCounter>[0]
4554
}) => {
46-
const liveNpmDownloadCount = useNpmDownloadCounter(npmData, {
47-
intervalMs: counterIntervalMs,
48-
})
49-
return <StableCounter value={liveNpmDownloadCount} />
55+
const { count, intervalMs } = useNpmDownloadCounter(npmData)
56+
return <StableCounter value={count} intervalMs={intervalMs} />
5057
}
5158

5259
export default function OssStats() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@convex-dev/react-query": "0.0.0-alpha.8",
2121
"@docsearch/css": "^3.5.2",
2222
"@docsearch/react": "^3.5.2",
23-
"@erquhart/convex-oss-stats": "0.4.2",
23+
"@erquhart/convex-oss-stats": "^0.5.0",
2424
"@headlessui/react": "1.7.18",
2525
"@number-flow/react": "^0.4.1",
2626
"@octokit/graphql": "^7.0.2",

0 commit comments

Comments
 (0)