├── .babelrc
├── .editorconfig
├── .eslintrc
├── .gitignore
├── .npmignore
├── LICENSE.md
├── README.md
├── demo
├── index.js
└── style.css
├── package.json
├── react-number-editor.gif
├── src
└── NumberEditor.jsx
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "latest",
4 | "react"
5 | ],
6 | "plugins": [
7 | "transform-object-rest-spread",
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*]
2 | end_of_line = lf
3 | insert_final_newline = true
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 4
7 |
8 | [*.{json,yml}]
9 | indent_size = 2
10 |
11 | [.*]
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tleunen-react"
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | npm-debug.log
4 | lib/
5 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .*
2 | demo/
3 | src/
4 | webpack.config.js
5 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Tommy Leunen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-number-editor
2 |
3 | [](https://nodei.co/npm/react-number-editor/)
4 |
5 | 
6 |
7 | A [react](https://github.com/facebook/react) component to easily use number inputs. This one acts like those in After Effects or similar software.
8 |
9 | - Click and drag to slide the value.
10 | - Double-click to enter manually a new value.
11 | - Use your Up/Down keys to increment/decrement the value.
12 | - Hold shift key to step by bigger value.
13 | - Hold control/command key to step by smaller value.
14 |
15 | ## Example
16 |
17 | ```js
18 | var React = require('react');
19 | var NumberEditor = require('react-number-editor');
20 |
21 | React.render(
22 | ,
23 | document.body
24 | );
25 | ```
26 |
27 | ## Usage
28 |
29 | ### ``
30 |
31 | Here are the list of properties available for the component:
32 |
33 | - `min` (number) the minimum value. Default no minimum
34 | - `max` (number) the maximum value. Default no maximum
35 | - `step` (number) the step to increment when sliding and with up/down arrows. Default 1.
36 | - `stepModifier` (number) how much to multiply/divide with the modifier keys (shift and control/command). Default is 10.
37 | - `decimals` (number) the number of decimals to show. Default 0.
38 | - `initialValue` (number) the default value to show. Default 0.
39 | - `className` (string) the class name to apply to the DOM element. Default empty.
40 | - `onValueChange` (function) The callback when the value changes. The value is passed as the parameter.
41 | - onKeyDown (function) This callback is called when a key is pressed, after the control has processed the key press, and allows developers to implement their own shortcuts, etc.
42 |
43 | ## demo
44 |
45 | To run the demo, executes this command and go to `http://localhost:8080`:
46 | `npm run demo`
47 |
48 | ## License
49 |
50 | MIT, see [LICENSE.md](/LICENSE.md) for details.
51 |
52 | ## Thanks
53 |
54 | Thanks to [@mattdesl](https://github.com/mattdesl) for his work on [number-editor](https://github.com/mattdesl/number-editor).
55 |
--------------------------------------------------------------------------------
/demo/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import React from 'react';
4 | import { render } from 'react-dom';
5 | import NumberEditor from '../';
6 | require("./style.css");
7 |
8 | var KEYS = {
9 | K: 75,
10 | M: 77
11 | };
12 |
13 | class Demo extends React.Component {
14 | constructor() {
15 | super();
16 | this._onNumberChange = this._onNumberChange.bind(this);
17 | this._onKeyDown = this._onKeyDown.bind(this);
18 |
19 | this.state = {
20 | numberValue: 0
21 | };
22 | }
23 |
24 | _onNumberChange(value) {
25 | this.setState({
26 | numberValue: value
27 | });
28 | }
29 |
30 | render() {
31 | return (
32 |
33 |
44 |
Value: {this.state.numberValue}
45 |
This control implements onKeyDown. Pressing 'k' will multiply the value by 1,000 and pressing 'm' will multiply the value by 1,000,000.