rsuite 5.6.4 → 5.7.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/cjs/Checkbox/Checkbox.js +36 -25
  3. package/cjs/CheckboxGroup/CheckboxGroupContext.d.ts +1 -1
  4. package/cjs/CheckboxGroup/CheckboxGroupContext.js +1 -1
  5. package/cjs/Dropdown/DropdownMenu.js +1 -9
  6. package/cjs/Form/Form.js +11 -12
  7. package/cjs/Form/index.d.ts +1 -0
  8. package/cjs/Form/index.js +9 -0
  9. package/cjs/Form/useFormClassNames.d.ts +5 -0
  10. package/cjs/Form/useFormClassNames.js +31 -0
  11. package/cjs/InputNumber/InputNumber.js +2 -0
  12. package/cjs/Menu/MenuItem.js +1 -0
  13. package/cjs/Picker/DropdownMenuCheckItem.js +2 -1
  14. package/cjs/Uploader/index.d.ts +1 -1
  15. package/cjs/index.d.ts +1 -1
  16. package/cjs/index.js +5 -2
  17. package/cjs/utils/getDataGroupBy.d.ts +1 -1
  18. package/cjs/utils/getDataGroupBy.js +13 -3
  19. package/dist/rsuite.js +21 -10
  20. package/dist/rsuite.js.map +1 -1
  21. package/dist/rsuite.min.js +1 -1
  22. package/dist/rsuite.min.js.map +1 -1
  23. package/esm/Checkbox/Checkbox.js +36 -26
  24. package/esm/CheckboxGroup/CheckboxGroupContext.d.ts +1 -1
  25. package/esm/CheckboxGroup/CheckboxGroupContext.js +1 -1
  26. package/esm/Dropdown/DropdownMenu.js +1 -9
  27. package/esm/Form/Form.js +10 -10
  28. package/esm/Form/index.d.ts +1 -0
  29. package/esm/Form/index.js +1 -0
  30. package/esm/Form/useFormClassNames.d.ts +5 -0
  31. package/esm/Form/useFormClassNames.js +26 -0
  32. package/esm/InputNumber/InputNumber.js +2 -0
  33. package/esm/Menu/MenuItem.js +1 -0
  34. package/esm/Picker/DropdownMenuCheckItem.js +2 -1
  35. package/esm/Uploader/index.d.ts +1 -1
  36. package/esm/index.d.ts +1 -1
  37. package/esm/index.js +1 -1
  38. package/esm/utils/getDataGroupBy.d.ts +1 -1
  39. package/esm/utils/getDataGroupBy.js +10 -3
  40. package/package.json +1 -1
@@ -4,20 +4,20 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
4
4
 
5
5
  var _templateObject, _templateObject2, _templateObject3;
6
6
 
7
- import React, { useContext, useCallback } from 'react';
7
+ import React, { useContext, useCallback, useMemo } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { useControlled, partitionHTMLProps, useClassNames, TypeChecker } from '../utils';
10
10
  import { CheckboxGroupContext } from '../CheckboxGroup';
11
11
  var Checkbox = /*#__PURE__*/React.forwardRef(function (props, ref) {
12
- var _useContext = useContext(CheckboxGroupContext),
13
- inlineContext = _useContext.inline,
14
- nameContext = _useContext.name,
15
- disabledContext = _useContext.disabled,
16
- readOnlyContext = _useContext.readOnly,
17
- plaintextContext = _useContext.plaintext,
18
- groupValue = _useContext.value,
19
- controlled = _useContext.controlled,
20
- onGroupChange = _useContext.onChange;
12
+ var checkboxGroupContext = useContext(CheckboxGroupContext);
13
+
14
+ var _ref = checkboxGroupContext !== null && checkboxGroupContext !== void 0 ? checkboxGroupContext : {},
15
+ inlineContext = _ref.inline,
16
+ nameContext = _ref.name,
17
+ disabledContext = _ref.disabled,
18
+ readOnlyContext = _ref.readOnly,
19
+ plaintextContext = _ref.plaintext,
20
+ onGroupChange = _ref.onChange;
21
21
 
22
22
  var _props$as = props.as,
23
23
  Component = _props$as === void 0 ? 'div' : _props$as,
@@ -28,7 +28,8 @@ var Checkbox = /*#__PURE__*/React.forwardRef(function (props, ref) {
28
28
  classPrefix = _props$classPrefix === void 0 ? 'checkbox' : _props$classPrefix,
29
29
  _props$checkable = props.checkable,
30
30
  checkable = _props$checkable === void 0 ? true : _props$checkable,
31
- defaultChecked = props.defaultChecked,
31
+ _props$defaultChecked = props.defaultChecked,
32
+ defaultChecked = _props$defaultChecked === void 0 ? false : _props$defaultChecked,
32
33
  title = props.title,
33
34
  inputRef = props.inputRef,
34
35
  inputProps = props.inputProps,
@@ -51,19 +52,24 @@ var Checkbox = /*#__PURE__*/React.forwardRef(function (props, ref) {
51
52
  onChange = props.onChange,
52
53
  rest = _objectWithoutPropertiesLoose(props, ["as", "checked", "className", "children", "classPrefix", "checkable", "defaultChecked", "title", "inputRef", "inputProps", "indeterminate", "tabIndex", "disabled", "readOnly", "plaintext", "inline", "name", "value", "onClick", "onCheckboxClick", "onChange"]);
53
54
 
54
- var isChecked = useCallback(function () {
55
- if (typeof groupValue !== 'undefined' && typeof value !== 'undefined') {
56
- return groupValue.some(function (i) {
57
- return i === value;
58
- });
59
- }
55
+ var _useControlled = useControlled(controlledChecked, defaultChecked),
56
+ selfChecked = _useControlled[0],
57
+ setSelfChecked = _useControlled[1],
58
+ selfControlled = _useControlled[2]; // Either <Checkbox> is checked itself or by parent <CheckboxGroup>
59
+
60
+
61
+ var checked = useMemo(function () {
62
+ var _checkboxGroupContext, _checkboxGroupContext2;
60
63
 
61
- return controlledChecked;
62
- }, [controlledChecked, groupValue, value]);
64
+ if (!checkboxGroupContext) {
65
+ return selfChecked;
66
+ } // fixme value from group should not be nullable
63
67
 
64
- var _useControlled = useControlled(isChecked(), defaultChecked),
65
- checked = _useControlled[0],
66
- setChecked = _useControlled[1];
68
+
69
+ return (_checkboxGroupContext = (_checkboxGroupContext2 = checkboxGroupContext.value) === null || _checkboxGroupContext2 === void 0 ? void 0 : _checkboxGroupContext2.some(function (checkedValue) {
70
+ return checkedValue === value;
71
+ })) !== null && _checkboxGroupContext !== void 0 ? _checkboxGroupContext : false;
72
+ }, [checkboxGroupContext, selfChecked, value]);
67
73
 
68
74
  var _useClassNames = useClassNames(classPrefix),
69
75
  merge = _useClassNames.merge,
@@ -79,7 +85,11 @@ var Checkbox = /*#__PURE__*/React.forwardRef(function (props, ref) {
79
85
 
80
86
  var _partitionHTMLProps = partitionHTMLProps(rest),
81
87
  htmlInputProps = _partitionHTMLProps[0],
82
- restProps = _partitionHTMLProps[1];
88
+ restProps = _partitionHTMLProps[1]; // If <Checkbox> is within a <CheckboxGroup>, it's bound to be controlled
89
+ // because its checked state is inferred from group's value, not retrieved from the DOM
90
+
91
+
92
+ var controlled = checkboxGroupContext ? true : selfControlled;
83
93
 
84
94
  if (typeof controlled !== 'undefined') {
85
95
  // In uncontrolled situations, use defaultChecked instead of checked
@@ -87,16 +97,16 @@ var Checkbox = /*#__PURE__*/React.forwardRef(function (props, ref) {
87
97
  }
88
98
 
89
99
  var handleChange = useCallback(function (event) {
90
- var nextChecked = !checked;
100
+ var nextChecked = !event.target.checked;
91
101
 
92
102
  if (disabled || readOnly) {
93
103
  return;
94
104
  }
95
105
 
96
- setChecked(nextChecked);
106
+ setSelfChecked(nextChecked);
97
107
  onChange === null || onChange === void 0 ? void 0 : onChange(value, nextChecked, event);
98
108
  onGroupChange === null || onGroupChange === void 0 ? void 0 : onGroupChange(value, nextChecked, event);
99
- }, [checked, disabled, readOnly, setChecked, onChange, value, onGroupChange]);
109
+ }, [disabled, readOnly, setSelfChecked, onChange, value, onGroupChange]);
100
110
 
101
111
  if (plaintext) {
102
112
  return checked ? /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {
@@ -10,4 +10,4 @@ export interface CheckboxGroupContextValue {
10
10
  plaintext?: boolean;
11
11
  onChange?: (value: any, checked: boolean, event: React.ChangeEvent<HTMLInputElement>) => void;
12
12
  }
13
- export declare const CheckboxGroupContext: React.Context<CheckboxGroupContextValue>;
13
+ export declare const CheckboxGroupContext: React.Context<CheckboxGroupContextValue | undefined>;
@@ -1,2 +1,2 @@
1
1
  import React from 'react';
2
- export var CheckboxGroupContext = /*#__PURE__*/React.createContext({});
2
+ export var CheckboxGroupContext = /*#__PURE__*/React.createContext(void 0);
@@ -87,15 +87,7 @@ var DropdownMenu = /*#__PURE__*/React.forwardRef(function (props, ref) {
87
87
  return /*#__PURE__*/React.createElement(DropdownContext.Provider, {
88
88
  value: contextValue
89
89
  }, /*#__PURE__*/React.createElement(Menubar, {
90
- vertical: true,
91
- onActivateItem: function onActivateItem(event) {
92
- var _dataset = event.target.dataset,
93
- eventKey = _dataset.eventKey,
94
- eventKeyType = _dataset.eventKeyType; // Only cast number type for now
95
-
96
- var eventKeyToEmit = eventKeyType === 'number' ? Number(eventKey) : eventKey;
97
- onSelect === null || onSelect === void 0 ? void 0 : onSelect(eventKeyToEmit, event);
98
- }
90
+ vertical: true
99
91
  }, function (menubar, menubarRef) {
100
92
  return /*#__PURE__*/React.createElement("ul", _extends({
101
93
  ref: mergeRefs(menubarRef, ref),
package/esm/Form/Form.js CHANGED
@@ -5,13 +5,13 @@ import PropTypes from 'prop-types';
5
5
  import isUndefined from 'lodash/isUndefined';
6
6
  import omit from 'lodash/omit';
7
7
  import { SchemaModel } from 'schema-typed';
8
- import { useClassNames } from '../utils';
9
8
  import FormContext, { FormValueContext } from './FormContext';
10
9
  import FormControl from '../FormControl';
11
10
  import FormControlLabel from '../FormControlLabel';
12
11
  import FormErrorMessage from '../FormErrorMessage';
13
12
  import FormGroup from '../FormGroup';
14
13
  import FormHelpText from '../FormHelpText';
14
+ import { useFormClassNames } from './useFormClassNames';
15
15
  var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
16
16
  var _props$checkTrigger = props.checkTrigger,
17
17
  checkTrigger = _props$checkTrigger === void 0 ? 'change' : _props$checkTrigger,
@@ -39,15 +39,15 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
39
39
  onChange = props.onChange,
40
40
  rest = _objectWithoutPropertiesLoose(props, ["checkTrigger", "classPrefix", "errorFromContext", "formDefaultValue", "formValue", "formError", "fluid", "layout", "model", "readOnly", "plaintext", "className", "children", "disabled", "onSubmit", "onCheck", "onError", "onChange"]);
41
41
 
42
- var _useClassNames = useClassNames(classPrefix),
43
- withClassPrefix = _useClassNames.withClassPrefix,
44
- merge = _useClassNames.merge;
45
-
46
- var classes = merge(className, withClassPrefix(layout, fluid && layout === 'vertical' ? 'fluid' : 'fixed-width', {
47
- readonly: readOnly,
48
- disabled: disabled,
49
- plaintext: plaintext
50
- }));
42
+ var classes = useFormClassNames({
43
+ classPrefix: classPrefix,
44
+ className: className,
45
+ fluid: fluid,
46
+ layout: layout,
47
+ readOnly: readOnly,
48
+ plaintext: plaintext,
49
+ disabled: disabled
50
+ });
51
51
 
52
52
  var _useState = useState(formDefaultValue),
53
53
  _formValue = _useState[0],
@@ -5,4 +5,5 @@ export type { FormErrorMessageProps } from '../FormErrorMessage';
5
5
  export type { FormControlLabelProps } from '../FormControlLabel';
6
6
  export type { FormHelpTextProps } from '../FormHelpText';
7
7
  export type { FormControlProps } from '../FormControl';
8
+ export * from './useFormClassNames';
8
9
  export default Form;
package/esm/Form/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  import Form from './Form';
2
+ export * from './useFormClassNames';
2
3
  export default Form;
@@ -0,0 +1,5 @@
1
+ import type { FormProps } from './Form';
2
+ /**
3
+ * Take <Form> props and return className for <Form> styles
4
+ */
5
+ export declare function useFormClassNames({ classPrefix, className, fluid, layout, readOnly, plaintext, disabled }: Pick<FormProps, 'classPrefix' | 'className' | 'fluid' | 'layout' | 'readOnly' | 'plaintext' | 'disabled'>): string;
@@ -0,0 +1,26 @@
1
+ import { useClassNames } from '../utils';
2
+
3
+ /**
4
+ * Take <Form> props and return className for <Form> styles
5
+ */
6
+ export function useFormClassNames(_ref) {
7
+ var _ref$classPrefix = _ref.classPrefix,
8
+ classPrefix = _ref$classPrefix === void 0 ? 'form' : _ref$classPrefix,
9
+ className = _ref.className,
10
+ fluid = _ref.fluid,
11
+ _ref$layout = _ref.layout,
12
+ layout = _ref$layout === void 0 ? 'vertical' : _ref$layout,
13
+ readOnly = _ref.readOnly,
14
+ plaintext = _ref.plaintext,
15
+ disabled = _ref.disabled;
16
+
17
+ var _useClassNames = useClassNames(classPrefix),
18
+ withClassPrefix = _useClassNames.withClassPrefix,
19
+ merge = _useClassNames.merge;
20
+
21
+ return merge(className, withClassPrefix(layout, fluid && layout === 'vertical' ? 'fluid' : 'fixed-width', {
22
+ readonly: readOnly,
23
+ disabled: disabled,
24
+ plaintext: plaintext
25
+ }));
26
+ }
@@ -267,11 +267,13 @@ var InputNumber = /*#__PURE__*/React.forwardRef(function (props, ref) {
267
267
  }), prefixElement && /*#__PURE__*/React.createElement(InputGroupAddon, null, prefixElement), input, /*#__PURE__*/React.createElement("span", {
268
268
  className: prefix('btn-group-vertical')
269
269
  }, /*#__PURE__*/React.createElement(Button, {
270
+ tabIndex: -1,
270
271
  appearance: buttonAppearance,
271
272
  className: prefix('touchspin-up'),
272
273
  onClick: handlePlus,
273
274
  disabled: disabledUpButton || disabled || readOnly
274
275
  }, /*#__PURE__*/React.createElement(AngleUpIcon, null)), /*#__PURE__*/React.createElement(Button, {
276
+ tabIndex: -1,
275
277
  appearance: buttonAppearance,
276
278
  className: prefix('touchspin-down'),
277
279
  onClick: handleMinus,
@@ -98,6 +98,7 @@ function MenuItem(props) {
98
98
 
99
99
  if ((menuState === null || menuState === void 0 ? void 0 : menuState.role) === 'menubar') {
100
100
  menuitemProps.onMouseDown = handleMouseDown;
101
+ menuitemProps.onMouseOver = handleMouseMove;
101
102
  }
102
103
 
103
104
  return children(menuitemProps, menuitemRef);
@@ -5,7 +5,8 @@ import PropTypes from 'prop-types';
5
5
  import { useClassNames } from '../utils';
6
6
  import Checkbox from '../Checkbox';
7
7
  var DropdownMenuCheckItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
8
- var active = props.active,
8
+ var _props$active = props.active,
9
+ active = _props$active === void 0 ? false : _props$active,
9
10
  _props$as = props.as,
10
11
  Component = _props$as === void 0 ? 'div' : _props$as,
11
12
  _props$checkboxAs = props.checkboxAs,
@@ -1,3 +1,3 @@
1
1
  import Uploader from './Uploader';
2
- export type { UploaderProps } from './Uploader';
2
+ export type { UploaderProps, FileStatusType, FileType } from './Uploader';
3
3
  export default Uploader;
package/esm/index.d.ts CHANGED
@@ -50,7 +50,7 @@ export { default as Steps } from './Steps';
50
50
  export type { StepsProps, StepItemProps } from './Steps';
51
51
  export { default as Toggle } from './Toggle';
52
52
  export type { ToggleProps } from './Toggle';
53
- export { default as Form } from './Form';
53
+ export { default as Form, useFormClassNames } from './Form';
54
54
  export type { FormProps, FormGroupProps, FormErrorMessageProps, FormControlLabelProps, FormHelpTextProps, FormControlProps } from './Form';
55
55
  export { default as Input } from './Input';
56
56
  export type { InputProps } from './Input';
package/esm/index.js CHANGED
@@ -27,7 +27,7 @@ export { default as Pagination } from './Pagination';
27
27
  export { default as Steps } from './Steps';
28
28
  // Data enter
29
29
  export { default as Toggle } from './Toggle';
30
- export { default as Form } from './Form';
30
+ export { default as Form, useFormClassNames } from './Form';
31
31
  export { default as Input } from './Input';
32
32
  export { default as MaskedInput } from './MaskedInput';
33
33
  export { default as InputNumber } from './InputNumber';
@@ -1,3 +1,3 @@
1
1
  export declare const KEY_GROUP: string | symbol;
2
2
  export declare const KEY_GROUP_TITLE = "groupTitle";
3
- export default function getDataGroupBy(data: any[] | undefined, key: string, sort: any): any[];
3
+ export default function getDataGroupBy(data: any[] | undefined, key: string, sort?: any): any[];
@@ -1,3 +1,4 @@
1
+ import _get from "lodash/get";
1
2
  import { flattenTree } from '../utils/treeUtils';
2
3
  var hasSymbol = typeof Symbol === 'function';
3
4
  export var KEY_GROUP = hasSymbol ? Symbol('_$grouped') : '_$grouped';
@@ -10,11 +11,17 @@ export default function getDataGroupBy(data, key, sort) {
10
11
  var tempData = {};
11
12
  var isSort = typeof sort === 'function';
12
13
  data.forEach(function (item) {
13
- if (!tempData[item[key]]) {
14
- tempData[item[key]] = [];
14
+ // this will allow getting data using dot notation
15
+ // i.e groupBy="country.name" as country will be a nested object
16
+ // to the item and the name will be nested key to the country object
17
+ // can be used with values in arrays, i.e groupBy="addresses.0.country.name"
18
+ var groupByValue = _get(item, key, '');
19
+
20
+ if (!tempData[groupByValue]) {
21
+ tempData[groupByValue] = [];
15
22
  }
16
23
 
17
- tempData[item[key]].push(item);
24
+ tempData[groupByValue].push(item);
18
25
  });
19
26
  var nextData = Object.entries(tempData).map(function (_ref) {
20
27
  var _ref2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.6.4",
3
+ "version": "5.7.0",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",