feat: add percent field component

This commit is contained in:
chenos 2020-12-09 20:49:17 +08:00
parent cbc81f1173
commit 2828a82f7d
2 changed files with 14 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import React from 'react';
import { connect } from '@formily/react-schema-renderer' import { connect } from '@formily/react-schema-renderer'
import { InputNumber } from 'antd' import { InputNumber } from 'antd'
import { acceptEnum, mapStyledProps, mapTextComponent } from '../shared' import { acceptEnum, mapStyledProps, mapTextComponent } from '../shared'
@ -7,4 +8,15 @@ export const NumberPicker = connect({
getComponent: mapTextComponent getComponent: mapTextComponent
})(acceptEnum(InputNumber)) })(acceptEnum(InputNumber))
export const Percent = connect({
getProps: mapStyledProps,
getComponent: mapTextComponent
})(acceptEnum((props) => (
<InputNumber
formatter={value => value ? `${value}%` : ''}
parser={value => value.replace('%', '')}
{...props}
/>
)))
export default NumberPicker export default NumberPicker

View File

@ -7,7 +7,7 @@ import { ArrayTable } from './array-table'
import { Checkbox } from './checkbox' import { Checkbox } from './checkbox'
import { DatePicker } from './date-picker' import { DatePicker } from './date-picker'
import { Input } from './input' import { Input } from './input'
import { NumberPicker } from './number-picker' import { NumberPicker, Percent } from './number-picker'
import { Password } from './password' import { Password } from './password'
import { Radio } from './radio' import { Radio } from './radio'
import { Range } from './range' import { Range } from './range'
@ -34,6 +34,7 @@ export const setup = () => {
string: Input, string: Input,
textarea: Input.TextArea, textarea: Input.TextArea,
number: NumberPicker, number: NumberPicker,
percent: Percent,
password: Password, password: Password,
radio: Radio.Group, radio: Radio.Group,
range: Range, range: Range,