1 | # rmc-input-number
|
2 | ---
|
3 |
|
4 | input number ui component for react (web & react-native)
|
5 |
|
6 | [![NPM version][npm-image]][npm-url]
|
7 | [![build status][travis-image]][travis-url]
|
8 | [![Test coverage][coveralls-image]][coveralls-url]
|
9 | [![gemnasium deps][gemnasium-image]][gemnasium-url]
|
10 | [![node version][node-image]][node-url]
|
11 | [![npm download][download-image]][download-url]
|
12 |
|
13 | [npm-image]: http://img.shields.io/npm/v/rmc-input-number.svg?style=flat-square
|
14 | [npm-url]: http://npmjs.org/package/rmc-input-number
|
15 | [travis-image]: https://img.shields.io/travis/react-component/m-input-number.svg?style=flat-square
|
16 | [travis-url]: https://travis-ci.org/react-component/m-input-number
|
17 | [coveralls-image]: https://img.shields.io/coveralls/react-component/m-input-number.svg?style=flat-square
|
18 | [coveralls-url]: https://coveralls.io/r/react-component/m-input-number?branch=master
|
19 | [gemnasium-image]: http://img.shields.io/gemnasium/react-component/m-input-number.svg?style=flat-square
|
20 | [gemnasium-url]: https://gemnasium.com/react-component/m-input-number
|
21 | [node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
|
22 | [node-url]: http://nodejs.org/download/
|
23 | [download-image]: https://img.shields.io/npm/dm/rmc-input-number.svg?style=flat-square
|
24 | [download-url]: https://npmjs.org/package/rmc-input-number
|
25 |
|
26 | ## Screenshots
|
27 | - web:
|
28 |
|
29 | <img src="http://gtms01.alicdn.com/tps/i1/TB18CIlIpXXXXaxXFXXDa5hRXXX-268-124.png" width="288"/>
|
30 |
|
31 | - react-native:
|
32 |
|
33 | <img src="https://zos.alipayobjects.com/rmsportal/dojvWLzTShEfSAU.png" width="288"/>
|
34 |
|
35 | ## install
|
36 |
|
37 | [![rmc-input-number](https://nodei.co/npm/rmc-input-number.png)](https://npmjs.org/package/rmc-input-number)
|
38 |
|
39 | ## Usage
|
40 |
|
41 | ```js
|
42 | var InputNumber = require('rmc-input-number');
|
43 | var React = require('react');
|
44 | var ReactDOM = require('react-dom');
|
45 | ReactDOM.render(<InputNumber defaultValue={19}/>, container);
|
46 | ```
|
47 |
|
48 | ## Development
|
49 |
|
50 | ```
|
51 | npm install
|
52 | npm run watch-tsc
|
53 | npm start
|
54 | ```
|
55 |
|
56 | ## Example
|
57 |
|
58 | http://127.0.0.1:8000/examples/
|
59 |
|
60 | online example: http://react-component.github.io/m-input-number/examples/
|
61 |
|
62 | ## react-native
|
63 |
|
64 | ```
|
65 | npm run watch-tsc
|
66 | npm run rn-init
|
67 | react-native run-ios
|
68 | ```
|
69 |
|
70 | ## API
|
71 |
|
72 | ### props
|
73 |
|
74 | <table class="table table-bordered table-striped">
|
75 | <thead>
|
76 | <tr>
|
77 | <th style="width: 100px;">name</th>
|
78 | <th style="width: 50px;">type</th>
|
79 | <th style="width: 50px;">default</th>
|
80 | <th>description</th>
|
81 | </tr>
|
82 | </thead>
|
83 | <tbody>
|
84 | <tr>
|
85 | <td>min</td>
|
86 | <td>Number</td>
|
87 | <td></td>
|
88 | <td>Specifies the minimum value</td>
|
89 | </tr>
|
90 | <tr>
|
91 | <td>max</td>
|
92 | <td>Number</td>
|
93 | <td></td>
|
94 | <td>Specifies the maximum value</td>
|
95 | </tr>
|
96 | <tr>
|
97 | <td>step</td>
|
98 | <td>Number or String</td>
|
99 | <td>1</td>
|
100 | <td>Specifies the legal number intervals</td>
|
101 | </tr>
|
102 | <tr>
|
103 | <td>precision</td>
|
104 | <td>Number</td>
|
105 | <td></td>
|
106 | <td>Specifies the precision length of value</td>
|
107 | </tr>
|
108 | <tr>
|
109 | <td>disabled</td>
|
110 | <td>Boolean</td>
|
111 | <td>false</td>
|
112 | <td>Specifies that an InputNumber should be disabled</td>
|
113 | </tr>
|
114 | <tr>
|
115 | <td>focusOnUpDown</td>
|
116 | <td>Boolean</td>
|
117 | <td>true</td>
|
118 | <td>whether focus input when click up or down button</td>
|
119 | </tr>
|
120 | <tr>
|
121 | <td>autoFocus</td>
|
122 | <td>Boolean</td>
|
123 | <td>false</td>
|
124 | <td>Specifies that an InputNumber should automatically get focus when the page loads</td>
|
125 | </tr>
|
126 | <tr>
|
127 | <td>readOnly</td>
|
128 | <td>Boolean</td>
|
129 | <td>false</td>
|
130 | <td>Specifies that an InputNumber is read only </td>
|
131 | </tr>
|
132 | <tr>
|
133 | <td>value</td>
|
134 | <td>Number</td>
|
135 | <td></td>
|
136 | <td>Specifies the value of an InputNumber</td>
|
137 | </tr>
|
138 | <tr>
|
139 | <td>defaultValue</td>
|
140 | <td>Number</td>
|
141 | <td></td>
|
142 | <td>Specifies the defaultValue of an InputNumber</td>
|
143 | </tr>
|
144 | <tr>
|
145 | <td>onChange</td>
|
146 | <td>Function</td>
|
147 | <td></td>
|
148 | <td>Called when value of an InputNumber changed</td>
|
149 | </tr>
|
150 | <tr>
|
151 | <td>style</td>
|
152 | <td>Object</td>
|
153 | <td></td>
|
154 | <td>root style. such as {width:100}</td>
|
155 | </tr>
|
156 | <tr>
|
157 | <td>styles</td>
|
158 | <td>ReactNative StyleSheet</td>
|
159 | <td></td>
|
160 | <td>component's stylesheet, can use lib/styles</td>
|
161 | </tr>
|
162 | <tr>
|
163 | <td>upStyle</td>
|
164 | <td>Object</td>
|
165 | <td></td>
|
166 | <td>up step wrap style. `react native only`</td>
|
167 | </tr>
|
168 | <tr>
|
169 | <td>downStyle</td>
|
170 | <td>Object</td>
|
171 | <td></td>
|
172 | <td>down step style. `react native only`</td>
|
173 | </tr>
|
174 | <tr>
|
175 | <td>inputStyle</td>
|
176 | <td>Object</td>
|
177 | <td></td>
|
178 | <td>input style. `react native only`</td>
|
179 | </tr>
|
180 | <tr>
|
181 | <td>upHandler</td>
|
182 | <td>React.Node</td>
|
183 | <td></td>
|
184 | <td>custom the up step element</td>
|
185 | </tr>
|
186 | <tr>
|
187 | <td>downHandler</td>
|
188 | <td>React.Node</td>
|
189 | <td></td>
|
190 | <td>custom the down step element</td>
|
191 | </tr>
|
192 | <tr>
|
193 | <td>formatter</td>
|
194 | <td>(value: number|string): displayValue: string</td>
|
195 | <td></td>
|
196 | <td>Specifies the format of the value presented</td>
|
197 | </tr>
|
198 | <tr>
|
199 | <td>parser</td>
|
200 | <td>(displayValue: string) => value: number</td>
|
201 | <td>`input => input.replace(/[^\w\.-]*/g, '')`</td>
|
202 | <td>Specifies the value extracted from formatter</td>
|
203 | </tr>
|
204 | </tbody>
|
205 | </table>
|
206 |
|
207 | ## Test Case
|
208 |
|
209 | ```
|
210 | npm test
|
211 | npm run chrome-test
|
212 | ```
|
213 |
|
214 | ## Coverage
|
215 |
|
216 | ```
|
217 | npm run coverage
|
218 | ```
|
219 |
|
220 | open coverage/ dir
|
221 |
|
222 | ## License
|
223 |
|
224 | rmc-input-number is released under the MIT license.
|