@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,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, { ComponentPropsWithRef, useEffect, useState } from "react";
|
|
17
|
+
import React, { ForwardRefRenderFunction, ComponentPropsWithRef, useEffect, useState } from "react";
|
|
18
18
|
import { ColumnName, Direction, HeaderCell, OnSortFunction, Sort } from "../datagrid.interfaces";
|
|
19
19
|
import { DataGridHeaderCell } from "./DataGridHeaderCell";
|
|
20
20
|
import classes from "./DataGridHeader.module.scss";
|
|
@@ -30,90 +30,90 @@ export interface Props extends ComponentPropsWithRef<"thead"> {
|
|
|
30
30
|
|
|
31
31
|
const sortingStates = [undefined, "ASC", "DESC"] as (Direction | undefined)[];
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const [sortList, setSortList] = useState(initialSort || []);
|
|
33
|
+
const DataGridHeaderComponent: ForwardRefRenderFunction<HTMLTableSectionElement, Props> = (
|
|
34
|
+
{
|
|
35
|
+
initialSort,
|
|
36
|
+
onSort,
|
|
37
|
+
headers,
|
|
38
|
+
disableContextMenuColumn,
|
|
39
|
+
enableMultiSorting,
|
|
40
|
+
spacing,
|
|
41
|
+
...rest
|
|
42
|
+
}: Props,
|
|
43
|
+
ref
|
|
44
|
+
) => {
|
|
45
|
+
const [sortList, setSortList] = useState(initialSort || []);
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
setSortList(initialSort || []);
|
|
49
|
+
}, [initialSort]);
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
const calculateNextSortState = (direction?: Direction) => {
|
|
52
|
+
const currentDirectionIdx = sortingStates.findIndex(item => item === direction);
|
|
53
|
+
return sortingStates[currentDirectionIdx + (1 % sortingStates.length)];
|
|
54
|
+
};
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
/**
|
|
57
|
+
* The sortList contains sorting columns objects. The order of those objects determinates priorities of sorting.
|
|
58
|
+
* Last modified sorting column has the highest priority.
|
|
59
|
+
*/
|
|
60
|
+
const updateSortList = (name: ColumnName): Sort => {
|
|
61
|
+
const current = sortList.find(item => item.name === name);
|
|
62
|
+
const restSortList = enableMultiSorting ? sortList.filter(item => item.name !== name) : [];
|
|
63
|
+
const newSortDirection = calculateNextSortState(current?.direction);
|
|
64
|
+
return newSortDirection
|
|
65
|
+
? [{ name, direction: newSortDirection }, ...restSortList]
|
|
66
|
+
: restSortList;
|
|
67
|
+
};
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
const wrapOnSort = (name: ColumnName) => {
|
|
70
|
+
const newSort = updateSortList(name);
|
|
71
|
+
onSort && onSort(newSort);
|
|
72
|
+
setSortList(newSort);
|
|
73
|
+
};
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
const headerCells = headers.map((header, index) => {
|
|
76
|
+
if (header.hidden) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
80
79
|
|
|
81
|
-
|
|
80
|
+
let headerStyle: React.CSSProperties = {};
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const sort = sortList.find(item => item.name === header.name);
|
|
91
|
-
return (
|
|
92
|
-
<DataGridHeaderCell
|
|
93
|
-
key={header.name}
|
|
94
|
-
name={header.name}
|
|
95
|
-
headline={header.headline}
|
|
96
|
-
disableSorting={header.disableSorting || !onSort}
|
|
97
|
-
onSort={wrapOnSort}
|
|
98
|
-
activeSortDirection={sort?.direction}
|
|
99
|
-
style={headerStyle}
|
|
100
|
-
/>
|
|
101
|
-
);
|
|
102
|
-
});
|
|
82
|
+
if (index === 0) {
|
|
83
|
+
headerStyle.paddingLeft = spacing?.paddingLeft;
|
|
84
|
+
}
|
|
85
|
+
if (index === headers.length - 1 && disableContextMenuColumn) {
|
|
86
|
+
headerStyle.paddingRight = spacing?.paddingRight;
|
|
87
|
+
}
|
|
103
88
|
|
|
89
|
+
const sort = sortList.find(item => item.name === header.name);
|
|
104
90
|
return (
|
|
105
|
-
<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
)}
|
|
115
|
-
</tr>
|
|
116
|
-
</thead>
|
|
91
|
+
<DataGridHeaderCell
|
|
92
|
+
key={header.name}
|
|
93
|
+
name={header.name}
|
|
94
|
+
headline={header.headline}
|
|
95
|
+
disableSorting={header.disableSorting || !onSort}
|
|
96
|
+
onSort={wrapOnSort}
|
|
97
|
+
activeSortDirection={sort?.direction}
|
|
98
|
+
style={headerStyle}
|
|
99
|
+
/>
|
|
117
100
|
);
|
|
118
|
-
}
|
|
119
|
-
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<thead {...rest} ref={ref} className={classes["thead"]}>
|
|
105
|
+
<tr className={classes["row"]}>
|
|
106
|
+
{headerCells}
|
|
107
|
+
{!disableContextMenuColumn && (
|
|
108
|
+
<td
|
|
109
|
+
style={{ paddingRight: spacing?.paddingRight }}
|
|
110
|
+
aria-label="context menu"
|
|
111
|
+
className={classes["context-menu"]}
|
|
112
|
+
></td>
|
|
113
|
+
)}
|
|
114
|
+
</tr>
|
|
115
|
+
</thead>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const DataGridHeader = React.forwardRef(DataGridHeaderComponent);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, { ComponentPropsWithRef, Fragment } from "react";
|
|
17
|
+
import React, { ForwardRefRenderFunction, ComponentPropsWithRef, Fragment } from "react";
|
|
18
18
|
import { Icon, Icons } from "../../Icon/Icon";
|
|
19
19
|
import { ColumnName, Direction } from "../datagrid.interfaces";
|
|
20
20
|
import classes from "./DataGridHeaderCell.module.scss";
|
|
@@ -32,57 +32,57 @@ const ariaSortMapping = {
|
|
|
32
32
|
DESC: "descending"
|
|
33
33
|
} as const;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const getSortingIndicatorClasses = (direction: Direction) => {
|
|
43
|
-
const sortingIndicatorClasses = [classes["indicator"]];
|
|
44
|
-
activeSortDirection &&
|
|
45
|
-
sortingIndicatorClasses.push(
|
|
46
|
-
activeSortDirection === direction ? classes["active"] : classes["hidden"]
|
|
47
|
-
);
|
|
48
|
-
return sortingIndicatorClasses;
|
|
49
|
-
};
|
|
35
|
+
const DataGridHeaderCellComponent: ForwardRefRenderFunction<HTMLTableCellElement, Props> = (
|
|
36
|
+
{ headline, name, disableSorting, activeSortDirection, onSort, ...rest }: Props,
|
|
37
|
+
ref
|
|
38
|
+
) => {
|
|
39
|
+
const onCellClick = () => {
|
|
40
|
+
onSort && onSort(name);
|
|
41
|
+
};
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
);
|
|
43
|
+
const sortingIndicator = () => {
|
|
44
|
+
const getSortingIndicatorClasses = (direction: Direction) => {
|
|
45
|
+
const sortingIndicatorClasses = [classes["indicator"]];
|
|
46
|
+
activeSortDirection &&
|
|
47
|
+
sortingIndicatorClasses.push(
|
|
48
|
+
activeSortDirection === direction ? classes["active"] : classes["hidden"]
|
|
49
|
+
);
|
|
50
|
+
return sortingIndicatorClasses;
|
|
60
51
|
};
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
return (
|
|
63
54
|
<Fragment>
|
|
64
|
-
<
|
|
65
|
-
{
|
|
66
|
-
<div className={classes["sorting-indicator-container"]}>{sortingIndicator()}</div>
|
|
67
|
-
)}
|
|
55
|
+
<Icon className={getSortingIndicatorClasses("ASC").join(" ")} icon={Icons.TriangleUp} />
|
|
56
|
+
<Icon className={getSortingIndicatorClasses("DESC").join(" ")} icon={Icons.TriangleDown} />
|
|
68
57
|
</Fragment>
|
|
69
58
|
);
|
|
59
|
+
};
|
|
70
60
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
className={classes["
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
61
|
+
const innerContent = (
|
|
62
|
+
<Fragment>
|
|
63
|
+
<span className={classes["headline"]}>{headline}</span>
|
|
64
|
+
{!disableSorting && (
|
|
65
|
+
<div className={classes["sorting-indicator-container"]}>{sortingIndicator()}</div>
|
|
66
|
+
)}
|
|
67
|
+
</Fragment>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<th
|
|
72
|
+
{...rest}
|
|
73
|
+
ref={ref}
|
|
74
|
+
className={classes["header-cell"]}
|
|
75
|
+
aria-sort={activeSortDirection && ariaSortMapping[activeSortDirection]}
|
|
76
|
+
>
|
|
77
|
+
{disableSorting ? (
|
|
78
|
+
<div key={name}>{innerContent}</div>
|
|
79
|
+
) : (
|
|
80
|
+
<button key={name} onClick={onCellClick}>
|
|
81
|
+
{innerContent}
|
|
82
|
+
</button>
|
|
83
|
+
)}
|
|
84
|
+
</th>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const DataGridHeaderCell = React.forwardRef(DataGridHeaderCellComponent);
|
|
@@ -14,7 +14,13 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, {
|
|
17
|
+
import React, {
|
|
18
|
+
ForwardRefRenderFunction,
|
|
19
|
+
ComponentPropsWithRef,
|
|
20
|
+
ReactElement,
|
|
21
|
+
ReactNode,
|
|
22
|
+
useEffect
|
|
23
|
+
} from "react";
|
|
18
24
|
import { Icon, Icons } from "../../Icon/Icon";
|
|
19
25
|
import { Props as FormHelperTextProps } from "../FormHelperText/FormHelperText";
|
|
20
26
|
import classes from "./Checkbox.module.scss";
|
|
@@ -36,141 +42,139 @@ export interface Props extends ComponentPropsWithRef<"input">, FormSelector {
|
|
|
36
42
|
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
37
43
|
}
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (!name) {
|
|
72
|
-
throw new Error("Please pass a 'name' prop to your <Checkbox> component.");
|
|
73
|
-
}
|
|
45
|
+
const CheckboxComponent: ForwardRefRenderFunction<HTMLInputElement, Props> = (
|
|
46
|
+
{
|
|
47
|
+
children,
|
|
48
|
+
name,
|
|
49
|
+
helperText,
|
|
50
|
+
helperProps,
|
|
51
|
+
indeterminate,
|
|
52
|
+
parentErrorId,
|
|
53
|
+
errorMessage,
|
|
54
|
+
disabled,
|
|
55
|
+
label,
|
|
56
|
+
parentHelperId,
|
|
57
|
+
className,
|
|
58
|
+
error,
|
|
59
|
+
checked = false,
|
|
60
|
+
formSelectorWrapperProps,
|
|
61
|
+
onChange,
|
|
62
|
+
...rest
|
|
63
|
+
}: Props,
|
|
64
|
+
ref
|
|
65
|
+
) => {
|
|
66
|
+
const { errorId, identifier, describedBy } = useFormSelector({
|
|
67
|
+
name,
|
|
68
|
+
helperText,
|
|
69
|
+
parentErrorId,
|
|
70
|
+
errorMessage,
|
|
71
|
+
error,
|
|
72
|
+
parentHelperId
|
|
73
|
+
});
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}, []);
|
|
81
|
-
|
|
82
|
-
const determineLabel = () => {
|
|
83
|
-
if (label) {
|
|
84
|
-
return label;
|
|
85
|
-
} else if (children === undefined) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
"Please make sure to pass either a string or more Checkbox components as a child of your Checkbox component."
|
|
88
|
-
);
|
|
89
|
-
}
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!name) {
|
|
77
|
+
throw new Error("Please pass a 'name' prop to your <Checkbox> component.");
|
|
78
|
+
}
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
if (typeof children === "object" && !isToggle(children) && indeterminate === undefined) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
"If you have nested checkboxes you have to manage the indeterminate state by passing a boolean to the `indeterminate` prop."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}, []);
|
|
94
86
|
|
|
87
|
+
const determineLabel = () => {
|
|
88
|
+
if (label) {
|
|
89
|
+
return label;
|
|
90
|
+
} else if (children === undefined) {
|
|
95
91
|
throw new Error(
|
|
96
|
-
"
|
|
92
|
+
"Please make sure to pass either a string or more Checkbox components as a child of your Checkbox component."
|
|
97
93
|
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
{...child.props}
|
|
107
|
-
parentHelperId={parentHelperId}
|
|
108
|
-
parentErrorId={parentErrorId}
|
|
109
|
-
error={error}
|
|
110
|
-
disabled={child.props.disabled ? child.props.disabled : disabled}
|
|
111
|
-
>
|
|
112
|
-
{child.props.children}
|
|
113
|
-
</Checkbox>
|
|
114
|
-
</li>
|
|
115
|
-
);
|
|
116
|
-
})}
|
|
117
|
-
</ul>
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (typeof children === "string") {
|
|
97
|
+
return children;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
throw new Error(
|
|
101
|
+
"If you pass Checkboxes as a child component (to create nested checkbox tree) you need to pass a label to the parent checkbox."
|
|
118
102
|
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const renderNestedCheckboxes = () => (
|
|
106
|
+
<ul className={classes["checkbox-list"]}>
|
|
107
|
+
{React.Children.map(children as ReactElement[], child => {
|
|
108
|
+
return (
|
|
109
|
+
<li>
|
|
110
|
+
<Checkbox
|
|
111
|
+
{...child.props}
|
|
112
|
+
parentHelperId={parentHelperId}
|
|
113
|
+
parentErrorId={parentErrorId}
|
|
114
|
+
error={error}
|
|
115
|
+
disabled={child.props.disabled ? child.props.disabled : disabled}
|
|
116
|
+
>
|
|
117
|
+
{child.props.children}
|
|
118
|
+
</Checkbox>
|
|
119
|
+
</li>
|
|
120
|
+
);
|
|
121
|
+
})}
|
|
122
|
+
</ul>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const onChangeHandler = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
126
|
+
if (disabled) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
onChange && onChange(event);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const renderToggle = () => React.Children.toArray(children).filter(isToggle);
|
|
119
133
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
134
|
+
const iconClasses = [classes["input"], disabled ? classes["disabled"] : ""];
|
|
135
|
+
|
|
136
|
+
/** Default return value is the default checkbox */
|
|
137
|
+
return (
|
|
138
|
+
<FormSelectorWrapper
|
|
139
|
+
{...formSelectorWrapperProps}
|
|
140
|
+
className={`${classes["checkbox-wrapper"]} ${className ? className : ""}`}
|
|
141
|
+
containerProps={{ className: classes["checkbox-container"] }}
|
|
142
|
+
helperText={helperText}
|
|
143
|
+
helperProps={helperProps}
|
|
144
|
+
parentErrorId={parentErrorId}
|
|
145
|
+
errorId={errorId}
|
|
146
|
+
errorMessage={errorMessage}
|
|
147
|
+
error={error}
|
|
148
|
+
disabled={disabled}
|
|
149
|
+
identifier={identifier}
|
|
150
|
+
nestedChildren={
|
|
151
|
+
typeof children === "object" && !isToggle(children) && renderNestedCheckboxes()
|
|
123
152
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const iconClasses = [classes["input"], disabled ? classes["disabled"] : ""];
|
|
130
|
-
|
|
131
|
-
/** Default return value is the default checkbox */
|
|
132
|
-
return (
|
|
133
|
-
<FormSelectorWrapper
|
|
134
|
-
{...formSelectorWrapperProps}
|
|
135
|
-
className={`${classes["checkbox-wrapper"]} ${className ? className : ""}`}
|
|
136
|
-
containerProps={{ className: classes["checkbox-container"] }}
|
|
137
|
-
helperText={helperText}
|
|
138
|
-
helperProps={helperProps}
|
|
139
|
-
parentErrorId={parentErrorId}
|
|
140
|
-
errorId={errorId}
|
|
141
|
-
errorMessage={errorMessage}
|
|
142
|
-
error={error}
|
|
153
|
+
>
|
|
154
|
+
<input
|
|
155
|
+
{...rest}
|
|
156
|
+
ref={ref}
|
|
143
157
|
disabled={disabled}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
<Icon className={iconClasses.join(" ")} icon={Icons.CheckmarkSquare} />
|
|
168
|
-
)}
|
|
169
|
-
{!checked && !indeterminate && (
|
|
170
|
-
<Icon className={iconClasses.join(" ")} icon={Icons.Square} />
|
|
171
|
-
)}
|
|
172
|
-
<label htmlFor={`${identifier}-checkbox`}>{determineLabel()}</label>
|
|
173
|
-
</FormSelectorWrapper>
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
);
|
|
158
|
+
className={`${classes["native-input"]} ${error ? classes["error"] : ""}`}
|
|
159
|
+
checked={checked}
|
|
160
|
+
onChange={onChangeHandler}
|
|
161
|
+
aria-invalid={error as boolean}
|
|
162
|
+
aria-checked={indeterminate ? "mixed" : checked}
|
|
163
|
+
aria-describedby={describedBy}
|
|
164
|
+
id={`${identifier}-checkbox`}
|
|
165
|
+
name={name}
|
|
166
|
+
type="checkbox"
|
|
167
|
+
/>
|
|
168
|
+
{renderToggle()}
|
|
169
|
+
|
|
170
|
+
{indeterminate && <Icon className={iconClasses.join(" ")} icon={Icons.MinusSquare} />}
|
|
171
|
+
{checked && !indeterminate && (
|
|
172
|
+
<Icon className={iconClasses.join(" ")} icon={Icons.CheckmarkSquare} />
|
|
173
|
+
)}
|
|
174
|
+
{!checked && !indeterminate && <Icon className={iconClasses.join(" ")} icon={Icons.Square} />}
|
|
175
|
+
<label htmlFor={`${identifier}-checkbox`}>{determineLabel()}</label>
|
|
176
|
+
</FormSelectorWrapper>
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export const Checkbox = React.forwardRef(CheckboxComponent);
|