rsuite 5.59.3-alpha.1 → 5.60.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.
Files changed (84) hide show
  1. package/Animation/styles/fade.less +1 -1
  2. package/Animation/styles/index.css +1 -1
  3. package/CHANGELOG.md +27 -0
  4. package/DateRangePicker/styles/index.css +2 -3
  5. package/DateRangePicker/styles/index.less +6 -5
  6. package/TagInput/styles/index.css +24 -24
  7. package/TagPicker/styles/index.css +24 -24
  8. package/TagPicker/styles/index.less +11 -10
  9. package/Toggle/styles/index.css +2 -1
  10. package/Toggle/styles/index.less +2 -1
  11. package/cjs/DateRangePicker/DateRangePicker.js +17 -9
  12. package/cjs/DateRangePicker/utils.d.ts +2 -2
  13. package/cjs/DateRangePicker/utils.js +2 -2
  14. package/cjs/Form/Form.d.ts +13 -9
  15. package/cjs/Form/Form.js +55 -11
  16. package/cjs/Form/FormContext.d.ts +2 -2
  17. package/cjs/Form/hooks/useFormRef.d.ts +9 -7
  18. package/cjs/Form/hooks/useFormRef.js +5 -32
  19. package/cjs/Form/hooks/useFormValidate.d.ts +6 -4
  20. package/cjs/Form/hooks/useFormValidate.js +18 -12
  21. package/cjs/Form/hooks/useFormValue.d.ts +8 -1
  22. package/cjs/Form/hooks/useFormValue.js +7 -1
  23. package/cjs/InputPicker/InputAutosize.js +2 -2
  24. package/cjs/InputPicker/InputPicker.d.ts +5 -7
  25. package/cjs/InputPicker/InputPicker.js +119 -151
  26. package/cjs/InputPicker/InputPickerContext.d.ts +11 -3
  27. package/cjs/InputPicker/InputPickerContext.js +7 -1
  28. package/cjs/InputPicker/hooks/useData.d.ts +17 -0
  29. package/cjs/InputPicker/hooks/useData.js +44 -0
  30. package/cjs/InputPicker/hooks/useInput.d.ts +21 -0
  31. package/cjs/InputPicker/hooks/useInput.js +46 -0
  32. package/cjs/InputPicker/hooks/useMaxWidth.d.ts +4 -0
  33. package/cjs/InputPicker/hooks/useMaxWidth.js +25 -0
  34. package/cjs/InputPicker/index.d.ts +2 -1
  35. package/cjs/InputPicker/utils.d.ts +1 -0
  36. package/cjs/InputPicker/utils.js +17 -0
  37. package/cjs/TagInput/index.js +2 -2
  38. package/cjs/TagPicker/index.js +2 -2
  39. package/dist/rsuite-no-reset-rtl.css +29 -29
  40. package/dist/rsuite-no-reset-rtl.min.css +1 -1
  41. package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
  42. package/dist/rsuite-no-reset.css +29 -29
  43. package/dist/rsuite-no-reset.min.css +1 -1
  44. package/dist/rsuite-no-reset.min.css.map +1 -1
  45. package/dist/rsuite-rtl.css +29 -29
  46. package/dist/rsuite-rtl.min.css +1 -1
  47. package/dist/rsuite-rtl.min.css.map +1 -1
  48. package/dist/rsuite.css +29 -29
  49. package/dist/rsuite.js +55 -11
  50. package/dist/rsuite.js.map +1 -1
  51. package/dist/rsuite.min.css +1 -1
  52. package/dist/rsuite.min.css.map +1 -1
  53. package/dist/rsuite.min.js +1 -1
  54. package/dist/rsuite.min.js.map +1 -1
  55. package/esm/DateRangePicker/DateRangePicker.js +17 -9
  56. package/esm/DateRangePicker/utils.d.ts +2 -2
  57. package/esm/DateRangePicker/utils.js +2 -2
  58. package/esm/Form/Form.d.ts +13 -9
  59. package/esm/Form/Form.js +55 -11
  60. package/esm/Form/FormContext.d.ts +2 -2
  61. package/esm/Form/hooks/useFormRef.d.ts +9 -7
  62. package/esm/Form/hooks/useFormRef.js +5 -32
  63. package/esm/Form/hooks/useFormValidate.d.ts +6 -4
  64. package/esm/Form/hooks/useFormValidate.js +18 -12
  65. package/esm/Form/hooks/useFormValue.d.ts +8 -1
  66. package/esm/Form/hooks/useFormValue.js +7 -1
  67. package/esm/InputPicker/InputAutosize.js +2 -2
  68. package/esm/InputPicker/InputPicker.d.ts +5 -7
  69. package/esm/InputPicker/InputPicker.js +111 -143
  70. package/esm/InputPicker/InputPickerContext.d.ts +11 -3
  71. package/esm/InputPicker/InputPickerContext.js +4 -0
  72. package/esm/InputPicker/hooks/useData.d.ts +17 -0
  73. package/esm/InputPicker/hooks/useData.js +38 -0
  74. package/esm/InputPicker/hooks/useInput.d.ts +21 -0
  75. package/esm/InputPicker/hooks/useInput.js +40 -0
  76. package/esm/InputPicker/hooks/useMaxWidth.d.ts +4 -0
  77. package/esm/InputPicker/hooks/useMaxWidth.js +19 -0
  78. package/esm/InputPicker/index.d.ts +2 -1
  79. package/esm/InputPicker/utils.d.ts +1 -0
  80. package/esm/InputPicker/utils.js +12 -0
  81. package/esm/TagInput/index.js +2 -2
  82. package/esm/TagPicker/index.js +2 -2
  83. package/package.json +1 -1
  84. package/styles/variables.less +0 -1
@@ -1,9 +1,6 @@
1
- /// <reference types="react" />
2
1
  /// <reference types="lodash" />
3
2
  import type { CheckResult } from 'schema-typed';
4
- import { FormInstance } from './useFormRef';
5
3
  export interface FormErrorProps {
6
- ref: React.Ref<FormInstance>;
7
4
  formValue: any;
8
5
  getCombinedModel: () => any;
9
6
  onCheck?: (formError: any) => void;
@@ -11,9 +8,14 @@ export interface FormErrorProps {
11
8
  nestedField?: boolean;
12
9
  }
13
10
  export default function useFormValidate(formError: any, props: FormErrorProps): {
14
- formRef: import("react").RefObject<HTMLFormElement>;
15
11
  formError: any;
16
12
  check: (...args: any[]) => any;
13
+ checkForField: (...args: any[]) => any;
14
+ checkAsync: (...args: any[]) => any;
15
+ checkForFieldAsync: (...args: any[]) => any;
16
+ cleanErrors: (...args: any[]) => any;
17
+ resetErrors: (...args: any[]) => any;
18
+ cleanErrorForField: (...args: any[]) => any;
17
19
  setFieldError: (fieldName: string, checkResult: string | CheckResult) => any;
18
20
  onRemoveError: (name: string) => import("lodash").Omit<any, string>;
19
21
  };
@@ -11,10 +11,8 @@ var _set = _interopRequireDefault(require("lodash/set"));
11
11
  var _utils = require("../../utils");
12
12
  var _utils2 = require("../../FormControl/utils");
13
13
  var _useEventCallback = _interopRequireDefault(require("../../utils/useEventCallback"));
14
- var _useFormRef = _interopRequireDefault(require("./useFormRef"));
15
14
  function useFormValidate(formError, props) {
16
- var ref = props.ref,
17
- formValue = props.formValue,
15
+ var formValue = props.formValue,
18
16
  getCombinedModel = props.getCombinedModel,
19
17
  onCheck = props.onCheck,
20
18
  onError = props.onError,
@@ -138,19 +136,27 @@ function useFormValidate(formError, props) {
138
136
  onCheck === null || onCheck === void 0 ? void 0 : onCheck(nextFormError);
139
137
  return nextFormError;
140
138
  }, [formError, nestedField, onCheck, onError, setFormError]);
141
- var formRef = (0, _useFormRef.default)(ref, {
142
- check: check,
143
- checkForField: checkForField,
144
- checkAsync: checkAsync,
145
- checkForFieldAsync: checkForFieldAsync,
146
- formError: formError,
147
- setFormError: setFormError,
148
- nestedField: nestedField
139
+ var cleanErrors = (0, _useEventCallback.default)(function () {
140
+ setFormError({});
141
+ });
142
+ var resetErrors = (0, _useEventCallback.default)(function (formError) {
143
+ if (formError === void 0) {
144
+ formError = {};
145
+ }
146
+ setFormError(formError);
147
+ });
148
+ var cleanErrorForField = (0, _useEventCallback.default)(function (fieldName) {
149
+ setFormError((0, _omit.default)(formError, [nestedField ? (0, _utils2.nameToPath)(fieldName) : fieldName]));
149
150
  });
150
151
  return {
151
- formRef: formRef,
152
152
  formError: realFormError,
153
153
  check: check,
154
+ checkForField: checkForField,
155
+ checkAsync: checkAsync,
156
+ checkForFieldAsync: checkForFieldAsync,
157
+ cleanErrors: cleanErrors,
158
+ resetErrors: resetErrors,
159
+ cleanErrorForField: cleanErrorForField,
154
160
  setFieldError: setFieldError,
155
161
  onRemoveError: onRemoveError
156
162
  };
@@ -1,7 +1,14 @@
1
1
  /// <reference types="lodash" />
2
- export default function useFormValue(controlledValue: any, props: any): {
2
+ declare type RecordAny = Record<string, any>;
3
+ interface UseFormValueProps<V = RecordAny> {
4
+ formDefaultValue: V;
5
+ nestedField: boolean;
6
+ }
7
+ export default function useFormValue<V>(controlledValue: any, props: UseFormValueProps<V>): {
3
8
  formValue: any;
4
9
  setFormValue: (value: any) => void;
5
10
  setFieldValue: (fieldName: string, fieldValue: any) => any;
6
11
  onRemoveValue: (name: string) => import("lodash").Omit<any, string>;
12
+ resetFormValue: (nextValue?: V) => V;
7
13
  };
14
+ export {};
@@ -33,10 +33,16 @@ function useFormValue(controlledValue, props) {
33
33
  setFormValue(formValue);
34
34
  return formValue;
35
35
  }, [setFormValue]);
36
+ var resetFormValue = (0, _react.useCallback)(function (nextValue) {
37
+ var value = nextValue || formDefaultValue;
38
+ setFormValue(value);
39
+ return value;
40
+ }, [formDefaultValue, setFormValue]);
36
41
  return {
37
42
  formValue: formValue,
38
43
  setFormValue: setFormValue,
39
44
  setFieldValue: setFieldValue,
40
- onRemoveValue: onRemoveValue
45
+ onRemoveValue: onRemoveValue,
46
+ resetFormValue: resetFormValue
41
47
  };
42
48
  }
@@ -48,9 +48,9 @@ var useInputWidth = function useInputWidth(props, sizerRef, placeholderRef) {
48
48
  }
49
49
  var width;
50
50
  if (placeholder && !value && placeholderRef.current) {
51
- width = Math.max(sizerRef.current.scrollWidth, placeholderRef.current.scrollWidth) + 2;
51
+ width = Math.max(sizerRef.current.scrollWidth, placeholderRef.current.scrollWidth) + 10;
52
52
  } else {
53
- width = sizerRef.current.scrollWidth + 2;
53
+ width = sizerRef.current.scrollWidth + 10;
54
54
  }
55
55
  if (width < minWidth) {
56
56
  width = minWidth;
@@ -1,24 +1,22 @@
1
1
  import React from 'react';
2
2
  import { PickerComponent, PickerToggleProps } from '../internals/Picker';
3
+ import { type InputItemDataType } from './hooks/useData';
3
4
  import type { ItemDataType, FormControlPickerProps } from '../@types/common';
4
5
  import type { InputPickerLocale } from '../locales';
5
6
  import type { SelectProps } from '../SelectPicker';
6
- export interface InputItemDataType extends ItemDataType {
7
- create?: boolean;
8
- }
9
7
  export declare type ValueType = any;
10
- export interface InputPickerProps<T = ValueType> extends FormControlPickerProps<T, InputPickerLocale, InputItemDataType>, SelectProps<T>, Pick<PickerToggleProps, 'caretAs' | 'loading'> {
8
+ export interface InputPickerProps<V = ValueType> extends FormControlPickerProps<V, InputPickerLocale, InputItemDataType>, SelectProps<V>, Pick<PickerToggleProps, 'caretAs' | 'loading'> {
11
9
  tabIndex?: number;
12
10
  /** Settings can create new options */
13
11
  creatable?: boolean;
14
12
  /** Option to cache value when searching asynchronously */
15
- cacheData?: InputItemDataType[];
13
+ cacheData?: InputItemDataType<V>[];
16
14
  /** The `onBlur` attribute for the `input` element. */
17
15
  onBlur?: React.FocusEventHandler;
18
16
  /** The `onFocus` attribute for the `input` element. */
19
17
  onFocus?: React.FocusEventHandler;
20
18
  /** Called when the option is created */
21
- onCreate?: (value: ValueType, item: ItemDataType, event: React.SyntheticEvent) => void;
19
+ onCreate?: (value: V, item: ItemDataType, event: React.SyntheticEvent) => void;
22
20
  /**
23
21
  * Customize whether to display "Create option" action with given textbox value
24
22
  *
@@ -27,7 +25,7 @@ export interface InputPickerProps<T = ValueType> extends FormControlPickerProps<
27
25
  * @param searchKeyword Value of the textbox
28
26
  * @param filteredData The items filtered by the searchKeyword
29
27
  */
30
- shouldDisplayCreateOption?: (searchKeyword: string, filteredData: InputItemDataType[]) => boolean;
28
+ shouldDisplayCreateOption?: (searchKeyword: string, filteredData: InputItemDataType<V>[]) => boolean;
31
29
  }
32
30
  /**
33
31
  * Single item selector with text box input.