@rc-component/cascader 1.5.0 → 1.6.1

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/es/Cascader.js CHANGED
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
  import { BaseSelect } from '@rc-component/select';
3
3
  import useId from "@rc-component/util/es/hooks/useId";
4
4
  import useEvent from "@rc-component/util/es/hooks/useEvent";
5
- import useMergedState from "@rc-component/util/es/hooks/useMergedState";
5
+ import useControlledState from "@rc-component/util/es/hooks/useControlledState";
6
6
  import * as React from 'react';
7
7
  import CascaderContext from "./context";
8
8
  import useDisplayValues from "./hooks/useDisplayValues";
@@ -60,10 +60,8 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
60
60
  const multiple = !!checkable;
61
61
 
62
62
  // =========================== Values ===========================
63
- const [rawValues, setRawValues] = useMergedState(defaultValue, {
64
- value,
65
- postState: toRawValues
66
- });
63
+ const [interanlRawValues, setRawValues] = useControlledState(defaultValue, value);
64
+ const rawValues = toRawValues(interanlRawValues);
67
65
 
68
66
  // ========================= FieldNames =========================
69
67
  const mergedFieldNames = React.useMemo(() => fillFieldNames(fieldNames), /* eslint-disable react-hooks/exhaustive-deps */
@@ -80,10 +78,8 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
80
78
  searchValue,
81
79
  onSearch
82
80
  } = searchConfig;
83
- const [mergedSearchValue, setSearchValue] = useMergedState('', {
84
- value: searchValue,
85
- postState: search => search || ''
86
- });
81
+ const [internalSearchValue, setSearchValue] = useControlledState('', searchValue);
82
+ const mergedSearchValue = internalSearchValue || '';
87
83
  const onInternalSearch = (searchText, info) => {
88
84
  setSearchValue(searchText);
89
85
  if (info.source !== 'blur' && onSearch) {
@@ -2,7 +2,7 @@ import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
2
2
  import * as React from 'react';
3
3
  import type { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
4
4
  declare const _default: (ref: React.Ref<RefOptionListProps>, options: DefaultOptionType[], fieldNames: InternalFieldNames, activeValueCells: LegacyKey[], setActiveValueCells: (activeValueCells: LegacyKey[]) => void, onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void, contextProps: {
5
- direction?: "rtl" | "ltr" | undefined;
5
+ direction?: "ltr" | "rtl" | undefined;
6
6
  searchValue: string;
7
7
  toggleOpen: (open?: boolean) => void;
8
8
  open?: boolean | undefined;
package/es/Panel.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import type { CascaderProps, DefaultOptionType } from './Cascader';
3
- export type PickType = 'value' | 'defaultValue' | 'changeOnSelect' | 'onChange' | 'options' | 'prefixCls' | 'checkable' | 'fieldNames' | 'showCheckedStrategy' | 'loadData' | 'expandTrigger' | 'expandIcon' | 'loadingIcon' | 'className' | 'style' | 'direction' | 'notFoundContent' | 'disabled';
3
+ export type PickType = 'value' | 'defaultValue' | 'changeOnSelect' | 'onChange' | 'options' | 'prefixCls' | 'checkable' | 'fieldNames' | 'showCheckedStrategy' | 'loadData' | 'expandTrigger' | 'expandIcon' | 'loadingIcon' | 'className' | 'style' | 'direction' | 'notFoundContent' | 'disabled' | 'optionRender';
4
4
  export type PanelProps<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType, Multiple extends boolean | React.ReactNode = false> = Pick<CascaderProps<OptionType, ValueField, Multiple>, PickType>;
5
5
  export default function Panel<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType, Multiple extends boolean | React.ReactNode = false>(props: PanelProps<OptionType, ValueField, Multiple>): React.JSX.Element;
package/es/Panel.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import classNames from 'classnames';
2
- import { useEvent, useMergedState } from '@rc-component/util';
2
+ import { useEvent, useControlledState } from '@rc-component/util';
3
3
  import * as React from 'react';
4
4
  import CascaderContext from "./context";
5
5
  import useMissingValues from "./hooks/useMissingValues";
@@ -29,17 +29,16 @@ export default function Panel(props) {
29
29
  loadingIcon,
30
30
  direction,
31
31
  notFoundContent = 'Not Found',
32
- disabled
32
+ disabled,
33
+ optionRender
33
34
  } = props;
34
35
 
35
36
  // ======================== Multiple ========================
36
37
  const multiple = !!checkable;
37
38
 
38
39
  // ========================= Values =========================
39
- const [rawValues, setRawValues] = useMergedState(defaultValue, {
40
- value,
41
- postState: toRawValues
42
- });
40
+ const [interanlRawValues, setRawValues] = useControlledState(defaultValue, value);
41
+ const rawValues = toRawValues(interanlRawValues);
43
42
 
44
43
  // ========================= FieldNames =========================
45
44
  const mergedFieldNames = React.useMemo(() => fillFieldNames(fieldNames), /* eslint-disable react-hooks/exhaustive-deps */
@@ -90,8 +89,9 @@ export default function Panel(props) {
90
89
  expandTrigger,
91
90
  expandIcon,
92
91
  loadingIcon,
93
- popupMenuColumnStyle: undefined
94
- }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, loadData, expandTrigger, expandIcon, loadingIcon]);
92
+ popupMenuColumnStyle: undefined,
93
+ optionRender
94
+ }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, loadData, expandTrigger, expandIcon, loadingIcon, optionRender]);
95
95
 
96
96
  // ========================= Render =========================
97
97
  const panelPrefixCls = `${prefixCls}-panel`;
package/lib/Cascader.js CHANGED
@@ -7,7 +7,7 @@ exports.default = void 0;
7
7
  var _select = require("@rc-component/select");
8
8
  var _useId = _interopRequireDefault(require("@rc-component/util/lib/hooks/useId"));
9
9
  var _useEvent = _interopRequireDefault(require("@rc-component/util/lib/hooks/useEvent"));
10
- var _useMergedState = _interopRequireDefault(require("@rc-component/util/lib/hooks/useMergedState"));
10
+ var _useControlledState = _interopRequireDefault(require("@rc-component/util/lib/hooks/useControlledState"));
11
11
  var React = _interopRequireWildcard(require("react"));
12
12
  var _context = _interopRequireDefault(require("./context"));
13
13
  var _useDisplayValues = _interopRequireDefault(require("./hooks/useDisplayValues"));
@@ -69,10 +69,8 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
69
69
  const multiple = !!checkable;
70
70
 
71
71
  // =========================== Values ===========================
72
- const [rawValues, setRawValues] = (0, _useMergedState.default)(defaultValue, {
73
- value,
74
- postState: _commonUtil.toRawValues
75
- });
72
+ const [interanlRawValues, setRawValues] = (0, _useControlledState.default)(defaultValue, value);
73
+ const rawValues = (0, _commonUtil.toRawValues)(interanlRawValues);
76
74
 
77
75
  // ========================= FieldNames =========================
78
76
  const mergedFieldNames = React.useMemo(() => (0, _commonUtil.fillFieldNames)(fieldNames), /* eslint-disable react-hooks/exhaustive-deps */
@@ -89,10 +87,8 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
89
87
  searchValue,
90
88
  onSearch
91
89
  } = searchConfig;
92
- const [mergedSearchValue, setSearchValue] = (0, _useMergedState.default)('', {
93
- value: searchValue,
94
- postState: search => search || ''
95
- });
90
+ const [internalSearchValue, setSearchValue] = (0, _useControlledState.default)('', searchValue);
91
+ const mergedSearchValue = internalSearchValue || '';
96
92
  const onInternalSearch = (searchText, info) => {
97
93
  setSearchValue(searchText);
98
94
  if (info.source !== 'blur' && onSearch) {
@@ -2,7 +2,7 @@ import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
2
2
  import * as React from 'react';
3
3
  import type { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
4
4
  declare const _default: (ref: React.Ref<RefOptionListProps>, options: DefaultOptionType[], fieldNames: InternalFieldNames, activeValueCells: LegacyKey[], setActiveValueCells: (activeValueCells: LegacyKey[]) => void, onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void, contextProps: {
5
- direction?: "rtl" | "ltr" | undefined;
5
+ direction?: "ltr" | "rtl" | undefined;
6
6
  searchValue: string;
7
7
  toggleOpen: (open?: boolean) => void;
8
8
  open?: boolean | undefined;
package/lib/Panel.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import type { CascaderProps, DefaultOptionType } from './Cascader';
3
- export type PickType = 'value' | 'defaultValue' | 'changeOnSelect' | 'onChange' | 'options' | 'prefixCls' | 'checkable' | 'fieldNames' | 'showCheckedStrategy' | 'loadData' | 'expandTrigger' | 'expandIcon' | 'loadingIcon' | 'className' | 'style' | 'direction' | 'notFoundContent' | 'disabled';
3
+ export type PickType = 'value' | 'defaultValue' | 'changeOnSelect' | 'onChange' | 'options' | 'prefixCls' | 'checkable' | 'fieldNames' | 'showCheckedStrategy' | 'loadData' | 'expandTrigger' | 'expandIcon' | 'loadingIcon' | 'className' | 'style' | 'direction' | 'notFoundContent' | 'disabled' | 'optionRender';
4
4
  export type PanelProps<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType, Multiple extends boolean | React.ReactNode = false> = Pick<CascaderProps<OptionType, ValueField, Multiple>, PickType>;
5
5
  export default function Panel<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType, Multiple extends boolean | React.ReactNode = false>(props: PanelProps<OptionType, ValueField, Multiple>): React.JSX.Element;
package/lib/Panel.js CHANGED
@@ -38,17 +38,16 @@ function Panel(props) {
38
38
  loadingIcon,
39
39
  direction,
40
40
  notFoundContent = 'Not Found',
41
- disabled
41
+ disabled,
42
+ optionRender
42
43
  } = props;
43
44
 
44
45
  // ======================== Multiple ========================
45
46
  const multiple = !!checkable;
46
47
 
47
48
  // ========================= Values =========================
48
- const [rawValues, setRawValues] = (0, _util.useMergedState)(defaultValue, {
49
- value,
50
- postState: _commonUtil.toRawValues
51
- });
49
+ const [interanlRawValues, setRawValues] = (0, _util.useControlledState)(defaultValue, value);
50
+ const rawValues = (0, _commonUtil.toRawValues)(interanlRawValues);
52
51
 
53
52
  // ========================= FieldNames =========================
54
53
  const mergedFieldNames = React.useMemo(() => (0, _commonUtil.fillFieldNames)(fieldNames), /* eslint-disable react-hooks/exhaustive-deps */
@@ -99,8 +98,9 @@ function Panel(props) {
99
98
  expandTrigger,
100
99
  expandIcon,
101
100
  loadingIcon,
102
- popupMenuColumnStyle: undefined
103
- }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, loadData, expandTrigger, expandIcon, loadingIcon]);
101
+ popupMenuColumnStyle: undefined,
102
+ optionRender
103
+ }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, loadData, expandTrigger, expandIcon, loadingIcon, optionRender]);
104
104
 
105
105
  // ========================= Render =========================
106
106
  const panelPrefixCls = `${prefixCls}-panel`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/cascader",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "cascade select ui component for react",
5
5
  "keywords": [
6
6
  "react",
@@ -45,7 +45,7 @@
45
45
  "dependencies": {
46
46
  "@rc-component/select": "~1.1.0",
47
47
  "@rc-component/tree": "~1.0.0",
48
- "@rc-component/util": "^1.2.1",
48
+ "@rc-component/util": "^1.3.0",
49
49
  "classnames": "^2.3.1"
50
50
  },
51
51
  "devDependencies": {