@onewelcome/react-lib-components 1.2.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.
- package/dist/Button/IconButton.d.ts +2 -1
- package/dist/DataGrid/DataGrid.d.ts +1 -0
- package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +2 -1
- package/dist/Form/Form.d.ts +3 -3
- package/dist/Notifications/SlideInModal/SlideInModal.d.ts +1 -1
- package/dist/Tabs/Tab.d.ts +5 -9
- package/dist/Tabs/TabButton.d.ts +3 -6
- package/dist/Tabs/Tabs.d.ts +1 -2
- package/dist/hooks/useDebouncedCallback.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/react-lib-components.cjs.development.js +472 -395
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +473 -397
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/Breadcrumbs/Breadcrumbs.tsx +46 -38
- package/src/Button/BaseButton.tsx +23 -20
- package/src/Button/Button.module.scss +9 -0
- package/src/Button/Button.tsx +40 -40
- package/src/Button/IconButton.tsx +28 -28
- package/src/ContextMenu/ContextMenu.tsx +161 -160
- package/src/ContextMenu/ContextMenuItem.tsx +55 -49
- package/src/DataGrid/DataGrid.tsx +1 -0
- package/src/DataGrid/DataGridActions/DataGridActions.module.scss +1 -1
- package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +4 -2
- package/src/DataGrid/DataGridActions/DataGridActions.tsx +95 -87
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +64 -64
- package/src/DataGrid/DataGridBody/DataGridCell.tsx +42 -44
- package/src/DataGrid/DataGridBody/DataGridRow.tsx +29 -29
- package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +78 -78
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +48 -48
- package/src/Form/Checkbox/Checkbox.tsx +134 -130
- package/src/Form/Fieldset/Fieldset.tsx +81 -78
- package/src/Form/Form.tsx +9 -4
- package/src/Form/FormControl/FormControl.module.scss +1 -20
- package/src/Form/FormControl/FormControl.tsx +36 -35
- package/src/Form/FormGroup/FormGroup.tsx +62 -62
- package/src/Form/FormHelperText/FormHelperText.tsx +19 -18
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +58 -53
- package/src/Form/Input/Input.tsx +90 -87
- package/src/Form/Label/Label.tsx +17 -16
- package/src/Form/Radio/Radio.tsx +91 -91
- package/src/Form/Select/Option.tsx +66 -60
- package/src/Form/Select/Select.tsx +207 -209
- package/src/Form/Textarea/Textarea.tsx +51 -53
- package/src/Form/Toggle/Toggle.tsx +26 -23
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +51 -43
- package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +112 -106
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +67 -62
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +42 -37
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +94 -94
- package/src/Form/Wrapper/Wrapper/Wrapper.tsx +73 -73
- package/src/Icon/Icon.module.scss +1 -0
- package/src/Icon/Icon.tsx +19 -16
- package/src/Link/Link.tsx +68 -63
- package/src/Notifications/BaseModal/BaseModal.tsx +68 -68
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +13 -10
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +33 -25
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +20 -17
- package/src/Notifications/Dialog/Dialog.tsx +83 -83
- package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +17 -14
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +15 -12
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +40 -40
- package/src/Notifications/SlideInModal/SlideInModal.module.scss +5 -5
- package/src/Notifications/SlideInModal/SlideInModal.test.tsx +7 -2
- package/src/Notifications/SlideInModal/SlideInModal.tsx +47 -27
- package/src/Pagination/Pagination.tsx +169 -169
- package/src/Popover/Popover.module.scss +1 -0
- package/src/Popover/Popover.tsx +43 -33
- package/src/ProgressBar/ProgressBar.tsx +17 -14
- package/src/Skeleton/Skeleton.tsx +23 -20
- package/src/StatusIndicator/StatusIndicator.tsx +18 -15
- package/src/Tabs/{TabPanel.module.scss → Tab.module.scss} +1 -1
- package/src/Tabs/Tab.test.tsx +1 -39
- package/src/Tabs/Tab.tsx +16 -10
- package/src/Tabs/TabButton.module.scss +0 -4
- package/src/Tabs/TabButton.test.tsx +3 -31
- package/src/Tabs/TabButton.tsx +35 -49
- package/src/Tabs/Tabs.test.tsx +40 -33
- package/src/Tabs/Tabs.tsx +107 -101
- package/src/TextEllipsis/TextEllipsis.tsx +50 -41
- package/src/Tiles/Tile.tsx +58 -56
- package/src/Tiles/Tiles.tsx +44 -41
- package/src/Tooltip/Tooltip.tsx +101 -100
- package/src/Typography/Typography.tsx +47 -44
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +55 -52
- package/src/Wizard/WizardSteps/WizardSteps.tsx +25 -22
- package/src/hooks/useDebouncedCallback.test.ts +140 -0
- package/src/hooks/useDebouncedCallback.tsx +32 -0
- package/src/index.ts +1 -0
- package/src/mixins.module.scss +2 -2
- package/src/util/helper.test.tsx +0 -28
- package/dist/Tabs/TabPanel.d.ts +0 -8
- package/src/Tabs/TabPanel.test.tsx +0 -92
- package/src/Tabs/TabPanel.tsx +0 -43
|
@@ -14,7 +14,12 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import 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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
disabled: child.props.disabled ?? disabled,
|
|
96
|
-
error: child.props.error ?? error
|
|
97
|
-
});
|
|
98
|
-
}
|
|
104
|
+
return child;
|
|
105
|
+
});
|
|
106
|
+
};
|
|
99
107
|
|
|
100
|
-
|
|
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
|
-
|
|
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, {
|
|
17
|
+
import React, { ComponentPropsWithRef, ForwardRefRenderFunction, ReactNode } from "react";
|
|
18
18
|
import classes from "./Form.module.scss";
|
|
19
19
|
|
|
20
|
-
export interface Props extends
|
|
20
|
+
export interface Props extends ComponentPropsWithRef<"form"> {
|
|
21
21
|
children?: ReactNode;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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, {
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
84
|
-
|
|
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);
|