@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
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, Fragment, useState } from
|
|
2
|
-
import classes from
|
|
3
|
-
import readyclasses from
|
|
4
|
-
import { IconButton } from
|
|
5
|
-
import { Icons, Icon } from
|
|
6
|
-
import { Input } from
|
|
7
|
-
import { Select } from
|
|
8
|
-
import { Option } from
|
|
9
|
-
import { Label } from
|
|
1
|
+
import React, { ComponentPropsWithRef, Fragment, useState } from "react";
|
|
2
|
+
import classes from "./Pagination.module.scss";
|
|
3
|
+
import readyclasses from "../readyclasses.module.scss";
|
|
4
|
+
import { IconButton } from "../Button/IconButton";
|
|
5
|
+
import { Icons, Icon } from "../Icon/Icon";
|
|
6
|
+
import { Input } from "../Form/Input/Input";
|
|
7
|
+
import { Select } from "../Form/Select/Select";
|
|
8
|
+
import { Option } from "../Form/Select/Option";
|
|
9
|
+
import { Label } from "../Form/Label/Label";
|
|
10
10
|
|
|
11
11
|
export type PaginationTranslations = {
|
|
12
12
|
totalItems: string;
|
|
@@ -16,19 +16,19 @@ export type PaginationTranslations = {
|
|
|
16
16
|
currentPageLabel: string;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export type PageChangeLabels =
|
|
19
|
+
export type PageChangeLabels = "next" | "previous" | "first" | "last";
|
|
20
20
|
|
|
21
21
|
enum DefaultTranslations {
|
|
22
|
-
totalItems =
|
|
23
|
-
itemsPerPage =
|
|
24
|
-
currentPage =
|
|
25
|
-
itemsPerPageLabel =
|
|
26
|
-
currentPageLabel =
|
|
22
|
+
totalItems = "Total items",
|
|
23
|
+
itemsPerPage = "Items per page",
|
|
24
|
+
currentPage = "Page %1 of %2",
|
|
25
|
+
itemsPerPageLabel = "Select how many items per page you want to see.",
|
|
26
|
+
currentPageLabel = "What page you are currently on."
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export type PageSize = 10 | 25 | 50;
|
|
30
30
|
|
|
31
|
-
export interface Props extends Omit<ComponentPropsWithRef<
|
|
31
|
+
export interface Props extends Omit<ComponentPropsWithRef<"div">, "translate"> {
|
|
32
32
|
currentPage?: number;
|
|
33
33
|
totalElements?: number;
|
|
34
34
|
pageSize?: PageSize;
|
|
@@ -52,7 +52,7 @@ export const Pagination = React.forwardRef<HTMLDivElement, Props>(
|
|
|
52
52
|
ref
|
|
53
53
|
) => {
|
|
54
54
|
/** We use an internal state variable, because we don't want to fire onCurrentPageChange whenever onChange fires on the input. Rather, only when the Enter key is pressed. */
|
|
55
|
-
const [internalCurrentPage, setInternalCurrentPage] = useState(currentPage?.toString() ||
|
|
55
|
+
const [internalCurrentPage, setInternalCurrentPage] = useState(currentPage?.toString() || "1");
|
|
56
56
|
const calculateAmountOfPages = () => {
|
|
57
57
|
if (!totalElements) return 1;
|
|
58
58
|
|
|
@@ -64,7 +64,7 @@ export const Pagination = React.forwardRef<HTMLDivElement, Props>(
|
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
const onEnterListener = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
67
|
-
if (event.code ===
|
|
67
|
+
if (event.code === "Enter") {
|
|
68
68
|
onPageChange(Number(internalCurrentPage));
|
|
69
69
|
}
|
|
70
70
|
};
|
|
@@ -73,16 +73,16 @@ export const Pagination = React.forwardRef<HTMLDivElement, Props>(
|
|
|
73
73
|
const amountOfPages = calculateAmountOfPages();
|
|
74
74
|
|
|
75
75
|
if (amountOfPages) {
|
|
76
|
-
const splitCurrentPageTranslation = translate.currentPage.split(
|
|
76
|
+
const splitCurrentPageTranslation = translate.currentPage.split(" ");
|
|
77
77
|
|
|
78
|
-
return splitCurrentPageTranslation.map(
|
|
79
|
-
if (string.includes(
|
|
78
|
+
return splitCurrentPageTranslation.map(string => {
|
|
79
|
+
if (string.includes("%1")) {
|
|
80
80
|
return (
|
|
81
81
|
<Fragment key={string}>
|
|
82
82
|
<Label
|
|
83
83
|
id="current-value-input-label"
|
|
84
84
|
htmlFor="current-value-input"
|
|
85
|
-
className={`${readyclasses[
|
|
85
|
+
className={`${readyclasses["sr-only"]} ${classes["current-value-input-label"]}`}
|
|
86
86
|
>
|
|
87
87
|
{translate.currentPageLabel}
|
|
88
88
|
</Label>
|
|
@@ -93,7 +93,7 @@ export const Pagination = React.forwardRef<HTMLDivElement, Props>(
|
|
|
93
93
|
type="text"
|
|
94
94
|
size={currentPage?.toString().length}
|
|
95
95
|
max={calculateAmountOfPages()}
|
|
96
|
-
wrapperProps={{ className: classes[
|
|
96
|
+
wrapperProps={{ className: classes["current-value-input"] }}
|
|
97
97
|
onKeyUp={onEnterListener}
|
|
98
98
|
onBlur={(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
99
99
|
onPageChange(Number(event.target.value))
|
|
@@ -103,16 +103,16 @@ export const Pagination = React.forwardRef<HTMLDivElement, Props>(
|
|
|
103
103
|
}
|
|
104
104
|
name="current-value-input"
|
|
105
105
|
value={internalCurrentPage}
|
|
106
|
-
className={`${classes[
|
|
106
|
+
className={`${classes["form-element"]} ${classes["current-page-input"]}`}
|
|
107
107
|
/>
|
|
108
108
|
</Fragment>
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
if (string.includes(
|
|
112
|
+
if (string.includes("%2")) {
|
|
113
113
|
return (
|
|
114
114
|
<div key={string}>
|
|
115
|
-
<strong>{string.replace(
|
|
115
|
+
<strong>{string.replace("%2", amountOfPages.toString())}</strong>
|
|
116
116
|
</div>
|
|
117
117
|
);
|
|
118
118
|
}
|
|
@@ -137,22 +137,22 @@ export const Pagination = React.forwardRef<HTMLDivElement, Props>(
|
|
|
137
137
|
<div
|
|
138
138
|
{...rest}
|
|
139
139
|
ref={ref}
|
|
140
|
-
className={`${classes[
|
|
140
|
+
className={`${classes["pagination-wrapper"]} ${className ? className : ""}`}
|
|
141
141
|
>
|
|
142
142
|
{totalElements && (
|
|
143
|
-
<div className={classes[
|
|
143
|
+
<div className={classes["total"]}>
|
|
144
144
|
<span tabIndex={0}>
|
|
145
145
|
{translate.totalItems}: <span>{totalElements}</span>
|
|
146
146
|
</span>
|
|
147
147
|
</div>
|
|
148
148
|
)}
|
|
149
|
-
<div className={classes[
|
|
149
|
+
<div className={classes["pagination"]}>
|
|
150
150
|
{pageSize && (
|
|
151
|
-
<div className={classes[
|
|
151
|
+
<div className={classes["per-page"]}>
|
|
152
152
|
<Label id="page-size-select-label">{translate.itemsPerPage}</Label>
|
|
153
153
|
<Select
|
|
154
154
|
labeledBy="page-size-select-label"
|
|
155
|
-
className={`${classes[
|
|
155
|
+
className={`${classes["form-element"]} ${classes["page-size-select"]}`}
|
|
156
156
|
value={pageSize.toString()}
|
|
157
157
|
onChange={onPageSizeChangeHandler}
|
|
158
158
|
>
|
|
@@ -164,7 +164,7 @@ export const Pagination = React.forwardRef<HTMLDivElement, Props>(
|
|
|
164
164
|
)}
|
|
165
165
|
<Fragment>
|
|
166
166
|
{!!((currentPage && currentPage > 2) || (currentPage && currentPage > 1)) && (
|
|
167
|
-
<div className={classes[
|
|
167
|
+
<div className={classes["previous"]}>
|
|
168
168
|
{currentPage > 2 && (
|
|
169
169
|
<IconButton
|
|
170
170
|
title="first"
|
|
@@ -185,10 +185,10 @@ export const Pagination = React.forwardRef<HTMLDivElement, Props>(
|
|
|
185
185
|
)}
|
|
186
186
|
</div>
|
|
187
187
|
)}
|
|
188
|
-
{totalElements && calculateAmountOfPages() && (
|
|
189
|
-
<div className={classes[
|
|
188
|
+
{totalElements && !!calculateAmountOfPages() && (
|
|
189
|
+
<div className={classes["page"]}>{renderCurrentPageTranslation()}</div>
|
|
190
190
|
)}
|
|
191
|
-
<div className={classes[
|
|
191
|
+
<div className={classes["next"]}>
|
|
192
192
|
{!!(
|
|
193
193
|
(currentPage !== undefined && currentPage < calculateAmountOfPages()!) ||
|
|
194
194
|
(currentPage !== undefined && !totalElements)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { Fragment, useRef } from
|
|
2
|
-
import { Popover, Props } from
|
|
3
|
-
import { render } from
|
|
4
|
-
import { usePosition } from
|
|
1
|
+
import React, { Fragment, useRef } from "react";
|
|
2
|
+
import { Popover, Props } from "./Popover";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { usePosition } from "../hooks/usePosition";
|
|
5
5
|
|
|
6
6
|
const createPopover = (params?: (defaultParams: Props) => Props) => {
|
|
7
7
|
const Component = () => {
|
|
@@ -17,7 +17,7 @@ const createPopover = (params?: (defaultParams: Props) => Props) => {
|
|
|
17
17
|
</ul>
|
|
18
18
|
),
|
|
19
19
|
show: false,
|
|
20
|
-
placement: { vertical:
|
|
20
|
+
placement: { vertical: "top", horizontal: "left" }
|
|
21
21
|
};
|
|
22
22
|
let parameters: Props = defaultParams;
|
|
23
23
|
|
|
@@ -28,7 +28,7 @@ const createPopover = (params?: (defaultParams: Props) => Props) => {
|
|
|
28
28
|
const { top, left, bottom, right, calculatePosition } = usePosition({
|
|
29
29
|
elementToBePositioned: elementToBePositioned,
|
|
30
30
|
relativeElement: relativeElement,
|
|
31
|
-
...parameters
|
|
31
|
+
...parameters
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
return (
|
|
@@ -49,34 +49,34 @@ const createPopover = (params?: (defaultParams: Props) => Props) => {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
const queries = render(<Component />);
|
|
52
|
-
const button = queries.getByTestId(
|
|
53
|
-
const popover = queries.getByTestId(
|
|
52
|
+
const button = queries.getByTestId("button");
|
|
53
|
+
const popover = queries.getByTestId("popover");
|
|
54
54
|
|
|
55
55
|
/** Let the hacking begin */
|
|
56
|
-
Object.defineProperty(button,
|
|
57
|
-
Object.defineProperty(button,
|
|
56
|
+
Object.defineProperty(button, "offsetHeight", { configurable: true, value: 500 });
|
|
57
|
+
Object.defineProperty(button, "offsetWidth", { configurable: true, value: 500 });
|
|
58
58
|
|
|
59
|
-
Object.defineProperty(window,
|
|
59
|
+
Object.defineProperty(window, "innerHeight", {
|
|
60
60
|
configurable: true,
|
|
61
|
-
value: 1000
|
|
61
|
+
value: 1000
|
|
62
62
|
});
|
|
63
|
-
Object.defineProperty(window,
|
|
63
|
+
Object.defineProperty(window, "innerWidth", {
|
|
64
64
|
configurable: true,
|
|
65
|
-
value: 1000
|
|
65
|
+
value: 1000
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
Object.defineProperty(popover,
|
|
69
|
-
Object.defineProperty(popover,
|
|
68
|
+
Object.defineProperty(popover, "offsetHeight", { configurable: true, value: 100 });
|
|
69
|
+
Object.defineProperty(popover, "offsetWidth", { configurable: true, value: 100 });
|
|
70
70
|
|
|
71
71
|
return {
|
|
72
72
|
...queries,
|
|
73
73
|
popover,
|
|
74
|
-
button
|
|
74
|
+
button
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
describe(
|
|
79
|
-
it(
|
|
78
|
+
describe("Popover should render", () => {
|
|
79
|
+
it("renders without crashing and has default left and top attributes", () => {
|
|
80
80
|
const { popover } = createPopover();
|
|
81
81
|
|
|
82
82
|
expect(popover).toBeTruthy();
|
package/src/Popover/Popover.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, ReactNode, RefObject, useEffect, useRef } from
|
|
2
|
-
import { Offset, Placement, usePosition } from
|
|
3
|
-
import classes from
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactNode, RefObject, useEffect, useRef } from "react";
|
|
2
|
+
import { Offset, Placement, usePosition } from "../hooks/usePosition";
|
|
3
|
+
import classes from "./Popover.module.scss";
|
|
4
4
|
|
|
5
|
-
export interface Props extends ComponentPropsWithRef<
|
|
5
|
+
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
6
6
|
children?: ReactNode;
|
|
7
7
|
show?: boolean;
|
|
8
|
-
anchorEl?: RefObject<HTMLOrSVGElement>;
|
|
8
|
+
anchorEl?: RefObject<HTMLOrSVGElement>; //eslint-disable-line no-undef
|
|
9
9
|
placement?: Placement;
|
|
10
10
|
offset?: Offset;
|
|
11
11
|
transformOrigin?: Placement;
|
|
@@ -24,7 +24,7 @@ export const Popover = React.forwardRef<HTMLDivElement, Props>(
|
|
|
24
24
|
relativeElement: anchorEl,
|
|
25
25
|
offset: offset,
|
|
26
26
|
placement: placement,
|
|
27
|
-
transformOrigin: transformOrigin
|
|
27
|
+
transformOrigin: transformOrigin
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
useEffect(() => {
|
|
@@ -35,7 +35,7 @@ export const Popover = React.forwardRef<HTMLDivElement, Props>(
|
|
|
35
35
|
<div ref={ref} {...rest}>
|
|
36
36
|
<div
|
|
37
37
|
ref={elToBePositioned}
|
|
38
|
-
className={`${classes.popover} ${className ??
|
|
38
|
+
className={`${classes.popover} ${className ?? ""} ${show ? classes.show : ""}`}
|
|
39
39
|
style={{ top: top, left: left, right: right, bottom: bottom }}
|
|
40
40
|
>
|
|
41
41
|
{children}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { Skeleton, Props } from
|
|
3
|
-
import { render } from
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { Skeleton, Props } from "./Skeleton";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
4
|
|
|
5
5
|
const defaultParams: Props = {};
|
|
6
6
|
|
|
@@ -10,70 +10,70 @@ const createSkeleton = (params?: (defaultParams: Props) => Props) => {
|
|
|
10
10
|
parameters = params(defaultParams);
|
|
11
11
|
}
|
|
12
12
|
const queries = render(<Skeleton {...parameters} data-testid="skeleton" />);
|
|
13
|
-
const skeleton = queries.getByTestId(
|
|
13
|
+
const skeleton = queries.getByTestId("skeleton");
|
|
14
14
|
|
|
15
15
|
return {
|
|
16
16
|
...queries,
|
|
17
|
-
skeleton
|
|
17
|
+
skeleton
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
describe(
|
|
22
|
-
it(
|
|
21
|
+
describe("Skeleton should render", () => {
|
|
22
|
+
it("renders without crashing", () => {
|
|
23
23
|
const { skeleton } = createSkeleton();
|
|
24
24
|
|
|
25
|
-
expect(skeleton).toHaveClass(
|
|
25
|
+
expect(skeleton).toHaveClass("skeleton text no-height", { exact: true });
|
|
26
26
|
|
|
27
27
|
expect(skeleton).toBeDefined();
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
it(
|
|
31
|
-
const testClass =
|
|
32
|
-
const { skeleton } = createSkeleton(
|
|
30
|
+
it("renders with properties passed", () => {
|
|
31
|
+
const testClass = "testclass";
|
|
32
|
+
const { skeleton } = createSkeleton(defaultParams => ({
|
|
33
33
|
...defaultParams,
|
|
34
|
-
className: testClass
|
|
34
|
+
className: testClass
|
|
35
35
|
}));
|
|
36
36
|
|
|
37
37
|
expect(skeleton).toHaveClass(`skeleton text no-height ${testClass}`, { exact: true });
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
it(
|
|
41
|
-
const width =
|
|
40
|
+
it("renders text variant with width and height", () => {
|
|
41
|
+
const width = "10rem";
|
|
42
42
|
const height = 10;
|
|
43
|
-
const { skeleton } = createSkeleton(
|
|
43
|
+
const { skeleton } = createSkeleton(defaultParams => ({
|
|
44
44
|
...defaultParams,
|
|
45
|
-
variant:
|
|
45
|
+
variant: "text",
|
|
46
46
|
width,
|
|
47
|
-
height
|
|
47
|
+
height
|
|
48
48
|
}));
|
|
49
49
|
|
|
50
50
|
expect(skeleton).toHaveClass(`skeleton text`, { exact: true });
|
|
51
|
-
expect(skeleton).toHaveStyle({ width, height:
|
|
51
|
+
expect(skeleton).toHaveStyle({ width, height: "10px" });
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it(
|
|
55
|
-
const { skeleton } = createSkeleton(
|
|
54
|
+
it("renders rectangle variant", () => {
|
|
55
|
+
const { skeleton } = createSkeleton(defaultParams => ({
|
|
56
56
|
...defaultParams,
|
|
57
|
-
variant:
|
|
57
|
+
variant: "rectangle"
|
|
58
58
|
}));
|
|
59
59
|
|
|
60
60
|
expect(skeleton).toHaveClass(`skeleton no-height`, { exact: true });
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
it(
|
|
64
|
-
const { skeleton } = createSkeleton(
|
|
63
|
+
it("renders circular variant", () => {
|
|
64
|
+
const { skeleton } = createSkeleton(defaultParams => ({
|
|
65
65
|
...defaultParams,
|
|
66
|
-
variant:
|
|
66
|
+
variant: "circular"
|
|
67
67
|
}));
|
|
68
68
|
|
|
69
69
|
expect(skeleton).toHaveClass(`skeleton no-height circular`, { exact: true });
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
describe(
|
|
74
|
-
it(
|
|
73
|
+
describe("ref should work", () => {
|
|
74
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
75
75
|
const ExampleComponent = ({
|
|
76
|
-
propagateRef
|
|
76
|
+
propagateRef
|
|
77
77
|
}: {
|
|
78
78
|
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
79
79
|
}) => {
|
|
@@ -87,10 +87,10 @@ describe('ref should work', () => {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
90
|
-
expect(ref.current).toHaveAttribute(
|
|
90
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
const container = document.createElement(
|
|
93
|
+
const container = document.createElement("tbody");
|
|
94
94
|
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
95
95
|
});
|
|
96
96
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef } from
|
|
2
|
-
import classes from
|
|
1
|
+
import React, { ComponentPropsWithRef } from "react";
|
|
2
|
+
import classes from "./Skeleton.module.scss";
|
|
3
3
|
|
|
4
|
-
export interface Props extends Omit<ComponentPropsWithRef<
|
|
5
|
-
variant?:
|
|
4
|
+
export interface Props extends Omit<ComponentPropsWithRef<"div">, "children"> {
|
|
5
|
+
variant?: "circular" | "rectangle" | "text";
|
|
6
6
|
height?: number | string;
|
|
7
7
|
width?: number | string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const Skeleton = React.forwardRef<HTMLDivElement, Props>(
|
|
11
|
-
({ variant =
|
|
12
|
-
const classNames = [classes[
|
|
13
|
-
!height && classNames.push(classes[
|
|
14
|
-
variant ===
|
|
15
|
-
variant ===
|
|
11
|
+
({ variant = "text", height, width, className, style, ...rest }: Props, ref) => {
|
|
12
|
+
const classNames = [classes["skeleton"]];
|
|
13
|
+
!height && classNames.push(classes["no-height"]);
|
|
14
|
+
variant === "text" && classNames.push(classes["text"]);
|
|
15
|
+
variant === "circular" && classNames.push(classes["circular"]);
|
|
16
16
|
className && classNames.push(className);
|
|
17
17
|
|
|
18
18
|
return (
|
|
@@ -22,7 +22,7 @@ export const Skeleton = React.forwardRef<HTMLDivElement, Props>(
|
|
|
22
22
|
aria-hidden="true"
|
|
23
23
|
ref={ref}
|
|
24
24
|
style={{ ...style, width, height }}
|
|
25
|
-
className={classNames.join(
|
|
25
|
+
className={classNames.join(" ")}
|
|
26
26
|
></span>
|
|
27
27
|
);
|
|
28
28
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { StatusIndicator, Props } from
|
|
3
|
-
import { render } from
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { StatusIndicator, Props } from "./StatusIndicator";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
4
|
|
|
5
5
|
const defaultParams: Props = {
|
|
6
|
-
status:
|
|
6
|
+
status: "active"
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
const createStatusIndicator = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -16,92 +16,92 @@ const createStatusIndicator = (params?: (defaultParams: Props) => Props) => {
|
|
|
16
16
|
content
|
|
17
17
|
</StatusIndicator>
|
|
18
18
|
);
|
|
19
|
-
const statusIndicator = queries.getByTestId(
|
|
19
|
+
const statusIndicator = queries.getByTestId("StatusIndicator");
|
|
20
20
|
|
|
21
21
|
return {
|
|
22
22
|
...queries,
|
|
23
|
-
statusIndicator
|
|
23
|
+
statusIndicator
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
describe(
|
|
28
|
-
it(
|
|
27
|
+
describe("StatusIndicator should render", () => {
|
|
28
|
+
it("renders without crashing", () => {
|
|
29
29
|
const { statusIndicator, getByText } = createStatusIndicator();
|
|
30
30
|
|
|
31
31
|
expect(statusIndicator).toBeDefined();
|
|
32
|
-
expect(getByText(
|
|
32
|
+
expect(getByText("content")).toBeInTheDocument();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it(
|
|
36
|
-
const { statusIndicator, getByText } = createStatusIndicator(
|
|
35
|
+
it("passes through custom typography props", () => {
|
|
36
|
+
const { statusIndicator, getByText } = createStatusIndicator(params => ({
|
|
37
37
|
...params,
|
|
38
38
|
typographyProps: {
|
|
39
|
-
variant:
|
|
40
|
-
children: <strong>custom children</strong
|
|
41
|
-
}
|
|
39
|
+
variant: "body",
|
|
40
|
+
children: <strong>custom children</strong>
|
|
41
|
+
}
|
|
42
42
|
}));
|
|
43
43
|
|
|
44
44
|
expect(statusIndicator).toBeDefined();
|
|
45
|
-
expect(getByText(
|
|
45
|
+
expect(getByText("custom children")).toBeInTheDocument();
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it(
|
|
49
|
-
const { statusIndicator } = createStatusIndicator(
|
|
48
|
+
it("passes through custom props", () => {
|
|
49
|
+
const { statusIndicator } = createStatusIndicator(params => ({
|
|
50
50
|
...params,
|
|
51
|
-
|
|
51
|
+
"aria-label": "status indicator"
|
|
52
52
|
}));
|
|
53
53
|
|
|
54
54
|
expect(statusIndicator).toBeDefined();
|
|
55
|
-
expect(statusIndicator).toHaveAttribute(
|
|
55
|
+
expect(statusIndicator).toHaveAttribute("aria-label", "status indicator");
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
it('should set "active" class on status badge', () => {
|
|
59
|
-
const { statusIndicator } = createStatusIndicator(
|
|
59
|
+
const { statusIndicator } = createStatusIndicator(params => ({
|
|
60
60
|
...params,
|
|
61
|
-
status:
|
|
61
|
+
status: "active"
|
|
62
62
|
}));
|
|
63
63
|
|
|
64
|
-
expect(statusIndicator.firstChild).toHaveClass(
|
|
64
|
+
expect(statusIndicator.firstChild).toHaveClass("active");
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it('should set "error" class on status badge', () => {
|
|
68
|
-
const { statusIndicator } = createStatusIndicator(
|
|
68
|
+
const { statusIndicator } = createStatusIndicator(params => ({ ...params, status: "error" }));
|
|
69
69
|
|
|
70
|
-
expect(statusIndicator.firstChild).toHaveClass(
|
|
70
|
+
expect(statusIndicator.firstChild).toHaveClass("error");
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it('should set "neutral" class on status badge', () => {
|
|
74
|
-
const { statusIndicator } = createStatusIndicator(
|
|
74
|
+
const { statusIndicator } = createStatusIndicator(params => ({
|
|
75
75
|
...params,
|
|
76
|
-
status:
|
|
76
|
+
status: "neutral"
|
|
77
77
|
}));
|
|
78
78
|
|
|
79
|
-
expect(statusIndicator.firstChild).toHaveClass(
|
|
79
|
+
expect(statusIndicator.firstChild).toHaveClass("neutral");
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it('should pass "warning" class to status badge', () => {
|
|
83
|
-
const { statusIndicator } = createStatusIndicator(
|
|
83
|
+
const { statusIndicator } = createStatusIndicator(params => ({
|
|
84
84
|
...params,
|
|
85
|
-
status:
|
|
85
|
+
status: "warning"
|
|
86
86
|
}));
|
|
87
87
|
|
|
88
|
-
expect(statusIndicator.firstChild).toHaveClass(
|
|
88
|
+
expect(statusIndicator.firstChild).toHaveClass("warning");
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
it(
|
|
92
|
-
const { statusIndicator } = createStatusIndicator(
|
|
91
|
+
it("should pass custom class to status badge", () => {
|
|
92
|
+
const { statusIndicator } = createStatusIndicator(params => ({
|
|
93
93
|
...params,
|
|
94
|
-
badgeProps: { className:
|
|
94
|
+
badgeProps: { className: "custom" }
|
|
95
95
|
}));
|
|
96
96
|
|
|
97
|
-
expect(statusIndicator.firstChild).toHaveClass(
|
|
97
|
+
expect(statusIndicator.firstChild).toHaveClass("custom");
|
|
98
98
|
});
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
describe(
|
|
102
|
-
it(
|
|
101
|
+
describe("ref should work", () => {
|
|
102
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
103
103
|
const ExampleComponent = ({
|
|
104
|
-
propagateRef
|
|
104
|
+
propagateRef
|
|
105
105
|
}: {
|
|
106
106
|
propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
|
|
107
107
|
}) => {
|
|
@@ -119,7 +119,7 @@ describe('ref should work', () => {
|
|
|
119
119
|
};
|
|
120
120
|
|
|
121
121
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
122
|
-
expect(ref.current).toHaveAttribute(
|
|
122
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
render(<ExampleComponent propagateRef={refCheck} />);
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, ReactNode } from
|
|
2
|
-
import { Typography, Props as TypographyProps } from
|
|
3
|
-
import classes from
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
+
import { Typography, Props as TypographyProps } from "../Typography/Typography";
|
|
3
|
+
import classes from "./StatusIndicator.module.scss";
|
|
4
4
|
|
|
5
|
-
export interface Props extends ComponentPropsWithRef<
|
|
5
|
+
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
6
6
|
children?: ReactNode;
|
|
7
|
-
status:
|
|
8
|
-
badgeProps?: ComponentPropsWithRef<
|
|
7
|
+
status: "active" | "error" | "neutral" | "warning";
|
|
8
|
+
badgeProps?: ComponentPropsWithRef<"div">;
|
|
9
9
|
typographyProps?: TypographyProps;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const StatusIndicator = React.forwardRef<HTMLDivElement, Props>(
|
|
13
13
|
({ children, status, badgeProps, typographyProps, ...rest }: Props, ref) => {
|
|
14
14
|
return (
|
|
15
|
-
<div {...rest} className={classes[
|
|
15
|
+
<div {...rest} className={classes["status-indicator"]} ref={ref}>
|
|
16
16
|
<div
|
|
17
|
-
className={`${classes[
|
|
17
|
+
className={`${classes["status-badge"]} ${classes[status]} ${badgeProps?.className ?? ""}`}
|
|
18
18
|
/>
|
|
19
|
-
<Typography {...typographyProps} spacing={{ margin:
|
|
19
|
+
<Typography {...typographyProps} spacing={{ margin: "0" }} variant="body" tag="div">
|
|
20
20
|
{typographyProps?.children || children}
|
|
21
21
|
</Typography>
|
|
22
22
|
</div>
|