Coder Social home page Coder Social logo

trendingtechnology / use-color-change Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonnyburger/use-color-change

0.0 0.0 0.0 371 KB

๐Ÿ“ˆ๐Ÿ“‰React hook for flashing a text when a value becomes higher or lower

Home Page: https://www.npmjs.com/package/use-color-change

JavaScript 2.54% TypeScript 97.46%

use-color-change's Introduction

use-color-change

React hook for flashing a numeric value when it changes

Installation

This module can be used in any React project that supports hooks.

npm i use-color-change

Usage

Use the hook and pass a number as the first parameter. Specify the colors you want to flash and how long the animation should take. The return value of the hook has the type {animation: string}, you can pass it as a style for any element and also further customize it for example using animation-timing-function if you please.

export const App = () => {
    const [value, setValue] = useState(0);
    const colorStyle = useColorChange(value, {
      higher: "limegreen",
      lower: "crimson",
      duration: 1800
    });

    return (
        <div style={colorStyle}>{value}</div>
    )
}

Function signature

useColorChange(value: number, {
    higher: string | null;
    lower: string | null;
    duration?: number | undefined;
})
  • value: The numeric value for which the animation should be based on.
  • options:
    • higher: The color which should be flashing when the value increases. You can pass null for no animation.
    • lower: The color which should be flashing when the value decreases. You can pass null for no animation.
    • duration: (optional) How long the flash should take in miliseconds. Default is 1800.

Author

ยฉ Jonny Burger

License

MIT

use-color-change's People

Contributors

jonnyburger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.