@hi-ui/input 4.0.0-alpha.20 → 4.0.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Input.js +52 -75
- package/lib/cjs/Input.js.map +1 -1
- package/lib/cjs/TextArea.js +102 -0
- package/lib/cjs/TextArea.js.map +1 -0
- package/lib/cjs/index.js +3 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/styles/index.scss.js +1 -1
- package/lib/cjs/use-input.js +126 -0
- package/lib/cjs/use-input.js.map +1 -0
- package/lib/cjs/utils/index.js +192 -0
- package/lib/cjs/utils/index.js.map +1 -0
- package/lib/esm/Input.js +51 -74
- package/lib/esm/Input.js.map +1 -1
- package/lib/esm/TextArea.js +81 -0
- package/lib/esm/TextArea.js.map +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/styles/index.scss.js +1 -1
- package/lib/esm/use-input.js +116 -0
- package/lib/esm/use-input.js.map +1 -0
- package/lib/esm/utils/index.js +176 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/types/Input.d.ts +3 -3
- package/lib/types/MockInput.d.ts +1 -1
- package/lib/types/TextArea.d.ts +22 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/use-input.d.ts +78 -0
- package/lib/types/utils/index.d.ts +9 -1
- package/package.json +12 -10
@@ -0,0 +1,126 @@
|
|
1
|
+
/** @LICENSE
|
2
|
+
* @hi-ui/input
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/input#readme
|
4
|
+
*
|
5
|
+
* Copyright (c) HIUI <mi-hiui@xiaomi.com>.
|
6
|
+
*
|
7
|
+
* This source code is licensed under the MIT license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
'use strict';
|
11
|
+
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
13
|
+
value: true
|
14
|
+
});
|
15
|
+
|
16
|
+
var React = require('react');
|
17
|
+
|
18
|
+
var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
|
19
|
+
|
20
|
+
var useLatest = require('@hi-ui/use-latest');
|
21
|
+
|
22
|
+
var domUtils = require('@hi-ui/dom-utils');
|
23
|
+
|
24
|
+
var index = require('./utils/index.js');
|
25
|
+
|
26
|
+
var useInput = function useInput(_ref) {
|
27
|
+
var name = _ref.name,
|
28
|
+
_ref$autoFocus = _ref.autoFocus,
|
29
|
+
autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
|
30
|
+
_ref$disabled = _ref.disabled,
|
31
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
32
|
+
_ref$readOnly = _ref.readOnly,
|
33
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
34
|
+
maxLength = _ref.maxLength,
|
35
|
+
placeholder = _ref.placeholder,
|
36
|
+
_ref$defaultValue = _ref.defaultValue,
|
37
|
+
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
|
38
|
+
valueProp = _ref.value,
|
39
|
+
onChange = _ref.onChange,
|
40
|
+
onFocus = _ref.onFocus,
|
41
|
+
onBlur = _ref.onBlur,
|
42
|
+
_ref$trimValueOnBlur = _ref.trimValueOnBlur,
|
43
|
+
trimValueOnBlur = _ref$trimValueOnBlur === void 0 ? false : _ref$trimValueOnBlur,
|
44
|
+
_ref$type = _ref.type,
|
45
|
+
type = _ref$type === void 0 ? 'text' : _ref$type,
|
46
|
+
clearElementRef = _ref.clearElementRef; // Object.is 避免 trimValueOnBlur 和 点击 clearIcon 触发 2 次相同的 onCHange
|
47
|
+
|
48
|
+
var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultValue, valueProp, onChange, Object.is),
|
49
|
+
value = _useUncontrolledState[0],
|
50
|
+
tryChangeValue = _useUncontrolledState[1];
|
51
|
+
|
52
|
+
var handleChange = React.useCallback(function (evt, trim) {
|
53
|
+
if (trim === void 0) {
|
54
|
+
trim = false;
|
55
|
+
}
|
56
|
+
|
57
|
+
evt.persist();
|
58
|
+
var nextValue = evt.target.value;
|
59
|
+
var valueTrue = index.pure(nextValue, type); // 防溢出,保证 onChange 拿到的是值是最新的 formatted value
|
60
|
+
|
61
|
+
var value = index.format(nextValue, type);
|
62
|
+
|
63
|
+
if (trim) {
|
64
|
+
valueTrue = valueTrue.trim();
|
65
|
+
value = value.trim();
|
66
|
+
}
|
67
|
+
|
68
|
+
evt.target.value = value;
|
69
|
+
tryChangeValue(valueTrue, evt);
|
70
|
+
}, [tryChangeValue, type]);
|
71
|
+
|
72
|
+
var _useState = React.useState(autoFocus),
|
73
|
+
focused = _useState[0],
|
74
|
+
setFocused = _useState[1];
|
75
|
+
|
76
|
+
var handleFocus = useLatest.useLatestCallback(function (evt) {
|
77
|
+
setFocused(true);
|
78
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(evt);
|
79
|
+
});
|
80
|
+
var handleBlur = useLatest.useLatestCallback(function (event) {
|
81
|
+
var relatedTarget = event.relatedTarget; // 拦截 clear 情况 触发 input 失焦
|
82
|
+
|
83
|
+
if (clearElementRef.current && clearElementRef.current === relatedTarget) {
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
|
87
|
+
setFocused(false); // amount 自动添加小数
|
88
|
+
|
89
|
+
if (type === 'amount') {
|
90
|
+
event.target.value = index.formatAmount(value, true);
|
91
|
+
handleChange(event, trimValueOnBlur);
|
92
|
+
} else if (trimValueOnBlur) {
|
93
|
+
handleChange(event, true);
|
94
|
+
}
|
95
|
+
|
96
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
97
|
+
});
|
98
|
+
var nativeInputProps = React.useMemo(function () {
|
99
|
+
return {
|
100
|
+
name: name,
|
101
|
+
disabled: disabled,
|
102
|
+
readOnly: readOnly,
|
103
|
+
autoFocus: autoFocus,
|
104
|
+
placeholder: placeholder,
|
105
|
+
maxLength: maxLength,
|
106
|
+
'data-focused': domUtils.setAttrStatus(focused)
|
107
|
+
};
|
108
|
+
}, [disabled, readOnly, autoFocus, placeholder, maxLength, name, focused]);
|
109
|
+
var getInputProps = React.useCallback(function () {
|
110
|
+
return Object.assign(Object.assign({}, nativeInputProps), {
|
111
|
+
value: index.format(value, type),
|
112
|
+
onChange: handleChange,
|
113
|
+
onFocus: handleFocus,
|
114
|
+
onBlur: handleBlur
|
115
|
+
});
|
116
|
+
}, [value, type, handleChange, handleFocus, handleBlur, nativeInputProps]);
|
117
|
+
return {
|
118
|
+
focused: focused,
|
119
|
+
value: value,
|
120
|
+
tryChangeValue: tryChangeValue,
|
121
|
+
getInputProps: getInputProps
|
122
|
+
};
|
123
|
+
};
|
124
|
+
|
125
|
+
exports.useInput = useInput;
|
126
|
+
//# sourceMappingURL=use-input.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"use-input.js","sources":["../../src/use-input.ts"],"sourcesContent":[null],"names":["useInput","name","autoFocus","disabled","readOnly","maxLength","placeholder","defaultValue","valueProp","value","onChange","onFocus","onBlur","trimValueOnBlur","type","clearElementRef","useUncontrolledState","Object","is","tryChangeValue","handleChange","useCallback","evt","trim","persist","nextValue","target","valueTrue","pure","format","useState","focused","setFocused","handleFocus","useLatestCallback","handleBlur","event","relatedTarget","current","formatAmount","nativeInputProps","useMemo","setAttrStatus","getInputProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;IAMaA,QAAQ,GAAG,SAAXA,QAAW,KAAA;MACtBC,YAAAA;4BACAC;MAAAA,wCAAY;2BACZC;MAAAA,sCAAW;2BACXC;MAAAA,sCAAW;MACXC,iBAAAA;MACAC,mBAAAA;+BACAC;MAAAA,8CAAe;MACRC,iBAAPC;MACAC,gBAAAA;MACAC,eAAAA;MACAC,cAAAA;kCACAC;MAAAA,oDAAkB;uBAClBC;MAAAA,8BAAO;MACPC,uBAAAA;;8BAGgCC,yCAAAA,CAAqBT,YAArBS,EAAmCR,SAAnCQ,EAA8CN,QAA9CM,EAAwDC,MAAM,CAACC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/tree/master/packages/ui/input#readme
|
4
|
+
*
|
5
|
+
* Copyright (c) HIUI <mi-hiui@xiaomi.com>.
|
6
|
+
*
|
7
|
+
* This source code is licensed under the MIT license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
'use strict';
|
11
|
+
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
13
|
+
value: true
|
14
|
+
});
|
15
|
+
/**
|
16
|
+
* 格式化身份证
|
17
|
+
*/
|
18
|
+
|
19
|
+
var formatId = function formatId(val) {
|
20
|
+
val = val.replace(/[^a-zA-Z0-9]/g, '');
|
21
|
+
var len = val.length;
|
22
|
+
|
23
|
+
if (val === '' || len < 7) {
|
24
|
+
return val;
|
25
|
+
}
|
26
|
+
|
27
|
+
if (len < 11) {
|
28
|
+
return val.slice(0, 6) + ' ' + val.slice(6, 10);
|
29
|
+
} else if (len < 15) {
|
30
|
+
return val.slice(0, 6) + ' ' + val.slice(6, 10) + ' ' + val.slice(10, 14);
|
31
|
+
} else {
|
32
|
+
return val.slice(0, 6) + ' ' + val.slice(6, 10) + ' ' + val.slice(10, 14) + ' ' + val.slice(14, 18);
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
var pureId = function pureId(val) {
|
37
|
+
var tmp = val.replace(/[^\d|.]/g, '');
|
38
|
+
return tmp.slice(0, 18);
|
39
|
+
};
|
40
|
+
/**
|
41
|
+
* 格式化手机号
|
42
|
+
*/
|
43
|
+
|
44
|
+
|
45
|
+
var formatTel = function formatTel(val) {
|
46
|
+
val = val.replace(/\D/g, '');
|
47
|
+
var len = val.length;
|
48
|
+
|
49
|
+
if (val === '' || len < 4) {
|
50
|
+
return val;
|
51
|
+
}
|
52
|
+
|
53
|
+
if (len < 8) {
|
54
|
+
return val.slice(0, 3) + ' ' + val.slice(3, 7);
|
55
|
+
} else {
|
56
|
+
return val.slice(0, 3) + ' ' + val.slice(3, 7) + ' ' + val.slice(7, 11);
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
var pureTel = function pureTel(val) {
|
61
|
+
var tmp = val.replace(/[^\d|.]/g, '');
|
62
|
+
return tmp.slice(0, 11);
|
63
|
+
};
|
64
|
+
/**
|
65
|
+
* 格式化银行卡号
|
66
|
+
*/
|
67
|
+
|
68
|
+
|
69
|
+
var formatCard = function formatCard(val) {
|
70
|
+
val = val.replace(/\D/g, '');
|
71
|
+
var len = val.length;
|
72
|
+
|
73
|
+
if (val === '' || val.length < 5) {
|
74
|
+
return val;
|
75
|
+
}
|
76
|
+
|
77
|
+
if (len < 9) {
|
78
|
+
return val.slice(0, 4) + ' ' + val.slice(4, 8);
|
79
|
+
} else if (len < 13) {
|
80
|
+
return val.slice(0, 4) + ' ' + val.slice(4, 8) + ' ' + val.slice(8, 12);
|
81
|
+
} else if (len < 17) {
|
82
|
+
return val.slice(0, 4) + ' ' + val.slice(4, 8) + ' ' + val.slice(8, 12) + ' ' + val.slice(12, 16);
|
83
|
+
} else {
|
84
|
+
return val.slice(0, 4) + ' ' + val.slice(4, 8) + ' ' + val.slice(8, 12) + ' ' + val.slice(12, 16) + ' ' + val.slice(16, 19);
|
85
|
+
}
|
86
|
+
};
|
87
|
+
|
88
|
+
var pureCard = function pureCard(val) {
|
89
|
+
var tmp = val.replace(/[^\d|.]/g, '');
|
90
|
+
return tmp.slice(0, 19);
|
91
|
+
};
|
92
|
+
/**
|
93
|
+
* 金额自动生成小数
|
94
|
+
* @param {string} val 需要处理的值
|
95
|
+
*/
|
96
|
+
|
97
|
+
|
98
|
+
var formatAmount = function formatAmount(val, fill) {
|
99
|
+
if (fill === void 0) {
|
100
|
+
fill = false;
|
101
|
+
}
|
102
|
+
|
103
|
+
val = val.replace(/[^\d|.|,]/g, '').replace(/(\.\d*?)(\.|,).*/, function (_, $1) {
|
104
|
+
return $1;
|
105
|
+
});
|
106
|
+
|
107
|
+
if (fill) {
|
108
|
+
if (!val) return val;
|
109
|
+
return val.indexOf('.') > -1 ? val : val + '.00';
|
110
|
+
}
|
111
|
+
|
112
|
+
return val;
|
113
|
+
};
|
114
|
+
|
115
|
+
var pureAmount = function pureAmount(val) {
|
116
|
+
var tmp = val.replace(/[^\d|.]/g, '');
|
117
|
+
return tmp;
|
118
|
+
};
|
119
|
+
|
120
|
+
var formatEmail = function formatEmail(val) {
|
121
|
+
return val.replace(/\W/g, '');
|
122
|
+
};
|
123
|
+
|
124
|
+
var pureEmail = function pureEmail(val) {
|
125
|
+
return val;
|
126
|
+
};
|
127
|
+
/**
|
128
|
+
* 输入规则
|
129
|
+
*/
|
130
|
+
|
131
|
+
|
132
|
+
var format = function format(val, type) {
|
133
|
+
switch (type) {
|
134
|
+
case 'id':
|
135
|
+
return formatId(val);
|
136
|
+
|
137
|
+
case 'tel':
|
138
|
+
return formatTel(val);
|
139
|
+
|
140
|
+
case 'card':
|
141
|
+
return formatCard(val);
|
142
|
+
|
143
|
+
case 'email':
|
144
|
+
return formatEmail(val);
|
145
|
+
|
146
|
+
case 'amount':
|
147
|
+
return formatAmount(val);
|
148
|
+
|
149
|
+
default:
|
150
|
+
return val;
|
151
|
+
}
|
152
|
+
};
|
153
|
+
/**
|
154
|
+
* 净化规则
|
155
|
+
*/
|
156
|
+
|
157
|
+
|
158
|
+
var pure = function pure(val, type) {
|
159
|
+
switch (type) {
|
160
|
+
case 'id':
|
161
|
+
return pureId(val);
|
162
|
+
|
163
|
+
case 'tel':
|
164
|
+
return pureTel(val);
|
165
|
+
|
166
|
+
case 'card':
|
167
|
+
return pureCard(val);
|
168
|
+
|
169
|
+
case 'email':
|
170
|
+
return pureEmail(val);
|
171
|
+
|
172
|
+
case 'amount':
|
173
|
+
return pureAmount(val);
|
174
|
+
|
175
|
+
default:
|
176
|
+
return val;
|
177
|
+
}
|
178
|
+
};
|
179
|
+
|
180
|
+
exports.format = format;
|
181
|
+
exports.formatAmount = formatAmount;
|
182
|
+
exports.formatCard = formatCard;
|
183
|
+
exports.formatEmail = formatEmail;
|
184
|
+
exports.formatId = formatId;
|
185
|
+
exports.formatTel = formatTel;
|
186
|
+
exports.pure = pure;
|
187
|
+
exports.pureAmount = pureAmount;
|
188
|
+
exports.pureCard = pureCard;
|
189
|
+
exports.pureEmail = pureEmail;
|
190
|
+
exports.pureId = pureId;
|
191
|
+
exports.pureTel = pureTel;
|
192
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/utils/index.ts"],"sourcesContent":[null],"names":["formatId","val","replace","len","length","slice","pureId","tmp","formatTel","pureTel","formatCard","pureCard","formatAmount","fill","_","$1","indexOf","pureAmount","formatEmail","pureEmail","format","type","pure"],"mappings":";;;;;;;;;;;;;;AAAA;;;;IAGaA,QAAQ,GAAG,SAAXA,QAAW,CAACC,GAAD;AACtBA,EAAAA,GAAG,GAAGA,GAAG,CAACC,OAAJD,CAAY,eAAZA,EAA6B,EAA7BA,CAANA;MACME,GAAG,GAAGF,GAAG,CAACG;;MAEZH,GAAG,KAAK,EAARA,IAAcE,GAAG,GAAG,GAAG;WAClBF;;;MAGLE,GAAG,GAAG,IAAI;WACLF,GAAG,CAACI,KAAJJ,CAAU,CAAVA,EAAa,CAAbA,IAAkB,GAAlBA,GAAwBA,GAAG,CAACI,KAAJJ,CAAU,CAAVA,EAAa,EAAbA;AADjC,SAEO,IAAIE,GAAG,GAAG,EAAV,EAAc;WACZF,GAAG,CAACI,KAAJJ,CAAU,CAAVA,EAAa,CAAbA,IAAkB,GAAlBA,GAAwBA,GAAG,CAACI,KAAJJ,CAAU,CAAVA,EAAa,EAAbA,CAAxBA,GAA2C,GAA3CA,GAAiDA,GAAG,CAACI,KAAJJ,CAAU,EAAVA,EAAc,EAAdA;AADnD,GAAA,MAEA;WAEHA,GAAG,CAACI,KAAJJ,CAAU,CAAVA,EAAa,CAAbA,IAAkB,GAAlBA,GAAwBA,GAAG,CAACI,KAAJJ,CAAU,CAAVA,EAAa,EAAbA,CAAxBA,GAA2C,GAA3CA,GAAiDA,GAA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IkB,SAAS,CAAClB,GAAD;;SACb;aACIgB,UAAU,CAAChB,GAAD;;;aAEVA;;;;;;;;;;;;;;;"}
|
package/lib/esm/Input.js
CHANGED
@@ -11,9 +11,9 @@ import { __rest } from 'tslib';
|
|
11
11
|
import React, { forwardRef, useMemo, isValidElement, useRef, useCallback, useState } from 'react';
|
12
12
|
import { getPrefixCls, cx } from '@hi-ui/classname';
|
13
13
|
import { __DEV__ } from '@hi-ui/env';
|
14
|
-
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
|
15
14
|
import { useMergeRefs } from '@hi-ui/use-merge-refs';
|
16
15
|
import { CloseCircleFilled } from '@hi-ui/icons';
|
16
|
+
import { useInput } from './use-input.js';
|
17
17
|
|
18
18
|
var _prefix = getPrefixCls('input');
|
19
19
|
/**
|
@@ -28,40 +28,34 @@ var Input = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
28
28
|
role = _a$role === void 0 ? 'input' : _a$role,
|
29
29
|
className = _a.className,
|
30
30
|
style = _a.style,
|
31
|
-
_a$autoFocus = _a.autoFocus,
|
32
|
-
autoFocus = _a$autoFocus === void 0 ? false : _a$autoFocus,
|
33
|
-
_a$disabled = _a.disabled,
|
34
|
-
disabled = _a$disabled === void 0 ? false : _a$disabled,
|
35
|
-
_a$readOnly = _a.readOnly,
|
36
|
-
readOnly = _a$readOnly === void 0 ? false : _a$readOnly,
|
37
|
-
name = _a.name,
|
38
|
-
maxLength = _a.maxLength,
|
39
|
-
_a$type = _a.type,
|
40
|
-
type = _a$type === void 0 ? 'text' : _a$type,
|
41
31
|
_a$size = _a.size,
|
42
32
|
size = _a$size === void 0 ? 'md' : _a$size,
|
43
33
|
_a$appearance = _a.appearance,
|
44
34
|
appearance = _a$appearance === void 0 ? 'outline' : _a$appearance,
|
45
|
-
placeholder = _a.placeholder,
|
46
35
|
prepend = _a.prepend,
|
47
36
|
append = _a.append,
|
48
37
|
prefix = _a.prefix,
|
49
38
|
suffix = _a.suffix,
|
50
|
-
_a$defaultValue = _a.defaultValue,
|
51
|
-
defaultValue = _a$defaultValue === void 0 ? '' : _a$defaultValue,
|
52
|
-
valueProp = _a.value,
|
53
|
-
onChange = _a.onChange,
|
54
|
-
onFocus = _a.onFocus,
|
55
|
-
onBlur = _a.onBlur,
|
56
39
|
_a$clearableTrigger = _a.clearableTrigger,
|
57
40
|
clearableTrigger = _a$clearableTrigger === void 0 ? 'hover' : _a$clearableTrigger,
|
58
41
|
_a$clearable = _a.clearable,
|
59
42
|
clearable = _a$clearable === void 0 ? false : _a$clearable,
|
60
|
-
_a$trimValueOnBlur = _a.trimValueOnBlur,
|
61
|
-
trimValueOnBlur = _a$trimValueOnBlur === void 0 ? false : _a$trimValueOnBlur,
|
62
43
|
_a$invalid = _a.invalid,
|
63
44
|
invalid = _a$invalid === void 0 ? false : _a$invalid,
|
64
|
-
|
45
|
+
name = _a.name,
|
46
|
+
autoFocus = _a.autoFocus,
|
47
|
+
disabled = _a.disabled,
|
48
|
+
readOnly = _a.readOnly,
|
49
|
+
maxLength = _a.maxLength,
|
50
|
+
placeholder = _a.placeholder,
|
51
|
+
defaultValue = _a.defaultValue,
|
52
|
+
valueProp = _a.value,
|
53
|
+
onChange = _a.onChange,
|
54
|
+
onFocus = _a.onFocus,
|
55
|
+
onBlur = _a.onBlur,
|
56
|
+
trimValueOnBlur = _a.trimValueOnBlur,
|
57
|
+
type = _a.type,
|
58
|
+
rest = __rest(_a, ["prefixCls", "role", "className", "style", "size", "appearance", "prepend", "append", "prefix", "suffix", "clearableTrigger", "clearable", "invalid", "name", "autoFocus", "disabled", "readOnly", "maxLength", "placeholder", "defaultValue", "value", "onChange", "onFocus", "onBlur", "trimValueOnBlur", "type"]); // @TODO: 临时方案,后面迁移至 InputGroup
|
65
59
|
|
66
60
|
|
67
61
|
var _useMemo = useMemo(function () {
|
@@ -83,65 +77,51 @@ var Input = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
83
77
|
unsetPrepend = _useMemo[0],
|
84
78
|
unsetAppend = _useMemo[1];
|
85
79
|
|
86
|
-
var
|
80
|
+
var inputElementRef = useRef(null);
|
87
81
|
var proxyOnChange = useCallback(function (value, evt) {
|
88
82
|
if (!onChange) return;
|
89
|
-
onChangeMock(onChange, evt,
|
83
|
+
onChangeMock(onChange, evt, inputElementRef.current, value);
|
90
84
|
}, [onChange]);
|
85
|
+
var clearElementRef = useRef(null);
|
86
|
+
|
87
|
+
var _useInput = useInput({
|
88
|
+
clearElementRef: clearElementRef,
|
89
|
+
name: name,
|
90
|
+
autoFocus: autoFocus,
|
91
|
+
disabled: disabled,
|
92
|
+
readOnly: readOnly,
|
93
|
+
maxLength: maxLength,
|
94
|
+
placeholder: placeholder,
|
95
|
+
defaultValue: defaultValue,
|
96
|
+
value: valueProp,
|
97
|
+
onChange: proxyOnChange,
|
98
|
+
onFocus: onFocus,
|
99
|
+
onBlur: onBlur,
|
100
|
+
trimValueOnBlur: trimValueOnBlur,
|
101
|
+
type: type
|
102
|
+
}),
|
103
|
+
tryChangeValue = _useInput.tryChangeValue,
|
104
|
+
focused = _useInput.focused,
|
105
|
+
value = _useInput.value,
|
106
|
+
getInputProps = _useInput.getInputProps;
|
91
107
|
|
92
|
-
var _useUncontrolledState = useUncontrolledState(defaultValue, valueProp, proxyOnChange),
|
93
|
-
value = _useUncontrolledState[0],
|
94
|
-
tryChangeValue = _useUncontrolledState[1];
|
95
|
-
|
96
|
-
var handleChange = useCallback(function (evt) {
|
97
|
-
var nextValue = evt.target.value;
|
98
|
-
tryChangeValue(nextValue, evt);
|
99
|
-
}, [tryChangeValue]);
|
100
|
-
|
101
|
-
var _useState = useState(autoFocus),
|
102
|
-
focused = _useState[0],
|
103
|
-
setFocused = _useState[1];
|
104
|
-
|
105
|
-
var handleFocus = useCallback(function (evt) {
|
106
|
-
setFocused(true);
|
107
|
-
onFocus === null || onFocus === void 0 ? void 0 : onFocus(evt);
|
108
|
-
}, [onFocus]);
|
109
|
-
var handleBlur = useCallback(function (event) {
|
110
|
-
setFocused(false);
|
111
|
-
|
112
|
-
if (trimValueOnBlur) {
|
113
|
-
var nextValue = event.target.value;
|
114
|
-
tryChangeValue(nextValue.trim(), event);
|
115
|
-
}
|
116
|
-
|
117
|
-
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
118
|
-
}, [onBlur, tryChangeValue, trimValueOnBlur]);
|
119
108
|
var focus = useCallback(function () {
|
120
109
|
var _a;
|
121
110
|
|
122
|
-
(_a =
|
111
|
+
(_a = inputElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
123
112
|
}, []);
|
124
113
|
var handleReset = useCallback(function (evt) {
|
125
114
|
tryChangeValue('', evt);
|
126
115
|
focus();
|
127
116
|
}, [tryChangeValue, focus]);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
readOnly: readOnly,
|
133
|
-
autoFocus: autoFocus,
|
134
|
-
placeholder: placeholder,
|
135
|
-
maxLength: maxLength
|
136
|
-
};
|
137
|
-
}, [disabled, readOnly, autoFocus, placeholder, maxLength, name]);
|
138
|
-
|
139
|
-
var _useState2 = useState(false),
|
140
|
-
hover = _useState2[0],
|
141
|
-
setHover = _useState2[1]; // 在开启 clearable 下展示 清除内容按钮,可点击进行内容清楚
|
117
|
+
|
118
|
+
var _useState = useState(false),
|
119
|
+
hover = _useState[0],
|
120
|
+
setHover = _useState[1]; // 在开启 clearable 下展示 清除内容按钮,可点击进行内容清楚
|
142
121
|
|
143
122
|
|
144
123
|
var showClearableIcon = clearable && !!value && !disabled;
|
124
|
+
var mergedRef = useMergeRefs(ref, inputElementRef);
|
145
125
|
var cls = cx(className, prefixCls + "__outer", prepend && prefixCls + "__outer--prepend", prepend && unsetPrepend && prefixCls + "__outer--prepend-unset", append && prefixCls + "__outer--append", append && unsetAppend && prefixCls + "__outer--append-unset", prefixCls + "--appearance-" + appearance, prefixCls + "--size-" + size);
|
146
126
|
return /*#__PURE__*/React.createElement("div", {
|
147
127
|
role: role,
|
@@ -161,16 +141,13 @@ var Input = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
161
141
|
}, prefix ? /*#__PURE__*/React.createElement("span", {
|
162
142
|
className: prefixCls + "__prefix"
|
163
143
|
}, prefix) : null, /*#__PURE__*/React.createElement("input", Object.assign({
|
164
|
-
ref:
|
144
|
+
ref: mergedRef,
|
165
145
|
className: cx(prefixCls, focused && "focused", disabled && 'disabled', readOnly && 'readonly'),
|
166
|
-
type: type
|
167
|
-
|
168
|
-
onChange: handleChange,
|
169
|
-
onFocus: handleFocus,
|
170
|
-
onBlur: handleBlur
|
171
|
-
}, rest, nativeInputProps)), suffix || showClearableIcon ? /*#__PURE__*/React.createElement("span", {
|
146
|
+
type: type
|
147
|
+
}, getInputProps(), rest)), suffix || showClearableIcon ? /*#__PURE__*/React.createElement("span", {
|
172
148
|
className: prefixCls + "__suffix"
|
173
149
|
}, showClearableIcon ? /*#__PURE__*/React.createElement("span", {
|
150
|
+
ref: clearElementRef,
|
174
151
|
className: cx(prefixCls + "__clear", (clearableTrigger === 'always' || hover) && 'active'),
|
175
152
|
role: "button",
|
176
153
|
tabIndex: -1,
|
@@ -204,13 +181,13 @@ function onChangeMock(onChange, evt, target, targetValue) {
|
|
204
181
|
event.target = target;
|
205
182
|
event.currentTarget = target;
|
206
183
|
target.value = targetValue;
|
207
|
-
onChange(event); // 重置为之前值
|
184
|
+
onChange(event, targetValue); // 重置为之前值
|
208
185
|
|
209
186
|
target.value = originalTargetValue;
|
210
187
|
return;
|
211
188
|
}
|
212
189
|
|
213
|
-
onChange(event);
|
190
|
+
onChange(event, targetValue);
|
214
191
|
}
|
215
192
|
|
216
193
|
export { Input, onChangeMock };
|
package/lib/esm/Input.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Input.js","sources":["../../src/Input.tsx"],"sourcesContent":[null],"names":["_prefix","getPrefixCls","Input","forwardRef","_a","ref","prefixCls","role","className","style","
|
1
|
+
{"version":3,"file":"Input.js","sources":["../../src/Input.tsx"],"sourcesContent":[null],"names":["_prefix","getPrefixCls","Input","forwardRef","_a","ref","prefixCls","role","className","style","size","appearance","prepend","append","prefix","suffix","clearableTrigger","clearable","invalid","name","autoFocus","disabled","readOnly","maxLength","placeholder","defaultValue","valueProp","value","onChange","onFocus","onBlur","trimValueOnBlur","type","rest","useMemo","shouldUnset","isValidElement","includes","HiName","unsetPrepend","unsetAppend","inputElementRef","useRef","proxyOnChange","useCallback","evt","onChangeMock","current","clearElementRef","useInput","tryChangeValue","focused","getInputProps","focus","handleReset","useState","hover","setHover","showClearableIcon","mergedRef","useMergeRefs","cls","cx","React","onMouseOver","e","onMouseLeave","tabIndex","onClick","CloseCircleFilled","__DEV__","displayName","target","targetValue","event","originalTargetValue","Object","create","currentTarget"],"mappings":";;;;;;;;;;;;;;;;;AAQA,IAAMA,OAAO,GAAGC,YAAY,CAAC,OAAD,CAA5B;AAEA;;;;;IAGaC,KAAK,gBAAGC,UAAU,CAC7B,UACEC,EADF,EA+BEC,GA/BF;wBAEIC;MAAAA,sCAAYN;mBACZO;MAAAA,4BAAO;MACPC,eAAAA;MACAC,WAAAA;mBACAC;MAAAA,4BAAO;yBACPC;MAAAA,wCAAa;MACbC,aAAAA;MACAC,YAAAA;MACAC,YAAAA;MACAC,YAAAA;+BACAC;MAAAA,oDAAmB;wBACnBC;MAAAA,sCAAY;sBACZC;MAAAA,kCAAU;MAEVC,UAAAA;MACAC,eAAAA;MACAC,cAAAA;MACAC,cAAAA;MACAC,eAAAA;MACAC,iBAAAA;MACAC,kBAAAA;MACOC,eAAPC;MACAC,cAAAA;MACAC,aAAAA;MACAC,YAAAA;MACAC,qBAAAA;MACAC,UAAAA;MACGC,kBA5BL,YAAA,QAAA,aAAA,SAAA,QAAA,cAAA,WAAA,UAAA,UAAA,UAAA,oBAAA,aAAA,WAAA,QAAA,aAAA,YAAA,YAAA,aAAA,eAAA,gBAAA,SAAA,YAAA,WAAA,UAAA,mBAAA,QAAA;;;iBAiCoCC,OAAO,CAAC;QACpCC,WA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kBG,IAnDNgD,CAFFA,EAuDGlD,MAAM,gBAAGkD,mBAAAA,MAAAA;AAAKvD,IAAAA,SAAS,EAAKF,SAAL;GAAdyD,EAAyClD,MAAzCkD,CAAH,GAA4D,IAvDrEA;AA5GyB,CAAA;;AA6P/B,IAAIO,OAAJ,EAAa;AACXpE,EAAAA,KAAK,CAACqE,WAANrE,GAAoB,OAApBA;;AAGF;;;;;;;;;;;SASgB4C,aACdlB,UACAiB,KACA2B,QACAC;MAEIC,KAAK,GAAG7B;;MAGRA,GAAG,CAACb,IAAJa,KAAa,UAAU;QACrB,CAAC2B,QAAQ;QAEPG,mBAAmB,GAAGH,MAAM,CAAC7C;AACnC+C,IAAAA,KAAK,GAAGE,MAAM,CAACC,MAAPD,CAAc/B,GAAd+B,CAARF;AAEAA,IAAAA,KAAK,CAACF,MAANE,GAAeF,MAAfE;AACAA,IAAAA,KAAK,CAACI,aAANJ,GAAsBF,MAAtBE;AACAF,IAAAA,MAAM,CAAC7C,KAAP6C,GAAeC,WAAfD;AACA5C,IAAAA,QAAQ,CAAC8C,KAAD,EAA+CD,WAA/C,CAAR7C,CATyB;;AAWzB4C,IAAAA,MAAM,CAAC7C,KAAP6C,GAAeG,mBAAfH;;;;AAIF5C,EAAAA,QAAQ,CAAC8C,KAAD,EAA+CD,WAA/C,CAAR7C;;;"}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
/** @LICENSE
|
2
|
+
* @hi-ui/input
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/input#readme
|
4
|
+
*
|
5
|
+
* Copyright (c) HIUI <mi-hiui@xiaomi.com>.
|
6
|
+
*
|
7
|
+
* This source code is licensed under the MIT license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
import { __rest } from 'tslib';
|
11
|
+
import React, { forwardRef } from 'react';
|
12
|
+
import { getPrefixCls, cx } from '@hi-ui/classname';
|
13
|
+
import { __DEV__ } from '@hi-ui/env';
|
14
|
+
import { useInput } from './use-input.js';
|
15
|
+
import { useLatestCallback } from '@hi-ui/use-latest';
|
16
|
+
|
17
|
+
var _prefix = getPrefixCls('input');
|
18
|
+
/**
|
19
|
+
* TODO: What is TextArea
|
20
|
+
*/
|
21
|
+
|
22
|
+
|
23
|
+
var TextArea = /*#__PURE__*/forwardRef(function (_a, ref) {
|
24
|
+
var _a$prefixCls = _a.prefixCls,
|
25
|
+
prefixCls = _a$prefixCls === void 0 ? _prefix : _a$prefixCls,
|
26
|
+
className = _a.className,
|
27
|
+
_a$size = _a.size,
|
28
|
+
size = _a$size === void 0 ? 'md' : _a$size,
|
29
|
+
_a$appearance = _a.appearance,
|
30
|
+
appearance = _a$appearance === void 0 ? 'outline' : _a$appearance,
|
31
|
+
_a$invalid = _a.invalid,
|
32
|
+
invalid = _a$invalid === void 0 ? false : _a$invalid,
|
33
|
+
name = _a.name,
|
34
|
+
autoFocus = _a.autoFocus,
|
35
|
+
disabled = _a.disabled,
|
36
|
+
readOnly = _a.readOnly,
|
37
|
+
maxLength = _a.maxLength,
|
38
|
+
placeholder = _a.placeholder,
|
39
|
+
defaultValue = _a.defaultValue,
|
40
|
+
valueProp = _a.value,
|
41
|
+
onChange = _a.onChange,
|
42
|
+
onFocus = _a.onFocus,
|
43
|
+
onBlur = _a.onBlur,
|
44
|
+
trimValueOnBlur = _a.trimValueOnBlur,
|
45
|
+
nativeProps = __rest(_a, ["prefixCls", "className", "style", "size", "appearance", "invalid", "name", "autoFocus", "disabled", "readOnly", "maxLength", "placeholder", "defaultValue", "value", "onChange", "onFocus", "onBlur", "trimValueOnBlur"]);
|
46
|
+
|
47
|
+
var proxyOnChange = useLatestCallback(function (_, evt) {
|
48
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(evt);
|
49
|
+
});
|
50
|
+
|
51
|
+
var _useInput = useInput({
|
52
|
+
name: name,
|
53
|
+
autoFocus: autoFocus,
|
54
|
+
disabled: disabled,
|
55
|
+
readOnly: readOnly,
|
56
|
+
maxLength: maxLength,
|
57
|
+
placeholder: placeholder,
|
58
|
+
defaultValue: defaultValue,
|
59
|
+
value: valueProp,
|
60
|
+
onChange: proxyOnChange,
|
61
|
+
onFocus: onFocus,
|
62
|
+
onBlur: onBlur,
|
63
|
+
trimValueOnBlur: trimValueOnBlur
|
64
|
+
}),
|
65
|
+
focused = _useInput.focused,
|
66
|
+
getInputProps = _useInput.getInputProps;
|
67
|
+
|
68
|
+
var cls = cx(prefixCls, className, disabled && 'disabled', readOnly && 'readonly', focused && "focused", invalid && 'invalid', prefixCls + "--appearance-" + appearance, prefixCls + "--size-" + size);
|
69
|
+
return /*#__PURE__*/React.createElement("textarea", Object.assign({
|
70
|
+
ref: ref,
|
71
|
+
className: cls,
|
72
|
+
autoComplete: "off"
|
73
|
+
}, getInputProps(), nativeProps));
|
74
|
+
});
|
75
|
+
|
76
|
+
if (__DEV__) {
|
77
|
+
TextArea.displayName = 'TextArea';
|
78
|
+
}
|
79
|
+
|
80
|
+
export { TextArea };
|
81
|
+
//# sourceMappingURL=TextArea.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TextArea.js","sources":["../../src/TextArea.tsx"],"sourcesContent":[null],"names":["_prefix","getPrefixCls","TextArea","forwardRef","_a","ref","prefixCls","className","size","appearance","invalid","name","autoFocus","disabled","readOnly","maxLength","placeholder","defaultValue","valueProp","value","onChange","onFocus","onBlur","trimValueOnBlur","nativeProps","proxyOnChange","useLatestCallback","_","evt","useInput","focused","getInputProps","cls","cx","React","autoComplete","__DEV__","displayName"],"mappings":";;;;;;;;;;;;;;;;AAQA,IAAMA,OAAO,GAAGC,YAAY,CAAC,OAAD,CAA5B;AAEA;;;;;IAGaC,QAAQ,gBAAGC,UAAU,CAChC,UACEC,EADF,EAuBEC,GAvBF;wBAEIC;MAAAA,sCAAYN;MACZO,eAAAA;mBAEAC;MAAAA,4BAAO;yBACPC;MAAAA,wCAAa;sBACbC;MAAAA,kCAAU;MAEVC,UAAAA;MACAC,eAAAA;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