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 { InputNumber } from 'antd'
import { acceptEnum, mapStyledProps, mapTextComponent } from '../shared'
@ -7,4 +8,15 @@ export const NumberPicker = connect({
getComponent: mapTextComponent
})(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

View File

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