import InputNumber from '../src/index';
import '../assets/index.less';
function getSum(str) {
let total = 0;
str.split('').forEach(c => {
const num = Number(c);
if (!isNaN(num)) {
total += num;
}
});
return total;
export default {
data() {
return {
value: 1000,
};
},
render() {
return (
<div style="margin: 10px;">
<InputNumber
defaultValue={1000}
formatter={value => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
/>
defaultValue={100}
formatter={value => `${value}%`}
parser={value => value.replace('%', '')}
style="width: 100px"
formatter={value => `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
<div>
<h1>In Control</h1>
value={this.value}
onChange={value => {
this.value = value;
}}
</div>
<h1>Strange Format</h1>
formatter={value => `$ ${value} - ${getSum(value)}`}
parser={value => (value.match(/^\$ ([\d\.]*) .*$/) || [])[1]}
);