react-spinning-number π
Welcome to react-spinning-number
! If you're tired of boring static numbers in your react app, then get ready to spin things upβliterally! This package adds some serious β¨ pizzazz β¨ to your numbers with smooth, eye-catching animations.
Features
- 𧩠Universal Format Support: Handles strings in any format β whether it's time, date, prices, or anything else.
- πͺΆ Less than 5kb: It's so lightweight, it might just disappear! (But it won't, we promise.)
- π‘οΈ Zero Dependencies: No baggage, no problems. Just pure spinning goodness.
- 𦴠Headless: You bring the style, react-spinning-number brings the spin.
- π¨ Cool Animation: Transform your digits into mesmerizing spinners.
Usage
To get started, just install react-spinning-number
via your favorite package manager:
npm install react-spinning-number
yarn add react-spinning-number
pnpm add react-spinning-number
bun add react-spinning-number
Want to see those numbers spin?
import React, { useState } from "react";
import SpinningNumber from "react-spinning-number";
export default function Component() {
const [value, setValue] = useState(1);
return (
<div>
<SpinningNumber fontSize={2}>{value}</SpinningNumber>
<button onClick={() => setValue(value + 1)}>Increase</button>
</div>
);
}
Configuration
There props are allowed for the SpinningNumber
component:
Property | Required | Type | Default | Description |
---|
children | β
| string | number | - | The number or string to spin. |
fontSize | β
| number | - | Sets the font size (in rem) for the spinning numbers. |
className | β | string | - | Adds a custom class for additional styling. |
style | β | CSSProperties | - | Custom inline styles, excluding lineHeight , fontSize , margin , whiteSpace and padding . |
duration | β | number | 300 | Controls the duration of the each digits spin animation, in milliseconds. |
stagger | β | number | 100 | Adds a stagger effect to the spin animation, in milliseconds. |
Credits
This project was inspired by the react-native-spinning-numbers library by birdwingo. A big thanks to them for their work, which served as a great inspiration for this project.