@onewelcome/react-lib-components 1.3.0 → 1.4.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 (90) hide show
  1. package/dist/Button/IconButton.d.ts +2 -1
  2. package/dist/DataGrid/DataGrid.d.ts +1 -0
  3. package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +2 -1
  4. package/dist/Form/Form.d.ts +3 -3
  5. package/dist/Notifications/SlideInModal/SlideInModal.d.ts +1 -1
  6. package/dist/Tabs/Tab.d.ts +5 -9
  7. package/dist/Tabs/TabButton.d.ts +3 -6
  8. package/dist/Tabs/Tabs.d.ts +1 -2
  9. package/dist/react-lib-components.cjs.development.js +437 -392
  10. package/dist/react-lib-components.cjs.development.js.map +1 -1
  11. package/dist/react-lib-components.cjs.production.min.js +1 -1
  12. package/dist/react-lib-components.cjs.production.min.js.map +1 -1
  13. package/dist/react-lib-components.esm.js +438 -393
  14. package/dist/react-lib-components.esm.js.map +1 -1
  15. package/package.json +1 -1
  16. package/src/Breadcrumbs/Breadcrumbs.tsx +46 -38
  17. package/src/Button/BaseButton.tsx +23 -20
  18. package/src/Button/Button.tsx +40 -40
  19. package/src/Button/IconButton.tsx +28 -28
  20. package/src/ContextMenu/ContextMenu.tsx +161 -160
  21. package/src/ContextMenu/ContextMenuItem.tsx +55 -49
  22. package/src/DataGrid/DataGrid.tsx +1 -0
  23. package/src/DataGrid/DataGridActions/DataGridActions.module.scss +1 -1
  24. package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +4 -2
  25. package/src/DataGrid/DataGridActions/DataGridActions.tsx +95 -87
  26. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +64 -64
  27. package/src/DataGrid/DataGridBody/DataGridCell.tsx +42 -44
  28. package/src/DataGrid/DataGridBody/DataGridRow.tsx +29 -29
  29. package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +78 -78
  30. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +48 -48
  31. package/src/Form/Checkbox/Checkbox.tsx +134 -130
  32. package/src/Form/Fieldset/Fieldset.tsx +81 -78
  33. package/src/Form/Form.tsx +9 -4
  34. package/src/Form/FormControl/FormControl.module.scss +1 -20
  35. package/src/Form/FormControl/FormControl.tsx +36 -35
  36. package/src/Form/FormGroup/FormGroup.tsx +62 -62
  37. package/src/Form/FormHelperText/FormHelperText.tsx +19 -18
  38. package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +58 -53
  39. package/src/Form/Input/Input.tsx +90 -87
  40. package/src/Form/Label/Label.tsx +17 -16
  41. package/src/Form/Radio/Radio.tsx +91 -91
  42. package/src/Form/Select/Option.tsx +66 -60
  43. package/src/Form/Select/Select.tsx +207 -209
  44. package/src/Form/Textarea/Textarea.tsx +51 -53
  45. package/src/Form/Toggle/Toggle.tsx +26 -23
  46. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +51 -43
  47. package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +112 -106
  48. package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +67 -62
  49. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +42 -37
  50. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +94 -94
  51. package/src/Form/Wrapper/Wrapper/Wrapper.tsx +73 -73
  52. package/src/Icon/Icon.tsx +19 -16
  53. package/src/Link/Link.tsx +68 -63
  54. package/src/Notifications/BaseModal/BaseModal.tsx +68 -68
  55. package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +13 -10
  56. package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +33 -25
  57. package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +20 -17
  58. package/src/Notifications/Dialog/Dialog.tsx +83 -83
  59. package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +17 -14
  60. package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +15 -12
  61. package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +40 -40
  62. package/src/Notifications/SlideInModal/SlideInModal.module.scss +5 -5
  63. package/src/Notifications/SlideInModal/SlideInModal.test.tsx +7 -2
  64. package/src/Notifications/SlideInModal/SlideInModal.tsx +47 -27
  65. package/src/Pagination/Pagination.tsx +169 -169
  66. package/src/Popover/Popover.module.scss +1 -0
  67. package/src/Popover/Popover.tsx +43 -33
  68. package/src/ProgressBar/ProgressBar.tsx +17 -14
  69. package/src/Skeleton/Skeleton.tsx +23 -20
  70. package/src/StatusIndicator/StatusIndicator.tsx +18 -15
  71. package/src/Tabs/{TabPanel.module.scss → Tab.module.scss} +1 -1
  72. package/src/Tabs/Tab.test.tsx +1 -39
  73. package/src/Tabs/Tab.tsx +16 -10
  74. package/src/Tabs/TabButton.module.scss +0 -4
  75. package/src/Tabs/TabButton.test.tsx +3 -31
  76. package/src/Tabs/TabButton.tsx +35 -49
  77. package/src/Tabs/Tabs.test.tsx +40 -33
  78. package/src/Tabs/Tabs.tsx +107 -101
  79. package/src/TextEllipsis/TextEllipsis.tsx +50 -41
  80. package/src/Tiles/Tile.tsx +58 -56
  81. package/src/Tiles/Tiles.tsx +44 -41
  82. package/src/Tooltip/Tooltip.tsx +101 -100
  83. package/src/Typography/Typography.tsx +47 -44
  84. package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +55 -52
  85. package/src/Wizard/WizardSteps/WizardSteps.tsx +25 -22
  86. package/src/mixins.module.scss +2 -2
  87. package/src/util/helper.test.tsx +0 -28
  88. package/dist/Tabs/TabPanel.d.ts +0 -8
  89. package/src/Tabs/TabPanel.test.tsx +0 -92
  90. package/src/Tabs/TabPanel.tsx +0 -43
@@ -14,7 +14,12 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import React, { ComponentPropsWithRef, ReactNode, ReactElement } from "react";
17
+ import React, {
18
+ ForwardRefRenderFunction,
19
+ ComponentPropsWithRef,
20
+ ReactNode,
21
+ ReactElement
22
+ } from "react";
18
23
  import readyclasses from "../../readyclasses.module.scss";
19
24
  import classes from "./Fieldset.module.scss";
20
25
  import { Typography, Variant } from "../../Typography/Typography";
@@ -45,87 +50,85 @@ export interface Props extends ComponentPropsWithRef<"fieldset"> {
45
50
  disablePropagation?: boolean;
46
51
  }
47
52
 
48
- export const Fieldset = React.forwardRef<HTMLFieldSetElement, Props>(
49
- (
50
- {
51
- children,
52
- className,
53
- legend,
54
- legendStyle = "body",
55
- hideLegend = false,
56
- noBackground,
57
- background = noBackground ? "" : "#FFF",
58
- noPadding = false,
59
- disabled = false,
60
- required = false,
61
- error = false,
62
- disablePropagation = false,
63
- ...rest
64
- }: Props,
65
- ref
66
- ) => {
67
- const renderChildren = () => {
68
- if (!children) {
69
- return;
70
- }
53
+ const FieldsetComponent: ForwardRefRenderFunction<HTMLFieldSetElement, Props> = (
54
+ {
55
+ children,
56
+ className,
57
+ legend,
58
+ legendStyle = "body",
59
+ hideLegend = false,
60
+ noBackground,
61
+ background = noBackground ? "" : "#FFF",
62
+ noPadding = false,
63
+ disabled = false,
64
+ required = false,
65
+ error = false,
66
+ disablePropagation = false,
67
+ ...rest
68
+ }: Props,
69
+ ref
70
+ ) => {
71
+ const renderChildren = () => {
72
+ if (!children) {
73
+ return;
74
+ }
71
75
 
72
- /* All right, so the issue is that whenever we try to add disabled and error to a component that doesn't accept it,
76
+ /* All right, so the issue is that whenever we try to add disabled and error to a component that doesn't accept it,
73
77
  React will throw an error. However, it might occur that we want a component inside of Fieldset because of aesthetic purposes
74
78
  (fieldset applies a sort of container with white background and if we want to display it inside of this container... then yea).
75
79
  So instead we supply an array of components that we want to add the disabled and error prop to and check if child.type equals one of these. */
76
- const allowedComponents: ReactNode[] = [
77
- Input,
78
- Select,
79
- Radio,
80
- Checkbox,
81
- Textarea,
82
- Toggle,
83
- Label,
84
- FormControl,
85
- FormSelectorWrapper,
86
- FormHelperText,
87
- InputWrapper,
88
- SelectWrapper,
89
- TextareaWrapper
90
- ];
80
+ const allowedComponents: ReactNode[] = [
81
+ Input,
82
+ Select,
83
+ Radio,
84
+ Checkbox,
85
+ Textarea,
86
+ Toggle,
87
+ Label,
88
+ FormControl,
89
+ FormSelectorWrapper,
90
+ FormHelperText,
91
+ InputWrapper,
92
+ SelectWrapper,
93
+ TextareaWrapper
94
+ ];
95
+
96
+ return React.Children.map(children, (child: ReactElement) => {
97
+ if (allowedComponents.includes(child.type) && !disablePropagation) {
98
+ return React.cloneElement(child, {
99
+ disabled: child.props.disabled ?? disabled,
100
+ error: child.props.error ?? error
101
+ });
102
+ }
91
103
 
92
- return React.Children.map(children, (child: ReactElement) => {
93
- if (allowedComponents.includes(child.type) && !disablePropagation) {
94
- return React.cloneElement(child, {
95
- disabled: child.props.disabled ?? disabled,
96
- error: child.props.error ?? error
97
- });
98
- }
104
+ return child;
105
+ });
106
+ };
99
107
 
100
- return child;
101
- });
102
- };
108
+ return (
109
+ <fieldset
110
+ {...rest}
111
+ ref={ref}
112
+ disabled={disabled}
113
+ style={{ backgroundColor: background, ...rest.style }}
114
+ className={`${classes.fieldset} ${noPadding ? classes["no-padding"] : ""} ${className ?? ""}`}
115
+ >
116
+ {legend && <legend className={readyclasses["sr-only"]}>{legend}</legend>}
117
+ {legend && !hideLegend && (
118
+ <Typography
119
+ variant={legendStyle}
120
+ tag="span"
121
+ aria-hidden="true"
122
+ className={`${classes["legend"]} ${required ? classes["required"] : ""} ${
123
+ error ? classes["error"] : ""
124
+ }`}
125
+ >
126
+ {legend}
127
+ </Typography>
128
+ )}
129
+ {renderChildren()}
130
+ </fieldset>
131
+ );
132
+ };
103
133
 
104
- return (
105
- <fieldset
106
- {...rest}
107
- ref={ref}
108
- disabled={disabled}
109
- style={{ backgroundColor: background, ...rest.style }}
110
- className={`${classes.fieldset} ${noPadding ? classes["no-padding"] : ""} ${
111
- className ?? ""
112
- }`}
113
- >
114
- {legend && <legend className={readyclasses["sr-only"]}>{legend}</legend>}
115
- {legend && !hideLegend && (
116
- <Typography
117
- variant={legendStyle}
118
- tag="span"
119
- aria-hidden="true"
120
- className={`${classes["legend"]} ${required ? classes["required"] : ""} ${
121
- error ? classes["error"] : ""
122
- }`}
123
- >
124
- {legend}
125
- </Typography>
126
- )}
127
- {renderChildren()}
128
- </fieldset>
129
- );
130
- }
131
- );
134
+ export const Fieldset = React.forwardRef(FieldsetComponent);
package/src/Form/Form.tsx CHANGED
@@ -14,17 +14,22 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import React, { HTMLProps, ReactNode } from "react";
17
+ import React, { ComponentPropsWithRef, ForwardRefRenderFunction, ReactNode } from "react";
18
18
  import classes from "./Form.module.scss";
19
19
 
20
- export interface Props extends HTMLProps<HTMLFormElement> {
20
+ export interface Props extends ComponentPropsWithRef<"form"> {
21
21
  children?: ReactNode;
22
22
  }
23
23
 
24
- export const Form = ({ children, className, ...rest }: Props) => {
24
+ const FormComponent: ForwardRefRenderFunction<HTMLFormElement, Props> = (
25
+ { children, className, ...rest }: Props,
26
+ ref
27
+ ) => {
25
28
  return (
26
- <form className={`${classes.form} ${className ?? ""}`} {...rest}>
29
+ <form ref={ref} className={`${classes.form} ${className ?? ""}`} {...rest}>
27
30
  {children}
28
31
  </form>
29
32
  );
30
33
  };
34
+
35
+ export const Form = React.forwardRef(FormComponent);
@@ -22,6 +22,7 @@
22
22
  &.grid {
23
23
  display: flex;
24
24
  flex-wrap: wrap;
25
+ gap: 1rem;
25
26
 
26
27
  &.center,
27
28
  &.middle {
@@ -54,26 +55,6 @@
54
55
  flex-shrink: 0;
55
56
  }
56
57
 
57
- .grid-2 {
58
- .column:nth-child(even) {
59
- margin-left: 1rem;
60
- }
61
-
62
- .column:nth-child(n + 3) {
63
- margin-top: 1rem;
64
- }
65
- }
66
-
67
- .grid-3 {
68
- .column:not(:nth-child(3n + 1)) {
69
- margin-left: 1rem;
70
- }
71
-
72
- .column:nth-child(n + 4) {
73
- margin-top: 1rem;
74
- }
75
- }
76
-
77
58
  .col-2 {
78
59
  flex-basis: calc(calc(100% - 1rem) / 2);
79
60
  }
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import React, { ComponentPropsWithRef, ReactElement } from "react";
17
+ import React, { ForwardRefRenderFunction, ComponentPropsWithRef, ReactElement } from "react";
18
18
  import classes from "./FormControl.module.scss";
19
19
 
20
20
  export interface Props extends ComponentPropsWithRef<"div"> {
@@ -25,39 +25,40 @@ export interface Props extends ComponentPropsWithRef<"div"> {
25
25
  disabled?: boolean;
26
26
  }
27
27
 
28
- export const FormControl = React.forwardRef<HTMLDivElement, Props>(
29
- ({ children, disabled, error, className, grid, align = "center", ...rest }: Props, ref) => {
30
- const renderChildren = () =>
31
- React.Children.map(children, child => {
32
- if (!child) {
33
- return null;
34
- }
35
-
36
- const childElement = React.cloneElement(child, {
37
- disabled: child.props.disabled !== undefined ? child.props.disabled : disabled,
38
- error: child.props.error !== undefined ? child.props.error : error
39
- });
40
-
41
- if (grid && grid > 1) {
42
- return (
43
- <div className={`${classes["col-" + grid]} ${classes.column}`}>{childElement}</div>
44
- );
45
- }
46
-
47
- return childElement;
28
+ const FormControlComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
29
+ { children, disabled, error, className, grid, align = "center", ...rest }: Props,
30
+ ref
31
+ ) => {
32
+ const renderChildren = () =>
33
+ React.Children.map(children, child => {
34
+ if (!child) {
35
+ return null;
36
+ }
37
+
38
+ const childElement = React.cloneElement(child, {
39
+ disabled: child.props.disabled !== undefined ? child.props.disabled : disabled,
40
+ error: child.props.error !== undefined ? child.props.error : error
48
41
  });
49
42
 
50
- return (
51
- <div
52
- {...rest}
53
- ref={ref}
54
- data-formcontrol
55
- className={`${classes["form-control"]} ${className ? className : ""} ${
56
- grid && grid > 1 ? `${classes.grid} ${classes["grid-" + grid]}` : ""
57
- } ${classes[align]}`}
58
- >
59
- {renderChildren()}
60
- </div>
61
- );
62
- }
63
- );
43
+ if (grid && grid > 1) {
44
+ return <div className={`${classes["col-" + grid]} ${classes.column}`}>{childElement}</div>;
45
+ }
46
+
47
+ return childElement;
48
+ });
49
+
50
+ return (
51
+ <div
52
+ {...rest}
53
+ ref={ref}
54
+ data-formcontrol
55
+ className={`${classes["form-control"]} ${className ? className : ""} ${
56
+ grid && grid > 1 ? `${classes.grid} ${classes["grid-" + grid]}` : ""
57
+ } ${classes[align]}`}
58
+ >
59
+ {renderChildren()}
60
+ </div>
61
+ );
62
+ };
63
+
64
+ export const FormControl = React.forwardRef(FormControlComponent);
@@ -16,7 +16,7 @@
16
16
 
17
17
  /** The empty className property on FormHelperText is on purpose! We want to basically "filter" out the className from helperProps because we're adding this to the surrounding div. This makes it so also the errormessage receives this styling. */
18
18
 
19
- import React, { ComponentPropsWithRef, ReactChild } from "react";
19
+ import React, { ForwardRefRenderFunction, ComponentPropsWithRef, ReactChild } from "react";
20
20
  import classes from "./FormGroup.module.scss";
21
21
  import { FormHelperText, Props as HelperProps } from "../FormHelperText/FormHelperText";
22
22
  import { Icon, Icons } from "../../Icon/Icon";
@@ -35,66 +35,66 @@ export interface Props extends ComponentPropsWithRef<"div"> {
35
35
  disabled?: boolean;
36
36
  }
37
37
 
38
- export const FormGroup = React.forwardRef<HTMLDivElement, Props>(
39
- (
40
- {
41
- children,
42
- className,
43
- error,
44
- errorMessage,
45
- errorId,
46
- errorMessageIcon,
47
- errorMessageIconPosition = "before",
48
- helperText,
49
- helperId,
50
- helperProps,
51
- helperIndent,
52
- ...rest
53
- }: Props,
54
- ref
55
- ) => {
56
- return (
57
- <div
58
- {...rest}
59
- ref={ref}
60
- className={`${classes["form-group"]} ${error ? classes.error : ""} ${className ?? ""}`}
61
- >
62
- {children}
38
+ const FormGroupComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
39
+ {
40
+ children,
41
+ className,
42
+ error,
43
+ errorMessage,
44
+ errorId,
45
+ errorMessageIcon,
46
+ errorMessageIconPosition = "before",
47
+ helperText,
48
+ helperId,
49
+ helperProps,
50
+ helperIndent,
51
+ ...rest
52
+ }: Props,
53
+ ref
54
+ ) => {
55
+ return (
56
+ <div
57
+ {...rest}
58
+ ref={ref}
59
+ className={`${classes["form-group"]} ${error ? classes.error : ""} ${className ?? ""}`}
60
+ >
61
+ {children}
63
62
 
64
- {(helperText || (errorMessage && error)) && (
65
- <div
66
- style={{ marginLeft: `${helperIndent}px` }}
67
- className={`${classes["default-helper"]} ${
68
- helperProps?.className ? helperProps.className : ""
69
- }`}
70
- >
71
- {((helperText && !error) || (helperText && error && !errorMessage)) && (
72
- <FormHelperText {...helperProps} className={""} id={helperId}>
73
- {(helperProps && helperProps.children) || helperText}
74
- </FormHelperText>
75
- )}
76
- {error && errorMessage && (
77
- <span className={classes["error-message"]}>
78
- <span className={classes.message} id={errorId}>
79
- {errorMessageIcon && errorMessageIconPosition === "before" && (
80
- <Icon
81
- className={`${classes["error-icon"]} ${classes["error-icon-before"]}`}
82
- icon={errorMessageIcon}
83
- />
84
- )}
85
- {errorMessage}
86
- {errorMessageIcon && errorMessageIconPosition === "after" && (
87
- <Icon
88
- className={`${classes["error-icon"]} ${classes["error-icon-after"]}`}
89
- icon={errorMessageIcon}
90
- />
91
- )}
92
- </span>
63
+ {(helperText || (errorMessage && error)) && (
64
+ <div
65
+ style={{ marginLeft: `${helperIndent}px` }}
66
+ className={`${classes["default-helper"]} ${
67
+ helperProps?.className ? helperProps.className : ""
68
+ }`}
69
+ >
70
+ {((helperText && !error) || (helperText && error && !errorMessage)) && (
71
+ <FormHelperText {...helperProps} className={""} id={helperId}>
72
+ {(helperProps && helperProps.children) || helperText}
73
+ </FormHelperText>
74
+ )}
75
+ {error && errorMessage && (
76
+ <span className={classes["error-message"]}>
77
+ <span className={classes.message} id={errorId}>
78
+ {errorMessageIcon && errorMessageIconPosition === "before" && (
79
+ <Icon
80
+ className={`${classes["error-icon"]} ${classes["error-icon-before"]}`}
81
+ icon={errorMessageIcon}
82
+ />
83
+ )}
84
+ {errorMessage}
85
+ {errorMessageIcon && errorMessageIconPosition === "after" && (
86
+ <Icon
87
+ className={`${classes["error-icon"]} ${classes["error-icon-after"]}`}
88
+ icon={errorMessageIcon}
89
+ />
90
+ )}
93
91
  </span>
94
- )}
95
- </div>
96
- )}
97
- </div>
98
- );
99
- }
100
- );
92
+ </span>
93
+ )}
94
+ </div>
95
+ )}
96
+ </div>
97
+ );
98
+ };
99
+
100
+ export const FormGroup = React.forwardRef(FormGroupComponent);
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import React, { ComponentPropsWithRef, ReactNode } from "react";
17
+ import React, { ForwardRefRenderFunction, ComponentPropsWithRef, ReactNode } from "react";
18
18
  import classes from "./FormHelperText.module.scss";
19
19
  import { Typography } from "../../Typography/Typography";
20
20
  import { FormElement } from "../form.interfaces";
@@ -23,20 +23,21 @@ export interface Props extends ComponentPropsWithRef<"div">, FormElement {
23
23
  children?: ReactNode;
24
24
  }
25
25
 
26
- export const FormHelperText = React.forwardRef<HTMLDivElement, Props>(
27
- ({ children, error, className, ...rest }: Props, ref) => {
28
- return (
29
- <Typography
30
- {...rest}
31
- ref={ref}
32
- variant="sub-text"
33
- tag="div"
34
- className={`${classes["form-helper-text"]} ${error ? classes.error : ""} ${
35
- className ?? ""
36
- }`}
37
- >
38
- {children}
39
- </Typography>
40
- );
41
- }
42
- );
26
+ const FormHelperTextComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
27
+ { children, error, className, ...rest }: Props,
28
+ ref
29
+ ) => {
30
+ return (
31
+ <Typography
32
+ {...rest}
33
+ ref={ref}
34
+ variant="sub-text"
35
+ tag="div"
36
+ className={`${classes["form-helper-text"]} ${error ? classes.error : ""} ${className ?? ""}`}
37
+ >
38
+ {children}
39
+ </Typography>
40
+ );
41
+ };
42
+
43
+ export const FormHelperText = React.forwardRef(FormHelperTextComponent);
@@ -14,7 +14,12 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import React, { ComponentPropsWithRef, createRef, ReactNode } from "react";
17
+ import React, {
18
+ ForwardRefRenderFunction,
19
+ ComponentPropsWithRef,
20
+ createRef,
21
+ ReactNode
22
+ } from "react";
18
23
  import { Icon, Icons } from "../../Icon/Icon";
19
24
  import { KeyValuePair } from "../../interfaces";
20
25
  import { FormSelector } from "../form.interfaces";
@@ -31,57 +36,57 @@ export interface Props extends ComponentPropsWithRef<"div">, FormSelector {
31
36
  identifier?: string;
32
37
  }
33
38
 
34
- export const FormSelectorWrapper = React.forwardRef<HTMLDivElement, Props>(
35
- (
36
- {
37
- children,
38
- className,
39
- nestedChildren,
40
- containerProps,
41
- helperProps,
42
- error,
43
- disabled,
44
- helperText,
45
- errorMessage,
46
- parentErrorId,
47
- errorId,
48
- identifier,
49
- ...rest
50
- }: Props,
51
- ref
52
- ) => {
53
- const helperRef = helperProps?.ref || createRef();
39
+ const FormSelectorWrapperComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
40
+ {
41
+ children,
42
+ className,
43
+ nestedChildren,
44
+ containerProps,
45
+ helperProps,
46
+ error,
47
+ disabled,
48
+ helperText,
49
+ errorMessage,
50
+ parentErrorId,
51
+ errorId,
52
+ identifier,
53
+ ...rest
54
+ }: Props,
55
+ ref
56
+ ) => {
57
+ const helperRef = helperProps?.ref || createRef();
54
58
 
55
- return (
56
- <div
57
- {...rest}
58
- ref={ref}
59
- className={`${error ? classes["error"] : ""} ${disabled ? classes["disabled"] : ""} ${
60
- className ?? ""
61
- }`}
62
- >
63
- <div {...containerProps}>{children}</div>
64
- {(helperText || (helperProps && helperProps.children)) &&
65
- (!error || parentErrorId || !errorMessage) && (
66
- <FormHelperText
67
- {...helperProps}
68
- ref={helperRef}
69
- id={`${identifier}`}
70
- className={`${classes["helper-text"]} ${helperProps?.className ?? ""} ${
71
- error ? classes["error"] : ""
72
- }`}
73
- >
74
- {(helperProps && helperProps.children) || helperText}
75
- </FormHelperText>
76
- )}
77
- {errorMessage && !parentErrorId && error && (
78
- <span className={classes["error-message"]}>
79
- <Icon className={classes["error-icon"]} icon={Icons.Error} />
80
- <span id={errorId}>{errorMessage}</span>
81
- </span>
59
+ return (
60
+ <div
61
+ {...rest}
62
+ ref={ref}
63
+ className={`${error ? classes["error"] : ""} ${disabled ? classes["disabled"] : ""} ${
64
+ className ?? ""
65
+ }`}
66
+ >
67
+ <div {...containerProps}>{children}</div>
68
+ {(helperText || (helperProps && helperProps.children)) &&
69
+ (!error || parentErrorId || !errorMessage) && (
70
+ <FormHelperText
71
+ {...helperProps}
72
+ ref={helperRef}
73
+ id={`${identifier}`}
74
+ className={`${classes["helper-text"]} ${helperProps?.className ?? ""} ${
75
+ error ? classes["error"] : ""
76
+ }`}
77
+ >
78
+ {(helperProps && helperProps.children) || helperText}
79
+ </FormHelperText>
82
80
  )}
83
- {nestedChildren}
84
- </div>
85
- );
86
- }
87
- );
81
+ {errorMessage && !parentErrorId && error && (
82
+ <span className={classes["error-message"]}>
83
+ <Icon className={classes["error-icon"]} icon={Icons.Error} />
84
+ <span id={errorId}>{errorMessage}</span>
85
+ </span>
86
+ )}
87
+ {nestedChildren}
88
+ </div>
89
+ );
90
+ };
91
+
92
+ export const FormSelectorWrapper = React.forwardRef(FormSelectorWrapperComponent);