Giter Site home page Giter Site logo

watt3r / react-odometerjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bezenson/react-odometerjs

0.0 0.0 0.0 1.87 MB

Odometer.js React Component. Adds new (D) format to force decimal digits in odometers

License: MIT License

JavaScript 35.66% TypeScript 64.34%

react-odometerjs's Introduction

Latest version Downloads

React Odometer.js

Simple React wrapper around Odometer.js.

Preview

How to use this library

  1. Install npm package:
npm install --save react-odometerjs

or

yarn add react-odometerjs
  1. Import CSS file in your app <head>:
<link rel="stylesheet" href="odometer-theme-default.css" />

Official themes can be found here.

  1. Include component in your application:
import React, { useEffect, useState } from 'react';
import Odometer from 'react-odometerjs';

const App = () => {
    const [value, setValue] = useState(1234);

    useEffect(() => {
        const timeoutId = setTimeout(() => setValue(4321), 2000);
        return () => {
            clearTimeout(timeoutId);
        };
    }, []);

    return <Odometer value={value} format="(.ddd),dd" />;
}

Options

Option Type Default Description
animation 'count' | undefined Count is a simpler animation method which just increments the value, use it when you're looking for something more subtle.
duration number 2000 Change how long the javascript expects the CSS animation to take.
format string '(,ddd).dd' Change how digit groups are formatted, and how many digits are shown after the decimal point.
theme string Specify the theme (if you have more than one theme css file on the page). Will add CSS class .odometer-theme-{prop value} to wrapper div.
value number Current value. Change it to run animation.

You can read about options on official website.

Also component can receive any div property.

Example:

// Pass `style` prop
return <Odometer value={1234} style={{ cursor: 'pointer' }} />;

Next.js integration

Because Odometer.js requires document object, we should load library using dynamic import, to avoid loading library on server-side.

Example snippet:

import dynamic from 'next/dynamic'

const Odometer = dynamic(import('react-odometerjs'), {
    ssr: false,
    loading: () => 0
});

const App = () => {
    return <Odometer value={1234} />;
}

Gatsby integration

Odometer.js

import Odometer from 'react-odometerjs'

export default Odometer;

App.js

import loadable from '@loadable/component'

const Odometer = loadable(() => import('./Odometer'))

const App = () => {
    return <Odometer value={1234} />;
}

Issues

Found an issue? You are welcome here.

react-odometerjs's People

Contributors

bezenson avatar dependabot[bot] avatar dasnixon avatar piecioshka avatar lorensr avatar mjtko avatar watt3r 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.