Skip to content

Commit 2e1a51b

Browse files
authored
feat: stringMode (#293)
* fix bigInt parse * test: more test case * rm father pre-commit * input it * add util * add validate check * support parse * update demo * back of disabled * fix decimal parser * up & down * up & down limit * click will also trigger update * add isInRange check * not update when in range * back of number logic * step clost to range should be in range * readonly not changable * keyboard props support * fix decimal logic * add empty check * fix empty revert * basic presicon support * fix E * fix presicon is 0 * blur to format back * add should validate * fix isE condition * use origin isE * update dwmo * support onPressEnter * update decimalSeparater demo * support parser decimalSeparator * fix validate number logix * fix parser * oor style * fix update logic & init value logic * update comment * fix parser logic * test for chinese parser * add compsition support * support compition * update logic * init input-control demo * update input & change demo * back of test * more * fix origin step parser * fix add logic * tmp update input sync logic * back of formatter * fix init value parser * safe i * adjust input range logic * fix number type * fix passed logic * more test case * mock support * more test case * more test case * decimal step logic * more test case of decimal * add github test * adjust loop logic * fix test case * test driven * fix test case * wrap test util * fix typing logic * change should check if user typing * fix format of control * more github issue * update onInput update test * fix onChange logic * test input changes * fix initvalue of invalidate * focus & blur test case * fix prescision update * more test case * add toFixed func * use toFixed for prescision * format test case * replace setup of test * format & parse test case * update test case * fix minDisabled logic * data & aria & role test * clean up * fix test case * final test case
1 parent e72ee08 commit 2e1a51b

36 files changed

+3101
-1016
lines changed

.eslintrc.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
const base = require("@umijs/fabric/dist/eslint");
2-
31
module.exports = {
4-
...base,
2+
extends: [require.resolve('@umijs/fabric/dist/eslint')],
53
rules: {
6-
...base.rules,
7-
"arrow-parens": 0,
8-
"react/no-array-index-key": 0,
9-
"react/sort-comp": 0,
10-
"react/no-access-state-in-setstate": 0,
11-
"react/no-string-refs": 0,
12-
"react/no-did-update-set-state": 0,
13-
"react/no-find-dom-node": 0,
14-
"@typescript-eslint/no-explicit-any": 0,
15-
"@typescript-eslint/no-empty-interface": 0,
16-
"@typescript-eslint/no-inferrable-types": 0,
17-
"react/require-default-props": 0,
18-
"no-confusing-arrow": 0,
19-
"no-restricted-globals": 0,
20-
"import/no-named-as-default-member": 0,
21-
"import/no-extraneous-dependencies": 0,
22-
"jsx-a11y/label-has-for": 0,
23-
"jsx-a11y/label-has-associated-control": 0,
24-
"jsx-a11y/no-autofocus": 0
4+
'arrow-parens': 0,
5+
'default-case': 0,
6+
'react/no-array-index-key': 0,
7+
'react/sort-comp': 0,
8+
'react/no-access-state-in-setstate': 0,
9+
'react/no-string-refs': 0,
10+
'react/no-did-update-set-state': 0,
11+
'react/no-find-dom-node': 0,
12+
'@typescript-eslint/no-explicit-any': 0,
13+
'@typescript-eslint/no-empty-interface': 0,
14+
'@typescript-eslint/no-inferrable-types': 0,
15+
'@typescript-eslint/consistent-type-imports': 0,
16+
'react/require-default-props': 0,
17+
'react-hooks/exhaustive-deps': 0,
18+
'no-confusing-arrow': 0,
19+
'no-restricted-globals': 0,
20+
'import/no-named-as-default-member': 0,
21+
'import/no-extraneous-dependencies': 0,
22+
'jsx-a11y/label-has-for': 0,
23+
'jsx-a11y/label-has-associated-control': 0,
24+
'jsx-a11y/no-autofocus': 0,
2525
},
26-
};
26+
};

.fatherrc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export default {
2-
cjs: "babel",
3-
esm: { type: "babel", importLibToEs: true },
2+
cjs: 'babel',
3+
esm: { type: 'babel', importLibToEs: true },
44
preCommit: {
5-
eslint: true,
6-
prettier: true,
5+
// Father preCommit is OOD. comment this tmp.
6+
// eslint: true,
7+
// prettier: true,
78
},
89
runtimeHelpers: true,
910
};

assets/index.less

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,97 @@
11
@inputNumberPrefixCls: rc-input-number;
22

33
.@{inputNumberPrefixCls} {
4+
display: inline-block;
5+
height: 26px;
46
margin: 0;
57
padding: 0;
6-
line-height: 26px;
78
font-size: 12px;
8-
height: 26px;
9-
display: inline-block;
9+
line-height: 26px;
1010
vertical-align: middle;
11-
border: 1px solid #D9D9D9;
11+
border: 1px solid #d9d9d9;
1212
border-radius: 4px;
13-
transition: all .3s;
13+
transition: all 0.3s;
1414

1515
&-focused {
1616
border-color: #1890ff;
17-
box-shadow: 0 0 0 2px rgba(24,144,255,.2);
17+
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
18+
}
19+
&-out-of-range {
20+
input {
21+
color: red;
22+
}
1823
}
1924

2025
&-handler {
21-
text-align: center;
22-
line-height: 12px;
26+
display: block;
2327
height: 12px;
2428
overflow: hidden;
25-
display:block;
29+
line-height: 12px;
30+
text-align: center;
2631
touch-action: none;
2732

2833
&-active {
2934
background: #ddd;
3035
}
3136
}
3237

33-
&-handler-up-inner, &-handler-down-inner {
38+
&-handler-up-inner,
39+
&-handler-down-inner {
3440
color: #666666;
35-
user-select: none;
3641
-webkit-user-select: none;
42+
user-select: none;
3743
}
3844

3945
&:hover {
4046
border-color: #1890ff;
4147

42-
.@{inputNumberPrefixCls}-handler-up, .@{inputNumberPrefixCls}-handler-wrap {
48+
.@{inputNumberPrefixCls}-handler-up,
49+
.@{inputNumberPrefixCls}-handler-wrap {
4350
border-color: #1890ff;
4451
}
4552
}
4653

4754
&-disabled:hover {
4855
border-color: #d9d9d9;
4956

50-
.@{inputNumberPrefixCls}-handler-up, .@{inputNumberPrefixCls}-handler-wrap {
57+
.@{inputNumberPrefixCls}-handler-up,
58+
.@{inputNumberPrefixCls}-handler-wrap {
5159
border-color: #d9d9d9;
5260
}
5361
}
5462

5563
&-input-wrap {
56-
overflow: hidden;
5764
height: 100%;
65+
overflow: hidden;
5866
}
5967

6068
&-input {
6169
width: 100%;
62-
text-align: center;
63-
outline: 0;
64-
-moz-appearance: textfield;
65-
line-height: 26px;
6670
height: 100%;
67-
transition: all 0.3s ease;
71+
padding: 0;
6872
color: #666666;
73+
line-height: 26px;
74+
text-align: center;
6975
border: 0;
7076
border-radius: 4px;
71-
padding: 0;
72-
transition: all .3s;
77+
outline: 0;
78+
transition: all 0.3s ease;
79+
transition: all 0.3s;
80+
-moz-appearance: textfield;
7381
}
7482

7583
&-handler-wrap {
7684
float: right;
77-
border-left: 1px solid #D9D9D9;
7885
width: 20px;
7986
height: 100%;
80-
transition: all .3s;
87+
border-left: 1px solid #d9d9d9;
88+
transition: all 0.3s;
8189
}
8290

8391
&-handler-up {
84-
border-bottom: 1px solid #D9D9D9;
8592
padding-top: 1px;
86-
transition: all .3s;
93+
border-bottom: 1px solid #d9d9d9;
94+
transition: all 0.3s;
8795

8896
&-inner {
8997
&:after {
@@ -93,7 +101,7 @@
93101
}
94102

95103
&-handler-down {
96-
transition: all .3s;
104+
transition: all 0.3s;
97105

98106
&-inner {
99107
&:after {
@@ -103,22 +111,23 @@
103111
}
104112

105113
.handler-disabled() {
106-
opacity: 0.72;
114+
opacity: 0.3;
107115
&:hover {
108116
color: #999;
109117
border-color: #d9d9d9;
110118
}
111119
}
112120

113-
&-handler-down-disabled, &-handler-up-disabled {
121+
&-handler-down-disabled,
122+
&-handler-up-disabled {
114123
.handler-disabled();
115124
}
116125

117126
&-disabled {
118127
.@{inputNumberPrefixCls}-input {
119-
opacity: 0.72;
120-
cursor: not-allowed;
121128
background-color: #f3f3f3;
129+
cursor: not-allowed;
130+
opacity: 0.72;
122131
}
123132
.@{inputNumberPrefixCls}-handler {
124133
.handler-disabled();

docs/demo/input-control.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## input-control
2+
3+
<code src="../examples/input-control.tsx">

docs/examples/combination-key-format.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Component extends React.Component {
1010
value: 50000,
1111
};
1212

13-
onChange = value => {
13+
onChange = (value) => {
1414
console.log('onChange:', value);
1515
this.setState({ value });
1616
};
@@ -27,24 +27,33 @@ class Component extends React.Component {
2727
});
2828
};
2929

30-
numberWithCommas = x => {
30+
numberWithCommas = (x) => {
3131
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
3232
};
3333

34-
format = num => {
34+
format = (num) => {
3535
return `$ ${this.numberWithCommas(num)} boeing737`;
3636
};
3737

38-
parser = num => {
39-
return num
40-
.toString()
41-
.split(' ')[1]
42-
.replace(/,*/g, '');
38+
parser = (num: string) => {
39+
const cells = num.toString().split(' ');
40+
if (!cells[1]) {
41+
return num;
42+
}
43+
44+
const parsed = cells[1].replace(/,*/g, '');
45+
46+
return parsed;
4347
};
4448

4549
render() {
4650
return (
4751
<div style={{ margin: 10 }}>
52+
<p>
53+
When number is validate in range, keep formatting.
54+
Else will flush when blur.
55+
</p>
56+
4857
<InputNumber
4958
aria-label="Number input example that demonstrates combination key format"
5059
min={-8000}

docs/examples/decimal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class Demo extends React.Component {
77
state = {
88
disabled: false,
99
readOnly: false,
10-
value: 8,
10+
value: 99,
1111
};
1212

1313
onChange = v => {
@@ -32,6 +32,7 @@ export default class Demo extends React.Component {
3232
render() {
3333
return (
3434
<div style={{ margin: 10 }}>
35+
<p>Value Range is [-8, 10], initialValue is out of range.</p>
3536
<InputNumber
3637
aria-label="Number input example that demonstrates using decimal values"
3738
min={-8}

0 commit comments

Comments
 (0)