@rc-component/tree-select 1.1.3 → 1.2.0

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.
@@ -8,7 +8,14 @@ import { SHOW_ALL, SHOW_CHILD, SHOW_PARENT } from './utils/strategyUtil';
8
8
  import type { SafeKey, DataNode, SimpleModeConfig, ChangeEventExtra, FieldNames, LegacyDataNode } from './interface';
9
9
  export type SemanticName = 'input' | 'prefix' | 'suffix';
10
10
  export type PopupSemantic = 'item' | 'itemTitle';
11
- export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = DataNode> extends Omit<BaseSelectPropsWithoutPrivate, 'mode' | 'classNames' | 'styles'> {
11
+ export interface SearchConfig {
12
+ searchValue?: string;
13
+ onSearch?: (value: string) => void;
14
+ autoClearSearchValue?: boolean;
15
+ filterTreeNode?: boolean | ((inputValue: string, treeNode: DataNode) => boolean);
16
+ treeNodeFilterProp?: string;
17
+ }
18
+ export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = DataNode> extends Omit<BaseSelectPropsWithoutPrivate, 'mode' | 'classNames' | 'styles' | 'showSearch'> {
12
19
  prefixCls?: string;
13
20
  id?: string;
14
21
  children?: React.ReactNode;
@@ -21,12 +28,18 @@ export interface TreeSelectProps<ValueType = any, OptionType extends DataNode =
21
28
  value?: ValueType;
22
29
  defaultValue?: ValueType;
23
30
  onChange?: (value: ValueType, labelList: React.ReactNode[], extra: ChangeEventExtra) => void;
31
+ showSearch?: boolean | SearchConfig;
32
+ /** @deprecated Use `showSearch.searchValue` instead */
24
33
  searchValue?: string;
25
- /** @deprecated Use `searchValue` instead */
34
+ /** @deprecated Use `showSearch.searchValue` instead */
26
35
  inputValue?: string;
36
+ /** @deprecated Use `showSearch.onSearch` instead */
27
37
  onSearch?: (value: string) => void;
38
+ /** @deprecated Use `showSearch.autoClearSearchValue` instead */
28
39
  autoClearSearchValue?: boolean;
40
+ /** @deprecated Use `showSearch.filterTreeNode` instead */
29
41
  filterTreeNode?: boolean | ((inputValue: string, treeNode: DataNode) => boolean);
42
+ /** @deprecated Use `showSearch.treeNodeFilterProp` instead */
30
43
  treeNodeFilterProp?: string;
31
44
  onSelect?: (value: ValueType, option: OptionType) => void;
32
45
  onDeselect?: (value: ValueType, option: OptionType) => void;
package/es/TreeSelect.js CHANGED
@@ -18,6 +18,7 @@ import { fillAdditionalInfo, fillLegacyProps } from "./utils/legacyUtil";
18
18
  import { formatStrategyValues, SHOW_ALL, SHOW_CHILD, SHOW_PARENT } from "./utils/strategyUtil";
19
19
  import { fillFieldNames, isNil, toArray } from "./utils/valueUtil";
20
20
  import warningProps from "./utils/warningPropsUtil";
21
+ import useSearchConfig from "./hooks/useSearchConfig";
21
22
  function isRawValue(value) {
22
23
  return !value || typeof value !== 'object';
23
24
  }
@@ -32,12 +33,7 @@ const TreeSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
32
33
  onSelect,
33
34
  onDeselect,
34
35
  // Search
35
- searchValue,
36
- inputValue,
37
- onSearch,
38
- autoClearSearchValue = true,
39
- filterTreeNode,
40
- treeNodeFilterProp = 'value',
36
+ showSearch,
41
37
  // Selector
42
38
  showCheckedStrategy,
43
39
  treeNodeLabelProp,
@@ -86,6 +82,14 @@ const TreeSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
86
82
  const mergedCheckable = treeCheckable || treeCheckStrictly;
87
83
  const mergedLabelInValue = treeCheckStrictly || labelInValue;
88
84
  const mergedMultiple = mergedCheckable || multiple;
85
+ const [mergedShowSearch, searchConfig] = useSearchConfig(showSearch, props);
86
+ const {
87
+ searchValue,
88
+ onSearch,
89
+ autoClearSearchValue = true,
90
+ filterTreeNode,
91
+ treeNodeFilterProp = 'value'
92
+ } = searchConfig;
89
93
  const [internalValue, setInternalValue] = useMergedState(defaultValue, {
90
94
  value
91
95
  });
@@ -110,7 +114,7 @@ const TreeSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
110
114
 
111
115
  // =========================== Search ===========================
112
116
  const [mergedSearchValue, setSearchValue] = useMergedState('', {
113
- value: searchValue !== undefined ? searchValue : inputValue,
117
+ value: searchValue,
114
118
  postState: search => search || ''
115
119
  });
116
120
  const onInternalSearch = searchText => {
@@ -498,7 +502,8 @@ const TreeSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
498
502
  displayValues: cachedDisplayValues,
499
503
  onDisplayValuesChange: onDisplayValuesChange
500
504
  // >>> Search
501
- ,
505
+ }, searchConfig, {
506
+ showSearch: mergedShowSearch,
502
507
  searchValue: mergedSearchValue,
503
508
  onSearch: onInternalSearch
504
509
  // >>> Options
@@ -0,0 +1,2 @@
1
+ import type { SearchConfig, TreeSelectProps } from "../TreeSelect";
2
+ export default function useSearchConfig(showSearch: boolean | SearchConfig, props: TreeSelectProps): [boolean, SearchConfig];
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+
3
+ // Convert `showSearch` to unique config
4
+ export default function useSearchConfig(showSearch, props) {
5
+ const {
6
+ searchValue,
7
+ inputValue,
8
+ onSearch,
9
+ autoClearSearchValue,
10
+ filterTreeNode,
11
+ treeNodeFilterProp
12
+ } = props;
13
+ return React.useMemo(() => {
14
+ const isObject = typeof showSearch === 'object';
15
+ const searchConfig = {
16
+ searchValue: searchValue ?? inputValue,
17
+ onSearch,
18
+ autoClearSearchValue,
19
+ filterTreeNode,
20
+ treeNodeFilterProp,
21
+ ...(isObject ? showSearch : {})
22
+ };
23
+ return [isObject ? true : showSearch, searchConfig];
24
+ }, [showSearch, searchValue, inputValue, onSearch, autoClearSearchValue, filterTreeNode, treeNodeFilterProp]);
25
+ }
@@ -8,7 +8,14 @@ import { SHOW_ALL, SHOW_CHILD, SHOW_PARENT } from './utils/strategyUtil';
8
8
  import type { SafeKey, DataNode, SimpleModeConfig, ChangeEventExtra, FieldNames, LegacyDataNode } from './interface';
9
9
  export type SemanticName = 'input' | 'prefix' | 'suffix';
10
10
  export type PopupSemantic = 'item' | 'itemTitle';
11
- export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = DataNode> extends Omit<BaseSelectPropsWithoutPrivate, 'mode' | 'classNames' | 'styles'> {
11
+ export interface SearchConfig {
12
+ searchValue?: string;
13
+ onSearch?: (value: string) => void;
14
+ autoClearSearchValue?: boolean;
15
+ filterTreeNode?: boolean | ((inputValue: string, treeNode: DataNode) => boolean);
16
+ treeNodeFilterProp?: string;
17
+ }
18
+ export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = DataNode> extends Omit<BaseSelectPropsWithoutPrivate, 'mode' | 'classNames' | 'styles' | 'showSearch'> {
12
19
  prefixCls?: string;
13
20
  id?: string;
14
21
  children?: React.ReactNode;
@@ -21,12 +28,18 @@ export interface TreeSelectProps<ValueType = any, OptionType extends DataNode =
21
28
  value?: ValueType;
22
29
  defaultValue?: ValueType;
23
30
  onChange?: (value: ValueType, labelList: React.ReactNode[], extra: ChangeEventExtra) => void;
31
+ showSearch?: boolean | SearchConfig;
32
+ /** @deprecated Use `showSearch.searchValue` instead */
24
33
  searchValue?: string;
25
- /** @deprecated Use `searchValue` instead */
34
+ /** @deprecated Use `showSearch.searchValue` instead */
26
35
  inputValue?: string;
36
+ /** @deprecated Use `showSearch.onSearch` instead */
27
37
  onSearch?: (value: string) => void;
38
+ /** @deprecated Use `showSearch.autoClearSearchValue` instead */
28
39
  autoClearSearchValue?: boolean;
40
+ /** @deprecated Use `showSearch.filterTreeNode` instead */
29
41
  filterTreeNode?: boolean | ((inputValue: string, treeNode: DataNode) => boolean);
42
+ /** @deprecated Use `showSearch.treeNodeFilterProp` instead */
30
43
  treeNodeFilterProp?: string;
31
44
  onSelect?: (value: ValueType, option: OptionType) => void;
32
45
  onDeselect?: (value: ValueType, option: OptionType) => void;
package/lib/TreeSelect.js CHANGED
@@ -23,6 +23,7 @@ var _legacyUtil = require("./utils/legacyUtil");
23
23
  var _strategyUtil = require("./utils/strategyUtil");
24
24
  var _valueUtil = require("./utils/valueUtil");
25
25
  var _warningPropsUtil = _interopRequireDefault(require("./utils/warningPropsUtil"));
26
+ var _useSearchConfig = _interopRequireDefault(require("./hooks/useSearchConfig"));
26
27
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
27
28
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
28
29
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -41,12 +42,7 @@ const TreeSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
41
42
  onSelect,
42
43
  onDeselect,
43
44
  // Search
44
- searchValue,
45
- inputValue,
46
- onSearch,
47
- autoClearSearchValue = true,
48
- filterTreeNode,
49
- treeNodeFilterProp = 'value',
45
+ showSearch,
50
46
  // Selector
51
47
  showCheckedStrategy,
52
48
  treeNodeLabelProp,
@@ -95,6 +91,14 @@ const TreeSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
95
91
  const mergedCheckable = treeCheckable || treeCheckStrictly;
96
92
  const mergedLabelInValue = treeCheckStrictly || labelInValue;
97
93
  const mergedMultiple = mergedCheckable || multiple;
94
+ const [mergedShowSearch, searchConfig] = (0, _useSearchConfig.default)(showSearch, props);
95
+ const {
96
+ searchValue,
97
+ onSearch,
98
+ autoClearSearchValue = true,
99
+ filterTreeNode,
100
+ treeNodeFilterProp = 'value'
101
+ } = searchConfig;
98
102
  const [internalValue, setInternalValue] = (0, _useMergedState.default)(defaultValue, {
99
103
  value
100
104
  });
@@ -119,7 +123,7 @@ const TreeSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
119
123
 
120
124
  // =========================== Search ===========================
121
125
  const [mergedSearchValue, setSearchValue] = (0, _useMergedState.default)('', {
122
- value: searchValue !== undefined ? searchValue : inputValue,
126
+ value: searchValue,
123
127
  postState: search => search || ''
124
128
  });
125
129
  const onInternalSearch = searchText => {
@@ -507,7 +511,8 @@ const TreeSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
507
511
  displayValues: cachedDisplayValues,
508
512
  onDisplayValuesChange: onDisplayValuesChange
509
513
  // >>> Search
510
- ,
514
+ }, searchConfig, {
515
+ showSearch: mergedShowSearch,
511
516
  searchValue: mergedSearchValue,
512
517
  onSearch: onInternalSearch
513
518
  // >>> Options
@@ -0,0 +1,2 @@
1
+ import type { SearchConfig, TreeSelectProps } from "../TreeSelect";
2
+ export default function useSearchConfig(showSearch: boolean | SearchConfig, props: TreeSelectProps): [boolean, SearchConfig];
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useSearchConfig;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
+ // Convert `showSearch` to unique config
11
+ function useSearchConfig(showSearch, props) {
12
+ const {
13
+ searchValue,
14
+ inputValue,
15
+ onSearch,
16
+ autoClearSearchValue,
17
+ filterTreeNode,
18
+ treeNodeFilterProp
19
+ } = props;
20
+ return React.useMemo(() => {
21
+ const isObject = typeof showSearch === 'object';
22
+ const searchConfig = {
23
+ searchValue: searchValue ?? inputValue,
24
+ onSearch,
25
+ autoClearSearchValue,
26
+ filterTreeNode,
27
+ treeNodeFilterProp,
28
+ ...(isObject ? showSearch : {})
29
+ };
30
+ return [isObject ? true : showSearch, searchConfig];
31
+ }, [showSearch, searchValue, inputValue, onSearch, autoClearSearchValue, filterTreeNode, treeNodeFilterProp]);
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/tree-select",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "description": "tree-select ui component for react",
5
5
  "keywords": [
6
6
  "react",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "classnames": "2.x",
48
- "@rc-component/select": "~1.0.7",
48
+ "@rc-component/select": "~1.1.0",
49
49
  "@rc-component/tree": "~1.0.1",
50
50
  "@rc-component/util": "^1.2.1"
51
51
  },