rsuite 5.80.2 → 5.81.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.
@@ -33,6 +33,10 @@ export interface CheckTreePickerProps<V = ValueType> extends Omit<CheckTreeViewP
33
33
  * Custom render selected items
34
34
  */
35
35
  renderValue?: (value: V, selectedNodes: TreeNode[], selectedElement: React.ReactNode) => React.ReactNode;
36
+ /**
37
+ * In the cascade case, the leaf node's value change callbacks
38
+ */
39
+ onCascadeChange?: (v: ValueType, event: React.SyntheticEvent) => void;
36
40
  }
37
41
  /**
38
42
  * The `CheckTreePicker` component is used for selecting multiple options which are organized in a tree structure.
@@ -5,7 +5,7 @@ import _omit from "lodash/omit";
5
5
  import _isFunction from "lodash/isFunction";
6
6
  import _pick from "lodash/pick";
7
7
  import _isNil from "lodash/isNil";
8
- var _excluded = ["as", "id", "appearance", "cleanable", "countable", "cascade", "classPrefix", "childrenKey", "disabled", "data", "defaultValue", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "placeholder", "popupClassName", "popupStyle", "popupAutoWidth", "placement", "treeHeight", "toggleAs", "menuAutoWidth", "menuClassName", "menuStyle", "style", "searchBy", "searchKeyword", "showIndentLine", "searchable", "valueKey", "value", "virtualized", "uncheckableItemValues", "locale", "labelKey", "listProps", "getChildren", "renderExtraFooter", "onEnter", "onChange", "onClean", "onExit", "onSearch", "onSelect", "onSelectItem", "onScroll", "onExpand", "renderValue", "renderMenu", "renderTree", "renderTreeIcon", "renderTreeNode"];
8
+ var _excluded = ["as", "id", "appearance", "cleanable", "countable", "cascade", "classPrefix", "childrenKey", "disabled", "data", "defaultValue", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "placeholder", "popupClassName", "popupStyle", "popupAutoWidth", "placement", "treeHeight", "toggleAs", "menuAutoWidth", "menuClassName", "menuStyle", "style", "searchBy", "searchKeyword", "showIndentLine", "searchable", "valueKey", "value", "virtualized", "uncheckableItemValues", "locale", "labelKey", "listProps", "getChildren", "renderExtraFooter", "onEnter", "onChange", "onClean", "onExit", "onSearch", "onSelect", "onSelectItem", "onScroll", "onExpand", "renderValue", "renderMenu", "renderTree", "renderTreeIcon", "renderTreeNode", "onCascadeChange"];
9
9
  import React, { useMemo } from 'react';
10
10
  import classNames from 'classnames';
11
11
  import { useClassNames, useEventCallback } from "../internals/hooks/index.js";
@@ -103,6 +103,7 @@ var CheckTreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
103
103
  renderTree = _propsWithDefaults$re === void 0 ? DEPRECATED_renderMenu : _propsWithDefaults$re,
104
104
  renderTreeIcon = propsWithDefaults.renderTreeIcon,
105
105
  renderTreeNode = propsWithDefaults.renderTreeNode,
106
+ onCascadeChange = propsWithDefaults.onCascadeChange,
106
107
  rest = _objectWithoutPropertiesLoose(propsWithDefaults, _excluded);
107
108
  var _usePickerRef = usePickerRef(ref),
108
109
  trigger = _usePickerRef.trigger,
@@ -167,6 +168,7 @@ var CheckTreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
167
168
  setFocusItemValue(null);
168
169
  setValue([]);
169
170
  onChange === null || onChange === void 0 || onChange([], event);
171
+ onCascadeChange === null || onCascadeChange === void 0 || onCascadeChange([], event);
170
172
  });
171
173
  var handleTreeKeyDown = useEventCallback(function (event) {
172
174
  onMenuKeyDown(event, {
@@ -186,9 +188,37 @@ var CheckTreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
186
188
  onExit: handleClean,
187
189
  onMenuKeyDown: handleTreeKeyDown
188
190
  }, rest));
191
+
192
+ // transform the parent node value to the leaf node value
193
+ var handleTransValue2Children = useEventCallback(function (nextSelectedNodes) {
194
+ return nextSelectedNodes.map(function (node) {
195
+ var currentNode = node.refKey ? flattenedNodes[node.refKey] : null;
196
+ if (currentNode && currentNode[childrenKey] && currentNode[childrenKey].length) {
197
+ var childNodes = currentNode[childrenKey].filter(function (child) {
198
+ var childValue = child[valueKey];
199
+ return !disabledItemValues.includes(childValue) && !uncheckableItemValues.includes(childValue);
200
+ });
201
+ return handleTransValue2Children(childNodes);
202
+ }
203
+ return node;
204
+ }).flat();
205
+ });
206
+ var handleChangeCascade = useEventCallback(function (nextValue, event) {
207
+ if (!cascade) {
208
+ onCascadeChange === null || onCascadeChange === void 0 || onCascadeChange(nextValue, event);
209
+ } else {
210
+ var nextSelectedNodes = getSelectedItems(flattenedNodes, nextValue);
211
+ var childrenNodes = handleTransValue2Children(nextSelectedNodes);
212
+ var childrenValue = childrenNodes.map(function (node) {
213
+ return node[valueKey];
214
+ });
215
+ onCascadeChange === null || onCascadeChange === void 0 || onCascadeChange(childrenValue, event);
216
+ }
217
+ });
189
218
  var handleChange = useEventCallback(function (nextValue, event) {
190
219
  setValue(nextValue);
191
220
  onChange === null || onChange === void 0 || onChange(nextValue, event);
221
+ handleChangeCascade(nextValue, event);
192
222
  });
193
223
  var treeContext = useMemo(function () {
194
224
  return {
@@ -35,7 +35,7 @@ var useEditState = function useEditState(props) {
35
35
  setResetValue(value);
36
36
  });
37
37
  var handleFocus = useEventCallback(function (event) {
38
- if (disabled) return;
38
+ if (disabled || isEditing) return;
39
39
  onFocus === null || onFocus === void 0 || onFocus(event);
40
40
  setIsEditing(true);
41
41
  setResetValue(value);
@@ -37,7 +37,7 @@ var CreatableComboBox = _extends({}, Combobox, {
37
37
  createOption: 'Crear opción "{0}"'
38
38
  });
39
39
  export default {
40
- code: 'es-AR',
40
+ code: 'es-ES',
41
41
  common: {
42
42
  loading: 'Cargando...',
43
43
  emptyMessage: 'Sin datos',
@@ -59,7 +59,9 @@ var useMessages = function useMessages() {
59
59
  // Remove all invisible messages after 400ms.
60
60
  // The delay removal here is to preserve the animation.
61
61
  setTimeout(function () {
62
- setMessages([]);
62
+ setMessages(function () {
63
+ return [];
64
+ });
63
65
  }, 400);
64
66
  }, [messages]);
65
67
  var remove = useCallback(function (key) {
@@ -73,9 +75,11 @@ var useMessages = function useMessages() {
73
75
 
74
76
  // Remove invisible messages after 400ms.
75
77
  setTimeout(function () {
76
- setMessages(messages.filter(function (msg) {
77
- return msg.visible;
78
- }));
78
+ setMessages(function (prevMessages) {
79
+ return prevMessages.filter(function (msg) {
80
+ return msg.visible;
81
+ });
82
+ });
79
83
  }, 400);
80
84
  }, [messages, getKey]);
81
85
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.80.2",
3
+ "version": "5.81.0",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",