@ucloud-fe/react-components 1.2.5 → 1.2.9

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.
@@ -1,5 +1,5 @@
1
- import React, { ReactNode, HTMLAttributes } from 'react';
2
- declare type InputProps = HTMLAttributes<HTMLDivElement>;
1
+ import React, { ReactNode } from 'react';
2
+ import { InputProps } from '../../components/Input';
3
3
  interface Item {
4
4
  value: string;
5
5
  label?: ReactNode;
@@ -31,8 +31,10 @@ interface AutoCompleteProps {
31
31
  onFocus?: () => void;
32
32
  /** 失焦回调 */
33
33
  onBlur?: () => void;
34
+ /** 状态 */
35
+ status: InputProps['status'];
34
36
  /** @ignore */
35
37
  placeholder?: InputProps['placeholder'];
36
38
  }
37
- declare const _default: React.MemoExoticComponent<({ value: _value, defaultValue, onChange: _onChange, options, disabled, loading, prefix, block, handleSearch, popoverProps, onFocus, onBlur, style, className, placeholder }: AutoCompleteProps & Omit<InputProps, keyof AutoCompleteProps>) => JSX.Element>;
39
+ declare const _default: React.MemoExoticComponent<({ value: _value, defaultValue, onChange: _onChange, options, disabled, loading, prefix, block, handleSearch, popoverProps, onFocus, onBlur, style, className, status, placeholder }: AutoCompleteProps & Omit<InputProps, keyof AutoCompleteProps>) => JSX.Element>;
38
40
  export default _default;
@@ -61,6 +61,7 @@ var AutoComplete = function AutoComplete(_ref) {
61
61
  onBlur = _ref.onBlur,
62
62
  style = _ref.style,
63
63
  className = _ref.className,
64
+ status = _ref.status,
64
65
  placeholder = _ref.placeholder;
65
66
 
66
67
  var _useUncontrolled = (0, _useUncontrolled3.default)(_value, defaultValue, _onChange),
@@ -149,7 +150,8 @@ var AutoComplete = function AutoComplete(_ref) {
149
150
  }),
150
151
  className: _style.inputCls,
151
152
  block: true,
152
- placeholder: placeholder
153
+ placeholder: placeholder,
154
+ status: status
153
155
  })));
154
156
  }.bind(void 0);
155
157
 
@@ -1,5 +1,5 @@
1
1
  import React, { InputHTMLAttributes, ReactNode } from 'react';
2
- import { Size } from '../../type';
2
+ import { Override, Size } from '../../type';
3
3
  export interface InputProps {
4
4
  /**
5
5
  * @deprecated 使用 suffix 替换
@@ -15,7 +15,7 @@ export interface InputProps {
15
15
  /** 尺寸 */
16
16
  size?: Size;
17
17
  /** 状态 */
18
- status?: 'error';
18
+ status?: 'default' | 'error';
19
19
  /** 展示变更为块占位 */
20
20
  block?: boolean;
21
21
  /** 点击 clear 按钮回调 */
@@ -37,5 +37,6 @@ export declare type InputRef = {
37
37
  /** input 元素 */
38
38
  input?: HTMLInputElement | null;
39
39
  };
40
+ export declare type FullInputProps = InputProps & Override<InputHTMLAttributes<HTMLInputElement>, InputProps>;
40
41
  declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<InputProps & Omit<React.InputHTMLAttributes<HTMLInputElement>, keyof InputProps> & React.RefAttributes<InputRef>>>;
41
42
  export default _default;
@@ -188,7 +188,7 @@ var Input = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
188
188
  focused: focused,
189
189
  style: style,
190
190
  disabled: disabled,
191
- status: status || _status,
191
+ status: _status || status,
192
192
  customStyle: customStyle,
193
193
  empty: !value
194
194
  }, /*#__PURE__*/_react.default.createElement("span", {
@@ -1,10 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import NumberInput from '../../components/NumberInput';
3
3
  import Textarea from '../../components/Textarea';
4
+ import { FullInputProps as InputProps } from './Input';
4
5
  declare const ExportClassInput: import("react").ComponentClass<import("./Input").InputProps & Omit<import("react").InputHTMLAttributes<HTMLInputElement>, keyof import("./Input").InputProps> & import("react").RefAttributes<import("./Input").InputRef>, any> & {
5
6
  Search: import("react").ComponentClass<import("./Search").SearchProps & import("./Input").InputProps & Omit<import("react").InputHTMLAttributes<HTMLInputElement>, keyof import("./Input").InputProps> & import("react").RefAttributes<import("./Input").InputRef>, any>;
6
7
  Number: typeof NumberInput;
7
8
  Textarea: typeof Textarea;
8
9
  Sizes: ["sm", "md", "lg"];
9
10
  };
11
+ export type { InputProps };
10
12
  export default ExportClassInput;
@@ -84,11 +84,15 @@ var deprecatedLogForPopover = (0, _once.default)(function () {
84
84
  exports.deprecatedLogForPopover = deprecatedLogForPopover;
85
85
  var warnLogForVirtualList = (0, _once.default)(function () {
86
86
  (0, _newArrowCheck2.default)(this, _this);
87
- return console.warn('Select virtualList only valid when use options');
87
+ return console.error('Select virtualList only valid when use options');
88
88
  }.bind(void 0));
89
89
  var warnLogForCustomHeight = (0, _once.default)(function () {
90
90
  (0, _newArrowCheck2.default)(this, _this);
91
- return console.warn('CustomStyle.optionListMaxHeight is invalid when use virtualList, please use virtualList.height');
91
+ return console.error('CustomStyle.optionListMaxHeight is invalid when use virtualList, please use virtualList.height');
92
+ }.bind(void 0));
93
+ var warnLogForSearchProps = (0, _once.default)(function () {
94
+ (0, _newArrowCheck2.default)(this, _this);
95
+ return console.error("Don't use item.props in custom search, just use item as props.");
92
96
  }.bind(void 0));
93
97
  var groupOptions = {
94
98
  itemTag: 'isMenuItem',
@@ -281,7 +285,8 @@ var Popup = function Popup(_ref2) {
281
285
 
282
286
  return /*#__PURE__*/_react.default.createElement(_style.MenuWrap, null, search && /*#__PURE__*/_react.default.createElement(_style.SelectSearchInput, {
283
287
  onChange: handleSearchInput,
284
- value: searchValue
288
+ value: searchValue,
289
+ status: "default"
285
290
  }), children || options ? /*#__PURE__*/_react.default.createElement(_style.BlockMenu, {
286
291
  onChange: handleChange,
287
292
  customStyle: newCustomStyle,
@@ -327,6 +332,11 @@ var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
327
332
  var subGroupMap = new Map();
328
333
  var childrenMap = new Map();
329
334
 
335
+ var isValidKey = function isValidKey(v) {
336
+ (0, _newArrowCheck2.default)(this, _this5);
337
+ return typeof v === 'string' || typeof v === 'number';
338
+ }.bind(this);
339
+
330
340
  var group = function group(options) {
331
341
  var _this6 = this;
332
342
 
@@ -342,6 +352,7 @@ var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
342
352
  if (subChildren) {
343
353
  var _key = child[subGroupKeyName] || child.key || "".concat(prefixKey, "-").concat(i);
344
354
 
355
+ var reactKey = child.key || isValidKey(child[subGroupKeyName]) ? child[subGroupKeyName] : "".concat(prefixKey, "-").concat(i);
345
356
  var isDisabled = disabled || child.disabled;
346
357
 
347
358
  var _group = group(subChildren, isDisabled, _key),
@@ -361,7 +372,7 @@ var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
361
372
 
362
373
  if (_visible) {
363
374
  renderChildren.push( /*#__PURE__*/_react.default.createElement(SubGroupComponent, (0, _extends2.default)({
364
- key: _key
375
+ key: reactKey
365
376
  }, child, (0, _defineProperty2.default)({
366
377
  disabled: globalDisabled || isDisabled
367
378
  }, subGroupKeyName, _key)), subRenderChildren));
@@ -371,6 +382,8 @@ var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
371
382
 
372
383
  var _key2 = child[itemKeyName] === undefined ? child.key : child[itemKeyName];
373
384
 
385
+ var _reactKey = child.key || isValidKey(child[itemKeyName]) ? child[itemKeyName] : "".concat(prefixKey, "-").concat(i);
386
+
374
387
  var _isDisabled = disabled || child.disabled;
375
388
 
376
389
  if (_isDisabled) {
@@ -385,7 +398,7 @@ var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
385
398
 
386
399
  if (_visible2) {
387
400
  renderChildren.push( /*#__PURE__*/_react.default.createElement(ItemComponent, (0, _extends2.default)({
388
- key: _key2
401
+ key: _reactKey
389
402
  }, child, (0, _defineProperty2.default)({
390
403
  disabled: globalDisabled || _isDisabled
391
404
  }, itemKeyName, _key2)), display));
@@ -457,6 +470,8 @@ var Select = function Select(_ref8) {
457
470
  if (virtualList && !options) warnLogForVirtualList();
458
471
  }.bind(this));
459
472
  var handleSearch = (0, _react.useCallback)(function (value, props) {
473
+ var _this8 = this;
474
+
460
475
  (0, _newArrowCheck2.default)(this, _this7);
461
476
 
462
477
  if (!search || !searchValue) {
@@ -464,14 +479,33 @@ var Select = function Select(_ref8) {
464
479
  }
465
480
 
466
481
  if ((0, _typeof2.default)(search) === 'object' && search.handleSearch) {
467
- return search.handleSearch(searchValue, value, _objectSpread(_objectSpread({}, props), {}, {
468
- props: props
469
- }));
482
+ var _beforeProps$label;
483
+
484
+ // assign props for forward compatible
485
+ var beforeProps = _objectSpread({}, props);
486
+
487
+ if (options) beforeProps.children = (_beforeProps$label = beforeProps.label) !== null && _beforeProps$label !== void 0 ? _beforeProps$label : beforeProps.value;
488
+
489
+ var itemInfo = _objectSpread({}, props);
490
+
491
+ if (!('props' in itemInfo)) {
492
+ Object.defineProperty(itemInfo, 'props', {
493
+ get: function get() {
494
+ (0, _newArrowCheck2.default)(this, _this8);
495
+ warnLogForSearchProps();
496
+ return beforeProps;
497
+ }.bind(this)
498
+ });
499
+ }
500
+
501
+ return search.handleSearch(searchValue, value, itemInfo);
470
502
  } else {
471
- var _children = props.children;
503
+ // use label for options case
504
+ var _children = options ? props.label : props.children;
505
+
472
506
  return (value + '').indexOf(searchValue) >= 0 || _children && typeof _children === 'string' && _children.indexOf(searchValue) >= 0;
473
507
  }
474
- }.bind(this), [search, searchValue]);
508
+ }.bind(this), [options, search, searchValue]);
475
509
  var childrenDataSource = (0, _react.useMemo)(function () {
476
510
  (0, _newArrowCheck2.default)(this, _this7);
477
511
  return options ? [] : (0, _group3.groupChildrenAsDataSource)(children, disabled, groupOptions);
@@ -57,6 +57,7 @@ var SearchInput = /*#__PURE__*/function (_Component) {
57
57
  (0, _newArrowCheck2.default)(this, _this);
58
58
  var handleSearch = _ref.handleSearch;
59
59
  return /*#__PURE__*/_react.default.createElement(_Input.default.Search, (0, _extends2.default)({
60
+ status: "default",
60
61
  onSearch: handleSearch
61
62
  }, rest));
62
63
  }.bind(this));
@@ -328,7 +328,8 @@ var Transfer = (_dec = (0, _uncontrolled.default)({
328
328
  block: true,
329
329
  onSearch: onSearch,
330
330
  onChange: onSearch,
331
- disabled: disabled
331
+ disabled: disabled,
332
+ status: "default"
332
333
  })), _this2.renderContent({
333
334
  part: part,
334
335
  dataSource: partDataSource,
@@ -66,6 +66,7 @@ var groupDataSource = function groupDataSource(dataSource) {
66
66
  var group = {};
67
67
  var allKeys = [];
68
68
  var allDisabledKeys = [];
69
+ if (!dataSource) dataSource = [];
69
70
 
70
71
  var _groupData2 = function _groupData(children, disabled) {
71
72
  var _this3 = this;
@@ -122,10 +123,10 @@ var keysToMap = function keysToMap() {
122
123
  return result;
123
124
  };
124
125
 
125
- var defaultSearchHandle = function defaultSearchHandle(searchValue, dataSource) {
126
+ var defaultSearchHandle = function defaultSearchHandle(searchValue) {
126
127
  var _this5 = this;
127
128
 
128
- (0, _newArrowCheck2.default)(this, _this);
129
+ var dataSource = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
129
130
  if (!searchValue) return {
130
131
  dataSource: dataSource,
131
132
  count: null
@@ -185,15 +186,14 @@ var defaultSearchHandle = function defaultSearchHandle(searchValue, dataSource)
185
186
  count: count,
186
187
  openKeys: Object.keys(finalExpandedKeyMap)
187
188
  };
188
- }.bind(void 0);
189
+ };
189
190
 
190
191
  var CommonTree = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
191
192
  var _this7 = this;
192
193
 
193
194
  (0, _newArrowCheck2.default)(this, _this);
194
195
 
195
- var _ref$dataSource = _ref.dataSource,
196
- dataSource = _ref$dataSource === void 0 ? [] : _ref$dataSource,
196
+ var dataSource = _ref.dataSource,
197
197
  _ref$disabled = _ref.disabled,
198
198
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
199
199
  _ref$multiple = _ref.multiple,
@@ -70,7 +70,8 @@ var Search = function Search(_ref) {
70
70
  prefix: prefix,
71
71
  onChange: handleChange,
72
72
  clearable: true,
73
- block: true
73
+ block: true,
74
+ status: "default"
74
75
  }), loading ? /*#__PURE__*/_react.default.createElement(_Loading.default, {
75
76
  loading: loading,
76
77
  className: _style.loadingCls
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucloud-fe/react-components",
3
- "version": "1.2.5",
3
+ "version": "1.2.9",
4
4
  "title": "UCloud react components",
5
5
  "description": "UCloud react components",
6
6
  "keywords": [