rsuite 5.58.1 → 5.59.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 (105) hide show
  1. package/Avatar/styles/index.css +74 -3
  2. package/Avatar/styles/index.less +25 -1
  3. package/Avatar/styles/mixin.less +8 -0
  4. package/AvatarGroup/styles/index.css +2 -0
  5. package/AvatarGroup/styles/index.less +2 -0
  6. package/CHANGELOG.md +29 -0
  7. package/CheckPicker/styles/index.css +2 -0
  8. package/CheckTree/styles/index.css +2 -0
  9. package/CheckTreePicker/styles/index.css +2 -0
  10. package/Checkbox/styles/index.css +2 -0
  11. package/Checkbox/styles/index.less +2 -0
  12. package/Drawer/styles/index.css +4 -0
  13. package/Drawer/styles/index.less +5 -0
  14. package/MultiCascadeTree/styles/index.css +2 -0
  15. package/MultiCascader/styles/index.css +2 -0
  16. package/Placeholder/styles/index.css +42 -6
  17. package/Placeholder/styles/index.less +18 -9
  18. package/Placeholder/styles/mixin.less +7 -0
  19. package/Sidenav/styles/index.css +3 -0
  20. package/Sidenav/styles/index.less +4 -0
  21. package/TagInput/styles/index.css +2 -0
  22. package/TagPicker/styles/index.css +2 -0
  23. package/cjs/Avatar/Avatar.d.ts +30 -5
  24. package/cjs/Avatar/Avatar.js +56 -22
  25. package/cjs/Avatar/AvatarIcon.d.ts +3 -0
  26. package/cjs/Avatar/AvatarIcon.js +24 -0
  27. package/cjs/Avatar/useImage.d.ts +39 -0
  28. package/cjs/Avatar/useImage.js +74 -0
  29. package/cjs/AvatarGroup/AvatarGroup.d.ts +15 -6
  30. package/cjs/AvatarGroup/AvatarGroup.js +12 -12
  31. package/cjs/Checkbox/Checkbox.js +1 -1
  32. package/cjs/DateInput/DateField.js +5 -0
  33. package/cjs/Form/Form.js +40 -56
  34. package/cjs/Form/FormContext.d.ts +1 -1
  35. package/cjs/Form/{useFormClassNames.d.ts → hooks/useFormClassNames.d.ts} +2 -2
  36. package/cjs/Form/{useFormClassNames.js → hooks/useFormClassNames.js} +2 -2
  37. package/cjs/Form/hooks/useFormError.d.ts +6 -0
  38. package/cjs/Form/hooks/useFormError.js +31 -0
  39. package/cjs/Form/hooks/useFormValue.d.ts +6 -0
  40. package/cjs/Form/hooks/useFormValue.js +31 -0
  41. package/cjs/Form/index.d.ts +1 -1
  42. package/cjs/Form/index.js +3 -9
  43. package/cjs/FormControl/FormControl.js +1 -1
  44. package/cjs/FormControl/useRegisterModel.d.ts +1 -1
  45. package/cjs/Modal/Modal.js +36 -21
  46. package/cjs/Placeholder/PlaceholderGraph.d.ts +13 -1
  47. package/cjs/Placeholder/PlaceholderGrid.d.ts +27 -1
  48. package/cjs/Placeholder/PlaceholderGrid.js +10 -13
  49. package/cjs/Placeholder/PlaceholderParagraph.d.ts +24 -1
  50. package/cjs/Placeholder/PlaceholderParagraph.js +13 -9
  51. package/cjs/internals/Overlay/Modal.js +2 -1
  52. package/dist/rsuite-no-reset-rtl.css +124 -9
  53. package/dist/rsuite-no-reset-rtl.min.css +1 -1
  54. package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
  55. package/dist/rsuite-no-reset.css +124 -9
  56. package/dist/rsuite-no-reset.min.css +1 -1
  57. package/dist/rsuite-no-reset.min.css.map +1 -1
  58. package/dist/rsuite-rtl.css +124 -9
  59. package/dist/rsuite-rtl.min.css +1 -1
  60. package/dist/rsuite-rtl.min.css.map +1 -1
  61. package/dist/rsuite.css +124 -9
  62. package/dist/rsuite.js +122 -36
  63. package/dist/rsuite.js.map +1 -1
  64. package/dist/rsuite.min.css +1 -1
  65. package/dist/rsuite.min.css.map +1 -1
  66. package/dist/rsuite.min.js +1 -1
  67. package/dist/rsuite.min.js.map +1 -1
  68. package/esm/Avatar/Avatar.d.ts +30 -5
  69. package/esm/Avatar/Avatar.js +58 -24
  70. package/esm/Avatar/AvatarIcon.d.ts +3 -0
  71. package/esm/Avatar/AvatarIcon.js +18 -0
  72. package/esm/Avatar/useImage.d.ts +39 -0
  73. package/esm/Avatar/useImage.js +69 -0
  74. package/esm/AvatarGroup/AvatarGroup.d.ts +15 -6
  75. package/esm/AvatarGroup/AvatarGroup.js +12 -12
  76. package/esm/Checkbox/Checkbox.js +1 -1
  77. package/esm/DateInput/DateField.js +5 -0
  78. package/esm/Form/Form.js +40 -56
  79. package/esm/Form/FormContext.d.ts +1 -1
  80. package/esm/Form/{useFormClassNames.d.ts → hooks/useFormClassNames.d.ts} +2 -2
  81. package/esm/Form/{useFormClassNames.js → hooks/useFormClassNames.js} +2 -2
  82. package/esm/Form/hooks/useFormError.d.ts +6 -0
  83. package/esm/Form/hooks/useFormError.js +26 -0
  84. package/esm/Form/hooks/useFormValue.d.ts +6 -0
  85. package/esm/Form/hooks/useFormValue.js +26 -0
  86. package/esm/Form/index.d.ts +1 -1
  87. package/esm/Form/index.js +1 -1
  88. package/esm/FormControl/FormControl.js +1 -1
  89. package/esm/FormControl/useRegisterModel.d.ts +1 -1
  90. package/esm/Modal/Modal.js +36 -21
  91. package/esm/Placeholder/PlaceholderGraph.d.ts +13 -1
  92. package/esm/Placeholder/PlaceholderGrid.d.ts +27 -1
  93. package/esm/Placeholder/PlaceholderGrid.js +10 -13
  94. package/esm/Placeholder/PlaceholderParagraph.d.ts +24 -1
  95. package/esm/Placeholder/PlaceholderParagraph.js +12 -8
  96. package/esm/internals/Overlay/Modal.js +2 -1
  97. package/package.json +2 -2
  98. package/styles/color-modes/dark.less +2 -0
  99. package/styles/color-modes/high-contrast.less +2 -0
  100. package/styles/color-modes/light.less +2 -0
  101. package/styles/variables.less +12 -20
  102. /package/cjs/Form/{useSchemaModel.d.ts → hooks/useSchemaModel.d.ts} +0 -0
  103. /package/cjs/Form/{useSchemaModel.js → hooks/useSchemaModel.js} +0 -0
  104. /package/esm/Form/{useSchemaModel.d.ts → hooks/useSchemaModel.d.ts} +0 -0
  105. /package/esm/Form/{useSchemaModel.js → hooks/useSchemaModel.js} +0 -0
@@ -1,8 +1,14 @@
1
1
  import React from 'react';
2
- import { TypeAttributes, WithAsProps, RsRefForwardingComponent } from '../@types/common';
2
+ import { WithAsProps, RsRefForwardingComponent, TypeAttributes } from '../@types/common';
3
+ import { type Size } from '../AvatarGroup/AvatarGroup';
3
4
  export interface AvatarProps extends WithAsProps {
4
- /** A avatar can have different sizes */
5
- size?: TypeAttributes.Size;
5
+ /**
6
+ * A avatar can have different sizes.
7
+ *
8
+ * @default 'md'
9
+ * @version xxl and xs added in v5.59.0
10
+ */
11
+ size?: Size;
6
12
  /**
7
13
  * The `src` attribute for the `img` element.
8
14
  */
@@ -21,10 +27,29 @@ export interface AvatarProps extends WithAsProps {
21
27
  * It can be used to listen for the loading error event.
22
28
  */
23
29
  imgProps?: React.ImgHTMLAttributes<HTMLImageElement>;
24
- /** Set avatar shape to circle */
30
+ /**
31
+ * Set avatar shape to circle
32
+ */
25
33
  circle?: boolean;
26
- /** This attribute defines an alternative text description of the image */
34
+ /**
35
+ * This attribute defines an alternative text description of the image
36
+ */
27
37
  alt?: string;
38
+ /**
39
+ * Show a border around the avatar.
40
+ * @version 5.59.0
41
+ */
42
+ bordered?: boolean;
43
+ /**
44
+ * Sets the avatar background color.
45
+ * @version 5.59.0
46
+ */
47
+ color?: TypeAttributes.Color;
48
+ /**
49
+ * Callback fired when the image failed to load.
50
+ * @version 5.59.0
51
+ */
52
+ onError?: OnErrorEventHandler;
28
53
  }
29
54
  /**
30
55
  * The Avatar component is used to represent user or brand.
@@ -1,51 +1,85 @@
1
1
  'use client';
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
2
  import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTemplateLiteralLoose";
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- var _templateObject;
6
- import React, { useContext } from 'react';
5
+ var _templateObject, _templateObject2;
6
+ import React, { useContext, useMemo } from 'react';
7
7
  import PropTypes from 'prop-types';
8
- import { useClassNames } from '../utils';
8
+ import { useClassNames, useCustom, isIE } from '../utils';
9
9
  import { AvatarGroupContext } from '../AvatarGroup/AvatarGroup';
10
10
  import { oneOf } from '../internals/propTypes';
11
+ import AvatarIcon from './AvatarIcon';
12
+ import useImage from './useImage';
11
13
  /**
12
14
  * The Avatar component is used to represent user or brand.
13
15
  * @see https://rsuitejs.com/components/avatar
14
16
  */
15
17
  var Avatar = /*#__PURE__*/React.forwardRef(function (props, ref) {
16
- var _props$classPrefix = props.classPrefix,
17
- classPrefix = _props$classPrefix === void 0 ? 'avatar' : _props$classPrefix,
18
- _props$as = props.as,
18
+ var _extends2;
19
+ var _useContext = useContext(AvatarGroupContext),
20
+ groupSize = _useContext.size,
21
+ spacing = _useContext.spacing;
22
+ var _props$as = props.as,
19
23
  Component = _props$as === void 0 ? 'div' : _props$as,
20
- sizeProp = props.size,
24
+ bordered = props.bordered,
25
+ alt = props.alt,
21
26
  className = props.className,
22
27
  children = props.children,
28
+ circle = props.circle,
29
+ color = props.color,
30
+ _props$classPrefix = props.classPrefix,
31
+ classPrefix = _props$classPrefix === void 0 ? 'avatar' : _props$classPrefix,
32
+ _props$size = props.size,
33
+ size = _props$size === void 0 ? groupSize : _props$size,
23
34
  src = props.src,
24
35
  srcSet = props.srcSet,
25
36
  sizes = props.sizes,
37
+ style = props.style,
26
38
  imgProps = props.imgProps,
27
- circle = props.circle,
28
- alt = props.alt,
29
- rest = _objectWithoutPropertiesLoose(props, ["classPrefix", "as", "size", "className", "children", "src", "srcSet", "sizes", "imgProps", "circle", "alt"]);
30
- var _useContext = useContext(AvatarGroupContext),
31
- size = _useContext.size;
39
+ onError = props.onError,
40
+ rest = _objectWithoutPropertiesLoose(props, ["as", "bordered", "alt", "className", "children", "circle", "color", "classPrefix", "size", "src", "srcSet", "sizes", "style", "imgProps", "onError"]);
32
41
  var _useClassNames = useClassNames(classPrefix),
33
42
  withClassPrefix = _useClassNames.withClassPrefix,
34
43
  prefix = _useClassNames.prefix,
35
44
  merge = _useClassNames.merge;
36
- var classes = merge(className, withClassPrefix(sizeProp || size, {
37
- circle: circle
45
+ var classes = merge(className, withClassPrefix(size, color, {
46
+ circle: circle,
47
+ bordered: bordered
38
48
  }));
39
- return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
40
- ref: ref,
41
- className: classes
42
- }), src || srcSet ? /*#__PURE__*/React.createElement("img", _extends({}, imgProps, {
43
- className: prefix(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["image"]))),
49
+ var imageProps = _extends({}, imgProps, {
50
+ alt: alt,
44
51
  src: src,
45
- sizes: sizes,
46
52
  srcSet: srcSet,
47
- alt: alt
48
- })) : children);
53
+ sizes: sizes
54
+ });
55
+ var _useImage = useImage(_extends({}, imageProps, {
56
+ onError: onError
57
+ })),
58
+ loaded = _useImage.loaded;
59
+ var _useCustom = useCustom('Avatar'),
60
+ rtl = _useCustom.rtl;
61
+ var altComponent = useMemo(function () {
62
+ if (alt) {
63
+ return /*#__PURE__*/React.createElement("span", {
64
+ role: "img",
65
+ "aria-label": alt
66
+ }, alt);
67
+ }
68
+ return null;
69
+ }, [alt]);
70
+ var placeholder = children || altComponent || /*#__PURE__*/React.createElement(AvatarIcon, {
71
+ className: prefix(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["icon"])))
72
+ });
73
+ var image = loaded ? /*#__PURE__*/React.createElement("img", _extends({}, imageProps, {
74
+ className: prefix(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["image"])))
75
+ })) : placeholder;
76
+ var margin = rtl ? 'marginLeft' : 'marginRight';
77
+ var insertStyles = isIE() && spacing ? _extends((_extends2 = {}, _extends2[margin] = spacing, _extends2), style) : style;
78
+ return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
79
+ ref: ref,
80
+ className: classes,
81
+ style: insertStyles
82
+ }), src ? image : placeholder);
49
83
  });
50
84
  Avatar.displayName = 'Avatar';
51
85
  Avatar.propTypes = {
@@ -53,7 +87,7 @@ Avatar.propTypes = {
53
87
  classPrefix: PropTypes.string,
54
88
  className: PropTypes.string,
55
89
  children: PropTypes.node,
56
- size: oneOf(['lg', 'md', 'sm', 'xs']),
90
+ size: oneOf(['xxl', 'xl', 'lg', 'md', 'sm', 'xs']),
57
91
  src: PropTypes.string,
58
92
  sizes: PropTypes.string,
59
93
  srcSet: PropTypes.string,
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const AvatarIcon: (props: React.HTMLAttributes<SVGElement>) => JSX.Element;
3
+ export default AvatarIcon;
@@ -0,0 +1,18 @@
1
+ 'use client';
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import React from 'react';
4
+ var AvatarIcon = function AvatarIcon(props) {
5
+ return /*#__PURE__*/React.createElement("svg", _extends({
6
+ role: "img",
7
+ "aria-label": "Avatar",
8
+ stroke: "currentColor",
9
+ fill: "currentColor",
10
+ strokeWidth: "0",
11
+ viewBox: "0 0 448 512",
12
+ height: "60%",
13
+ width: "60%"
14
+ }, props), /*#__PURE__*/React.createElement("path", {
15
+ d: "M224 256A128 128 0 1 0 224 0a128 128 0 1 0 0 256zm-45.7 48C79.8 304 0 383.8 0 482.3C0 498.7 13.3 512 29.7 512H418.3c16.4 0 29.7-13.3 29.7-29.7C448 383.8 368.2 304 269.7 304H178.3z"
16
+ }));
17
+ };
18
+ export default AvatarIcon;
@@ -0,0 +1,39 @@
1
+ import { ImgHTMLAttributes } from 'react';
2
+ interface UseImageProps {
3
+ /**
4
+ * The image `src` attribute
5
+ */
6
+ src?: string;
7
+ /**
8
+ * The image `srcSet` attribute
9
+ */
10
+ srcSet?: string;
11
+ /**
12
+ * The image `sizes` attribute
13
+ */
14
+ sizes?: string;
15
+ /**
16
+ * The image `crossOrigin` attribute
17
+ */
18
+ crossOrigin?: ImgHTMLAttributes<HTMLImageElement>['crossOrigin'];
19
+ /**
20
+ * Callback fired when the image failed to load.
21
+ */
22
+ onError?: OnErrorEventHandler;
23
+ }
24
+ declare type Status = 'pending' | 'loading' | 'error' | 'loaded';
25
+ /**
26
+ * A hook that loads an image and returns the status of the image.
27
+ *
28
+ * @example
29
+ * ```jsx
30
+ * const { loaded } = useImage({ src:'https://example.com/image.jpg' });
31
+ *
32
+ * return loaded ? <img src="https://example.com/image.jpg" /> : <Placeholder />;
33
+ * ```
34
+ */
35
+ declare const useImage: (props: UseImageProps) => {
36
+ loaded: boolean;
37
+ status: Status;
38
+ };
39
+ export default useImage;
@@ -0,0 +1,69 @@
1
+ 'use client';
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { useIsomorphicLayoutEffect } from '../utils';
4
+ /**
5
+ * A hook that loads an image and returns the status of the image.
6
+ *
7
+ * @example
8
+ * ```jsx
9
+ * const { loaded } = useImage({ src:'https://example.com/image.jpg' });
10
+ *
11
+ * return loaded ? <img src="https://example.com/image.jpg" /> : <Placeholder />;
12
+ * ```
13
+ */
14
+ var useImage = function useImage(props) {
15
+ var src = props.src,
16
+ srcSet = props.srcSet,
17
+ sizes = props.sizes,
18
+ crossOrigin = props.crossOrigin,
19
+ onError = props.onError;
20
+ var _useState = useState('pending'),
21
+ status = _useState[0],
22
+ setStatus = _useState[1];
23
+ var imgRef = useRef(null);
24
+ var flush = function flush() {
25
+ if (imgRef.current) {
26
+ imgRef.current.onload = null;
27
+ imgRef.current.onerror = null;
28
+ imgRef.current = null;
29
+ }
30
+ };
31
+ var handleLoad = useCallback(function () {
32
+ setStatus('loaded');
33
+ flush();
34
+ }, []);
35
+ var handleError = useCallback(function (event) {
36
+ setStatus('error');
37
+ flush();
38
+ onError === null || onError === void 0 ? void 0 : onError(event);
39
+ }, [onError]);
40
+ useEffect(function () {
41
+ setStatus(src ? 'loading' : 'pending');
42
+ }, [src]);
43
+ var loadImge = useCallback(function () {
44
+ if (!src) {
45
+ return;
46
+ }
47
+ var img = new Image();
48
+ img.onload = handleLoad;
49
+ img.onerror = handleError;
50
+ if (src) img.src = src;
51
+ if (srcSet) img.srcset = srcSet;
52
+ if (sizes) img.sizes = sizes;
53
+ if (crossOrigin) img.crossOrigin = crossOrigin;
54
+ imgRef.current = img;
55
+ }, [crossOrigin, handleError, handleLoad, sizes, src, srcSet]);
56
+ useIsomorphicLayoutEffect(function () {
57
+ if (status === 'loading') {
58
+ loadImge();
59
+ }
60
+ }, [loadImge, status]);
61
+ useEffect(function () {
62
+ return flush;
63
+ }, []);
64
+ return {
65
+ loaded: status === 'loaded',
66
+ status: status
67
+ };
68
+ };
69
+ export default useImage;
@@ -1,15 +1,24 @@
1
1
  import React from 'react';
2
- import { TypeAttributes, WithAsProps, RsRefForwardingComponent } from '../@types/common';
2
+ import { WithAsProps, RsRefForwardingComponent } from '../@types/common';
3
+ export declare type Size = 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs';
3
4
  export interface AvatarGroupProps extends WithAsProps {
4
- /** Render all avatars as stacks */
5
+ /**
6
+ * Render all avatars as stacks
7
+ */
5
8
  stack?: boolean;
6
- /** Set the spacing of the avatar */
9
+ /**
10
+ * Set the spacing of the avatar
11
+ */
7
12
  spacing?: number;
8
- /** Set the size of all avatars. */
9
- size?: TypeAttributes.Size;
13
+ /**
14
+ * Set the size of all avatars.
15
+ * @version xxl and xs added in v5.59.0
16
+ */
17
+ size?: Size;
10
18
  }
11
19
  export declare const AvatarGroupContext: React.Context<{
12
- size?: TypeAttributes.Size | undefined;
20
+ size?: Size | undefined;
21
+ spacing?: number | undefined;
13
22
  }>;
14
23
  /**
15
24
  * The AvatarGroup component is used to represent a collection of avatars.
@@ -3,7 +3,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
4
  import React, { useMemo } from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { useClassNames, useCustom } from '../utils';
6
+ import { useClassNames, isIE } from '../utils';
7
7
  import { oneOf } from '../internals/propTypes';
8
8
  export var AvatarGroupContext = /*#__PURE__*/React.createContext({});
9
9
 
@@ -21,9 +21,8 @@ var AvatarGroup = /*#__PURE__*/React.forwardRef(function (props, ref) {
21
21
  children = props.children,
22
22
  stack = props.stack,
23
23
  size = props.size,
24
- rest = _objectWithoutPropertiesLoose(props, ["as", "classPrefix", "spacing", "className", "children", "stack", "size"]);
25
- var _useCustom = useCustom('AvatarGroup'),
26
- rtl = _useCustom.rtl;
24
+ style = props.style,
25
+ rest = _objectWithoutPropertiesLoose(props, ["as", "classPrefix", "spacing", "className", "children", "stack", "size", "style"]);
27
26
  var _useClassNames = useClassNames(classPrefix),
28
27
  withClassPrefix = _useClassNames.withClassPrefix,
29
28
  merge = _useClassNames.merge;
@@ -35,17 +34,18 @@ var AvatarGroup = /*#__PURE__*/React.forwardRef(function (props, ref) {
35
34
  size: size
36
35
  };
37
36
  }, [size]);
38
- return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
37
+ var styles = isIE() ? style : _extends({}, style, {
38
+ gap: spacing
39
+ });
40
+ return /*#__PURE__*/React.createElement(Component, _extends({
41
+ role: "group"
42
+ }, rest, {
39
43
  ref: ref,
40
- className: classes
44
+ className: classes,
45
+ style: styles
41
46
  }), /*#__PURE__*/React.createElement(AvatarGroupContext.Provider, {
42
47
  value: contextValue
43
- }, spacing ? React.Children.map(children, function (child) {
44
- var _extends2;
45
- return /*#__PURE__*/React.cloneElement(child, {
46
- style: _extends((_extends2 = {}, _extends2[rtl ? 'marginLeft' : 'marginRight'] = spacing, _extends2), child.props.style)
47
- });
48
- }) : children));
48
+ }, children));
49
49
  });
50
50
  AvatarGroup.displayName = 'AvatarGroup';
51
51
  AvatarGroup.propTypes = {
@@ -131,7 +131,7 @@ var Checkbox = /*#__PURE__*/React.forwardRef(function (props, ref) {
131
131
  })), /*#__PURE__*/React.createElement("span", {
132
132
  className: prefix(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["inner"]))),
133
133
  "aria-hidden": true,
134
- role: "presentation"
134
+ "data-testid": "checkbox-control-inner"
135
135
  }));
136
136
  return /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {
137
137
  ref: ref,
@@ -174,6 +174,11 @@ export var useDateField = function useDateField(format, localize, date) {
174
174
  if (isEmptyValue(type, value)) {
175
175
  return null;
176
176
  }
177
+
178
+ // Invalid Date
179
+ return new Date('');
180
+ } else if (type === 'day' && value === 0) {
181
+ // Invalid Date. If the type is day and the value is 0, it is considered an invalid date.
177
182
  return new Date('');
178
183
  }
179
184
  if (type === 'meridian' && typeof hour === 'number') {
package/esm/Form/Form.js CHANGED
@@ -12,10 +12,12 @@ import FormControlLabel from '../FormControlLabel';
12
12
  import FormErrorMessage from '../FormErrorMessage';
13
13
  import FormGroup from '../FormGroup';
14
14
  import FormHelpText from '../FormHelpText';
15
- import { useFormClassNames } from './useFormClassNames';
16
- import useSchemaModel from './useSchemaModel';
17
- import { useControlled, useEventCallback } from '../utils';
15
+ import { useEventCallback } from '../utils';
18
16
  import { oneOf } from '../internals/propTypes';
17
+ import useSchemaModel from './hooks/useSchemaModel';
18
+ import useFormError from './hooks/useFormError';
19
+ import useFormValue from './hooks/useFormValue';
20
+ import useFormClassNames from './hooks/useFormClassNames';
19
21
  /**
20
22
  * The `Form` component is a form interface for collecting and validating user input.
21
23
  * @see https://rsuitejs.com/components/form
@@ -29,8 +31,8 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
29
31
  errorFromContext = _props$errorFromConte === void 0 ? true : _props$errorFromConte,
30
32
  _props$formDefaultVal = props.formDefaultValue,
31
33
  formDefaultValue = _props$formDefaultVal === void 0 ? {} : _props$formDefaultVal,
32
- formValue = props.formValue,
33
- formError = props.formError,
34
+ formValueProp = props.formValue,
35
+ formErrorProp = props.formError,
34
36
  fluid = props.fluid,
35
37
  _props$nestedField = props.nestedField,
36
38
  nestedField = _props$nestedField === void 0 ? false : _props$nestedField,
@@ -61,29 +63,25 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
61
63
  plaintext: plaintext,
62
64
  disabled: disabled
63
65
  });
64
- var _useControlled = useControlled(formValue, formDefaultValue),
65
- realFormValue = _useControlled[0],
66
- setFormValue = _useControlled[1];
67
- var _useControlled2 = useControlled(formError, {}),
68
- realFormError = _useControlled2[0],
69
- setFormError = _useControlled2[1];
70
- var realFormValueRef = useRef(realFormValue);
71
- realFormValueRef.current = realFormValue;
72
- var realFormErrorRef = useRef(realFormError);
73
- realFormErrorRef.current = realFormError;
74
-
66
+ var _useFormValue = useFormValue(formValueProp, formDefaultValue),
67
+ formValue = _useFormValue.formValue,
68
+ setFormValue = _useFormValue.setFormValue,
69
+ onRemoveValue = _useFormValue.onRemoveValue;
70
+ var _useFormError = useFormError(formErrorProp),
71
+ formError = _useFormError.formError,
72
+ setFormError = _useFormError.setFormError,
73
+ onRemoveError = _useFormError.onRemoveError;
75
74
  /**
76
75
  * Validate the form data and return a boolean.
77
76
  * The error message after verification is returned in the callback.
78
77
  * @param callback
79
78
  */
80
79
  var check = useEventCallback(function (callback) {
81
- var formValue = realFormValue || {};
82
80
  var formError = {};
83
81
  var errorCount = 0;
84
82
  var model = getCombinedModel();
85
- Object.keys(model.spec).forEach(function (key) {
86
- var checkResult = model.checkForField(key, formValue);
83
+ Object.keys(model.getSchemaSpec()).forEach(function (key) {
84
+ var checkResult = model.checkForField(key, formValue || {});
87
85
  if (checkResult.hasError === true) {
88
86
  errorCount += 1;
89
87
  formError[key] = (checkResult === null || checkResult === void 0 ? void 0 : checkResult.errorMessage) || checkResult;
@@ -106,15 +104,14 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
106
104
  */
107
105
  var checkForField = useEventCallback(function (fieldName, callback) {
108
106
  var _extends2;
109
- var formValue = realFormValue || {};
110
107
  var model = getCombinedModel();
111
- var checkResult = model.checkForField(fieldName, formValue);
112
- var formError = _extends({}, realFormError, (_extends2 = {}, _extends2[fieldName] = (checkResult === null || checkResult === void 0 ? void 0 : checkResult.errorMessage) || checkResult, _extends2));
113
- setFormError(formError);
114
- onCheck === null || onCheck === void 0 ? void 0 : onCheck(formError);
108
+ var checkResult = model.checkForField(fieldName, formValue || {});
109
+ var nextFormError = _extends({}, formError, (_extends2 = {}, _extends2[fieldName] = (checkResult === null || checkResult === void 0 ? void 0 : checkResult.errorMessage) || checkResult, _extends2));
110
+ setFormError(nextFormError);
111
+ onCheck === null || onCheck === void 0 ? void 0 : onCheck(nextFormError);
115
112
  callback === null || callback === void 0 ? void 0 : callback(checkResult);
116
113
  if (checkResult.hasError) {
117
- onError === null || onError === void 0 ? void 0 : onError(formError);
114
+ onError === null || onError === void 0 ? void 0 : onError(nextFormError);
118
115
  }
119
116
  return !checkResult.hasError;
120
117
  });
@@ -123,13 +120,12 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
123
120
  * Check form data asynchronously and return a Promise
124
121
  */
125
122
  var checkAsync = useEventCallback(function () {
126
- var formValue = realFormValue || {};
127
123
  var promises = [];
128
124
  var keys = [];
129
125
  var model = getCombinedModel();
130
- Object.keys(model.spec).forEach(function (key) {
126
+ Object.keys(model.getSchemaSpec()).forEach(function (key) {
131
127
  keys.push(key);
132
- promises.push(model.checkForFieldAsync(key, formValue));
128
+ promises.push(model.checkForFieldAsync(key, formValue || {}));
133
129
  });
134
130
  return Promise.all(promises).then(function (values) {
135
131
  var formError = {};
@@ -157,15 +153,14 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
157
153
  * @param fieldName
158
154
  */
159
155
  var checkForFieldAsync = useEventCallback(function (fieldName) {
160
- var formValue = realFormValue || {};
161
156
  var model = getCombinedModel();
162
- return model.checkForFieldAsync(fieldName, formValue).then(function (checkResult) {
157
+ return model.checkForFieldAsync(fieldName, formValue || {}).then(function (checkResult) {
163
158
  var _extends3;
164
- var formError = _extends({}, realFormError, (_extends3 = {}, _extends3[fieldName] = checkResult.errorMessage, _extends3));
165
- onCheck === null || onCheck === void 0 ? void 0 : onCheck(formError);
166
- setFormError(formError);
159
+ var nextFormError = _extends({}, formError, (_extends3 = {}, _extends3[fieldName] = checkResult.errorMessage, _extends3));
160
+ onCheck === null || onCheck === void 0 ? void 0 : onCheck(nextFormError);
161
+ setFormError(nextFormError);
167
162
  if (checkResult.hasError) {
168
- onError === null || onError === void 0 ? void 0 : onError(formError);
163
+ onError === null || onError === void 0 ? void 0 : onError(nextFormError);
169
164
  }
170
165
  return checkResult;
171
166
  });
@@ -174,7 +169,7 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
174
169
  setFormError({});
175
170
  });
176
171
  var cleanErrorForField = useEventCallback(function (fieldName) {
177
- setFormError(omit(realFormError, [fieldName]));
172
+ setFormError(omit(formError, [fieldName]));
178
173
  });
179
174
  var resetErrors = useEventCallback(function (formError) {
180
175
  if (formError === void 0) {
@@ -195,23 +190,12 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
195
190
  };
196
191
  });
197
192
  var removeFieldError = useEventCallback(function (name) {
198
- /**
199
- * when this function is called when the children component is unmount, it's an old render frame
200
- * so use Ref to get future error
201
- */
202
- var formError = omit(realFormErrorRef.current, [name]);
203
- realFormErrorRef.current = formError;
193
+ var formError = onRemoveError(name);
204
194
  setFormError(formError);
205
195
  onCheck === null || onCheck === void 0 ? void 0 : onCheck(formError);
206
196
  });
207
197
  var removeFieldValue = useEventCallback(function (name) {
208
- /**
209
- * when this function is called when the children component is unmount, it's an old render frame
210
- * so use Ref to get future value
211
- */
212
- var formValue = omit(realFormValueRef.current, [name]);
213
- realFormValueRef.current = formValue;
214
- setFormValue(formValue);
198
+ var formValue = onRemoveValue(name);
215
199
  onChange === null || onChange === void 0 ? void 0 : onChange(formValue);
216
200
  });
217
201
  var handleSubmit = useEventCallback(function (event) {
@@ -225,10 +209,10 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
225
209
  });
226
210
  var handleFieldError = useEventCallback(function (name, errorMessage) {
227
211
  var _extends4;
228
- var formError = _extends({}, realFormError, (_extends4 = {}, _extends4[name] = errorMessage, _extends4));
229
- setFormError(formError);
230
- onError === null || onError === void 0 ? void 0 : onError(formError);
231
- onCheck === null || onCheck === void 0 ? void 0 : onCheck(formError);
212
+ var nextFormError = _extends({}, formError, (_extends4 = {}, _extends4[name] = errorMessage, _extends4));
213
+ setFormError(nextFormError);
214
+ onError === null || onError === void 0 ? void 0 : onError(nextFormError);
215
+ onCheck === null || onCheck === void 0 ? void 0 : onCheck(nextFormError);
232
216
  });
233
217
  var handleFieldSuccess = useEventCallback(function (name) {
234
218
  removeFieldError(name);
@@ -241,7 +225,7 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
241
225
  return _extends({}, formValue, (_extends5 = {}, _extends5[fieldName] = fieldValue, _extends5));
242
226
  };
243
227
  var handleFieldChange = useEventCallback(function (name, value, event) {
244
- var nextFormValue = setFieldValue(realFormValue, name, value);
228
+ var nextFormValue = setFieldValue(formValue, name, value);
245
229
  setFormValue(nextFormValue);
246
230
  onChange === null || onChange === void 0 ? void 0 : onChange(nextFormValue, event);
247
231
  });
@@ -254,7 +238,7 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
254
238
  readOnly: readOnly,
255
239
  plaintext: plaintext,
256
240
  disabled: disabled,
257
- formError: realFormError,
241
+ formError: formError,
258
242
  nestedField: nestedField,
259
243
  removeFieldValue: removeFieldValue,
260
244
  removeFieldError: removeFieldError,
@@ -264,7 +248,7 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
264
248
  onFieldError: handleFieldError,
265
249
  onFieldSuccess: handleFieldSuccess
266
250
  };
267
- }, [getCombinedModel, checkTrigger, errorFromContext, readOnly, plaintext, disabled, realFormError, nestedField, removeFieldValue, removeFieldError, pushFieldRule, removeFieldRule, handleFieldChange, handleFieldError, handleFieldSuccess]);
251
+ }, [getCombinedModel, checkTrigger, errorFromContext, readOnly, plaintext, disabled, formError, nestedField, removeFieldValue, removeFieldError, pushFieldRule, removeFieldRule, handleFieldChange, handleFieldError, handleFieldSuccess]);
268
252
  return /*#__PURE__*/React.createElement("form", _extends({}, rest, {
269
253
  ref: rootRef,
270
254
  onSubmit: handleSubmit,
@@ -272,7 +256,7 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
272
256
  }), /*#__PURE__*/React.createElement(FormContext.Provider, {
273
257
  value: formContextValue
274
258
  }, /*#__PURE__*/React.createElement(FormValueContext.Provider, {
275
- value: realFormValue
259
+ value: formValue
276
260
  }, children)));
277
261
  });
278
262
  Form.Control = FormControl;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { TypeAttributes } from '../@types/common';
3
3
  import type { Schema } from 'schema-typed';
4
- import type { FieldRuleType } from './useSchemaModel';
4
+ import type { FieldRuleType } from './hooks/useSchemaModel';
5
5
  interface TrulyFormContextValue<T = Record<string, any>, errorMsgType = any, E = {
6
6
  [P in keyof T]?: errorMsgType;
7
7
  }> {
@@ -1,5 +1,5 @@
1
- import type { FormProps } from './Form';
1
+ import type { FormProps } from '../Form';
2
2
  /**
3
3
  * Take <Form> props and return className for <Form> styles
4
4
  */
5
- export declare function useFormClassNames({ classPrefix, className, fluid, layout, readOnly, plaintext, disabled }: Pick<FormProps, 'classPrefix' | 'className' | 'fluid' | 'layout' | 'readOnly' | 'plaintext' | 'disabled'>): string;
5
+ export default function useFormClassNames({ classPrefix, className, fluid, layout, readOnly, plaintext, disabled }: Pick<FormProps, 'classPrefix' | 'className' | 'fluid' | 'layout' | 'readOnly' | 'plaintext' | 'disabled'>): string;
@@ -1,9 +1,9 @@
1
1
  'use client';
2
- import { useClassNames } from '../utils';
2
+ import { useClassNames } from '../../utils';
3
3
  /**
4
4
  * Take <Form> props and return className for <Form> styles
5
5
  */
6
- export function useFormClassNames(_ref) {
6
+ export default function useFormClassNames(_ref) {
7
7
  var _ref$classPrefix = _ref.classPrefix,
8
8
  classPrefix = _ref$classPrefix === void 0 ? 'form' : _ref$classPrefix,
9
9
  className = _ref.className,
@@ -0,0 +1,6 @@
1
+ /// <reference types="lodash" />
2
+ export default function useFormError(formError: any): {
3
+ formError: any;
4
+ setFormError: (value: any) => void;
5
+ onRemoveError: (name: string) => import("lodash").Omit<any, string>;
6
+ };