NumberFlow
repository·main·Indexed 27 days ago
https://github.com/barvian/number-flowA library of animated number components providing smooth transitions for changing numeric values. It is available for React, Vue, Svelte, and vanilla TypeScript/JavaScript. The library includes a custom element <number-flow>, SSR support via renderInnerHTML, and a core engine (NumberFlowLite) that allows for custom animation timing, digit spinning trends, and plugin extensions.
What's inside NumberFlow
- NumberFlow for Vue is an animated number component that provides smooth transitions when numbers change. For complete API details and advanced usage, refer to the official documentation at number-flow.barvian.me/vue.
Install and use NumberFlow
mainNumberFlow is an animated number component available for React, Vue, Svelte, and vanilla TypeScript/JavaScript. It provides smooth transitions when numbers change.Use NumberFlow for Svelte
mainNumberFlow provides an animated number component for Svelte applications. For complete API details and usage examples, refer to the official documentation at number-flow.barvian.me/svelte.Use NumberFlowGroup for grouping numbers
mainTo group multipleNumberFlowcomponents together so they animate in sync (e.g., when digits shift positions), wrap them in a<NumberFlowGroup>component. This ensures that the layout transitions are coordinated across the group.Install @number-flow/svelte
mainTo use animated numbers in your Svelte application, install the@number-flow/sveltepackage via npm.Install @number-flow/vue
mainTo use NumberFlow in your Vue project, install the@number-flow/vuepackage via npm.Install and use NumberFlow for React
mainNumberFlow for React is an animated number component. It provides smooth transitions when numbers change. For full documentation and advanced usage, visit number-flow.barvian.me.Sync transitions with NumberFlowGroup
mainIf one NumberFlow component affects the position of another, wrap them in a<NumberFlowGroup>to sync their transitions. In Vanilla JS, ensure youimport 'number-flow/group'.Basic usage of NumberFlow
mainNumberFlow provides framework-specific packages for React, Vue, Svelte, and Vanilla JavaScript. It automatically transitions when the
valueprop changes.// React import NumberFlow from '@number-flow/react' function Example() { return <NumberFlow value={123} /> }<!-- Vue --> <script setup> import NumberFlow from '@number-flow/vue' </script> <template> <NumberFlow :value="123" /> </template><!-- Svelte --> <script> import NumberFlow from '@number-flow/svelte' </script> <NumberFlow value={123} /><!-- Vanilla JS --> <number-flow></number-flow> <script type="module"> import 'number-flow' const flow = document.querySelector('number-flow') flow.update(123) </script>Customize animation timings
mainCustomize the duration and easing of different animation types usingEffectTimingobjects. Each acceptsdurationandeasing.Server-side rendering with renderInnerHTML
mainFor SSR (like Astro), use
renderInnerHTMLto generate the initial HTML. Ensure you pass the samelocales,format, andnonceto both the renderer and the client-side hydration.--- import { renderInnerHTML } from 'number-flow' --- <number-flow nonce="..." set:html={renderInnerHTML(123, { locales: 'en-US', format: { notation: 'compact' }, nonce: '...' })} /> <script> import 'number-flow' const flow = document.querySelector('number-flow') flow.locales = 'en-US' flow.format = { notation: 'compact' } flow.update(123) </script>Add custom prefixes and suffixes
mainYou can add custom strings before or after the number using
numberPrefix(vanilla) orprefix/suffix(frameworks).<NumberFlow value={value} format={{ style: 'currency', currency: 'USD', trailingZeroDisplay: 'stripIfInteger' }} suffix="/mo" />// Vanilla JS flow.numberPrefix = "$" flow.numberSuffix = "/mo"