Skip to content

Commit aaaa776

Browse files
committed
add inputNumber
1 parent 23a89b1 commit aaaa776

File tree

18 files changed

+538
-9
lines changed

18 files changed

+538
-9
lines changed

components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,5 @@ export { default as Progress } from './progress'
146146
import Timeline from './timeline'
147147
const TimelineItem = Timeline.Item
148148
export { Timeline, TimelineItem }
149+
150+
export { default as InputNumber } from './input-number'

components/input-number/demo/basic.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<cn>
2+
#### 基本
3+
数字输入框。
4+
</cn>
5+
6+
<us>
7+
#### Basic
8+
Numeric-only input box.
9+
</us>
10+
11+
```html
12+
<template>
13+
<div>
14+
<a-input-number :min="1" :max="10" v-model="value" @change="onChange" />
15+
当前值:{{value}}
16+
</div>
17+
</template>
18+
<script>
19+
export default {
20+
data() {
21+
return {
22+
value: 3
23+
}
24+
},
25+
methods: {
26+
onChange(value) {
27+
console.log('changed', value);
28+
},
29+
},
30+
}
31+
</script>
32+
```
33+
34+
35+

components/input-number/demo/digit.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<cn>
2+
#### 小数
3+
和原生的数字输入框一样,value 的精度由 step 的小数位数决定。
4+
</cn>
5+
6+
<us>
7+
#### Decimals
8+
A numeric-only input box whose values can be increased or decreased using a decimal step. The number of decimals (also known as precision) is determined by the step prop.
9+
</us>
10+
11+
```html
12+
<template>
13+
<a-input-number :min="0" :max="10" :step="0.1" @change="onChange" />
14+
</template>
15+
<script>
16+
export default {
17+
methods: {
18+
onChange(value) {
19+
console.log('changed', value);
20+
},
21+
},
22+
}
23+
</script>
24+
```
25+
26+
27+
28+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<cn>
2+
#### 不可用
3+
点击按钮切换可用状态。
4+
</cn>
5+
6+
<us>
7+
#### Disabled
8+
Click the button to toggle between available and disabled states.
9+
</us>
10+
11+
```html
12+
<template>
13+
<div>
14+
<a-input-number :min="1" :max="10" :disabled="disabled" :defaultValue="3" />
15+
<div style="marginTop:20px">
16+
<a-button @click="toggle" type="primary">Toggle disabled</a-button>
17+
</div>
18+
</div>
19+
</template>
20+
<script>
21+
export default {
22+
data () {
23+
return {
24+
disabled: true,
25+
}
26+
},
27+
methods: {
28+
toggle() {
29+
this.disabled = !this.disabled
30+
}
31+
},
32+
}
33+
</script>
34+
```
35+
36+
37+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<cn>
2+
#### 格式化展示
3+
通过 `formatter` 格式化数字,以展示具有具体含义的数据,往往需要配合 `parser` 一起使用。
4+
</cn>
5+
6+
<us>
7+
#### Formatter
8+
Display value within it's situation with `formatter`, and we usually use `parser` at the same time.
9+
</us>
10+
11+
```html
12+
<template>
13+
<div>
14+
<a-input-number
15+
:defaultValue="1000"
16+
:formatter="value => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
17+
:parser="value => value.replace(/\$\s?|(,*)/g, '')"
18+
@change="onChange"
19+
/>
20+
<a-input-number
21+
:defaultValue="100"
22+
:min="0"
23+
:max="100"
24+
:formatter="value => `${value}%`"
25+
:parser="value => value.replace('%', '')"
26+
@change="onChange"
27+
/>
28+
</div>
29+
</template>
30+
<script>
31+
export default {
32+
methods: {
33+
onChange(value) {
34+
console.log('changed', value);
35+
},
36+
},
37+
}
38+
</script>
39+
```
40+
41+
42+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<script>
2+
import Basic from './basic.md'
3+
import Disabled from './disabled.md'
4+
import Digit from './digit.md'
5+
import Formatter from './formatter.md'
6+
import Size from './size.md'
7+
import CN from '../index.zh-CN.md'
8+
import US from '../index.en-US.md'
9+
10+
const md = {
11+
cn: `# 数字输入框
12+
通过鼠标或键盘,输入范围内的数值。
13+
## 何时使用
14+
当需要获取标准数值时。
15+
## 代码演示`,
16+
us: `# Data Entry
17+
Enter a number within certain range with the mouse or keyboard.
18+
## When To Use
19+
When a numeric value needs to be provided.
20+
## Examples
21+
`,
22+
}
23+
export default {
24+
category: 'Components',
25+
subtitle: '数字输入框',
26+
type: 'Data Entry',
27+
title: 'InputNumber',
28+
render () {
29+
return (
30+
<div>
31+
<md cn={md.cn} us={md.us}/>
32+
<br/>
33+
<Basic />
34+
<br/>
35+
<Size />
36+
<br />
37+
<Disabled />
38+
<br/>
39+
<Digit />
40+
<br/>
41+
<Formatter />
42+
<br/>
43+
<api>
44+
<template slot='cn'>
45+
<CN/>
46+
</template>
47+
<US/>
48+
</api>
49+
</div>
50+
)
51+
},
52+
}
53+
</script>

components/input-number/demo/size.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<cn>
2+
#### 三种大小
3+
三种大小的数字输入框,当 size 分别为 `large``small` 时,输入框高度为 `40px``24px` ,默认高度为 `32px`
4+
</cn>
5+
6+
<us>
7+
#### Sizes
8+
There are three sizes available to a numeric input box. By default, the size is `32px`. The two additional sizes are `large` and `small` which means `40px` and `24px`, respectively.
9+
</us>
10+
11+
```html
12+
<template>
13+
<div>
14+
<a-input-number size="large" :min="1" :max="100000" :defaultValue="3" @change="onChange" />
15+
<a-input-number :min="1" :max="100000" :defaultValue="3" @change="onChange" />
16+
<a-input-number size="small" :min="1" :max="100000" :defaultValue="3" @change="onChange" />
17+
</div>
18+
</template>
19+
<script>
20+
export default {
21+
methods: {
22+
onChange(value) {
23+
console.log('changed', value);
24+
},
25+
},
26+
}
27+
</script>
28+
<style scoped>
29+
.ant-input-number {
30+
margin-right: 10px;
31+
}
32+
</style>
33+
```
34+
35+
36+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## API
2+
3+
| property | description | type | default |
4+
| -------- | ----------- | ---- | ------- |
5+
| autoFocus | get focus when component mounted | boolean | false |
6+
| defaultValue | initial value | number | |
7+
| disabled | disable the input | boolean | false |
8+
| formatter | Specifies the format of the value presented | function(value: number \| string): string | - |
9+
| max | max vale | number | Infinity |
10+
| min | min value | number | -Infinity |
11+
| parser | Specifies the value extracted from formatter | function( string): number | - |
12+
| precision | precision of input value | number | - |
13+
| size | width of input box | string | - |
14+
| step | The number to which the current value is increased or decreased. It can be an integer or decimal. | number\|string | 1 |
15+
| value(v-model) | current value | number | |
16+
17+
18+
### events
19+
| Events Name | Description | Arguments |
20+
| --- | --- | --- |
21+
| change | The callback triggered when the value is changed. | function(value: number \| string) | |
22+
23+
## Methods
24+
25+
| Name | Description |
26+
| ---- | ----------- |
27+
| blur() | remove focus |
28+
| focus() | get focus |

components/input-number/index.jsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import PropTypes from '../_util/vue-types'
2+
import { initDefaultProps, getOptionProps } from '../_util/props-util'
3+
import classNames from 'classnames'
4+
import VcInputNumber from '../vc-input-number/src'
5+
6+
export const InputNumberProps = {
7+
prefixCls: PropTypes.string,
8+
min: PropTypes.number,
9+
max: PropTypes.number,
10+
value: PropTypes.number,
11+
step: PropTypes.oneOfType([
12+
PropTypes.number,
13+
PropTypes.string,
14+
]),
15+
defaultValue: PropTypes.number,
16+
tabIndex: PropTypes.number,
17+
disabled: PropTypes.bool,
18+
size: PropTypes.oneOf(['large', 'small', 'default']),
19+
formatter: PropTypes.func,
20+
parser: PropTypes.func,
21+
placeholder: PropTypes.string,
22+
name: PropTypes.string,
23+
id: PropTypes.string,
24+
precision: PropTypes.number,
25+
}
26+
27+
export default {
28+
name: 'InputNumber',
29+
model: {
30+
prop: 'value',
31+
event: 'change',
32+
},
33+
props: initDefaultProps(InputNumberProps, {
34+
prefixCls: 'ant-input-number',
35+
step: 1,
36+
}),
37+
methods: {
38+
focus () {
39+
this.$refs.inputNumberRef.focus()
40+
},
41+
blur () {
42+
this.$refs.inputNumberRef.blur()
43+
},
44+
},
45+
46+
render () {
47+
const { size, ...others } = getOptionProps(this)
48+
const inputNumberClass = classNames({
49+
[`${this.prefixCls}-lg`]: size === 'large',
50+
[`${this.prefixCls}-sm`]: size === 'small',
51+
})
52+
const vcInputNumberprops = {
53+
props: {
54+
...others,
55+
},
56+
class: inputNumberClass,
57+
ref: 'inputNumberRef',
58+
on: this.$listeners,
59+
}
60+
return <VcInputNumber {...vcInputNumberprops} />
61+
},
62+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## API
2+
3+
属性如下
4+
5+
| 成员 | 说明 | 类型 | 默认值 |
6+
| --- | --- | --- | --- |
7+
| autoFocus | 自动获取焦点 | boolean | false |
8+
| defaultValue | 初始值 | number | |
9+
| disabled | 禁用 | boolean | false |
10+
| formatter | 指定输入框展示值的格式 | function(value: number \| string): string | - |
11+
| max | 最大值 | number | Infinity |
12+
| min | 最小值 | number | -Infinity |
13+
| parser | 指定从 formatter 里转换回数字的方式,和 formatter 搭配使用 | function( string): number | - |
14+
| precision | 数值精度 | number | - |
15+
| size | 输入框大小 | string ||
16+
| step | 每次改变步数,可以为小数 | number\|string | 1 |
17+
| value(v-model) | 当前值 | number | |
18+
19+
### 事件
20+
| 事件名称 | 说明 | 回调参数 |
21+
| --- | --- | --- |
22+
| change | 变化回调 | Function(value: number \| string) | |
23+
24+
## 方法
25+
26+
| 名称 | 描述 |
27+
| --- | --- |
28+
| blur() | 移除焦点 |
29+
| focus() | 获取焦点 |

0 commit comments

Comments
 (0)