🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

react-animated-numbers

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-animated-numbers

Library showing animation of number changes in react.js

0.4.2
Source
npm
Version published
Weekly downloads
9.5K
15.47%
Maintainers
1
Weekly downloads
 
Created
Source
npm version

react-animated-numbers

Library showing animation of number changes in react.js

Test

Homepage

Props

nametypedefaultdescription
animateToNumbernumbernoneNumber to be animated
animationType"calm" or "random"`"random"Decide whether to increase sequentially, starting with the smallest number
fontStyleReact.CSSProperties?noneStyle of number text
includeCommaboolean?falseWhether the number contains commas
delaynumber(ms)?undefinedMilliseconds to decide how late to start animation
includeCommaboolean?falseWhether the number contains commas
onStart(): void?undefinedFunction executed when animation is started
onFinish(): void?undefinedFunction executed when animation is finished (not support calm animation type)
configSpringConfig?config.defaultThis module is using react-spring and you can refer to this config option

Example

import React from 'react';
import AnimatedNumber from "react-animated-numbers"

function App() {
  const [number, setNumber] = React.useState(0)
  const [diff, setDiff] = React.useState(0)

  const increaseNumber = () => {
    setNumber(number + diff)
  }

  const decreaseNumber = () => {
    setNumber(number - diff)
  }

  const onChangeValue = (e) => {
    const number = Number(e.target.value)
    setDiff(number)
  }

  return (
    <div className="App">
      <div
        style={{
          display: "flex",
          justifyContent: "center",
          alignItems: "center",
          height: "100vh",
          flexDirection: "column",
        }}
      >
        <label htmlFor="value">Number Difference</label>
        <input
          id="value"
          title="value"
          placeholder="Difference"
          type="number"
          style={{ marginBottom: 30 }}
          onChange={onChangeValue}
        />
        <AnimatedNumber
          fontStyle={{ fontFamily: "Nunito", fontSize: 40 }}
          animateToNumber={number}
          includeComma
          config={{ tension: 89, friction: 40 }}
          onStart={() => console.log("onStart")}
          onFinish={() => console.log("onFinish")}
          animationType={"calm"}
        />
        <div
          style={{
            height: 60,
            display: "flex",
            flexDirection: "column",
            justifyContent: "space-between",
            marginTop: 40,
          }}
        >
          <button onClick={increaseNumber}>increase Number</button>
          <button onClick={decreaseNumber}>decrease Number</button>
        </div>
      </div>
    </div>
  )
}

Keywords

react

FAQs

Package last updated on 12 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts