@onewelcome/react-lib-components 0.2.0 → 0.2.3
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/Breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/Button/BaseButton.d.ts +4 -4
- package/dist/Button/Button.d.ts +3 -3
- package/dist/Button/IconButton.d.ts +4 -4
- package/dist/ContextMenu/ContextMenu.d.ts +5 -5
- package/dist/ContextMenu/ContextMenuItem.d.ts +2 -2
- package/dist/DataGrid/DataGrid.d.ts +6 -6
- package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +4 -4
- package/dist/DataGrid/DataGridActions/DataGridColumnsToggle.d.ts +3 -3
- package/dist/DataGrid/DataGridBody/DataGridBody.d.ts +3 -3
- package/dist/DataGrid/DataGridBody/DataGridCell.d.ts +2 -2
- package/dist/DataGrid/DataGridBody/DataGridRow.d.ts +3 -3
- package/dist/DataGrid/DataGridHeader/DataGridHeader.d.ts +3 -3
- package/dist/DataGrid/DataGridHeader/DataGridHeaderCell.d.ts +3 -3
- package/dist/DataGrid/datagrid.interfaces.d.ts +1 -1
- package/dist/Form/Checkbox/Checkbox.d.ts +5 -5
- package/dist/Form/Fieldset/Fieldset.d.ts +3 -3
- package/dist/Form/Form.d.ts +1 -1
- package/dist/Form/FormControl/FormControl.d.ts +3 -3
- package/dist/Form/FormGroup/FormGroup.d.ts +5 -5
- package/dist/Form/FormHelperText/FormHelperText.d.ts +3 -3
- package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +6 -6
- package/dist/Form/Input/Input.d.ts +5 -5
- package/dist/Form/Label/Label.d.ts +2 -2
- package/dist/Form/Radio/Radio.d.ts +5 -5
- package/dist/Form/Select/Option.d.ts +2 -2
- package/dist/Form/Select/Select.d.ts +5 -5
- package/dist/Form/Textarea/Textarea.d.ts +6 -6
- package/dist/Form/Toggle/Toggle.d.ts +3 -3
- package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +6 -6
- package/dist/Form/form.interfaces.d.ts +1 -1
- package/dist/Icon/Icon.d.ts +3 -3
- package/dist/Link/Link.d.ts +7 -7
- package/dist/Notifications/BaseModal/BaseModal.d.ts +4 -4
- package/dist/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +2 -2
- package/dist/Notifications/BaseModal/BaseModalContent/BaseModalContent.d.ts +2 -2
- package/dist/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +2 -2
- package/dist/Notifications/Dialog/Dialog.d.ts +5 -5
- package/dist/Notifications/Dialog/DialogActions/DialogActions.d.ts +3 -3
- package/dist/Notifications/Dialog/DialogTitle/DialogTitle.d.ts +2 -2
- package/dist/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.d.ts +3 -3
- package/dist/Notifications/DiscardChangesModal/DiscardChangesModal.d.ts +7 -7
- package/dist/Notifications/Modal/Modal.d.ts +1 -1
- package/dist/Notifications/Modal/ModalActions/ModalActions.d.ts +1 -1
- package/dist/Notifications/Modal/ModalContent/ModalContent.d.ts +1 -1
- package/dist/Notifications/Modal/ModalHeader/ModalHeader.d.ts +1 -1
- package/dist/Notifications/SlideInModal/SlideInModal.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarItem/SnackbarItem.d.ts +2 -2
- package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +2 -2
- package/dist/Notifications/Snackbar/interfaces.d.ts +2 -2
- package/dist/Pagination/Pagination.d.ts +3 -3
- package/dist/Popover/Popover.d.ts +3 -3
- package/dist/Skeleton/Skeleton.d.ts +3 -3
- package/dist/StatusIndicator/StatusIndicator.d.ts +5 -5
- package/dist/Tabs/Tab.d.ts +1 -1
- package/dist/Tabs/TabButton.d.ts +2 -2
- package/dist/Tabs/TabPanel.d.ts +2 -2
- package/dist/Tabs/Tabs.d.ts +4 -4
- package/dist/TextEllipsis/TextEllipsis.d.ts +2 -2
- package/dist/Tiles/Tile.d.ts +5 -5
- package/dist/Tiles/Tiles.d.ts +2 -2
- package/dist/Tooltip/Tooltip.d.ts +3 -3
- package/dist/Typography/Typography.d.ts +3 -3
- package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +2 -2
- package/dist/Wizard/Wizard.d.ts +3 -3
- package/dist/Wizard/WizardActions/WizardActions.d.ts +2 -2
- package/dist/Wizard/WizardStateProvider.d.ts +2 -2
- package/dist/Wizard/WizardSteps/WizardSteps.d.ts +2 -2
- package/dist/Wizard/wizardStateReducer.d.ts +5 -5
- package/dist/_BaseStyling_/BaseStyling.d.ts +1 -1
- package/dist/hooks/usePosition.d.ts +4 -4
- package/dist/hooks/useRepeater.d.ts +1 -1
- package/dist/hooks/useScroll.d.ts +1 -1
- package/dist/hooks/useSpacing.d.ts +1 -1
- package/dist/hooks/useWrapper.d.ts +1 -1
- package/dist/index.d.ts +55 -55
- package/dist/react-lib-components.cjs.development.js +676 -578
- 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 +676 -578
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +27 -16
- package/src/Breadcrumbs/Breadcrumbs.test.tsx +15 -15
- package/src/Breadcrumbs/Breadcrumbs.tsx +11 -11
- package/src/Button/BaseButton.module.scss +1 -1
- package/src/Button/BaseButton.test.tsx +27 -27
- package/src/Button/BaseButton.tsx +8 -8
- package/src/Button/Button.module.scss +5 -5
- package/src/Button/Button.test.tsx +39 -39
- package/src/Button/Button.tsx +10 -10
- package/src/Button/IconButton.module.scss +5 -5
- package/src/Button/IconButton.test.tsx +29 -29
- package/src/Button/IconButton.tsx +11 -11
- package/src/ContextMenu/ContextMenu.test.tsx +97 -76
- package/src/ContextMenu/ContextMenu.tsx +48 -42
- package/src/ContextMenu/ContextMenuItem.module.scss +1 -1
- package/src/ContextMenu/ContextMenuItem.tsx +7 -5
- package/src/DataGrid/DataGrid.test.tsx +193 -193
- package/src/DataGrid/DataGrid.tsx +26 -26
- package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +63 -63
- package/src/DataGrid/DataGridActions/DataGridActions.tsx +15 -15
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss +1 -1
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +21 -21
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +20 -20
- package/src/DataGrid/DataGridBody/DataGridBody.test.tsx +40 -40
- package/src/DataGrid/DataGridBody/DataGridBody.tsx +10 -10
- package/src/DataGrid/DataGridBody/DataGridCell.module.scss +1 -1
- package/src/DataGrid/DataGridBody/DataGridCell.test.tsx +25 -25
- package/src/DataGrid/DataGridBody/DataGridCell.tsx +6 -6
- package/src/DataGrid/DataGridBody/DataGridRow.test.tsx +38 -38
- package/src/DataGrid/DataGridBody/DataGridRow.tsx +8 -8
- package/src/DataGrid/DataGridHeader/DataGridHeader.module.scss +1 -2
- package/src/DataGrid/DataGridHeader/DataGridHeader.test.tsx +119 -119
- package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +13 -13
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +2 -0
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +51 -51
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +14 -14
- package/src/DataGrid/datagrid.interfaces.ts +1 -1
- package/src/Form/Checkbox/Checkbox.test.tsx +74 -74
- package/src/Form/Checkbox/Checkbox.tsx +27 -27
- package/src/Form/Fieldset/Fieldset.module.scss +1 -1
- package/src/Form/Fieldset/Fieldset.test.tsx +35 -35
- package/src/Form/Fieldset/Fieldset.tsx +27 -27
- package/src/Form/Form.test.tsx +18 -18
- package/src/Form/Form.tsx +3 -3
- package/src/Form/FormControl/FormControl.test.tsx +22 -22
- package/src/Form/FormControl/FormControl.tsx +10 -10
- package/src/Form/FormGroup/FormGroup.test.tsx +37 -37
- package/src/Form/FormGroup/FormGroup.tsx +16 -16
- package/src/Form/FormHelperText/FormHelperText.test.tsx +18 -18
- package/src/Form/FormHelperText/FormHelperText.tsx +7 -7
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +15 -15
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +14 -14
- package/src/Form/Input/Input.module.scss +20 -44
- package/src/Form/Input/Input.test.tsx +121 -73
- package/src/Form/Input/Input.tsx +96 -35
- package/src/Form/Label/Label.test.tsx +13 -13
- package/src/Form/Label/Label.tsx +6 -6
- package/src/Form/Radio/Radio.test.tsx +35 -35
- package/src/Form/Radio/Radio.tsx +17 -17
- package/src/Form/Select/Option.test.tsx +10 -10
- package/src/Form/Select/Option.tsx +8 -8
- package/src/Form/Select/Select.module.scss +7 -9
- package/src/Form/Select/Select.test.tsx +144 -141
- package/src/Form/Select/Select.tsx +79 -78
- package/src/Form/Textarea/Textarea.module.scss +8 -18
- package/src/Form/Textarea/Textarea.test.tsx +27 -27
- package/src/Form/Textarea/Textarea.tsx +33 -13
- package/src/Form/Toggle/Toggle.module.scss +1 -1
- package/src/Form/Toggle/Toggle.test.tsx +22 -22
- package/src/Form/Toggle/Toggle.tsx +10 -10
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +39 -39
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +12 -12
- package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +2 -8
- package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +55 -55
- package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +30 -35
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +35 -35
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +12 -12
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +55 -55
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +12 -12
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +2 -11
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +50 -50
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +22 -22
- package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +2 -2
- package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +11 -11
- package/src/Form/Wrapper/Wrapper/Wrapper.tsx +17 -17
- package/src/Form/form.interfaces.ts +1 -1
- package/src/Icon/Icon.module.scss +71 -71
- package/src/Icon/Icon.test.tsx +18 -18
- package/src/Icon/Icon.tsx +70 -70
- package/src/Link/Link.module.scss +5 -5
- package/src/Link/Link.test.tsx +76 -76
- package/src/Link/Link.tsx +27 -27
- package/src/Link/types.d.ts +1 -1
- package/src/Notifications/BaseModal/BaseModal.module.scss +1 -1
- package/src/Notifications/BaseModal/BaseModal.test.tsx +53 -53
- package/src/Notifications/BaseModal/BaseModal.tsx +16 -16
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +13 -13
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +5 -5
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +16 -16
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +5 -5
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +19 -19
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +10 -10
- package/src/Notifications/Dialog/Dialog.test.tsx +35 -35
- package/src/Notifications/Dialog/Dialog.tsx +19 -19
- package/src/Notifications/Dialog/DialogActions/DialogActions.test.tsx +14 -14
- package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +6 -6
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +12 -12
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +6 -6
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +20 -20
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +7 -7
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +36 -36
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.tsx +8 -8
- package/src/Notifications/Modal/Modal.test.tsx +6 -6
- package/src/Notifications/Modal/Modal.tsx +1 -1
- package/src/Notifications/Modal/ModalActions/ModalActions.tsx +2 -2
- package/src/Notifications/Modal/ModalContent/ModalContent.tsx +2 -2
- package/src/Notifications/Modal/ModalHeader/ModalHeader.tsx +2 -2
- package/src/Notifications/SlideInModal/SlideInModal.test.tsx +16 -16
- package/src/Notifications/SlideInModal/SlideInModal.tsx +16 -11
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +16 -16
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.tsx +6 -6
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +2 -2
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +17 -17
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +23 -23
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +32 -32
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +18 -18
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +3 -3
- package/src/Notifications/Snackbar/interfaces.ts +2 -2
- package/src/Notifications/Snackbar/useSnackbar.ts +2 -2
- package/src/Pagination/Pagination.module.scss +2 -0
- package/src/Pagination/Pagination.test.tsx +47 -47
- package/src/Pagination/Pagination.tsx +35 -35
- package/src/Popover/Popover.test.tsx +19 -19
- package/src/Popover/Popover.tsx +7 -7
- package/src/Skeleton/Skeleton.module.scss +2 -2
- package/src/Skeleton/Skeleton.test.tsx +29 -29
- package/src/Skeleton/Skeleton.tsx +10 -10
- package/src/StatusIndicator/StatusIndicator.test.tsx +38 -38
- package/src/StatusIndicator/StatusIndicator.tsx +9 -9
- package/src/Tabs/Tab.test.tsx +13 -13
- package/src/Tabs/Tab.tsx +1 -1
- package/src/Tabs/TabButton.test.tsx +28 -28
- package/src/Tabs/TabButton.tsx +7 -7
- package/src/Tabs/TabPanel.test.tsx +30 -30
- package/src/Tabs/TabPanel.tsx +4 -4
- package/src/Tabs/Tabs.test.tsx +93 -93
- package/src/Tabs/Tabs.tsx +25 -25
- package/src/TextEllipsis/TextEllipsis.test.tsx +22 -22
- package/src/TextEllipsis/TextEllipsis.tsx +6 -6
- package/src/Tiles/Tile.module.scss +1 -1
- package/src/Tiles/Tile.test.tsx +42 -42
- package/src/Tiles/Tile.tsx +22 -22
- package/src/Tiles/Tiles.test.tsx +30 -30
- package/src/Tiles/Tiles.tsx +9 -9
- package/src/Tooltip/Tooltip.test.tsx +35 -35
- package/src/Tooltip/Tooltip.tsx +21 -21
- package/src/Typography/Typography.module.scss +1 -1
- package/src/Typography/Typography.test.tsx +49 -49
- package/src/Typography/Typography.tsx +42 -42
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.module.scss +1 -1
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +26 -26
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +24 -24
- package/src/Wizard/Wizard.test.tsx +56 -56
- package/src/Wizard/Wizard.tsx +6 -6
- package/src/Wizard/WizardActions/WizardActions.test.tsx +34 -34
- package/src/Wizard/WizardActions/WizardActions.tsx +14 -14
- package/src/Wizard/WizardStateProvider.tsx +3 -3
- package/src/Wizard/WizardSteps/WizardSteps.test.tsx +27 -27
- package/src/Wizard/WizardSteps/WizardSteps.tsx +7 -7
- package/src/Wizard/wizardStateReducer.ts +9 -9
- package/src/_BaseStyling_/BaseStyling.test.tsx +14 -14
- package/src/_BaseStyling_/BaseStyling.tsx +50 -50
- package/src/hooks/useAnimation.test.tsx +12 -12
- package/src/hooks/useAnimation.ts +4 -4
- package/src/hooks/useBodyClick.test.tsx +8 -8
- package/src/hooks/useBodyClick.ts +3 -3
- package/src/hooks/useFormSelector.test.ts +17 -17
- package/src/hooks/useFormSelector.ts +4 -4
- package/src/hooks/usePosition.test.tsx +215 -215
- package/src/hooks/usePosition.ts +68 -68
- package/src/hooks/useRepeater.test.tsx +26 -26
- package/src/hooks/useRepeater.ts +5 -5
- package/src/hooks/useScroll.test.tsx +5 -5
- package/src/hooks/useScroll.ts +3 -3
- package/src/hooks/useSpacing.test.ts +40 -40
- package/src/hooks/useSpacing.ts +3 -3
- package/src/hooks/useWrapper.test.ts +12 -12
- package/src/hooks/useWrapper.ts +14 -7
- package/src/index.ts +67 -67
- package/src/mixins.module.scss +76 -27
- package/src/types.d.ts +1 -1
- package/src/util/helper.test.tsx +25 -25
- package/src/util/helper.tsx +64 -64
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, ReactElement, Ref, useEffect, useState } from
|
|
2
|
-
import { Props as ButtonProps } from
|
|
3
|
-
import classes from
|
|
4
|
-
import { DataGridHeader } from
|
|
5
|
-
import { DataGridActions } from
|
|
6
|
-
import { DataGridBody } from
|
|
7
|
-
import { ColumnName, HeaderCell, OnSortFunction, Sort } from
|
|
8
|
-
import { Pagination, Props as PaginationProps } from
|
|
9
|
-
import { Spacing, useSpacing } from
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactElement, Ref, useEffect, useState } from "react";
|
|
2
|
+
import { Props as ButtonProps } from "../Button/Button";
|
|
3
|
+
import classes from "./DataGrid.module.scss";
|
|
4
|
+
import { DataGridHeader } from "./DataGridHeader/DataGridHeader";
|
|
5
|
+
import { DataGridActions } from "./DataGridActions/DataGridActions";
|
|
6
|
+
import { DataGridBody } from "./DataGridBody/DataGridBody";
|
|
7
|
+
import { ColumnName, HeaderCell, OnSortFunction, Sort } from "./datagrid.interfaces";
|
|
8
|
+
import { Pagination, Props as PaginationProps } from "../Pagination/Pagination";
|
|
9
|
+
import { Spacing, useSpacing } from "../hooks/useSpacing";
|
|
10
10
|
|
|
11
|
-
export interface Props<T> extends ComponentPropsWithRef<
|
|
11
|
+
export interface Props<T> extends ComponentPropsWithRef<"div"> {
|
|
12
12
|
children: ({ item, index }: { item: T; index: number }) => ReactElement;
|
|
13
13
|
data?: T[];
|
|
14
14
|
initialSort?: Sort;
|
|
@@ -50,10 +50,10 @@ const DataGridInner = <T extends {}>(
|
|
|
50
50
|
ref: Ref<HTMLDivElement>
|
|
51
51
|
) => {
|
|
52
52
|
if (!headers) {
|
|
53
|
-
throw new Error(
|
|
53
|
+
throw new Error("Headers definition has to be provided");
|
|
54
54
|
}
|
|
55
55
|
if (!children) {
|
|
56
|
-
throw new Error(
|
|
56
|
+
throw new Error("DataGridBody should be provieded with a template how to render rows");
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const [internalHeaders, setInternalHeaders] = useState(headers);
|
|
@@ -63,14 +63,14 @@ const DataGridInner = <T extends {}>(
|
|
|
63
63
|
|
|
64
64
|
const onColumnToggled = (colName: ColumnName) => {
|
|
65
65
|
setInternalHeaders(
|
|
66
|
-
internalHeaders.map(
|
|
66
|
+
internalHeaders.map(item =>
|
|
67
67
|
item.name !== colName ? item : { ...item, hidden: !item.hidden }
|
|
68
68
|
)
|
|
69
69
|
);
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
if (styleWithSpacing?.padding) {
|
|
73
|
-
const splitPaddings = styleWithSpacing.padding.toString().split(
|
|
73
|
+
const splitPaddings = styleWithSpacing.padding.toString().split(" ");
|
|
74
74
|
|
|
75
75
|
let paddingLeftIndex: number = 0;
|
|
76
76
|
|
|
@@ -83,41 +83,41 @@ const DataGridInner = <T extends {}>(
|
|
|
83
83
|
|
|
84
84
|
Object.defineProperties(styleWithSpacing, {
|
|
85
85
|
paddingTop: {
|
|
86
|
-
value: splitPaddings[0]
|
|
86
|
+
value: splitPaddings[0]
|
|
87
87
|
},
|
|
88
88
|
paddingRight: {
|
|
89
|
-
value: splitPaddings[splitPaddings.length - 1 > 0 ? 1 : 0]
|
|
89
|
+
value: splitPaddings[splitPaddings.length - 1 > 0 ? 1 : 0]
|
|
90
90
|
},
|
|
91
91
|
paddingBottom: {
|
|
92
|
-
value: splitPaddings[splitPaddings.length / 3 >= 1 ? 2 : 0]
|
|
92
|
+
value: splitPaddings[splitPaddings.length / 3 >= 1 ? 2 : 0]
|
|
93
93
|
},
|
|
94
94
|
paddingLeft: {
|
|
95
|
-
value: splitPaddings[paddingLeftIndex]
|
|
96
|
-
}
|
|
95
|
+
value: splitPaddings[paddingLeftIndex]
|
|
96
|
+
}
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
return (
|
|
101
101
|
<div
|
|
102
102
|
{...rest}
|
|
103
|
-
className={classes[
|
|
103
|
+
className={classes["grid-wrapper"]}
|
|
104
104
|
ref={ref}
|
|
105
105
|
style={{
|
|
106
106
|
paddingTop: styleWithSpacing?.paddingTop,
|
|
107
|
-
paddingBottom: styleWithSpacing?.paddingBottom
|
|
107
|
+
paddingBottom: styleWithSpacing?.paddingBottom
|
|
108
108
|
}}
|
|
109
109
|
>
|
|
110
110
|
<DataGridActions
|
|
111
111
|
{...actions}
|
|
112
112
|
style={{
|
|
113
113
|
paddingLeft: styleWithSpacing?.paddingLeft,
|
|
114
|
-
paddingRight: styleWithSpacing?.paddingRight
|
|
114
|
+
paddingRight: styleWithSpacing?.paddingRight
|
|
115
115
|
}}
|
|
116
116
|
headers={internalHeaders}
|
|
117
117
|
onColumnToggled={onColumnToggled}
|
|
118
118
|
/>
|
|
119
|
-
<div className={classes[
|
|
120
|
-
<table className={classes[
|
|
119
|
+
<div className={classes["table-wrapper"]}>
|
|
120
|
+
<table className={classes["table"]}>
|
|
121
121
|
<DataGridHeader
|
|
122
122
|
headers={internalHeaders}
|
|
123
123
|
initialSort={initialSort}
|
|
@@ -143,9 +143,9 @@ const DataGridInner = <T extends {}>(
|
|
|
143
143
|
style={{
|
|
144
144
|
...paginationProps.style,
|
|
145
145
|
paddingLeft: styleWithSpacing?.paddingLeft,
|
|
146
|
-
paddingRight: styleWithSpacing?.paddingRight
|
|
146
|
+
paddingRight: styleWithSpacing?.paddingRight
|
|
147
147
|
}}
|
|
148
|
-
className={`${classes[
|
|
148
|
+
className={`${classes["pagination"]} ${paginationProps.className ?? ""}`}
|
|
149
149
|
/>
|
|
150
150
|
)}
|
|
151
151
|
</div>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { DataGridActions, Props } from
|
|
3
|
-
import { render } from
|
|
4
|
-
import userEvent from
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { DataGridActions, Props } from "./DataGridActions";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
5
|
|
|
6
6
|
const defaultParams: Props = {
|
|
7
7
|
headers: [],
|
|
8
|
-
onColumnToggled: jest.fn()
|
|
8
|
+
onColumnToggled: jest.fn()
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const createDataGridActions = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -14,115 +14,115 @@ const createDataGridActions = (params?: (defaultParams: Props) => Props) => {
|
|
|
14
14
|
parameters = params(defaultParams);
|
|
15
15
|
}
|
|
16
16
|
const queries = render(<DataGridActions {...parameters} data-testid="dataGridActions" />);
|
|
17
|
-
const dataGridActions = queries.getByTestId(
|
|
17
|
+
const dataGridActions = queries.getByTestId("dataGridActions");
|
|
18
18
|
|
|
19
19
|
return {
|
|
20
20
|
...queries,
|
|
21
|
-
dataGridActions
|
|
21
|
+
dataGridActions
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
describe(
|
|
26
|
-
it(
|
|
25
|
+
describe("DataGridActions should render", () => {
|
|
26
|
+
it("renders without crashing", () => {
|
|
27
27
|
const { container } = render(<DataGridActions {...defaultParams} />);
|
|
28
28
|
|
|
29
29
|
expect(container).toBeEmptyDOMElement();
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
it(
|
|
33
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(
|
|
32
|
+
it("renders all buttons", () => {
|
|
33
|
+
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
34
34
|
...params,
|
|
35
35
|
enableAddBtn: true,
|
|
36
36
|
enableColumnsBtn: true,
|
|
37
|
-
enableSearchBtn: true
|
|
37
|
+
enableSearchBtn: true
|
|
38
38
|
}));
|
|
39
39
|
|
|
40
40
|
expect(dataGridActions).toBeDefined();
|
|
41
|
-
const buttons = getAllByRole(
|
|
41
|
+
const buttons = getAllByRole("button");
|
|
42
42
|
expect(buttons).toHaveLength(5);
|
|
43
|
-
expect(buttons[0]).toHaveTextContent(
|
|
44
|
-
expect(buttons[1]).toHaveTextContent(
|
|
45
|
-
expect(buttons[2]).toHaveTextContent(
|
|
46
|
-
expect(buttons[3]).toHaveTextContent(
|
|
47
|
-
expect(buttons[4]).toHaveTextContent(
|
|
43
|
+
expect(buttons[0]).toHaveTextContent("Add item");
|
|
44
|
+
expect(buttons[1]).toHaveTextContent("Columns");
|
|
45
|
+
expect(buttons[2]).toHaveTextContent("Show/hide columns");
|
|
46
|
+
expect(buttons[3]).toHaveTextContent("Search");
|
|
47
|
+
expect(buttons[4]).toHaveTextContent("Search");
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
it(
|
|
51
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(
|
|
50
|
+
it("renders only add button", () => {
|
|
51
|
+
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
52
52
|
...params,
|
|
53
|
-
enableAddBtn: true
|
|
53
|
+
enableAddBtn: true
|
|
54
54
|
}));
|
|
55
55
|
|
|
56
56
|
expect(dataGridActions).toBeDefined();
|
|
57
|
-
const buttons = getAllByRole(
|
|
57
|
+
const buttons = getAllByRole("button");
|
|
58
58
|
expect(buttons).toHaveLength(1);
|
|
59
|
-
expect(buttons[0]).toHaveTextContent(
|
|
59
|
+
expect(buttons[0]).toHaveTextContent("Add item");
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
it(
|
|
63
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(
|
|
62
|
+
it("renders only columns button", () => {
|
|
63
|
+
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
64
64
|
...params,
|
|
65
|
-
enableColumnsBtn: true
|
|
65
|
+
enableColumnsBtn: true
|
|
66
66
|
}));
|
|
67
67
|
|
|
68
68
|
expect(dataGridActions).toBeDefined();
|
|
69
|
-
const buttons = getAllByRole(
|
|
69
|
+
const buttons = getAllByRole("button");
|
|
70
70
|
expect(buttons).toHaveLength(2);
|
|
71
|
-
expect(buttons[0]).toHaveTextContent(
|
|
72
|
-
expect(buttons[1]).toHaveTextContent(
|
|
71
|
+
expect(buttons[0]).toHaveTextContent("Columns");
|
|
72
|
+
expect(buttons[1]).toHaveTextContent("Show/hide columns");
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it(
|
|
76
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(
|
|
75
|
+
it("renders only search button", () => {
|
|
76
|
+
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
77
77
|
...params,
|
|
78
|
-
enableSearchBtn: true
|
|
78
|
+
enableSearchBtn: true
|
|
79
79
|
}));
|
|
80
80
|
|
|
81
81
|
expect(dataGridActions).toBeDefined();
|
|
82
|
-
const buttons = getAllByRole(
|
|
82
|
+
const buttons = getAllByRole("button");
|
|
83
83
|
expect(buttons).toHaveLength(2);
|
|
84
|
-
expect(buttons[0]).toHaveTextContent(
|
|
85
|
-
expect(buttons[1]).toHaveTextContent(
|
|
84
|
+
expect(buttons[0]).toHaveTextContent("Search");
|
|
85
|
+
expect(buttons[1]).toHaveTextContent("Search");
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
it(
|
|
89
|
-
const addBtnProps = { children:
|
|
90
|
-
const columnsBtnProps = { children:
|
|
91
|
-
const searchBtnProps = { children:
|
|
92
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(
|
|
88
|
+
it("renders buttons with overwritten props", () => {
|
|
89
|
+
const addBtnProps = { children: "button1", title: "title1" };
|
|
90
|
+
const columnsBtnProps = { children: "button2", title: "title2" };
|
|
91
|
+
const searchBtnProps = { children: "button3", title: "title3" };
|
|
92
|
+
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
93
93
|
...params,
|
|
94
94
|
enableAddBtn: true,
|
|
95
95
|
enableColumnsBtn: true,
|
|
96
96
|
enableSearchBtn: true,
|
|
97
97
|
addBtnProps,
|
|
98
98
|
columnsBtnProps,
|
|
99
|
-
searchBtnProps
|
|
99
|
+
searchBtnProps
|
|
100
100
|
}));
|
|
101
101
|
|
|
102
102
|
expect(dataGridActions).toBeDefined();
|
|
103
103
|
const [addBtn, desktopColumnsBtn, mobileColumnsBtn, desktopSearchBtn, mobileSearchBtn] =
|
|
104
|
-
getAllByRole(
|
|
104
|
+
getAllByRole("button");
|
|
105
105
|
expect(addBtn).toHaveTextContent(addBtnProps.children);
|
|
106
|
-
expect(addBtn).toHaveAttribute(
|
|
106
|
+
expect(addBtn).toHaveAttribute("title", addBtnProps.title);
|
|
107
107
|
expect(desktopColumnsBtn).toHaveTextContent(columnsBtnProps.children);
|
|
108
|
-
expect(desktopColumnsBtn).toHaveAttribute(
|
|
108
|
+
expect(desktopColumnsBtn).toHaveAttribute("title", columnsBtnProps.title);
|
|
109
109
|
expect(mobileColumnsBtn).toHaveTextContent(columnsBtnProps.title);
|
|
110
110
|
expect(desktopSearchBtn).toHaveTextContent(searchBtnProps.children);
|
|
111
|
-
expect(desktopSearchBtn).toHaveAttribute(
|
|
111
|
+
expect(desktopSearchBtn).toHaveAttribute("title", searchBtnProps.title);
|
|
112
112
|
expect(mobileSearchBtn).toHaveTextContent(searchBtnProps.title);
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
describe(
|
|
117
|
-
it(
|
|
118
|
-
const toggleHeader = { name:
|
|
119
|
-
const { getAllByRole, findByLabelText } = createDataGridActions(
|
|
116
|
+
describe("DataGridActions should be interactive", () => {
|
|
117
|
+
it("clicking on columns button opens show/hide columns popover", async () => {
|
|
118
|
+
const toggleHeader = { name: "test", headline: "Label" };
|
|
119
|
+
const { getAllByRole, findByLabelText } = createDataGridActions(params => ({
|
|
120
120
|
...params,
|
|
121
121
|
enableColumnsBtn: true,
|
|
122
|
-
headers: [toggleHeader]
|
|
122
|
+
headers: [toggleHeader]
|
|
123
123
|
}));
|
|
124
124
|
|
|
125
|
-
userEvent.click(getAllByRole(
|
|
125
|
+
userEvent.click(getAllByRole("button")[0]);
|
|
126
126
|
|
|
127
127
|
const toggle = await findByLabelText(toggleHeader.headline);
|
|
128
128
|
expect(toggle).toBeDefined();
|
|
@@ -132,37 +132,37 @@ describe('DataGridActions should be interactive', () => {
|
|
|
132
132
|
expect(defaultParams.onColumnToggled).toBeCalledWith(toggleHeader.name);
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
it(
|
|
135
|
+
it("clicking on add button runs callback", () => {
|
|
136
136
|
const onClick = jest.fn();
|
|
137
|
-
const { getAllByRole } = createDataGridActions(
|
|
137
|
+
const { getAllByRole } = createDataGridActions(params => ({
|
|
138
138
|
...params,
|
|
139
139
|
enableAddBtn: true,
|
|
140
|
-
addBtnProps: { onClick }
|
|
140
|
+
addBtnProps: { onClick }
|
|
141
141
|
}));
|
|
142
142
|
|
|
143
|
-
userEvent.click(getAllByRole(
|
|
143
|
+
userEvent.click(getAllByRole("button")[0]);
|
|
144
144
|
|
|
145
145
|
expect(onClick).toBeCalledTimes(1);
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
it(
|
|
148
|
+
it("clicking on search button runs callback", () => {
|
|
149
149
|
const onClick = jest.fn();
|
|
150
|
-
const { getAllByRole } = createDataGridActions(
|
|
150
|
+
const { getAllByRole } = createDataGridActions(params => ({
|
|
151
151
|
...params,
|
|
152
152
|
enableSearchBtn: true,
|
|
153
|
-
searchBtnProps: { onClick }
|
|
153
|
+
searchBtnProps: { onClick }
|
|
154
154
|
}));
|
|
155
155
|
|
|
156
|
-
userEvent.click(getAllByRole(
|
|
156
|
+
userEvent.click(getAllByRole("button")[0]);
|
|
157
157
|
|
|
158
158
|
expect(onClick).toBeCalledTimes(1);
|
|
159
159
|
});
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
-
describe(
|
|
163
|
-
it(
|
|
162
|
+
describe("ref should work", () => {
|
|
163
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
164
164
|
const ExampleComponent = ({
|
|
165
|
-
propagateRef
|
|
165
|
+
propagateRef
|
|
166
166
|
}: {
|
|
167
167
|
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
168
168
|
}) => {
|
|
@@ -176,7 +176,7 @@ describe('ref should work', () => {
|
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
179
|
-
expect(ref.current).toHaveAttribute(
|
|
179
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
180
180
|
};
|
|
181
181
|
|
|
182
182
|
render(<ExampleComponent propagateRef={refCheck} />);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, Fragment, useRef, useState } from
|
|
2
|
-
import { Button, Props as ButtonProps } from
|
|
3
|
-
import { IconButton } from
|
|
4
|
-
import { Icon, Icons } from
|
|
5
|
-
import { HeaderCell, ColumnName } from
|
|
6
|
-
import classes from
|
|
7
|
-
import { DataGridColumnsToggle } from
|
|
1
|
+
import React, { ComponentPropsWithRef, Fragment, useRef, useState } from "react";
|
|
2
|
+
import { Button, Props as ButtonProps } from "../../Button/Button";
|
|
3
|
+
import { IconButton } from "../../Button/IconButton";
|
|
4
|
+
import { Icon, Icons } from "../../Icon/Icon";
|
|
5
|
+
import { HeaderCell, ColumnName } from "../datagrid.interfaces";
|
|
6
|
+
import classes from "./DataGridActions.module.scss";
|
|
7
|
+
import { DataGridColumnsToggle } from "./DataGridColumnsToggle";
|
|
8
8
|
|
|
9
|
-
export interface Props extends ComponentPropsWithRef<
|
|
9
|
+
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
10
10
|
enableAddBtn?: boolean;
|
|
11
11
|
enableColumnsBtn?: boolean;
|
|
12
12
|
enableSearchBtn?: boolean;
|
|
@@ -38,8 +38,8 @@ export const DataGridActions = React.forwardRef<HTMLDivElement, Props>(
|
|
|
38
38
|
const showColumnBtn = useRef<HTMLButtonElement>(null);
|
|
39
39
|
|
|
40
40
|
return isHidden ? null : (
|
|
41
|
-
<div {...rest} ref={ref} className={`${classes[
|
|
42
|
-
<div className={classes[
|
|
41
|
+
<div {...rest} ref={ref} className={`${classes["actions"]} ${className ?? ""}`}>
|
|
42
|
+
<div className={classes["left-actions"]}>
|
|
43
43
|
{enableAddBtn && (
|
|
44
44
|
<Button
|
|
45
45
|
color="primary"
|
|
@@ -52,7 +52,7 @@ export const DataGridActions = React.forwardRef<HTMLDivElement, Props>(
|
|
|
52
52
|
/>
|
|
53
53
|
)}
|
|
54
54
|
</div>
|
|
55
|
-
<div className={classes[
|
|
55
|
+
<div className={classes["right-actions"]}>
|
|
56
56
|
{enableColumnsBtn && (
|
|
57
57
|
<Fragment>
|
|
58
58
|
<Button
|
|
@@ -61,7 +61,7 @@ export const DataGridActions = React.forwardRef<HTMLDivElement, Props>(
|
|
|
61
61
|
variant="text"
|
|
62
62
|
children="Columns"
|
|
63
63
|
{...columnsBtnProps}
|
|
64
|
-
className={`${classes[
|
|
64
|
+
className={`${classes["desktop"]} ${columnsBtnProps?.className ?? ""}`}
|
|
65
65
|
ref={showColumnBtn}
|
|
66
66
|
onClick={() => setShowColsPopover(true)}
|
|
67
67
|
/>
|
|
@@ -69,7 +69,7 @@ export const DataGridActions = React.forwardRef<HTMLDivElement, Props>(
|
|
|
69
69
|
title="Show/hide columns"
|
|
70
70
|
{...columnsBtnProps}
|
|
71
71
|
onClick={() => setShowColsPopover(true)}
|
|
72
|
-
className={`${classes[
|
|
72
|
+
className={`${classes["mobile"]} ${columnsBtnProps?.className ?? ""}`}
|
|
73
73
|
>
|
|
74
74
|
<Icon icon={Icons.Change} />
|
|
75
75
|
</IconButton>
|
|
@@ -91,12 +91,12 @@ export const DataGridActions = React.forwardRef<HTMLDivElement, Props>(
|
|
|
91
91
|
variant="text"
|
|
92
92
|
children="Search"
|
|
93
93
|
{...searchBtnProps}
|
|
94
|
-
className={`${classes[
|
|
94
|
+
className={`${classes["desktop"]} ${searchBtnProps?.className ?? ""}`}
|
|
95
95
|
/>
|
|
96
96
|
<IconButton
|
|
97
97
|
title="Search"
|
|
98
98
|
{...searchBtnProps}
|
|
99
|
-
className={`${classes[
|
|
99
|
+
className={`${classes["mobile"]} ${columnsBtnProps?.className ?? ""}`}
|
|
100
100
|
>
|
|
101
101
|
<Icon icon={Icons.TableSearch} />
|
|
102
102
|
</IconButton>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { DataGridColumnsToggle, Props } from
|
|
3
|
-
import { render } from
|
|
4
|
-
import userEvent from
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { DataGridColumnsToggle, Props } from "./DataGridColumnsToggle";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
5
|
|
|
6
6
|
const defaultParams: Props = {
|
|
7
7
|
open: true,
|
|
8
8
|
headers: [
|
|
9
|
-
{ headline:
|
|
10
|
-
{ headline:
|
|
9
|
+
{ headline: "Name", name: "name" },
|
|
10
|
+
{ headline: "Date", name: "date", hidden: true }
|
|
11
11
|
],
|
|
12
12
|
onClose: jest.fn(),
|
|
13
|
-
onToggleClicked: jest.fn()
|
|
13
|
+
onToggleClicked: jest.fn()
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
const createDataGridColumnsToggle = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -21,47 +21,47 @@ const createDataGridColumnsToggle = (params?: (defaultParams: Props) => Props) =
|
|
|
21
21
|
const queries = render(
|
|
22
22
|
<DataGridColumnsToggle {...parameters} data-testid="dataGridColumnsToggle" />
|
|
23
23
|
);
|
|
24
|
-
const dataGridColumnsToggle = queries.getByTestId(
|
|
24
|
+
const dataGridColumnsToggle = queries.getByTestId("dataGridColumnsToggle");
|
|
25
25
|
|
|
26
26
|
return {
|
|
27
27
|
...queries,
|
|
28
|
-
dataGridColumnsToggle
|
|
28
|
+
dataGridColumnsToggle
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
describe(
|
|
33
|
-
it(
|
|
32
|
+
describe("DataGridColumnsToggle should render", () => {
|
|
33
|
+
it("renders without crashing", () => {
|
|
34
34
|
const { dataGridColumnsToggle, getByLabelText, getByText } = createDataGridColumnsToggle();
|
|
35
35
|
|
|
36
36
|
expect(dataGridColumnsToggle).toBeDefined();
|
|
37
|
-
expect(getByText(
|
|
37
|
+
expect(getByText("Show columns")).toBeDefined();
|
|
38
38
|
expect(getByLabelText(defaultParams.headers[0].headline)).toBeChecked();
|
|
39
39
|
expect(getByLabelText(defaultParams.headers[1].headline)).not.toBeChecked();
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
describe(
|
|
44
|
-
it(
|
|
43
|
+
describe("DataGridColumnsToggle should be interactive", () => {
|
|
44
|
+
it("clicking on close calls onClose callback", () => {
|
|
45
45
|
const { getByRole } = createDataGridColumnsToggle();
|
|
46
46
|
|
|
47
|
-
userEvent.click(getByRole(
|
|
47
|
+
userEvent.click(getByRole("button"));
|
|
48
48
|
|
|
49
49
|
expect(defaultParams.onClose).toBeCalledTimes(1);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it(
|
|
52
|
+
it("clicking outside of container (on backdrop layer) calls onClose callback", () => {
|
|
53
53
|
createDataGridColumnsToggle();
|
|
54
54
|
|
|
55
|
-
userEvent.click(document.querySelector(
|
|
55
|
+
userEvent.click(document.querySelector(".backdrop")!);
|
|
56
56
|
|
|
57
57
|
expect(defaultParams.onClose).toBeCalledTimes(1);
|
|
58
58
|
});
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
describe(
|
|
62
|
-
it(
|
|
61
|
+
describe("ref should work", () => {
|
|
62
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
63
63
|
const ExampleComponent = ({
|
|
64
|
-
propagateRef
|
|
64
|
+
propagateRef
|
|
65
65
|
}: {
|
|
66
66
|
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
67
67
|
}) => {
|
|
@@ -75,7 +75,7 @@ describe('ref should work', () => {
|
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
78
|
-
expect(ref.current).toHaveAttribute(
|
|
78
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
render(<ExampleComponent propagateRef={refCheck} />);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import React, { Fragment, useState } from
|
|
2
|
-
import { IconButton } from
|
|
3
|
-
import { Toggle } from
|
|
4
|
-
import { Icon, Icons } from
|
|
5
|
-
import { Popover, Props as PopoverProps } from
|
|
6
|
-
import { Typography } from
|
|
7
|
-
import { generateID } from
|
|
8
|
-
import { ColumnName, HeaderCell } from
|
|
9
|
-
import classes from
|
|
10
|
-
import { createPortal } from
|
|
1
|
+
import React, { Fragment, useState } from "react";
|
|
2
|
+
import { IconButton } from "../../Button/IconButton";
|
|
3
|
+
import { Toggle } from "../../Form/Toggle/Toggle";
|
|
4
|
+
import { Icon, Icons } from "../../Icon/Icon";
|
|
5
|
+
import { Popover, Props as PopoverProps } from "../../Popover/Popover";
|
|
6
|
+
import { Typography } from "../../Typography/Typography";
|
|
7
|
+
import { generateID } from "../../util/helper";
|
|
8
|
+
import { ColumnName, HeaderCell } from "../datagrid.interfaces";
|
|
9
|
+
import classes from "./DataGridColumnsToggle.module.scss";
|
|
10
|
+
import { createPortal } from "react-dom";
|
|
11
11
|
|
|
12
12
|
export interface Props extends PopoverProps {
|
|
13
13
|
open: boolean;
|
|
@@ -24,8 +24,8 @@ export const DataGridColumnsToggle = React.forwardRef<HTMLDivElement, Props>(
|
|
|
24
24
|
{
|
|
25
25
|
open,
|
|
26
26
|
headers,
|
|
27
|
-
titleLabel =
|
|
28
|
-
closeButtonTitle =
|
|
27
|
+
titleLabel = "Show columns",
|
|
28
|
+
closeButtonTitle = "Close show columns dialog",
|
|
29
29
|
onClose,
|
|
30
30
|
onToggleClicked,
|
|
31
31
|
className,
|
|
@@ -35,9 +35,9 @@ export const DataGridColumnsToggle = React.forwardRef<HTMLDivElement, Props>(
|
|
|
35
35
|
ref
|
|
36
36
|
) => {
|
|
37
37
|
const [id] = useState(generateID());
|
|
38
|
-
const labelledId = id +
|
|
38
|
+
const labelledId = id + "_header";
|
|
39
39
|
|
|
40
|
-
const toggles = headers.map(
|
|
40
|
+
const toggles = headers.map(item => (
|
|
41
41
|
<Toggle
|
|
42
42
|
key={item.name}
|
|
43
43
|
name={item.name}
|
|
@@ -54,7 +54,7 @@ export const DataGridColumnsToggle = React.forwardRef<HTMLDivElement, Props>(
|
|
|
54
54
|
<Popover
|
|
55
55
|
{...rest}
|
|
56
56
|
ref={ref}
|
|
57
|
-
className={`${classes[
|
|
57
|
+
className={`${classes["popover"]} ${className}`}
|
|
58
58
|
show={open}
|
|
59
59
|
role="dialog"
|
|
60
60
|
aria-modal="true"
|
|
@@ -62,24 +62,24 @@ export const DataGridColumnsToggle = React.forwardRef<HTMLDivElement, Props>(
|
|
|
62
62
|
>
|
|
63
63
|
{open &&
|
|
64
64
|
createPortal(
|
|
65
|
-
<div className={classes[
|
|
65
|
+
<div className={classes["backdrop"]} onClick={handleBackdropClick}></div>,
|
|
66
66
|
domRoot
|
|
67
67
|
)}
|
|
68
68
|
{open && (
|
|
69
69
|
<Fragment>
|
|
70
|
-
<div className={classes[
|
|
71
|
-
<Typography id={labelledId} className={classes[
|
|
70
|
+
<div className={classes["header"]}>
|
|
71
|
+
<Typography id={labelledId} className={classes["title"]} tag="span" variant="h4">
|
|
72
72
|
{titleLabel}
|
|
73
73
|
</Typography>
|
|
74
74
|
<IconButton
|
|
75
75
|
onClick={onClose}
|
|
76
|
-
className={`${classes[
|
|
76
|
+
className={`${classes["close-btn"]}`}
|
|
77
77
|
title={closeButtonTitle}
|
|
78
78
|
>
|
|
79
79
|
<Icon icon={Icons.Times} />
|
|
80
80
|
</IconButton>
|
|
81
81
|
</div>
|
|
82
|
-
<div className={classes[
|
|
82
|
+
<div className={classes["content"]}>{toggles}</div>
|
|
83
83
|
</Fragment>
|
|
84
84
|
)}
|
|
85
85
|
</Popover>
|