1 | # rc-input-number
|
2 |
|
3 | Input number control.
|
4 |
|
5 | [![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![Dependencies][david-image]][david-url] [![DevDependencies][david-dev-image]][david-dev-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
|
6 |
|
7 | [npm-image]: http://img.shields.io/npm/v/rc-input-number.svg?style=flat-square
|
8 | [npm-url]: http://npmjs.org/package/rc-input-number
|
9 | [github-actions-image]: https://github.com/react-component/input-number/workflows/CI/badge.svg
|
10 | [github-actions-url]: https://github.com/react-component/input-number/actions
|
11 | [circleci-image]: https://img.shields.io/circleci/react-component/input-number/master?style=flat-square
|
12 | [circleci-url]: https://circleci.com/gh/react-component/input-number
|
13 | [coveralls-image]: https://img.shields.io/coveralls/react-component/input-number.svg?style=flat-square
|
14 | [coveralls-url]: https://coveralls.io/r/react-component/input-number?branch=master
|
15 | [david-url]: https://david-dm.org/react-component/input-number
|
16 | [david-image]: https://david-dm.org/react-component/input-number/status.svg?style=flat-square
|
17 | [david-dev-url]: https://david-dm.org/react-component/input-number?type=dev
|
18 | [david-dev-image]: https://david-dm.org/react-component/input-number/dev-status.svg?style=flat-square
|
19 | [download-image]: https://img.shields.io/npm/dm/rc-input-number.svg?style=flat-square
|
20 | [download-url]: https://npmjs.org/package/rc-input-number
|
21 | [bundlephobia-url]: https://bundlephobia.com/result?p=rc-input-number
|
22 | [bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-input-number
|
23 |
|
24 | ## Screenshots
|
25 |
|
26 | <img src="https://user-images.githubusercontent.com/507615/83162463-61414a80-a13c-11ea-9420-971f8697d490.png" width="288"/>
|
27 |
|
28 | ## Install
|
29 |
|
30 | [![rc-input-number](https://nodei.co/npm/rc-input-number.png)](https://npmjs.org/package/rc-input-number)
|
31 |
|
32 | ## Usage
|
33 |
|
34 | ```js
|
35 | import InputNumber from 'rc-input-number';
|
36 |
|
37 | export default () => <InputNumber defaultValue={10} />;
|
38 | ```
|
39 |
|
40 | ## Development
|
41 |
|
42 | ```
|
43 | npm install
|
44 | npm start
|
45 | ```
|
46 |
|
47 | ## Example
|
48 |
|
49 | http://127.0.0.1:8000/examples/
|
50 |
|
51 | online example: https://input-number.vercel.app/
|
52 |
|
53 | ## API
|
54 |
|
55 | ### props
|
56 |
|
57 | <table class="table table-bordered table-striped">
|
58 | <thead>
|
59 | <tr>
|
60 | <th style="width: 100px;">name</th>
|
61 | <th style="width: 50px;">type</th>
|
62 | <th style="width: 50px;">default</th>
|
63 | <th>description</th>
|
64 | </tr>
|
65 | </thead>
|
66 | <tbody>
|
67 | <tr>
|
68 | <td>prefixCls</td>
|
69 | <td>string</td>
|
70 | <td>rc-input-number</td>
|
71 | <td>Specifies the class prefix</td>
|
72 | </tr>
|
73 | <tr>
|
74 | <td>min</td>
|
75 | <td>Number</td>
|
76 | <td></td>
|
77 | <td>Specifies the minimum value</td>
|
78 | </tr>
|
79 | <tr>
|
80 | <td>onClick</td>
|
81 | <td></td>
|
82 | <td></td>
|
83 | <td></td>
|
84 | </tr>
|
85 | <tr>
|
86 | <td>placeholder</td>
|
87 | <td>string</td>
|
88 | <td></td>
|
89 | <td></td>
|
90 | </tr>
|
91 | <tr>
|
92 | <td>max</td>
|
93 | <td>Number</td>
|
94 | <td></td>
|
95 | <td>Specifies the maximum value</td>
|
96 | </tr>
|
97 | <tr>
|
98 | <td>step</td>
|
99 | <td>Number or String</td>
|
100 | <td>1</td>
|
101 | <td>Specifies the legal number intervals</td>
|
102 | </tr>
|
103 | <tr>
|
104 | <td>precision</td>
|
105 | <td>Number</td>
|
106 | <td></td>
|
107 | <td>Specifies the precision length of value</td>
|
108 | </tr>
|
109 | <tr>
|
110 | <td>disabled</td>
|
111 | <td>Boolean</td>
|
112 | <td>false</td>
|
113 | <td>Specifies that an InputNumber should be disabled</td>
|
114 | </tr>
|
115 | <tr>
|
116 | <td>focusOnUpDown</td>
|
117 | <td>Boolean</td>
|
118 | <td>true</td>
|
119 | <td>whether focus input when click up or down button</td>
|
120 | </tr>
|
121 | <tr>
|
122 | <td>required</td>
|
123 | <td>Boolean</td>
|
124 | <td>false</td>
|
125 | <td>Specifies that an InputNumber is required</td>
|
126 | </tr>
|
127 | <tr>
|
128 | <td>autoFocus</td>
|
129 | <td>Boolean</td>
|
130 | <td>false</td>
|
131 | <td>Specifies that an InputNumber should automatically get focus when the page loads</td>
|
132 | </tr>
|
133 | <tr>
|
134 | <td>readOnly</td>
|
135 | <td>Boolean</td>
|
136 | <td>false</td>
|
137 | <td>Specifies that an InputNumber is read only </td>
|
138 | </tr>
|
139 | <tr>
|
140 | <td>controls</td>
|
141 | <td>Boolean</td>
|
142 | <td>true</td>
|
143 | <td>Whether to enable the control buttons</td>
|
144 | </tr>
|
145 | <tr>
|
146 | <td>name</td>
|
147 | <td>String</td>
|
148 | <td></td>
|
149 | <td>Specifies the name of an InputNumber</td>
|
150 | </tr>
|
151 | <tr>
|
152 | <td>id</td>
|
153 | <td>String</td>
|
154 | <td></td>
|
155 | <td>Specifies the id of an InputNumber</td>
|
156 | </tr>
|
157 | <tr>
|
158 | <td>value</td>
|
159 | <td>Number</td>
|
160 | <td></td>
|
161 | <td>Specifies the value of an InputNumber</td>
|
162 | </tr>
|
163 | <tr>
|
164 | <td>defaultValue</td>
|
165 | <td>Number</td>
|
166 | <td></td>
|
167 | <td>Specifies the defaultValue of an InputNumber</td>
|
168 | </tr>
|
169 | <tr>
|
170 | <td>onChange</td>
|
171 | <td>Function</td>
|
172 | <td></td>
|
173 | <td>Called when value of an InputNumber changed</td>
|
174 | </tr>
|
175 | <tr>
|
176 | <td>onBlur</td>
|
177 | <td>Function</td>
|
178 | <td></td>
|
179 | <td>Called when user leaves an input field</td>
|
180 | </tr>
|
181 | <tr>
|
182 | <td>onPressEnter</td>
|
183 | <td>Function</td>
|
184 | <td></td>
|
185 | <td>The callback function that is triggered when Enter key is pressed.</td>
|
186 | </tr>
|
187 | <tr>
|
188 | <td>onFocus</td>
|
189 | <td>Function</td>
|
190 | <td></td>
|
191 | <td>Called when an element gets focus</td>
|
192 | </tr>
|
193 | <tr>
|
194 | <td>style</td>
|
195 | <td>Object</td>
|
196 | <td></td>
|
197 | <td>root style. such as {width:100}</td>
|
198 | </tr>
|
199 | <tr>
|
200 | <td>upHandler</td>
|
201 | <td>React.Node</td>
|
202 | <td></td>
|
203 | <td>custom the up step element</td>
|
204 | </tr>
|
205 | <tr>
|
206 | <td>downHandler</td>
|
207 | <td>React.Node</td>
|
208 | <td></td>
|
209 | <td>custom the down step element</td>
|
210 | </tr>
|
211 | <tr>
|
212 | <td>formatter</td>
|
213 | <td>(value: number|string): displayValue: string</td>
|
214 | <td></td>
|
215 | <td>Specifies the format of the value presented</td>
|
216 | </tr>
|
217 | <tr>
|
218 | <td>parser</td>
|
219 | <td>(displayValue: string) => value: number</td>
|
220 | <td>`input => input.replace(/[^\w\.-]*/g, '')`</td>
|
221 | <td>Specifies the value extracted from formatter</td>
|
222 | </tr>
|
223 | <tr>
|
224 | <td>pattern</td>
|
225 | <td>string</td>
|
226 | <td></td>
|
227 | <td>Specifies a regex pattern to be added to the input number element - useful for forcing iOS to open the number pad instead of the normal keyboard (supply a regex of "\d*" to do this) or form validation</td>
|
228 | </tr>
|
229 | <tr>
|
230 | <td>decimalSeparator</td>
|
231 | <td>string</td>
|
232 | <td></td>
|
233 | <td>Specifies the decimal separator</td>
|
234 | </tr>
|
235 | <tr>
|
236 | <td>inputMode</td>
|
237 | <td>string</td>
|
238 | <td></td>
|
239 | <td>Specifies the inputmode of input</td>
|
240 | </tr>
|
241 | </tbody>
|
242 | </table>
|
243 |
|
244 | ## Keyboard Navigation
|
245 | * When you hit the <kbd>⬆</kbd> or <kbd>⬇</kbd> key, the input value will be increased or decreased by `step`
|
246 | * With the <kbd>Shift</kbd> key (<kbd>Shift+⬆</kbd>, <kbd>Shift+⬇</kbd>), the input value will be changed by `10 * step`
|
247 | * With the <kbd>Ctrl</kbd> or <kbd>⌘</kbd> key (<kbd>Ctrl+⬆</kbd> or <kbd>⌘+⬆</kbd> or <kbd>Ctrl+⬇</kbd> or <kbd>⌘+⬇</kbd> ), the input value will be changed by `0.1 * step`
|
248 |
|
249 | ## Test Case
|
250 |
|
251 | ```
|
252 | npm test
|
253 | npm run chrome-test
|
254 | ```
|
255 |
|
256 | ## Coverage
|
257 |
|
258 | ```
|
259 | npm run coverage
|
260 | ```
|
261 |
|
262 | open coverage/ dir
|
263 |
|
264 | ## License
|
265 |
|
266 | rc-input-number is released under the MIT license.
|