2.0.4 • Published 10 months ago

react-countplus v2.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

A flexible and customizable React component for animated number counting.

Installation

Install the package using npm:

npm install react-countplus

Usage

Here's a basic example of how to use the CountPlus component:

import { useState } from "react";
import { CountPlus } from "react-countplus";

const App = () => {
  const [key, setKey] = useState(0);

  const handleRestart = () => {
    setKey((prevKey) => prevKey + 1);
  };
  return (
    <div style={{ textAlign: "center", padding: "50px" }}>
      <h1>CountPlus Demo</h1>
      <div style={{ fontSize: "48px", marginBottom: "20px" }}>
        <CountPlus
          key={key}
          start={0}
          end={1000}
          duration={5}
          separator=","
          decimals={2}
          decimal="."
          prefix="$"
          suffix=" USD"
          onStart={() => console.log("Animation started")}
          onUpdate={(value) => console.log("Current value:", value)}
          onEnd={() => console.log("Animation ended")}
        />
      </div>
      <button onClick={handleRestart}>Restart Animation</button>
    </div>
  );
};

export default App;

Props

The CountPlus component accepts the following props:

Prop NameTypeDescriptionDefault Value
startnumberThe number to start counting from0
endnumberThe final number to count up to (required)-
durationnumberDuration of the count animation in seconds2
decimalsnumberNumber of decimal places to show0
separatorstringCharacter used as the thousands separator","
decimalstringCharacter used as the decimal point"."
prefixstringString to display before the number""
suffixstringString to display after the number""
delaynumberDelay in milliseconds before starting the animation0
onStartfunctionCallback function called when the animation starts-
onUpdatefunctionCallback function called on each update with the current value-
onEndfunctionCallback function called when the animation completes-

Features

  • Smooth counting animation
  • Customizable duration and easing
  • Support for decimal numbers
  • Prefix and suffix support
  • Customizable thousand separator and decimal point
  • Delay option for starting the animation
  • Start, update, and end callbacks

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please open an issue or submit a pull request if you'd like to contribute to this project.

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository.

2.0.3

10 months ago

2.0.2

11 months ago

2.0.4

10 months ago

2.0.1

12 months ago

2.0.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago