npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-input-percentage

v1.0.7

Published

An input control built with and for ReactJS

Downloads

25

Readme

NPM CircleCI Coverage Status

React-input-percentage

The React Input control for React. Initially built for use in KeystoneJS.

Features include:

  • Flexible amount of decimal positions (0, 1 or 2)
  • Support for comma (',') instead of dot ('.') as a separator
  • Support for min, max, and change steps (with arrows)
  • Only managed mode

This is my first upload to Github, so feel free to suggest improvements or changes!

Installation and usage

The easiest way to use react-input-percentage is to install it from npm and build it into your app with Webpack.

yarn add react-input-percentage

Then use it in your app:

With React Component

import React from 'react';
import InputPercentage from 'react-input-percentage';
import "react-input-percentage/dist/react-input-percentage.cjs.css';

class App extends React.Component {
  state = {
    value: null,
  };
  handleChange = (value) => {
    this.setState({ value }, () =>
      console.log(`Value received:`, this.state.value)
    );
  };
  render() {
    const { value } = this.state;

    return (
      <InputPercentage
        value={value}
        onChange={this.handleChange}
      />
    );
  }
}

With React Hooks

import React, { useState } from 'react';
import InputPercentage from 'react-input-percentage';
import "react-input-percentage/dist/react-input-percentage.cjs.css';

export default function App() {
  const [value, setValue] = useState(null);

  return (
    <div className="App">
      <InputPercentage
        value={value}
        onChange={setValue}
      />
    </div>
  );
}

Props

Common props you may want to specify include:

  • className - apply a className to the control (i.e. 'form-control', for Bootstrap)
  • disabled - disable the control
  • readOnly - control is read-only
  • onChange - subscribe to new values (it will receive string or null, not an event)
  • value - control the current value
  • decimals - how many decimals (aka precission) to use (0, 1 or 2). A value of 2, for example, will send values like '99.23%' to onChange().
  • decimal_point - what to use as a decimal point (',' or '.'). Some languages use comma to separate them. Will only be used for rendering.
  • min - you can limit the minimum acceptable value (i.e., 0). You can still receive nulls though.
  • max - you can limit the maximum acceptable value (i.e., 100). You can still receive nulls though.
  • step - how much do the arrows increment/decrement the current value. By default, 1.
  • symbol - symbol to append to the value. It will be included in the onChange() calls. By default, '%', though you can use '', '$', etc.

See the props documentation for complete documentation on the props react-input-percentage supports.

Controllable Props

This control right now accepts only 'managed mode'. That means that the parent has to supply some value and act on changes. Not all changes get promoted to the parent (only the ones with valid values, or null).

  • value / onChange - specify the current value of the control

License

GNU GPL v3. Copyright (c) Fernando del Valle 2021.