@qsxy/element-plus-react 1.0.1 → 1.0.2

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.
Files changed (66) hide show
  1. package/dist/Calendar/Calendar.js +12 -3
  2. package/dist/Calendar/Footer.js +4 -2
  3. package/dist/Calendar/QuarterPanel.d.ts +4 -0
  4. package/dist/Calendar/QuarterPanel.js +109 -0
  5. package/dist/Calendar/WeekPanel.js +1 -1
  6. package/dist/Calendar/typings.d.ts +1 -1
  7. package/dist/Card/Card.js +9 -4
  8. package/dist/Card/typings.d.ts +1 -1
  9. package/dist/Cascader/Cascader.js +1 -1
  10. package/dist/DatePicker/DatePicker.js +38 -12
  11. package/dist/DatePicker/DateRangePicker.js +27 -9
  12. package/dist/DatePicker/main.js +1 -1
  13. package/dist/DatePicker/typings.d.ts +1 -1
  14. package/dist/DateTimePicker/DateTimePicker.js +2 -2
  15. package/dist/Input/Input.1.d.ts +16 -0
  16. package/dist/Input/Input.1.js +376 -0
  17. package/dist/Input/Input.js +137 -121
  18. package/dist/Input/InputRange.js +1 -1
  19. package/dist/Input/TextArea.js +87 -12
  20. package/dist/Input/typings.d.ts +15 -5
  21. package/dist/Input/useComposition.d.ts +23 -0
  22. package/dist/Input/useComposition.js +63 -0
  23. package/dist/Input/utils.d.ts +6 -0
  24. package/dist/Input/utils.js +91 -0
  25. package/dist/InputNumber/InputNumber.js +1 -1
  26. package/dist/InputNumber/typings.d.ts +1 -1
  27. package/dist/Select/Option.js +30 -14
  28. package/dist/Select/SelectContext.d.ts +3 -4
  29. package/dist/Select/SelectCore.d.ts +2 -2
  30. package/dist/Select/SelectCore.js +164 -447
  31. package/dist/Select/SelectDropdown.js +67 -145
  32. package/dist/Select/typings.d.ts +47 -21
  33. package/dist/Select/useSelect.d.ts +125 -0
  34. package/dist/Select/useSelect.js +516 -0
  35. package/dist/Table/util.js +6 -5
  36. package/dist/Tag/Tag.js +22 -17
  37. package/dist/TimePicker/TimePicker.js +2 -2
  38. package/dist/TreeSelect/TreeSelect.js +2 -2
  39. package/dist/Util/aria.d.ts +25 -0
  40. package/dist/Util/aria.js +118 -0
  41. package/dist/hooks/useCalcInputWidth.d.ts +8 -0
  42. package/dist/hooks/useCalcInputWidth.js +30 -0
  43. package/dist/hooks/useComposition.d.ts +16 -0
  44. package/dist/hooks/useComposition.js +39 -0
  45. package/dist/hooks/useCursor.d.ts +2 -0
  46. package/dist/hooks/useCursor.js +52 -0
  47. package/dist/hooks/useFocusController.d.ts +27 -0
  48. package/dist/hooks/useFocusController.js +72 -0
  49. package/dist/index.css +1 -1
  50. package/dist/locale/en.d.ts +15 -0
  51. package/dist/locale/en.js +15 -0
  52. package/dist/locale/zhCn.d.ts +15 -0
  53. package/dist/locale/zhCn.js +15 -0
  54. package/package.json +1 -1
  55. package/theme-chalk/calendar/index.scss +1 -0
  56. package/theme-chalk/calendar/quarter-table.scss +78 -0
  57. package/theme-chalk/common/var.scss +1 -1
  58. package/theme-chalk/input/input.scss +424 -578
  59. package/theme-chalk/input/input.scss--bak +578 -0
  60. package/theme-chalk/select/index.scss +272 -247
  61. package/theme-chalk/select/index.scss--bak +247 -0
  62. package/theme-chalk/select/option-group.scss +2 -2
  63. package/theme-chalk/select/option.scss +2 -2
  64. package/theme-chalk/select/select-dropdown.scss +2 -2
  65. package/theme-chalk/tag.scss +181 -203
  66. package/theme-chalk/tag.scss--bak +203 -0
@@ -1,6 +1,6 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18;
3
- var _excluded = ["name", "title", "prefix", "suffix", "prepend", "append", "error", "warning", "debounceInput", "debounceTime", "placeholder", "readOnly", "plain", "classPrefix", "onChange", "onClear", "showPassword", "onFocus", "onBlur", "maxLength", "showWordLimit", "hiddenValue", "defaultValue"];
2
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19;
3
+ var _excluded = ["name", "title", "prefix", "suffix", "prepend", "append", "error", "warning", "debounceInput", "debounceTime", "placeholder", "readOnly", "plain", "classPrefix", "onChange", "onClear", "showPassword", "onFocus", "onBlur", "maxLength", "showWordLimit", "hiddenValue", "defaultValue", "formatter"];
4
4
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
5
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -21,17 +21,24 @@ import classNames from 'classnames';
21
21
  import { addClass, addStyle, hasClass, removeClass } from 'dom-lib';
22
22
  import isObject from 'lodash/isObject';
23
23
  import React, { cloneElement, forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
24
+ import { useTranslation } from 'react-i18next';
25
+ import { useConfigProvider } from "../ConfigProvider/ConfigProviderContext";
24
26
  import Icon from "../Icon/Icon";
25
27
  import { isNotEmpty, mergeDefaultProps } from "../Util";
26
28
  import { partitionHTMLProps, useClassNames, useControlled, useDisabled, useSize } from "../hooks";
27
- import InputGroup from "./InputGroup";
28
29
  import InputRange from "./InputRange";
29
30
  import TextArea from "./TextArea";
30
31
  function InternalInput(props, ref) {
31
32
  var _this = this;
33
+ var _useConfigProvider = useConfigProvider(),
34
+ locale = _useConfigProvider.locale;
35
+ var _useTranslation = useTranslation(),
36
+ t = _useTranslation.t;
32
37
  props = mergeDefaultProps({
33
38
  type: 'text',
34
- placeholder: '请输入',
39
+ placeholder: t('el.input.placeholder', {
40
+ lng: locale
41
+ }),
35
42
  clearable: true,
36
43
  debounceTime: 200,
37
44
  defaultValue: ''
@@ -61,11 +68,14 @@ function InternalInput(props, ref) {
61
68
  showWordLimit = _props.showWordLimit,
62
69
  hiddenValue = _props.hiddenValue,
63
70
  defaultValue = _props.defaultValue,
71
+ formatter = _props.formatter,
64
72
  rest = _objectWithoutProperties(_props, _excluded);
65
73
  var _useClassNames = useClassNames(classPrefix),
66
74
  b = _useClassNames.b,
67
75
  e = _useClassNames.e,
68
76
  m = _useClassNames.m,
77
+ be = _useClassNames.be,
78
+ bm = _useClassNames.bm,
69
79
  is = _useClassNames.is;
70
80
  var _partitionHTMLProps = partitionHTMLProps(rest),
71
81
  _partitionHTMLProps2 = _slicedToArray(_partitionHTMLProps, 1),
@@ -82,7 +92,7 @@ function InternalInput(props, ref) {
82
92
  var size = useSize(props.size);
83
93
  var containerRef = useRef(null);
84
94
  var inputRef = useRef(null);
85
- var contentRef = useRef(null);
95
+ var wrapperRef = useRef(null);
86
96
  var clearRef = useRef(null);
87
97
  var suffixRef = useRef(null);
88
98
  // 搜索框是否输入完毕
@@ -90,6 +100,15 @@ function InternalInput(props, ref) {
90
100
 
91
101
  // const containerRef = useMemo(() => props.containerRef ?? rootRef, [props.containerRef]);
92
102
 
103
+ /** 格式化的数据 */
104
+ var formatValue = useMemo(function () {
105
+ var val = value;
106
+ if (formatter) {
107
+ val = formatter(val);
108
+ }
109
+ return val;
110
+ }, [formatter, value]);
111
+
93
112
  /** 是否可清空 */
94
113
  var clearable = useMemo(function () {
95
114
  // 只读不显示清除按钮只有input组件适用,加上了那些引用input组件就无法显示清空按钮了,这里添加说明,下次别再添加了
@@ -168,12 +187,16 @@ function InternalInput(props, ref) {
168
187
  addStyle(clearRef.current, 'display', 'none');
169
188
  }
170
189
  hideClear();
171
- if (!readOnly && !disabled) {
172
- var _inputRef$current;
173
- (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
174
- }
175
190
  onClear === null || onClear === void 0 || onClear(event);
176
191
  onChange === null || onChange === void 0 || onChange('', event);
192
+ if (requestAnimationFrame) {
193
+ requestAnimationFrame(function () {
194
+ if (!readOnly && !disabled) {
195
+ var _inputRef$current;
196
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
197
+ }
198
+ });
199
+ }
177
200
  }, [disabled, hideClear, onChange, onClear, readOnly, setValue]);
178
201
 
179
202
  /** 后缀点击事件 */
@@ -185,6 +208,7 @@ function InternalInput(props, ref) {
185
208
 
186
209
  /** 输入事件 */
187
210
  var handleInput = useCallback(function (event) {
211
+ // console.log('handleInput', event.target.value);
188
212
  if (inputOver.current) {
189
213
  // 让搜索变成异步的
190
214
  setValue(event.target.value);
@@ -202,6 +226,7 @@ function InternalInput(props, ref) {
202
226
  handleDebounceInput = _useDebounceFn.run;
203
227
  var handleComposition = useCallback(function (event) {
204
228
  var _type = event.type;
229
+ // console.log(_type);
205
230
  if (_type === 'compositionstart') {
206
231
  inputOver.current = false;
207
232
  } else if (_type === 'compositionend') {
@@ -209,14 +234,21 @@ function InternalInput(props, ref) {
209
234
  handleInput(event);
210
235
  }
211
236
  }, [handleInput]);
237
+
238
+ // useEffect(() => {
239
+ // const input = inputRef.current;
240
+ // if (input) {
241
+ // input.addEventListener('compositionstart', handleComposition);
242
+ // input.addEventListener('compositionupdate', handleComposition);
243
+ // input.addEventListener('compositionend', handleComposition);
244
+ // }
245
+ // }, [debounceInput, handleComposition]);
246
+
212
247
  useEffect(function () {
213
- var input = inputRef.current;
214
- if (input && debounceInput) {
215
- input.addEventListener('compositionstart', handleComposition);
216
- input.addEventListener('compositionupdate', handleComposition);
217
- input.addEventListener('compositionend', handleComposition);
218
- }
219
- }, [debounceInput, handleComposition]);
248
+ requestAnimationFrame(function () {
249
+ inputRef.current.value = formatValue;
250
+ });
251
+ }, []);
220
252
  useImperativeHandle(ref, function () {
221
253
  return {
222
254
  ref: containerRef,
@@ -247,7 +279,7 @@ function InternalInput(props, ref) {
247
279
  var _nodeType2;
248
280
  var nodeType = prefix === null || prefix === void 0 ? void 0 : prefix.type;
249
281
  nodeType = ((_nodeType2 = nodeType) === null || _nodeType2 === void 0 ? void 0 : _nodeType2.displayName) || nodeType;
250
- if (nodeType.toString().startsWith('Icon')) {
282
+ if (nodeType.toString().startsWith('ElIcon')) {
251
283
  var _prefix$props;
252
284
  return /*#__PURE__*/cloneElement(prefix, _objectSpread(_objectSpread({}, prefix.props), {}, {
253
285
  className: classNames((_prefix$props = prefix.props) === null || _prefix$props === void 0 ? void 0 : _prefix$props.className, e(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["icon"]))))
@@ -258,115 +290,99 @@ function InternalInput(props, ref) {
258
290
  }
259
291
  return null;
260
292
  }, [type, prefix, e]);
261
- var content = useMemo(function () {
262
- return type === 'hidden' ? /*#__PURE__*/React.createElement("input", _extends({
263
- ref: inputRef,
264
- type: "hidden",
265
- name: name,
266
- value: value,
267
- disabled: disabled,
268
- onChange: debounceInput ? handleDebounceInput : handleInput,
269
- onClick: props.onClick,
270
- className: props.className,
271
- style: props.innerStyle
272
- }, htmlInputProps)) : /*#__PURE__*/React.createElement("div", {
273
- className: classNames(e(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["wrapper"]))), is({
274
- error: error,
275
- warning: warning
276
- })),
277
- ref: contentRef,
278
- onMouseEnter: function onMouseEnter() {
279
- return showClear(value);
280
- },
281
- onMouseLeave: function onMouseLeave() {
282
- if (!hasClass(contentRef.current, is('focus'))) {
283
- hideClear();
284
- }
285
- }
286
- }, ['text', 'password'].includes(type) && preffixSlot && /*#__PURE__*/React.createElement("span", {
287
- className: e(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["prefix"])))
288
- }, /*#__PURE__*/React.createElement("span", {
289
- className: e(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["prefix-inner"])))
290
- }, preffixSlot, " ")), /*#__PURE__*/React.createElement("input", _extends({
291
- ref: inputRef,
292
- type: type,
293
- name: name,
294
- title: title,
295
- value: hiddenValue ? '' : value,
296
- className: e(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["inner"]))),
297
- style: props.innerStyle,
298
- placeholder: placeholder,
299
- autoComplete: "off",
300
- readOnly: readOnly,
293
+ return /*#__PURE__*/React.createElement("div", {
294
+ ref: containerRef,
295
+ className: classNames(b(), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, bm('group', 'prepend'), prepend), bm('group', 'append'), append), m(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["prefix"]))), preffixSlot), m(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["suffix"]))), suffixSlot || clearable), m(size), size), b(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["hidden"]))), type === 'hidden'), is({
301
296
  disabled: disabled,
302
- maxLength: maxLength,
303
- onInput: handleInput,
304
- onClick: props.onClick,
305
- onFocus: function onFocus(event) {
306
- if (contentRef.current) {
307
- addClass(contentRef.current, is('focus'));
308
- }
309
- showClear(value);
310
- _onFocus === null || _onFocus === void 0 || _onFocus.call(_this, event);
311
- },
312
- onBlur: function onBlur(event) {
313
- if (contentRef.current) {
314
- removeClass(contentRef.current, is('focus'));
315
- }
297
+ plain: plain
298
+ }), props.className),
299
+ style: props.style,
300
+ onClick: function onClick(event) {
301
+ return event.stopPropagation();
302
+ }
303
+ }, prepend ? /*#__PURE__*/React.createElement("div", {
304
+ className: be('group', 'prepend')
305
+ }, prepend) : null, /*#__PURE__*/React.createElement("div", {
306
+ ref: wrapperRef,
307
+ className: classNames(e(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["wrapper"]))), is({
308
+ error: error,
309
+ warning: warning
310
+ })),
311
+ onMouseEnter: function onMouseEnter() {
312
+ return showClear(value);
313
+ },
314
+ onMouseLeave: function onMouseLeave() {
315
+ if (!hasClass(wrapperRef.current, is('focus'))) {
316
316
  hideClear();
317
- _onBlur === null || _onBlur === void 0 || _onBlur.call(_this, event);
318
317
  }
319
- }, htmlInputProps)), /*#__PURE__*/React.createElement("span", {
320
- ref: clearRef,
321
- key: "clearIcon",
322
- className: e(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["suffix"]))),
323
- style: {
324
- display: 'none'
325
- },
326
- onClick: handelClear
327
- }, /*#__PURE__*/React.createElement("span", {
328
- className: e(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["suffix-inner"])))
329
- }, /*#__PURE__*/React.createElement(Icon, {
330
- prefix: "fal",
331
- name: "circle-xmark",
332
- className: classNames(e(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["icon"]))), e(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["clear"])))),
333
- onMouseDown: function onMouseDown(event) {
334
- event.preventDefault();
335
- event.stopPropagation();
318
+ }
319
+ }, ['text', 'password'].includes(type) && preffixSlot && /*#__PURE__*/React.createElement("span", {
320
+ className: e(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["prefix"])))
321
+ }, /*#__PURE__*/React.createElement("span", {
322
+ className: e(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["prefix-inner"])))
323
+ }, preffixSlot)), /*#__PURE__*/React.createElement("input", _extends({
324
+ ref: inputRef,
325
+ type: type,
326
+ name: name,
327
+ title: title,
328
+ value: hiddenValue ? '' : value,
329
+ className: e(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["inner"]))),
330
+ style: props.innerStyle,
331
+ placeholder: placeholder,
332
+ autoComplete: "off",
333
+ readOnly: readOnly,
334
+ disabled: disabled,
335
+ maxLength: maxLength,
336
+ onInput: handleInput
337
+ // onCompositionStart={handleComposition}
338
+ // onCompositionUpdate={handleComposition}
339
+ // onCompositionEnd={handleComposition}
340
+ ,
341
+ onClick: props.onClick,
342
+ onFocus: function onFocus(event) {
343
+ inputRef.current.value = value;
344
+ if (wrapperRef.current) {
345
+ addClass(wrapperRef.current, is('focus'));
336
346
  }
337
- }))), suffixSlot && /*#__PURE__*/React.createElement("span", {
338
- ref: suffixRef,
339
- key: "suffixSlot",
340
- className: classNames(e(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["suffix"]))), _defineProperty({}, b('click', false), suffixCanClick)),
341
- onClick: onClickSuffix
342
- }, /*#__PURE__*/React.createElement("span", {
343
- className: e(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["suffix-inner"])))
344
- }, suffixSlot)));
345
- }, [type, name, value, disabled, debounceInput, handleDebounceInput, handleInput, props.onClick, props.className, props.innerStyle, htmlInputProps, e, is, error, warning, preffixSlot, title, hiddenValue, placeholder, readOnly, maxLength, handelClear, suffixSlot, b, suffixCanClick, onClickSuffix, showClear, hideClear, _onFocus, _onBlur]);
346
- if (append || prepend) {
347
- return /*#__PURE__*/React.createElement(InputGroup, {
348
- prepend: prepend,
349
- append: append,
350
- ref: containerRef,
351
- className: classNames(_defineProperty({}, m(size), size), is({
352
- disabled: disabled,
353
- plain: plain
354
- }), b(), props.className),
355
- style: props.style
356
- }, content);
357
- } else {
358
- return /*#__PURE__*/React.createElement("div", {
359
- ref: containerRef,
360
- className: classNames(b(), _defineProperty(_defineProperty(_defineProperty({}, m(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["prefix"]))), preffixSlot), m(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["suffix"]))), suffixSlot || clearable), m(size), size), is({
361
- disabled: disabled,
362
- plain: plain
363
- }), props.className),
364
- style: append || prepend ? {} : props.style,
365
- onClick: function onClick(event) {
366
- return event.stopPropagation();
347
+ showClear(value);
348
+ _onFocus === null || _onFocus === void 0 || _onFocus.call(_this, event);
349
+ },
350
+ onBlur: function onBlur(event) {
351
+ inputRef.current.value = formatValue;
352
+ if (wrapperRef.current) {
353
+ removeClass(wrapperRef.current, is('focus'));
367
354
  }
368
- }, content);
369
- }
355
+ hideClear();
356
+ _onBlur === null || _onBlur === void 0 || _onBlur.call(_this, event);
357
+ }
358
+ }, htmlInputProps)), /*#__PURE__*/React.createElement("span", {
359
+ ref: clearRef,
360
+ key: "clearIcon",
361
+ className: e(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["suffix"]))),
362
+ style: {
363
+ display: 'none'
364
+ },
365
+ onClick: handelClear
366
+ }, /*#__PURE__*/React.createElement("span", {
367
+ className: e(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["suffix-inner"])))
368
+ }, /*#__PURE__*/React.createElement(Icon, {
369
+ prefix: "fal",
370
+ name: "circle-xmark",
371
+ className: classNames(e(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["icon"]))), e(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["clear"])))),
372
+ onMouseDown: function onMouseDown(event) {
373
+ event.preventDefault();
374
+ event.stopPropagation();
375
+ }
376
+ }))), suffixSlot && /*#__PURE__*/React.createElement("span", {
377
+ ref: suffixRef,
378
+ key: "suffixSlot",
379
+ className: classNames(e(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["suffix"]))), _defineProperty({}, b('click', false), suffixCanClick)),
380
+ onClick: onClickSuffix
381
+ }, /*#__PURE__*/React.createElement("span", {
382
+ className: e(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["suffix-inner"])))
383
+ }, suffixSlot))), append ? /*#__PURE__*/React.createElement("div", {
384
+ className: be('group', 'append')
385
+ }, append) : null);
370
386
  }
371
387
  var ForwardInput = /*#__PURE__*/forwardRef(InternalInput);
372
388
  var Input = ForwardInput;
@@ -271,7 +271,7 @@ var InputRange = /*#__PURE__*/forwardRef(function (props, ref) {
271
271
  var _ref;
272
272
  return /*#__PURE__*/React.createElement("div", {
273
273
  className: classNames(b(_templateObject || (_templateObject = _taggedTemplateLiteral(["range-editor"]))), b('input-range', false), be('input', 'wrapper', false), be('tooltip', 'trigger', false), is({
274
- active: active || focus,
274
+ focus: active || focus,
275
275
  disabled: disabled,
276
276
  warning: warning,
277
277
  error: error
@@ -1,10 +1,16 @@
1
- var _excluded = ["name", "title", "error", "placeholder", "readOnly", "plain", "rows", "classPrefix", "onFocus", "onBlur", "onChange", "warning", "maxLength", "showWordLimit"];
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["name", "title", "error", "placeholder", "readOnly", "plain", "rows", "classPrefix", "onFocus", "onBlur", "onChange", "warning", "maxLength", "showWordLimit", "resize", "autosize", "inputStyle"];
2
3
  var _this = this,
3
4
  _templateObject,
4
5
  _templateObject2,
5
6
  _templateObject3;
6
7
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
7
8
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
14
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
15
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
16
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -14,15 +20,19 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
20
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
21
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
22
  import classNames from 'classnames';
17
- import React, { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react';
23
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
18
24
  import { mergeDefaultProps } from "../Util";
19
25
  import { partitionHTMLProps, useClassNames, useControlled, useDisabled } from "../hooks";
26
+ import { useResizeObserver } from "../hooks/useResizeObserver";
27
+ import { calcTextareaHeight } from "./utils";
20
28
  var TextArea = /*#__PURE__*/forwardRef(function (props, ref) {
21
29
  props = mergeDefaultProps({
22
30
  placeholder: '请输入',
23
31
  style: {
24
32
  width: '100%'
25
- }
33
+ },
34
+ autosize: true,
35
+ inputStyle: {}
26
36
  }, props);
27
37
  var _props = props,
28
38
  name = _props.name,
@@ -40,6 +50,9 @@ var TextArea = /*#__PURE__*/forwardRef(function (props, ref) {
40
50
  warning = _props.warning,
41
51
  maxLength = _props.maxLength,
42
52
  showWordLimit = _props.showWordLimit,
53
+ resize = _props.resize,
54
+ autosize = _props.autosize,
55
+ inputStyle = _props.inputStyle,
43
56
  rest = _objectWithoutProperties(_props, _excluded);
44
57
  var _useClassNames = useClassNames(classPrefix),
45
58
  b = _useClassNames.b,
@@ -54,20 +67,78 @@ var TextArea = /*#__PURE__*/forwardRef(function (props, ref) {
54
67
  _useState2 = _slicedToArray(_useState, 2),
55
68
  focus = _useState2[0],
56
69
  setFocus = _useState2[1];
70
+ var _useState3 = useState({}),
71
+ _useState4 = _slicedToArray(_useState3, 2),
72
+ textareaCalcStyle = _useState4[0],
73
+ setTextareaCalcStyle = _useState4[1];
57
74
  var disabled = useDisabled(props.disabled);
58
75
  var containerRef = useRef(null);
59
- var inputRef = useRef(null);
76
+ var textareaRef = useRef(null);
77
+ var countRef = useRef(null);
60
78
  var _partitionHTMLProps = partitionHTMLProps(rest),
61
79
  _partitionHTMLProps2 = _slicedToArray(_partitionHTMLProps, 1),
62
80
  htmlInputProps = _partitionHTMLProps2[0];
81
+ var isWordLimitVisible = useMemo(function () {
82
+ return showWordLimit && !!maxLength && !disabled && !readOnly;
83
+ }, [showWordLimit, maxLength, disabled, readOnly]);
63
84
  var handleInput = useCallback(function (event) {
64
85
  setValue(event.target.value);
65
86
  onChange === null || onChange === void 0 || onChange(event.target.value);
66
87
  }, [onChange, setValue]);
88
+ var resizeTextarea = useCallback(function () {
89
+ if (!textareaRef.current) {
90
+ return;
91
+ }
92
+ if (autosize) {
93
+ var minRows = typeof autosize !== 'boolean' ? autosize.minRows : undefined;
94
+ var maxRows = typeof autosize !== 'boolean' ? autosize.maxRows : undefined;
95
+ var textareaStyle = calcTextareaHeight(textareaRef.current, minRows, maxRows);
96
+ setTextareaCalcStyle(function (prev) {
97
+ return _objectSpread(_objectSpread({}, prev), textareaStyle);
98
+ });
99
+ } else {
100
+ setTextareaCalcStyle(function (prev) {
101
+ return _objectSpread(_objectSpread({}, prev), {}, {
102
+ minHeight: calcTextareaHeight(textareaRef.current).minHeight
103
+ });
104
+ });
105
+ }
106
+ }, [autosize]);
107
+ var createOnceInitResize = useCallback(function () {
108
+ var isInit = false;
109
+ return function () {
110
+ var _textareaRef$current;
111
+ if (isInit || !autosize) {
112
+ return;
113
+ }
114
+ var isElHidden = ((_textareaRef$current = textareaRef.current) === null || _textareaRef$current === void 0 ? void 0 : _textareaRef$current.offsetParent) === null;
115
+ if (!isElHidden) {
116
+ setTimeout(resizeTextarea);
117
+ isInit = true;
118
+ }
119
+ };
120
+ }, [autosize, resizeTextarea]);
121
+ var onceInitSizeTextarea = createOnceInitResize();
122
+ useResizeObserver(textareaRef, function (entries) {
123
+ onceInitSizeTextarea();
124
+ if (!isWordLimitVisible || resize !== 'both') {
125
+ return;
126
+ }
127
+ var entry = entries[0];
128
+ var width = entry.contentRect.width;
129
+ if (countRef.current) {
130
+ countRef.current.style.right = "calc(100% - ".concat(width + 15 + 6, "px)");
131
+ }
132
+ });
133
+ useEffect(function () {
134
+ if (autosize) {
135
+ resizeTextarea();
136
+ }
137
+ }, [value]);
67
138
  useImperativeHandle(ref, function () {
68
139
  return {
69
140
  get input() {
70
- return inputRef.current;
141
+ return textareaRef.current;
71
142
  },
72
143
  getValue: function getValue() {
73
144
  return value;
@@ -82,12 +153,12 @@ var TextArea = /*#__PURE__*/forwardRef(function (props, ref) {
82
153
  onChange === null || onChange === void 0 || onChange('');
83
154
  },
84
155
  focus: function focus() {
85
- var _inputRef$current;
86
- return (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
156
+ var _textareaRef$current2;
157
+ return (_textareaRef$current2 = textareaRef.current) === null || _textareaRef$current2 === void 0 ? void 0 : _textareaRef$current2.focus();
87
158
  },
88
159
  blur: function blur() {
89
- var _inputRef$current2;
90
- return (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.blur();
160
+ var _textareaRef$current3;
161
+ return (_textareaRef$current3 = textareaRef.current) === null || _textareaRef$current3 === void 0 ? void 0 : _textareaRef$current3.blur();
91
162
  }
92
163
  };
93
164
  });
@@ -100,6 +171,7 @@ var TextArea = /*#__PURE__*/forwardRef(function (props, ref) {
100
171
  style: props.style,
101
172
  ref: containerRef
102
173
  }, /*#__PURE__*/React.createElement("textarea", _extends({
174
+ ref: textareaRef,
103
175
  rows: rows,
104
176
  name: name,
105
177
  title: title,
@@ -108,13 +180,15 @@ var TextArea = /*#__PURE__*/forwardRef(function (props, ref) {
108
180
  error: error,
109
181
  warning: warning
110
182
  })),
111
- style: props.innerStyle,
183
+ style: _objectSpread(_objectSpread({
184
+ minHeight: 31,
185
+ resize: disabled ? 'none' : resize
186
+ }, textareaCalcStyle), inputStyle),
112
187
  placeholder: placeholder,
113
188
  readOnly: readOnly,
114
189
  disabled: disabled,
115
190
  maxLength: maxLength,
116
191
  onChange: handleInput,
117
- ref: inputRef,
118
192
  onFocus: useCallback(function (event) {
119
193
  setFocus(true);
120
194
  onFocus === null || onFocus === void 0 || onFocus.call(_this, event);
@@ -124,8 +198,9 @@ var TextArea = /*#__PURE__*/forwardRef(function (props, ref) {
124
198
  onBlur === null || onBlur === void 0 || onBlur.call(_this, event);
125
199
  }, [onBlur])
126
200
  }, htmlInputProps)), maxLength && showWordLimit ? /*#__PURE__*/React.createElement("span", {
201
+ ref: countRef,
127
202
  className: e(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["count"])))
128
203
  }, typeof value === 'string' ? value.length : 0, " / ", maxLength) : null);
129
204
  });
130
- TextArea.displayName = 'TextArea';
205
+ TextArea.displayName = 'ElTextArea';
131
206
  export default TextArea;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { BaseProps, FormControlBaseProps, NativeProps, TypeAttributes } from '../types/common';
3
3
  export type LiteralUnion<T extends U, U> = T | (U & {});
4
- export type ValueType = React.AllHTMLAttributes<HTMLInputElement>['value'];
4
+ export type ValueType = string | number;
5
5
  export type BaseInputRef = {
6
6
  /** 获取值 */
7
7
  getValue: () => ValueType;
@@ -24,10 +24,11 @@ export type InputRef = {
24
24
  export type TextareaRef = {
25
25
  input: HTMLTextAreaElement;
26
26
  } & BaseInputRef;
27
- export interface InputProps extends FormControlBaseProps<ValueType>, BaseProps, NativeProps, Omit<React.AllHTMLAttributes<HTMLInputElement>, 'defaultValue' | 'size' | 'prefix' | 'type' | 'onInput' | 'onChange' | 'style' | 'children'> {
27
+ export interface InputProps extends FormControlBaseProps<string | number>, BaseProps, NativeProps, Omit<React.AllHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue' | 'size' | 'prefix' | 'type' | 'onInput' | 'onChange' | 'style' | 'children'> {
28
28
  size?: TypeAttributes.Size;
29
+ value?: string | number;
29
30
  /** 初始值 */
30
- defaultValue?: ValueType;
31
+ defaultValue?: string | number;
31
32
  /**
32
33
  * text,textarea 和其他原生 input 的 type 值
33
34
  * ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#%3Cinput%3E_types */
@@ -42,6 +43,8 @@ export interface InputProps extends FormControlBaseProps<ValueType>, BaseProps,
42
43
  append?: React.ReactElement | string | number;
43
44
  /** 是否可清空 */
44
45
  clearable?: boolean;
46
+ /** 指定输入值的格式。(只有当 type 是"text"时才能工作) */
47
+ formatter?: (value: ValueType) => ValueType;
45
48
  /** 是否显示切换密码图标 */
46
49
  showPassword?: boolean;
47
50
  /** 是否纯文本模式,即无边框 */
@@ -79,7 +82,7 @@ export interface InputGroupProps extends BaseProps, NativeProps {
79
82
  /** 输入框后置内容,只对 type="text" 有效 */
80
83
  append?: React.ReactElement | string | number;
81
84
  }
82
- export interface TextareaProps extends Omit<React.AllHTMLAttributes<HTMLInputElement>, 'defaultValue' | 'size' | 'prefix' | 'type' | 'onInput' | 'onChange' | 'style' | 'children'>, FormControlBaseProps<ValueType>, BaseProps, NativeProps {
85
+ export interface TextareaProps extends Omit<React.AllHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue' | 'size' | 'prefix' | 'type' | 'onInput' | 'onChange' | 'style' | 'children'>, FormControlBaseProps<ValueType>, BaseProps, NativeProps {
83
86
  /** 初始值 */
84
87
  defaultValue?: ValueType;
85
88
  /** 表单校验错误提示 */
@@ -90,13 +93,20 @@ export interface TextareaProps extends Omit<React.AllHTMLAttributes<HTMLInputEle
90
93
  plain?: boolean;
91
94
  rows?: number;
92
95
  /** input自定义内联样式 */
93
- innerStyle?: React.CSSProperties;
96
+ inputStyle?: React.CSSProperties;
94
97
  /** 最大输入长度 */
95
98
  maxLength?: number;
96
99
  /** 原生属性,最小输入长度 */
97
100
  minLength?: number;
98
101
  /** 是否显示统计字数, 只在 type 为 'text' 或 'textarea' 的时候生效 */
99
102
  showWordLimit?: boolean;
103
+ /** 控制是否能被用户缩放 */
104
+ resize?: 'none' | 'both' | 'horizontal' | 'vertical';
105
+ /** 高度是否自适应,可以接受一个对象,比如: { minRows: 2, maxRows: 6 } */
106
+ autosize?: boolean | {
107
+ minRows?: number;
108
+ maxRows?: number;
109
+ };
100
110
  /** 在 Input 值改变时触发 */
101
111
  onChange?: (value: ValueType, event?: React.ChangeEvent) => void;
102
112
  }
@@ -0,0 +1,23 @@
1
+ import { ChangeEventHandler, CompositionEventHandler, KeyboardEventHandler } from 'react';
2
+ import { InputProps, TextareaProps } from './typings';
3
+ interface useCompositionProps {
4
+ value: string;
5
+ maxLength: number;
6
+ onChange: InputProps['onChange'];
7
+ onKeyDown: InputProps['onKeyDown'] | TextareaProps['onKeyDown'];
8
+ onPressEnter: InputProps['onProgress'];
9
+ }
10
+ /**
11
+ * Handle input text like Chinese
12
+ * chrome: compositionstart -> onChange -> compositionend
13
+ * other browser: compositionstart -> compositionend -> onChange
14
+ */
15
+ export declare function useComposition({ value, maxLength, onChange, onKeyDown, onPressEnter }: useCompositionProps): {
16
+ compositionValue: string;
17
+ triggerValueChange: typeof onChange;
18
+ handleCompositionStart: CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
19
+ handleCompositionEnd: CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
20
+ handleValueChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
21
+ handleKeyDown: KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
22
+ };
23
+ export {};