@onewelcome/react-lib-components 0.2.1 → 0.2.4
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 +2 -2
- 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 +5 -5
- 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/interfaces.d.ts +1 -1
- package/dist/react-lib-components.cjs.development.js +683 -581
- 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 +683 -581
- 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 +8 -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 +9 -9
- 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 +2 -2
- 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 +2 -2
- 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 +73 -72
- 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 +10 -10
- package/src/index.ts +67 -67
- package/src/interfaces.ts +1 -1
- 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
package/src/hooks/usePosition.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
|
|
3
3
|
export interface ConfigObject {
|
|
4
4
|
relativeElement: RefElement;
|
|
@@ -8,10 +8,10 @@ export interface ConfigObject {
|
|
|
8
8
|
offset?: Offset;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type
|
|
12
|
-
export type VerticalPlacement =
|
|
11
|
+
export type HorizontalPlacement = "left" | "center" | "centerh" | "right";
|
|
12
|
+
export type VerticalPlacement = "top" | "center" | "centerv" | "bottom";
|
|
13
13
|
|
|
14
|
-
type Axis =
|
|
14
|
+
type Axis = "vertical" | "horizontal";
|
|
15
15
|
type RefElement = React.RefObject<HTMLOrSVGElement> | undefined;
|
|
16
16
|
|
|
17
17
|
interface DomRectObject {
|
|
@@ -29,7 +29,7 @@ interface DomRectObject {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export interface Placement {
|
|
32
|
-
horizontal:
|
|
32
|
+
horizontal: HorizontalPlacement;
|
|
33
33
|
vertical: VerticalPlacement;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -52,27 +52,28 @@ interface Dimensions {
|
|
|
52
52
|
width: number;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
type PositionType = number |
|
|
55
|
+
type PositionType = number | "initial";
|
|
56
56
|
|
|
57
57
|
const defaultConfigObject: ConfigObject = {
|
|
58
58
|
relativeElement: undefined,
|
|
59
59
|
elementToBePositioned: undefined,
|
|
60
60
|
transformOrigin: {
|
|
61
|
-
horizontal:
|
|
62
|
-
vertical:
|
|
61
|
+
horizontal: "left",
|
|
62
|
+
vertical: "top"
|
|
63
63
|
},
|
|
64
64
|
placement: {
|
|
65
|
-
horizontal:
|
|
66
|
-
vertical:
|
|
65
|
+
horizontal: "left",
|
|
66
|
+
vertical: "top"
|
|
67
67
|
},
|
|
68
68
|
offset: {
|
|
69
69
|
top: 0,
|
|
70
70
|
right: 0,
|
|
71
71
|
bottom: 0,
|
|
72
|
-
left: 0
|
|
73
|
-
}
|
|
72
|
+
left: 0
|
|
73
|
+
}
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain*/
|
|
76
77
|
export const usePosition = (providedConfigObject: ConfigObject = defaultConfigObject) => {
|
|
77
78
|
const configObject = { ...defaultConfigObject, ...providedConfigObject };
|
|
78
79
|
|
|
@@ -91,8 +92,8 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
91
92
|
const [position, setPosition] = useState<Position>({
|
|
92
93
|
left: 0,
|
|
93
94
|
top: 0,
|
|
94
|
-
right:
|
|
95
|
-
bottom:
|
|
95
|
+
right: "initial",
|
|
96
|
+
bottom: "initial"
|
|
96
97
|
});
|
|
97
98
|
|
|
98
99
|
const _fixPossibleViewportOverflow = (
|
|
@@ -104,43 +105,43 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
104
105
|
let returnValue = value;
|
|
105
106
|
|
|
106
107
|
if (
|
|
107
|
-
(transformOrigin[requestedReturnValue] ===
|
|
108
|
-
(transformOrigin[requestedReturnValue] ===
|
|
109
|
-
(transformOrigin[requestedReturnValue] ===
|
|
110
|
-
(transformOrigin[requestedReturnValue] ===
|
|
108
|
+
(transformOrigin[requestedReturnValue] === "left" && returnValue < 0) ||
|
|
109
|
+
(transformOrigin[requestedReturnValue] === "top" && returnValue < 0) ||
|
|
110
|
+
(transformOrigin[requestedReturnValue] === "center" && returnValue < 0) ||
|
|
111
|
+
(transformOrigin[requestedReturnValue] === "bottom" && returnValue < 0)
|
|
111
112
|
) {
|
|
112
113
|
returnValue = 0;
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
if (
|
|
116
|
-
(transformOrigin[requestedReturnValue] ===
|
|
117
|
+
(transformOrigin[requestedReturnValue] === "left" &&
|
|
117
118
|
returnValue > window.innerWidth - elDimensions.width) ||
|
|
118
|
-
(transformOrigin[requestedReturnValue] ===
|
|
119
|
-
requestedReturnValue ===
|
|
119
|
+
(transformOrigin[requestedReturnValue] === "center" &&
|
|
120
|
+
requestedReturnValue === "horizontal" &&
|
|
120
121
|
returnValue > window.innerWidth - elDimensions.width)
|
|
121
122
|
) {
|
|
122
123
|
returnValue = window.innerWidth - elDimensions.width;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
if (
|
|
126
|
-
(transformOrigin[requestedReturnValue] ===
|
|
127
|
+
(transformOrigin[requestedReturnValue] === "top" &&
|
|
127
128
|
returnValue > window.innerHeight - elDimensions.height) ||
|
|
128
|
-
(transformOrigin[requestedReturnValue] ===
|
|
129
|
-
requestedReturnValue ===
|
|
129
|
+
(transformOrigin[requestedReturnValue] === "center" &&
|
|
130
|
+
requestedReturnValue === "vertical" &&
|
|
130
131
|
returnValue > window.innerHeight - elDimensions.height)
|
|
131
132
|
) {
|
|
132
133
|
returnValue = window.innerHeight - elDimensions.height;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
if (
|
|
136
|
-
transformOrigin[requestedReturnValue] ===
|
|
137
|
+
transformOrigin[requestedReturnValue] === "right" &&
|
|
137
138
|
returnValue > window.innerWidth - elDimensions.width
|
|
138
139
|
) {
|
|
139
140
|
returnValue = window.innerWidth - elDimensions.width;
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
if (
|
|
143
|
-
transformOrigin[requestedReturnValue] ===
|
|
144
|
+
transformOrigin[requestedReturnValue] === "bottom" &&
|
|
144
145
|
returnValue > window.innerHeight - elDimensions.height
|
|
145
146
|
) {
|
|
146
147
|
returnValue = window.innerHeight - elDimensions.height;
|
|
@@ -156,36 +157,36 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
156
157
|
) => {
|
|
157
158
|
let returnValue = value;
|
|
158
159
|
if (
|
|
159
|
-
(requestedReturnValue ===
|
|
160
|
-
(requestedReturnValue ===
|
|
160
|
+
(requestedReturnValue === "horizontal" && configObject.offset?.left !== 0) ||
|
|
161
|
+
(requestedReturnValue === "horizontal" && configObject.offset?.right !== 0)
|
|
161
162
|
) {
|
|
162
163
|
if (
|
|
163
|
-
transformOrigin[requestedReturnValue] ===
|
|
164
|
-
transformOrigin[requestedReturnValue] ===
|
|
164
|
+
transformOrigin[requestedReturnValue] === "left" ||
|
|
165
|
+
transformOrigin[requestedReturnValue] === "center"
|
|
165
166
|
) {
|
|
166
167
|
returnValue += configObject.offset?.left!;
|
|
167
168
|
returnValue -= configObject.offset?.right!;
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
if (transformOrigin[requestedReturnValue] ===
|
|
171
|
+
if (transformOrigin[requestedReturnValue] === "right") {
|
|
171
172
|
returnValue -= configObject.offset?.left!;
|
|
172
173
|
returnValue += configObject.offset?.right!;
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
if (
|
|
177
|
-
(requestedReturnValue ===
|
|
178
|
-
(requestedReturnValue ===
|
|
178
|
+
(requestedReturnValue === "vertical" && configObject.offset?.top !== 0) ||
|
|
179
|
+
(requestedReturnValue === "vertical" && configObject.offset?.bottom !== 0)
|
|
179
180
|
) {
|
|
180
181
|
if (
|
|
181
|
-
transformOrigin[requestedReturnValue] ===
|
|
182
|
-
transformOrigin[requestedReturnValue] ===
|
|
182
|
+
transformOrigin[requestedReturnValue] === "top" ||
|
|
183
|
+
transformOrigin[requestedReturnValue] === "center"
|
|
183
184
|
) {
|
|
184
185
|
returnValue += configObject.offset?.top!;
|
|
185
186
|
returnValue -= configObject.offset?.bottom!;
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
if (transformOrigin[requestedReturnValue] ===
|
|
189
|
+
if (transformOrigin[requestedReturnValue] === "bottom") {
|
|
189
190
|
returnValue -= configObject.offset?.top!;
|
|
190
191
|
returnValue += configObject.offset?.bottom!;
|
|
191
192
|
}
|
|
@@ -198,26 +199,26 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
198
199
|
transformOrigin: Placement,
|
|
199
200
|
requestedReturnValue: Axis,
|
|
200
201
|
relEl: DomRectObject,
|
|
201
|
-
placementOriginDefinition:
|
|
202
|
+
placementOriginDefinition: HorizontalPlacement | VerticalPlacement,
|
|
202
203
|
elDimensions: Dimensions
|
|
203
204
|
) => {
|
|
204
205
|
let value = 0;
|
|
205
206
|
|
|
206
207
|
if (
|
|
207
|
-
transformOrigin[requestedReturnValue] ===
|
|
208
|
-
transformOrigin[requestedReturnValue] ===
|
|
208
|
+
transformOrigin[requestedReturnValue] === "left" ||
|
|
209
|
+
transformOrigin[requestedReturnValue] === "top"
|
|
209
210
|
) {
|
|
210
211
|
value = relEl[placementOriginDefinition];
|
|
211
|
-
} else if (transformOrigin[requestedReturnValue] ===
|
|
212
|
+
} else if (transformOrigin[requestedReturnValue] === "center") {
|
|
212
213
|
value =
|
|
213
214
|
relEl[placementOriginDefinition] -
|
|
214
|
-
elDimensions[requestedReturnValue ===
|
|
215
|
+
elDimensions[requestedReturnValue === "horizontal" ? "width" : "height"] / 2;
|
|
215
216
|
} else if (
|
|
216
|
-
transformOrigin[requestedReturnValue] ===
|
|
217
|
-
transformOrigin[requestedReturnValue] ===
|
|
217
|
+
transformOrigin[requestedReturnValue] === "right" ||
|
|
218
|
+
transformOrigin[requestedReturnValue] === "bottom"
|
|
218
219
|
) {
|
|
219
220
|
value =
|
|
220
|
-
window[requestedReturnValue ===
|
|
221
|
+
window[requestedReturnValue === "horizontal" ? "innerWidth" : "innerHeight"] -
|
|
221
222
|
relEl[placementOriginDefinition];
|
|
222
223
|
}
|
|
223
224
|
|
|
@@ -230,25 +231,25 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
230
231
|
* @returns either the horizontally centered placement definition (centerh) or the vertically centered one (centerv)
|
|
231
232
|
*/
|
|
232
233
|
const _determineCenteredPlacementOrigin = (requestedReturnValue: Axis) => {
|
|
233
|
-
if (requestedReturnValue ===
|
|
234
|
-
return
|
|
235
|
-
} else if (requestedReturnValue ===
|
|
236
|
-
return
|
|
234
|
+
if (requestedReturnValue === "horizontal") {
|
|
235
|
+
return "centerh";
|
|
236
|
+
} else if (requestedReturnValue === "vertical") {
|
|
237
|
+
return "centerv";
|
|
237
238
|
}
|
|
238
239
|
throw new Error(
|
|
239
|
-
`the requested return value isn
|
|
240
|
+
`the requested return value isn't "vertical" or "horizontal" ${requestedReturnValue} was given.`
|
|
240
241
|
);
|
|
241
242
|
};
|
|
242
243
|
|
|
243
244
|
const _calculatePlacementValue = (
|
|
244
245
|
transformOrigin: Placement,
|
|
245
|
-
placement:
|
|
246
|
+
placement: HorizontalPlacement | VerticalPlacement,
|
|
246
247
|
requestedReturnValue: Axis,
|
|
247
248
|
relEl: DomRectObject,
|
|
248
249
|
elDimensions: Dimensions
|
|
249
250
|
): number => {
|
|
250
251
|
const placementOriginDefinition =
|
|
251
|
-
placement ===
|
|
252
|
+
placement === "center" ? _determineCenteredPlacementOrigin(requestedReturnValue) : placement;
|
|
252
253
|
|
|
253
254
|
const value = _calculateInitialPlacementValue(
|
|
254
255
|
transformOrigin,
|
|
@@ -283,29 +284,29 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
283
284
|
elDimensions
|
|
284
285
|
);
|
|
285
286
|
|
|
286
|
-
let direction =
|
|
287
|
-
let oppositeDirection =
|
|
287
|
+
let direction = "left";
|
|
288
|
+
let oppositeDirection = "right";
|
|
288
289
|
|
|
289
|
-
if (axis ===
|
|
290
|
-
direction =
|
|
291
|
-
oppositeDirection =
|
|
292
|
-
} else if (axis ===
|
|
293
|
-
direction =
|
|
294
|
-
oppositeDirection =
|
|
290
|
+
if (axis === "horizontal" && configObject.transformOrigin?.horizontal === "right") {
|
|
291
|
+
direction = "right";
|
|
292
|
+
oppositeDirection = "left";
|
|
293
|
+
} else if (axis === "horizontal") {
|
|
294
|
+
direction = "left";
|
|
295
|
+
oppositeDirection = "right";
|
|
295
296
|
}
|
|
296
297
|
|
|
297
|
-
if (axis ===
|
|
298
|
-
direction =
|
|
299
|
-
oppositeDirection =
|
|
300
|
-
} else if (axis ===
|
|
301
|
-
direction =
|
|
302
|
-
oppositeDirection =
|
|
298
|
+
if (axis === "vertical" && configObject.transformOrigin?.vertical === "bottom") {
|
|
299
|
+
direction = "bottom";
|
|
300
|
+
oppositeDirection = "top";
|
|
301
|
+
} else if (axis === "vertical") {
|
|
302
|
+
direction = "top";
|
|
303
|
+
oppositeDirection = "bottom";
|
|
303
304
|
}
|
|
304
305
|
|
|
305
|
-
setPosition(
|
|
306
|
+
setPosition(prevState => ({
|
|
306
307
|
...prevState,
|
|
307
308
|
[direction]: placementValue,
|
|
308
|
-
[oppositeDirection]:
|
|
309
|
+
[oppositeDirection]: "initial"
|
|
309
310
|
}));
|
|
310
311
|
};
|
|
311
312
|
|
|
@@ -315,7 +316,7 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
315
316
|
.current as HTMLElement)!.getBoundingClientRect();
|
|
316
317
|
const elementToBePositionedDimensions: Dimensions = {
|
|
317
318
|
height: (configObject.elementToBePositioned!.current as HTMLElement).offsetHeight,
|
|
318
|
-
width: (configObject.elementToBePositioned!.current as HTMLElement).offsetWidth
|
|
319
|
+
width: (configObject.elementToBePositioned!.current as HTMLElement).offsetWidth
|
|
319
320
|
};
|
|
320
321
|
|
|
321
322
|
/** We want to add a center (horizontal and vertical) property to the DOMRect object. Since it's a special object we can't modify so we clone it and add it. */
|
|
@@ -330,11 +331,11 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
330
331
|
width: relativeElRect.width,
|
|
331
332
|
height: relativeElRect.height,
|
|
332
333
|
x: relativeElRect.x,
|
|
333
|
-
y: relativeElRect.y
|
|
334
|
+
y: relativeElRect.y
|
|
334
335
|
};
|
|
335
336
|
|
|
336
|
-
_calculatePlacement(clonedRelEl, elementToBePositionedDimensions,
|
|
337
|
-
_calculatePlacement(clonedRelEl, elementToBePositionedDimensions,
|
|
337
|
+
_calculatePlacement(clonedRelEl, elementToBePositionedDimensions, "horizontal");
|
|
338
|
+
_calculatePlacement(clonedRelEl, elementToBePositionedDimensions, "vertical");
|
|
338
339
|
};
|
|
339
340
|
|
|
340
341
|
return {
|
|
@@ -342,6 +343,6 @@ export const usePosition = (providedConfigObject: ConfigObject = defaultConfigOb
|
|
|
342
343
|
bottom: position.bottom,
|
|
343
344
|
left: position.left,
|
|
344
345
|
right: position.right,
|
|
345
|
-
calculatePosition
|
|
346
|
+
calculatePosition
|
|
346
347
|
};
|
|
347
348
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { Fragment, useEffect, useState } from
|
|
2
|
-
import { useRepeater } from
|
|
3
|
-
import { render } from
|
|
4
|
-
import { InputWrapper } from
|
|
5
|
-
import { generateID } from
|
|
6
|
-
import userEvent from
|
|
1
|
+
import React, { Fragment, useEffect, useState } from "react";
|
|
2
|
+
import { useRepeater } from "./useRepeater";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { InputWrapper } from "../Form/Wrapper/InputWrapper/InputWrapper";
|
|
5
|
+
import { generateID } from "../util/helper";
|
|
6
|
+
import userEvent from "@testing-library/user-event";
|
|
7
7
|
|
|
8
8
|
export interface RepeatedComponentProps {
|
|
9
9
|
onChange?: (state: { [key: string]: unknown }) => void;
|
|
@@ -12,10 +12,10 @@ export interface RepeatedComponentProps {
|
|
|
12
12
|
|
|
13
13
|
const ComponentToRepeat = ({ onChange, identifier }: RepeatedComponentProps) => {
|
|
14
14
|
const [inputState, setInputState] = useState({
|
|
15
|
-
errorMessage:
|
|
15
|
+
errorMessage: "random error",
|
|
16
16
|
error: false,
|
|
17
|
-
value:
|
|
18
|
-
identifier: identifier
|
|
17
|
+
value: "",
|
|
18
|
+
identifier: identifier
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
useEffect(() => {
|
|
@@ -31,27 +31,27 @@ const ComponentToRepeat = ({ onChange, identifier }: RepeatedComponentProps) =>
|
|
|
31
31
|
error={inputState.error}
|
|
32
32
|
value={inputState.value}
|
|
33
33
|
label="Label for this inputfield"
|
|
34
|
-
onChange={
|
|
35
|
-
setInputState(
|
|
34
|
+
onChange={event => {
|
|
35
|
+
setInputState(prevState => ({ ...prevState, value: event.target.value }));
|
|
36
36
|
}}
|
|
37
37
|
/>
|
|
38
38
|
);
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
describe(
|
|
42
|
-
it(
|
|
41
|
+
describe("useRepeater should render", () => {
|
|
42
|
+
it("renders without crashing and repeats 1 item", () => {
|
|
43
43
|
const onChangeHandler = jest.fn();
|
|
44
44
|
|
|
45
45
|
const App = () => {
|
|
46
46
|
const { repeatedComponents } = useRepeater({
|
|
47
|
-
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler}
|
|
47
|
+
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler} />
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
return (
|
|
51
51
|
<div>
|
|
52
52
|
{repeatedComponents.map((component, index) =>
|
|
53
53
|
React.cloneElement(component, {
|
|
54
|
-
identifier: `component_${index}
|
|
54
|
+
identifier: `component_${index}`
|
|
55
55
|
})
|
|
56
56
|
)}
|
|
57
57
|
</div>
|
|
@@ -60,17 +60,17 @@ describe('useRepeater should render', () => {
|
|
|
60
60
|
|
|
61
61
|
const renderedItems = render(<App />);
|
|
62
62
|
|
|
63
|
-
const inputWrappers = renderedItems.container.querySelectorAll(
|
|
63
|
+
const inputWrappers = renderedItems.container.querySelectorAll(".wrapper.input-wrapper");
|
|
64
64
|
|
|
65
65
|
expect(inputWrappers.length).toBe(1);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
it(
|
|
68
|
+
it("should repeat 2 items", () => {
|
|
69
69
|
const onChangeHandler = jest.fn();
|
|
70
70
|
|
|
71
71
|
const App = () => {
|
|
72
72
|
const { repeatedComponents, repeat } = useRepeater({
|
|
73
|
-
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler}
|
|
73
|
+
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler} />
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
useEffect(() => {
|
|
@@ -81,7 +81,7 @@ describe('useRepeater should render', () => {
|
|
|
81
81
|
<div>
|
|
82
82
|
{repeatedComponents.map((component, index) =>
|
|
83
83
|
React.cloneElement(component, {
|
|
84
|
-
identifier: `component_${index}
|
|
84
|
+
identifier: `component_${index}`
|
|
85
85
|
})
|
|
86
86
|
)}
|
|
87
87
|
</div>
|
|
@@ -90,17 +90,17 @@ describe('useRepeater should render', () => {
|
|
|
90
90
|
|
|
91
91
|
const renderedItems = render(<App />);
|
|
92
92
|
|
|
93
|
-
const inputWrappers = renderedItems.container.querySelectorAll(
|
|
93
|
+
const inputWrappers = renderedItems.container.querySelectorAll(".wrapper.input-wrapper");
|
|
94
94
|
|
|
95
95
|
expect(inputWrappers.length).toBe(2);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
it(
|
|
98
|
+
it("should repeat 3 items and remove the first index", () => {
|
|
99
99
|
const onChangeHandler = jest.fn();
|
|
100
100
|
|
|
101
101
|
const App = () => {
|
|
102
102
|
const { repeatedComponents, repeat, remove } = useRepeater({
|
|
103
|
-
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler}
|
|
103
|
+
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler} />
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
useEffect(() => {
|
|
@@ -113,7 +113,7 @@ describe('useRepeater should render', () => {
|
|
|
113
113
|
{repeatedComponents.map((component, index) => (
|
|
114
114
|
<Fragment key={index}>
|
|
115
115
|
{React.cloneElement(component, {
|
|
116
|
-
identifier: generateID()
|
|
116
|
+
identifier: generateID()
|
|
117
117
|
})}
|
|
118
118
|
<button id={`remove_input_${index}`} onClick={() => remove(component)}>
|
|
119
119
|
Remove
|
|
@@ -126,14 +126,14 @@ describe('useRepeater should render', () => {
|
|
|
126
126
|
|
|
127
127
|
const renderedItems = render(<App />);
|
|
128
128
|
|
|
129
|
-
const secondInputID = renderedItems.container.querySelectorAll(
|
|
129
|
+
const secondInputID = renderedItems.container.querySelectorAll(".input-wrapper input")[1].id;
|
|
130
130
|
|
|
131
|
-
const removeButton = renderedItems.container.querySelector(
|
|
131
|
+
const removeButton = renderedItems.container.querySelector("#remove_input_1");
|
|
132
132
|
|
|
133
133
|
userEvent.click(removeButton!);
|
|
134
134
|
|
|
135
135
|
expect(renderedItems.container.querySelector(`#${secondInputID}`)).toBeFalsy();
|
|
136
|
-
const inputWrappers = renderedItems.container.querySelectorAll(
|
|
136
|
+
const inputWrappers = renderedItems.container.querySelectorAll(".wrapper.input-wrapper");
|
|
137
137
|
expect(inputWrappers.length).toBe(2);
|
|
138
138
|
});
|
|
139
139
|
});
|
package/src/hooks/useRepeater.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useEffect, useState } from
|
|
2
|
-
import { generateID } from
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { generateID } from "../util/helper";
|
|
3
3
|
|
|
4
4
|
interface Arguments {
|
|
5
5
|
componentToRepeat: React.ReactElement;
|
|
@@ -15,12 +15,12 @@ export const useRepeater = <T>({ componentToRepeat }: Arguments) => {
|
|
|
15
15
|
const repeat = () => {
|
|
16
16
|
const clonedComponent = React.cloneElement(componentToRepeat, { key: generateID(20) });
|
|
17
17
|
|
|
18
|
-
setRepeatedComponents(
|
|
18
|
+
setRepeatedComponents(prevState => [...prevState, clonedComponent]);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const remove = (componentToRemove: React.ReactElement<T>) => {
|
|
22
22
|
const newRepeatedComponents = repeatedComponents.filter(
|
|
23
|
-
|
|
23
|
+
component => component !== componentToRemove
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
setRepeatedComponents(newRepeatedComponents);
|
|
@@ -29,6 +29,6 @@ export const useRepeater = <T>({ componentToRepeat }: Arguments) => {
|
|
|
29
29
|
return {
|
|
30
30
|
repeatedComponents,
|
|
31
31
|
repeat,
|
|
32
|
-
remove
|
|
32
|
+
remove
|
|
33
33
|
};
|
|
34
34
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { fireEvent, render } from
|
|
3
|
-
import { useScroll } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react";
|
|
3
|
+
import { useScroll } from "./useScroll";
|
|
4
4
|
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
5
|
+
describe("function should be executed", () => {
|
|
6
|
+
it("should execute", () => {
|
|
7
7
|
const scrollHandler = jest.fn();
|
|
8
8
|
|
|
9
9
|
const Component = () => {
|
package/src/hooks/useScroll.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useLayoutEffect } from
|
|
1
|
+
import React, { useLayoutEffect } from "react";
|
|
2
2
|
|
|
3
3
|
export const useScroll = (
|
|
4
4
|
callbackFunction: (event: Event) => unknown,
|
|
@@ -7,10 +7,10 @@ export const useScroll = (
|
|
|
7
7
|
const scrollListener = (event: Event) => callbackFunction(event);
|
|
8
8
|
|
|
9
9
|
useLayoutEffect(() => {
|
|
10
|
-
window.addEventListener(
|
|
10
|
+
window.addEventListener("scroll", scrollListener);
|
|
11
11
|
|
|
12
12
|
return () => {
|
|
13
|
-
window.removeEventListener(
|
|
13
|
+
window.removeEventListener("scroll", scrollListener);
|
|
14
14
|
};
|
|
15
15
|
}, [...dependingStateVariable]);
|
|
16
16
|
};
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { useSpacing } from
|
|
1
|
+
import { useSpacing } from "./useSpacing";
|
|
2
2
|
|
|
3
|
-
describe(
|
|
4
|
-
it(
|
|
5
|
-
const styles = useSpacing({ padding:
|
|
6
|
-
expect(styles).toHaveProperty(
|
|
7
|
-
expect(styles).toHaveProperty(
|
|
3
|
+
describe("useSpacing should set propert padding and margin css properties", () => {
|
|
4
|
+
it("should set padding and margin for 4 values definition", () => {
|
|
5
|
+
const styles = useSpacing({ padding: "0 0.5 1 2", margin: "0 0.5 1 2" });
|
|
6
|
+
expect(styles).toHaveProperty("padding", "0rem 0.125rem 0.25rem 0.5rem");
|
|
7
|
+
expect(styles).toHaveProperty("margin", "0rem 0.125rem 0.25rem 0.5rem");
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
it(
|
|
11
|
-
const styles = useSpacing({ padding:
|
|
12
|
-
expect(styles).toHaveProperty(
|
|
13
|
-
expect(styles).toHaveProperty(
|
|
10
|
+
it("should set padding and margin for 3 values definition", () => {
|
|
11
|
+
const styles = useSpacing({ padding: "3 4 5", margin: "3 4 5" });
|
|
12
|
+
expect(styles).toHaveProperty("padding", "0.75rem 1rem 1.25rem");
|
|
13
|
+
expect(styles).toHaveProperty("margin", "0.75rem 1rem 1.25rem");
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
it(
|
|
17
|
-
const styles = useSpacing({ padding:
|
|
18
|
-
expect(styles).toHaveProperty(
|
|
19
|
-
expect(styles).toHaveProperty(
|
|
16
|
+
it("should set padding and margin for 2 values definition", () => {
|
|
17
|
+
const styles = useSpacing({ padding: "6 7", margin: "6 7" });
|
|
18
|
+
expect(styles).toHaveProperty("padding", "1.5rem 1.75rem");
|
|
19
|
+
expect(styles).toHaveProperty("margin", "1.5rem 1.75rem");
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
it(
|
|
23
|
-
const styles = useSpacing({ padding: 8, margin:
|
|
24
|
-
expect(styles).toHaveProperty(
|
|
25
|
-
expect(styles).toHaveProperty(
|
|
22
|
+
it("should set padding and margin for 1 value definition", () => {
|
|
23
|
+
const styles = useSpacing({ padding: 8, margin: "8" });
|
|
24
|
+
expect(styles).toHaveProperty("padding", "2rem");
|
|
25
|
+
expect(styles).toHaveProperty("margin", "2rem");
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it(
|
|
28
|
+
it("should set paddingLeft, paddingRight, paddingTop, paddingBottom, marginLeft, marginRight, marginTop, marginBottom css values when all provided", async () => {
|
|
29
29
|
const styles = useSpacing({
|
|
30
|
-
paddingLeft:
|
|
30
|
+
paddingLeft: "1",
|
|
31
31
|
paddingRight: 1,
|
|
32
|
-
paddingTop:
|
|
32
|
+
paddingTop: "2",
|
|
33
33
|
paddingBottom: 0.5,
|
|
34
34
|
marginLeft: 3,
|
|
35
35
|
marginRight: 4,
|
|
36
36
|
marginTop: 5,
|
|
37
|
-
marginBottom: 6
|
|
37
|
+
marginBottom: 6
|
|
38
38
|
});
|
|
39
|
-
expect(styles).toHaveProperty(
|
|
40
|
-
expect(styles).toHaveProperty(
|
|
41
|
-
expect(styles).toHaveProperty(
|
|
42
|
-
expect(styles).toHaveProperty(
|
|
43
|
-
expect(styles).toHaveProperty(
|
|
44
|
-
expect(styles).toHaveProperty(
|
|
45
|
-
expect(styles).toHaveProperty(
|
|
46
|
-
expect(styles).toHaveProperty(
|
|
39
|
+
expect(styles).toHaveProperty("paddingLeft", "0.25rem");
|
|
40
|
+
expect(styles).toHaveProperty("paddingRight", "0.25rem");
|
|
41
|
+
expect(styles).toHaveProperty("paddingTop", "0.5rem");
|
|
42
|
+
expect(styles).toHaveProperty("paddingBottom", "0.125rem");
|
|
43
|
+
expect(styles).toHaveProperty("marginLeft", "0.75rem");
|
|
44
|
+
expect(styles).toHaveProperty("marginRight", "1rem");
|
|
45
|
+
expect(styles).toHaveProperty("marginTop", "1.25rem");
|
|
46
|
+
expect(styles).toHaveProperty("marginBottom", "1.5rem");
|
|
47
47
|
expect(styles?.padding).toBeUndefined();
|
|
48
48
|
expect(styles?.margin).toBeUndefined();
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
describe(
|
|
53
|
-
it(
|
|
54
|
-
const styles = useSpacing({ padding: 8, margin:
|
|
55
|
-
expect(styles).toStrictEqual({ padding:
|
|
52
|
+
describe("useSpacing should add/repalce properties in passed style object", () => {
|
|
53
|
+
it("should add properties to style object", () => {
|
|
54
|
+
const styles = useSpacing({ padding: 8, margin: "8" }, { backgroundColor: "red" });
|
|
55
|
+
expect(styles).toStrictEqual({ padding: "2rem", margin: "2rem", backgroundColor: "red" });
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
it(
|
|
58
|
+
it("should add and replace properties to style object", () => {
|
|
59
59
|
const styles = useSpacing(
|
|
60
|
-
{ padding: 8, margin:
|
|
61
|
-
{ padding:
|
|
60
|
+
{ padding: 8, margin: "8" },
|
|
61
|
+
{ padding: "2px", paddingTop: 2, backgroundColor: "red" }
|
|
62
62
|
);
|
|
63
63
|
expect(styles).toStrictEqual({
|
|
64
|
-
padding:
|
|
65
|
-
margin:
|
|
64
|
+
padding: "2rem",
|
|
65
|
+
margin: "2rem",
|
|
66
66
|
paddingTop: 2,
|
|
67
|
-
backgroundColor:
|
|
67
|
+
backgroundColor: "red"
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
});
|