@onewelcome/react-lib-components 0.1.0-alpha → 0.1.3-alpha
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/README.md +16 -1
- package/dist/Breadcrumbs/Breadcrumbs.d.ts +3 -3
- package/dist/Button/BaseButton.d.ts +3 -4
- package/dist/Button/Button.d.ts +3 -4
- package/dist/Button/IconButton.d.ts +4 -5
- package/dist/ContextMenu/ContextMenu.d.ts +3 -3
- package/dist/Form/Checkbox/Checkbox.d.ts +5 -5
- package/dist/Form/Fieldset/Fieldset.d.ts +9 -7
- package/dist/Form/FormControl/FormControl.d.ts +6 -5
- package/dist/Form/FormGroup/FormGroup.d.ts +4 -4
- package/dist/Form/FormHelperText/FormHelperText.d.ts +4 -5
- package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +8 -12
- package/dist/Form/Input/Input.d.ts +7 -6
- package/dist/Form/Label/Label.d.ts +4 -5
- package/dist/Form/Radio/Radio.d.ts +5 -5
- package/dist/Form/Select/Option.d.ts +3 -4
- package/dist/Form/Select/Select.d.ts +4 -4
- package/dist/Form/Textarea/Textarea.d.ts +9 -5
- package/dist/Form/Toggle/Toggle.d.ts +3 -3
- package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +4 -3
- package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +5 -5
- package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +8 -4
- package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +3 -3
- package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +6 -6
- package/dist/Form/form.interfaces.d.ts +4 -3
- package/dist/Icon/Icon.d.ts +4 -4
- package/dist/Link/Link.d.ts +3 -5
- package/dist/Notifications/BaseModal/BaseModal.d.ts +17 -0
- package/dist/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +5 -0
- package/dist/Notifications/BaseModal/BaseModalContent/BaseModalContent.d.ts +8 -0
- package/dist/{BaseModal → Notifications/BaseModal}/BaseModalContext.d.ts +0 -0
- package/dist/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +8 -0
- package/dist/Notifications/Dialog/Dialog.d.ts +19 -0
- package/dist/Notifications/Dialog/DialogActions/DialogActions.d.ts +6 -0
- package/dist/Notifications/Dialog/DialogTitle/DialogTitle.d.ts +6 -0
- package/dist/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.d.ts +13 -0
- package/dist/Notifications/DiscardChangesModal/DiscardChangesModal.d.ts +13 -0
- package/dist/{Modal → Notifications/Modal}/Modal.d.ts +0 -0
- package/dist/{Modal → Notifications/Modal}/ModalActions/ModalActions.d.ts +0 -0
- package/dist/{Modal → Notifications/Modal}/ModalContent/ModalContent.d.ts +0 -0
- package/dist/{Modal → Notifications/Modal}/ModalHeader/ModalHeader.d.ts +0 -0
- package/dist/{Snackbar → Notifications/Snackbar}/SnackbarContainer/SnackbarContainer.d.ts +0 -0
- package/dist/{Snackbar → Notifications/Snackbar}/SnackbarItem/SnackbarItem.d.ts +0 -0
- package/dist/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarProvider.d.ts +1 -1
- package/dist/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarStateProvider.d.ts +0 -0
- package/dist/{Snackbar → Notifications/Snackbar}/interfaces.d.ts +0 -0
- package/dist/{Snackbar → Notifications/Snackbar}/useSnackbar.d.ts +0 -0
- package/dist/Pagination/Pagination.d.ts +19 -0
- package/dist/Popover/Popover.d.ts +3 -3
- package/dist/Tabs/Tab.d.ts +11 -0
- package/dist/Tabs/TabButton.d.ts +10 -0
- package/dist/Tabs/TabPanel.d.ts +8 -0
- package/dist/Tabs/Tabs.d.ts +9 -0
- package/dist/TextEllipsis/TextEllipsis.d.ts +6 -0
- package/dist/Tiles/Tile.d.ts +6 -7
- package/dist/Tiles/Tiles.d.ts +3 -3
- package/dist/Tooltip/Tooltip.d.ts +3 -3
- package/dist/Typography/Typography.d.ts +6 -4
- package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +3 -3
- package/dist/Wizard/WizardSteps/WizardSteps.d.ts +3 -3
- package/dist/_BaseStyling_/BaseStyling.d.ts +9 -0
- package/dist/hooks/useRepeater.d.ts +10 -0
- package/dist/hooks/useSpacing.d.ts +2 -2
- package/dist/hooks/useWrapper.d.ts +1 -1
- package/dist/index.d.ts +12 -7
- package/dist/interfaces.d.ts +2 -11
- package/dist/react-lib-components.cjs.development.js +1861 -1287
- 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 +1858 -1289
- package/dist/react-lib-components.esm.js.map +1 -1
- package/dist/util/helper.d.ts +6 -1
- package/package.json +30 -24
- package/src/Breadcrumbs/Breadcrumbs.tsx +39 -37
- package/src/Button/BaseButton.test.tsx +65 -19
- package/src/Button/BaseButton.tsx +2 -3
- package/src/Button/Button.test.tsx +63 -17
- package/src/Button/Button.tsx +15 -4
- package/src/Button/IconButton.test.tsx +57 -22
- package/src/Button/IconButton.tsx +21 -12
- package/src/ContextMenu/ContextMenu.test.tsx +27 -1
- package/src/ContextMenu/ContextMenu.tsx +70 -65
- package/src/Form/Checkbox/Checkbox.module.scss +4 -0
- package/src/Form/Checkbox/Checkbox.test.tsx +28 -2
- package/src/Form/Checkbox/Checkbox.tsx +132 -117
- package/src/Form/Fieldset/Fieldset.module.scss +11 -1
- package/src/Form/Fieldset/Fieldset.test.tsx +30 -4
- package/src/Form/Fieldset/Fieldset.tsx +101 -43
- package/src/Form/FormControl/FormControl.test.tsx +27 -1
- package/src/Form/FormControl/FormControl.tsx +37 -37
- package/src/Form/FormGroup/FormGroup.test.tsx +27 -1
- package/src/Form/FormGroup/FormGroup.tsx +64 -58
- package/src/Form/FormHelperText/FormHelperText.test.tsx +27 -1
- package/src/Form/FormHelperText/FormHelperText.tsx +20 -16
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +78 -0
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +61 -55
- package/src/Form/Input/Input.module.scss +34 -15
- package/src/Form/Input/Input.test.tsx +27 -1
- package/src/Form/Input/Input.tsx +88 -47
- package/src/Form/Label/Label.test.tsx +27 -1
- package/src/Form/Label/Label.tsx +18 -14
- package/src/Form/Radio/Radio.module.scss +4 -0
- package/src/Form/Radio/Radio.test.tsx +28 -2
- package/src/Form/Radio/Radio.tsx +98 -80
- package/src/Form/Select/Option.test.tsx +27 -1
- package/src/Form/Select/Option.tsx +49 -42
- package/src/Form/Select/Select.module.scss +5 -1
- package/src/Form/Select/Select.test.tsx +224 -30
- package/src/Form/Select/Select.tsx +248 -182
- package/src/Form/Textarea/Textarea.module.scss +2 -1
- package/src/Form/Textarea/Textarea.test.tsx +28 -2
- package/src/Form/Textarea/Textarea.tsx +44 -29
- package/src/Form/Toggle/Toggle.module.scss +9 -0
- package/src/Form/Toggle/Toggle.test.tsx +27 -1
- package/src/Form/Toggle/Toggle.tsx +25 -12
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +28 -2
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +45 -48
- package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +17 -1
- package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +89 -1
- package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +134 -74
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +1 -1
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +64 -59
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.module.scss +1 -1
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +43 -1
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +55 -44
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +5 -7
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +43 -1
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +100 -85
- package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +1 -1
- package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +27 -1
- package/src/Form/Wrapper/Wrapper/Wrapper.tsx +76 -71
- package/src/Form/form.interfaces.ts +4 -3
- package/src/Icon/Icon.module.scss +4 -0
- package/src/Icon/Icon.test.tsx +30 -2
- package/src/Icon/Icon.tsx +5 -5
- package/src/Link/Link.test.tsx +27 -1
- package/src/Link/Link.tsx +4 -6
- package/src/{BaseModal → Notifications/BaseModal}/BaseModal.module.scss +0 -0
- package/src/{BaseModal → Notifications/BaseModal}/BaseModal.test.tsx +35 -16
- package/src/Notifications/BaseModal/BaseModal.tsx +105 -0
- package/src/{BaseModal → Notifications/BaseModal}/BaseModalActions/BaseModalActions.module.scss +0 -0
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +42 -0
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +16 -0
- package/src/{BaseModal → Notifications/BaseModal}/BaseModalContent/BaseModalContent.module.scss +0 -0
- package/src/{BaseModal → Notifications/BaseModal}/BaseModalContent/BaseModalContent.test.tsx +27 -1
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +36 -0
- package/src/{BaseModal → Notifications/BaseModal}/BaseModalContext.ts +0 -0
- package/src/{BaseModal → Notifications/BaseModal}/BaseModalHeader/BaseModalHeader.module.scss +0 -0
- package/src/{BaseModal → Notifications/BaseModal}/BaseModalHeader/BaseModalHeader.test.tsx +29 -1
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +30 -0
- package/src/{Dialog → Notifications/Dialog}/Dialog.module.scss +0 -0
- package/src/{Dialog → Notifications/Dialog}/Dialog.test.tsx +52 -17
- package/src/Notifications/Dialog/Dialog.tsx +113 -0
- package/src/{Dialog → Notifications/Dialog}/DialogActions/DialogActions.module.scss +0 -0
- package/src/Notifications/Dialog/DialogActions/DialogActions.test.tsx +51 -0
- package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +24 -0
- package/src/{Dialog → Notifications/Dialog}/DialogTitle/DialogTitle.module.scss +0 -0
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +44 -0
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +20 -0
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +95 -0
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +55 -0
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +162 -0
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.tsx +61 -0
- package/src/{Modal → Notifications/Modal}/Modal.test.tsx +0 -0
- package/src/{Modal → Notifications/Modal}/Modal.tsx +0 -0
- package/src/{Modal → Notifications/Modal}/ModalActions/ModalActions.tsx +0 -0
- package/src/{Modal → Notifications/Modal}/ModalContent/ModalContent.tsx +0 -0
- package/src/{Modal → Notifications/Modal}/ModalHeader/ModalHeader.tsx +0 -0
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarContainer/SnackbarContainer.module.scss +0 -0
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarContainer/SnackbarContainer.test.tsx +0 -0
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarContainer/SnackbarContainer.tsx +0 -0
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarItem/SnackbarItem.module.scss +1 -1
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarItem/SnackbarItem.test.tsx +0 -0
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarItem/SnackbarItem.tsx +6 -7
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarProvider.test.tsx +0 -0
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarProvider.tsx +2 -2
- package/src/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarStateProvider.tsx +0 -0
- package/src/{Snackbar → Notifications/Snackbar}/interfaces.ts +0 -0
- package/src/{Snackbar → Notifications/Snackbar}/useSnackbar.ts +0 -0
- package/src/Pagination/Pagination.module.scss +120 -0
- package/src/Pagination/Pagination.test.tsx +176 -0
- package/src/Pagination/Pagination.tsx +205 -0
- package/src/Popover/Popover.test.tsx +3 -3
- package/src/Popover/Popover.tsx +3 -3
- package/src/Tabs/Tab.test.tsx +71 -0
- package/src/Tabs/Tab.tsx +17 -0
- package/src/Tabs/TabButton.module.scss +36 -0
- package/src/Tabs/TabButton.test.tsx +77 -0
- package/src/Tabs/TabButton.tsx +58 -0
- package/src/Tabs/TabPanel.module.scss +7 -0
- package/src/Tabs/TabPanel.test.tsx +76 -0
- package/src/Tabs/TabPanel.tsx +27 -0
- package/src/Tabs/Tabs.module.scss +41 -0
- package/src/Tabs/Tabs.test.tsx +268 -0
- package/src/Tabs/Tabs.tsx +149 -0
- package/src/TextEllipsis/TextEllipsis.module.scss +18 -0
- package/src/TextEllipsis/TextEllipsis.test.tsx +80 -0
- package/src/TextEllipsis/TextEllipsis.tsx +55 -0
- package/src/Tiles/Tile.module.scss +1 -1
- package/src/Tiles/Tile.test.tsx +48 -12
- package/src/Tiles/Tile.tsx +68 -34
- package/src/Tiles/Tiles.test.tsx +38 -10
- package/src/Tiles/Tiles.tsx +42 -39
- package/src/Tooltip/Tooltip.test.tsx +27 -1
- package/src/Tooltip/Tooltip.tsx +104 -92
- package/src/Typography/Typography.test.tsx +27 -1
- package/src/Typography/Typography.tsx +66 -68
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +67 -62
- package/src/Wizard/Wizard.tsx +2 -2
- package/src/Wizard/WizardActions/WizardActions.tsx +3 -3
- package/src/Wizard/WizardSteps/WizardSteps.tsx +24 -21
- package/src/_BaseStyling_/BaseStyling.tsx +19 -1
- package/src/hooks/usePosition.test.tsx +3 -3
- package/src/hooks/useRepeater.test.tsx +139 -0
- package/src/hooks/useRepeater.ts +34 -0
- package/src/hooks/useSpacing.ts +1 -1
- package/src/hooks/useWrapper.ts +7 -2
- package/src/index.ts +20 -8
- package/src/interfaces.ts +2 -12
- package/src/util/helper.test.tsx +38 -1
- package/src/util/helper.tsx +21 -0
- package/dist/BaseModal/BaseModal.d.ts +0 -16
- package/dist/BaseModal/BaseModalActions/BaseModalActions.d.ts +0 -5
- package/dist/BaseModal/BaseModalContent/BaseModalContent.d.ts +0 -8
- package/dist/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +0 -8
- package/dist/Dialog/Dialog.d.ts +0 -18
- package/dist/Dialog/DialogActions/DialogActions.d.ts +0 -6
- package/dist/Dialog/DialogTitle/DialogTitle.d.ts +0 -6
- package/src/BaseModal/BaseModal.tsx +0 -113
- package/src/BaseModal/BaseModalActions/BaseModalActions.test.tsx +0 -17
- package/src/BaseModal/BaseModalActions/BaseModalActions.tsx +0 -14
- package/src/BaseModal/BaseModalContent/BaseModalContent.tsx +0 -35
- package/src/BaseModal/BaseModalHeader/BaseModalHeader.tsx +0 -28
- package/src/Dialog/Dialog.tsx +0 -96
- package/src/Dialog/DialogActions/DialogActions.test.tsx +0 -25
- package/src/Dialog/DialogActions/DialogActions.tsx +0 -21
- package/src/Dialog/DialogTitle/DialogTitle.test.tsx +0 -18
- package/src/Dialog/DialogTitle/DialogTitle.tsx +0 -18
|
@@ -1,84 +1,82 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactNode } from 'react';
|
|
2
2
|
import classes from './Typography.module.scss';
|
|
3
3
|
import { Spacing, useSpacing } from '../hooks/useSpacing';
|
|
4
4
|
|
|
5
5
|
const validVariants = ['h1', 'h2', 'h3', 'h4', 'body', 'body-bold', 'sub-text', 'code'] as const;
|
|
6
6
|
export type Variant = typeof validVariants[number];
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type Tags =
|
|
9
|
+
| 'h1'
|
|
10
|
+
| 'h2'
|
|
11
|
+
| 'h3'
|
|
12
|
+
| 'h4'
|
|
13
|
+
| 'p'
|
|
14
|
+
| 'div'
|
|
15
|
+
| 'code'
|
|
16
|
+
| 'span'
|
|
17
|
+
| 'sup'
|
|
18
|
+
| 'sub'
|
|
19
|
+
| 'strong'
|
|
20
|
+
| 'em'
|
|
21
|
+
| 'small'
|
|
22
|
+
| 'mark'
|
|
23
|
+
| 'del'
|
|
24
|
+
| 'ins'
|
|
25
|
+
| 'blockquote';
|
|
26
|
+
|
|
27
|
+
/** I couldn't find anything on the internet that indicated that ComponentPropsWithRef can take multiple tags. Since the TagName can be many different things I have to use any here. Using a mix of tags (like the Tags type) will throw an error. */
|
|
28
|
+
export interface Props extends ComponentPropsWithRef<any> {
|
|
9
29
|
children: ReactNode;
|
|
10
30
|
variant: Variant;
|
|
11
|
-
tag?:
|
|
12
|
-
| 'h1'
|
|
13
|
-
| 'h2'
|
|
14
|
-
| 'h3'
|
|
15
|
-
| 'h4'
|
|
16
|
-
| 'p'
|
|
17
|
-
| 'div'
|
|
18
|
-
| 'code'
|
|
19
|
-
| 'span'
|
|
20
|
-
| 'sup'
|
|
21
|
-
| 'sub'
|
|
22
|
-
| 'strong'
|
|
23
|
-
| 'em'
|
|
24
|
-
| 'small'
|
|
25
|
-
| 'mark'
|
|
26
|
-
| 'del'
|
|
27
|
-
| 'ins'
|
|
28
|
-
| 'blockquote';
|
|
31
|
+
tag?: Tags;
|
|
29
32
|
spacing?: Spacing;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
export const Typography = (
|
|
33
|
-
children,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...rest
|
|
40
|
-
}: Props) => {
|
|
41
|
-
if (!validVariants.includes(variant)) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
`You entered an invalid variant. You can choose from: ${validVariants}, you entered: ${variant}`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
35
|
+
export const Typography = React.forwardRef<any, Props>(
|
|
36
|
+
({ children, variant, tag, style, spacing, className = '', ...rest }: Props, ref) => {
|
|
37
|
+
if (!validVariants.includes(variant)) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`You entered an invalid variant. You can choose from: ${validVariants}, you entered: ${variant}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
const styleWithSpacing = useSpacing(spacing, style);
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
45
|
+
if (!tag) {
|
|
46
|
+
switch (variant) {
|
|
47
|
+
case 'h1':
|
|
48
|
+
case 'h2':
|
|
49
|
+
case 'h3':
|
|
50
|
+
case 'h4':
|
|
51
|
+
case 'code':
|
|
52
|
+
tag = variant;
|
|
53
|
+
break;
|
|
54
|
+
case 'body':
|
|
55
|
+
tag = 'p';
|
|
56
|
+
break;
|
|
57
|
+
case 'body-bold':
|
|
58
|
+
tag = 'p';
|
|
59
|
+
break;
|
|
60
|
+
case 'sub-text':
|
|
61
|
+
tag = 'span';
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
tag = 'div';
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
70
67
|
}
|
|
71
|
-
}
|
|
72
68
|
|
|
73
|
-
|
|
69
|
+
let TagName = tag;
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
return (
|
|
72
|
+
<TagName
|
|
73
|
+
{...rest}
|
|
74
|
+
ref={ref}
|
|
75
|
+
style={styleWithSpacing}
|
|
76
|
+
className={`${classes['typography_style_' + variant]} ${className}`}
|
|
77
|
+
>
|
|
78
|
+
{children}
|
|
79
|
+
</TagName>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ComponentPropsWithRef, Fragment } from 'react';
|
|
2
2
|
import classes from './BaseWizardSteps.module.scss';
|
|
3
3
|
import readyclasses from '../../readyclasses.module.scss';
|
|
4
4
|
import { Icon, Icons } from '../../Icon/Icon';
|
|
@@ -10,7 +10,7 @@ export interface Step {
|
|
|
10
10
|
disabled?: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export interface Props extends Omit<
|
|
13
|
+
export interface Props extends Omit<ComponentPropsWithRef<'div'>, 'onClick'> {
|
|
14
14
|
steps: Step[];
|
|
15
15
|
currentStepNo: number;
|
|
16
16
|
onClick?: (stepNo: number) => void;
|
|
@@ -18,69 +18,74 @@ export interface Props extends Omit<React.HTMLProps<HTMLDivElement>, 'onClick'>
|
|
|
18
18
|
stepScreenReaderLabel: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const BaseWizardSteps = (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
export const BaseWizardSteps = React.forwardRef<HTMLDivElement, Props>(
|
|
22
|
+
(
|
|
23
|
+
{
|
|
24
|
+
steps,
|
|
25
|
+
currentStepNo,
|
|
26
|
+
onClick,
|
|
27
|
+
futureStepsClickable = false,
|
|
28
|
+
stepScreenReaderLabel,
|
|
29
|
+
...rest
|
|
30
|
+
}: Props,
|
|
31
|
+
ref
|
|
32
|
+
) => {
|
|
33
|
+
const getStepState = (stepNo: number): StepState => {
|
|
34
|
+
if (currentStepNo === stepNo) {
|
|
35
|
+
return 'current';
|
|
36
|
+
} else if (stepNo < currentStepNo) {
|
|
37
|
+
return 'finished';
|
|
38
|
+
}
|
|
39
|
+
return 'future';
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const getStepContent = (stepState: StepState, index: number, disabled?: boolean) => {
|
|
43
|
+
const stepNumberString = String(index + 1);
|
|
44
|
+
if (stepState === 'finished') {
|
|
45
|
+
return disabled ? null : <Icon className={classes['checkmark']} icon={Icons.Checkmark} />;
|
|
46
|
+
} else {
|
|
47
|
+
return (
|
|
48
|
+
<Fragment>
|
|
49
|
+
<span className={readyclasses['sr-only']}>{stepScreenReaderLabel} </span>
|
|
50
|
+
{stepNumberString}
|
|
51
|
+
</Fragment>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const generatedSteps = steps.map((step, index) => {
|
|
57
|
+
const stepState = getStepState(index);
|
|
58
|
+
const disabledStyleClassName = step.disabled ? classes['disabled'] : '';
|
|
59
|
+
const clickableClassName = futureStepsClickable ? classes['clickable'] : '';
|
|
37
60
|
|
|
38
|
-
const getStepContent = (stepState: StepState, index: number, disabled?: boolean) => {
|
|
39
|
-
const stepNumberString = String(index + 1);
|
|
40
|
-
if (stepState === 'finished') {
|
|
41
|
-
return disabled ? null : <Icon className={classes['checkmark']} icon={Icons.Checkmark} />;
|
|
42
|
-
} else {
|
|
43
61
|
return (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
|
|
62
|
+
<button
|
|
63
|
+
key={step.label.toLowerCase().replace(/\s/, '-')}
|
|
64
|
+
disabled={
|
|
65
|
+
step.disabled ||
|
|
66
|
+
(stepState === 'future' && !futureStepsClickable) ||
|
|
67
|
+
stepState === 'current'
|
|
68
|
+
}
|
|
69
|
+
aria-current={stepState === 'current' ? 'step' : undefined}
|
|
70
|
+
onClick={() => onClick && onClick(index)}
|
|
71
|
+
className={`${classes['wizard-element']} ${classes[stepState]} ${clickableClassName} ${disabledStyleClassName}`}
|
|
72
|
+
>
|
|
73
|
+
<div className={classes['number-wrapper']}>
|
|
74
|
+
<span className={classes['number']}>
|
|
75
|
+
{getStepContent(stepState, index, step.disabled)}
|
|
76
|
+
</span>
|
|
77
|
+
</div>
|
|
78
|
+
<div className={classes['two-line-text-overflow']}>
|
|
79
|
+
<span className={classes['label']}>{step.label}</span>
|
|
80
|
+
</div>
|
|
81
|
+
</button>
|
|
48
82
|
);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const generatedSteps = steps.map((step, index) => {
|
|
53
|
-
const stepState = getStepState(index);
|
|
54
|
-
const disabledStyleClassName = step.disabled ? classes['disabled'] : '';
|
|
55
|
-
const clickableClassName = futureStepsClickable ? classes['clickable'] : '';
|
|
83
|
+
});
|
|
56
84
|
|
|
57
85
|
return (
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
step.disabled ||
|
|
62
|
-
(stepState === 'future' && !futureStepsClickable) ||
|
|
63
|
-
stepState === 'current'
|
|
64
|
-
}
|
|
65
|
-
aria-current={stepState === 'current' ? 'step' : undefined}
|
|
66
|
-
onClick={() => onClick && onClick(index)}
|
|
67
|
-
className={`${classes['wizard-element']} ${classes[stepState]} ${clickableClassName} ${disabledStyleClassName}`}
|
|
68
|
-
>
|
|
69
|
-
<div className={classes['number-wrapper']}>
|
|
70
|
-
<span className={classes['number']}>
|
|
71
|
-
{getStepContent(stepState, index, step.disabled)}
|
|
72
|
-
</span>
|
|
73
|
-
</div>
|
|
74
|
-
<div className={classes['two-line-text-overflow']}>
|
|
75
|
-
<span className={classes['label']}>{step.label}</span>
|
|
76
|
-
</div>
|
|
77
|
-
</button>
|
|
86
|
+
<div {...rest} ref={ref} className={classes['wizard']}>
|
|
87
|
+
{generatedSteps}
|
|
88
|
+
</div>
|
|
78
89
|
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<div {...restProps} className={classes['wizard']}>
|
|
83
|
-
{generatedSteps}
|
|
84
|
-
</div>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
90
|
+
}
|
|
91
|
+
);
|
package/src/Wizard/Wizard.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useEffect } from 'react';
|
|
1
|
+
import React, { Fragment, useContext, useEffect } from 'react';
|
|
2
2
|
import { Step } from './BaseWizardSteps/BaseWizardSteps';
|
|
3
3
|
import { WizardStateContext, WizardStateProvider } from './WizardStateProvider';
|
|
4
4
|
import { setWizardState } from './wizardStateReducer';
|
|
@@ -36,7 +36,7 @@ const WizardContent = ({ steps, mode, stepScreenReaderLabel, onStepChange, child
|
|
|
36
36
|
useSetWizardState(steps, mode, stepScreenReaderLabel);
|
|
37
37
|
useStepChanging(onStepChange);
|
|
38
38
|
|
|
39
|
-
return
|
|
39
|
+
return <Fragment>{children}</Fragment>;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export const Wizard = (props: Props) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useMemo } from 'react';
|
|
1
|
+
import React, { Fragment, useContext, useMemo } from 'react';
|
|
2
2
|
import { Button } from '../../Button/Button';
|
|
3
3
|
import { Step } from '../BaseWizardSteps/BaseWizardSteps';
|
|
4
4
|
import { WizardMode } from '../Wizard';
|
|
@@ -78,7 +78,7 @@ export const WizardActions = ({
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
return (
|
|
81
|
-
|
|
81
|
+
<Fragment>
|
|
82
82
|
<Button variant="text" onClick={onCancel}>
|
|
83
83
|
{cancelButtonLabel}
|
|
84
84
|
</Button>
|
|
@@ -95,6 +95,6 @@ export const WizardActions = ({
|
|
|
95
95
|
{isLastStepOrEditMode && (
|
|
96
96
|
<Button onClick={onSaveAndCloseWrapper}>{saveAndCloseButtonLabel}</Button>
|
|
97
97
|
)}
|
|
98
|
-
|
|
98
|
+
</Fragment>
|
|
99
99
|
);
|
|
100
100
|
};
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
1
|
+
import React, { ComponentPropsWithRef, useContext } from 'react';
|
|
2
2
|
import { WizardStateContext } from '../WizardStateProvider';
|
|
3
3
|
import { BaseWizardSteps } from '../BaseWizardSteps/BaseWizardSteps';
|
|
4
4
|
import { changeCurrentStepNo } from '../wizardStateReducer';
|
|
5
5
|
|
|
6
|
-
export interface Props extends
|
|
6
|
+
export interface Props extends ComponentPropsWithRef<'div'> {
|
|
7
7
|
onStepClick: (currentStepNo: number, selectedStepNo: number) => boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const WizardSteps =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
export const WizardSteps = React.forwardRef<HTMLDivElement, Props>(
|
|
11
|
+
({ onStepClick, ...rest }: Props, ref) => {
|
|
12
|
+
const {
|
|
13
|
+
state: { currentStepNo, mode, stepScreenReaderLabel, steps },
|
|
14
|
+
dispatch,
|
|
15
|
+
} = useContext(WizardStateContext);
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const onClick = (selectedStepNo: number) => {
|
|
18
|
+
onStepClick(currentStepNo, selectedStepNo) && dispatch(changeCurrentStepNo(selectedStepNo));
|
|
19
|
+
};
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
return (
|
|
22
|
+
<BaseWizardSteps
|
|
23
|
+
{...rest}
|
|
24
|
+
ref={ref}
|
|
25
|
+
onClick={onClick}
|
|
26
|
+
steps={steps}
|
|
27
|
+
currentStepNo={currentStepNo}
|
|
28
|
+
stepScreenReaderLabel={stepScreenReaderLabel}
|
|
29
|
+
futureStepsClickable={mode === 'edit'}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { Fragment, HTMLAttributes, ReactChild, useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
interface CSSProperties {
|
|
4
|
+
colorFocus?: string;
|
|
4
5
|
colorPrimary?: string;
|
|
5
6
|
colorSecondary?: string;
|
|
6
7
|
colorTertiary?: string;
|
|
@@ -16,6 +17,7 @@ interface CSSProperties {
|
|
|
16
17
|
inputBorderRadius?: string;
|
|
17
18
|
inputBorderWidth?: string;
|
|
18
19
|
inputBorderStyle?: string;
|
|
20
|
+
inputBackgroundColor?: string;
|
|
19
21
|
modalShadowColor?: string;
|
|
20
22
|
modalBackgroundColor?: string;
|
|
21
23
|
modalHeaderBackgroundColor?: string;
|
|
@@ -24,6 +26,13 @@ interface CSSProperties {
|
|
|
24
26
|
snackbarSuccessBackgroundColor?: string;
|
|
25
27
|
snackbarErrorBackgroundColor?: string;
|
|
26
28
|
snackbarBorderRadius?: string;
|
|
29
|
+
tabsBackgroundColor?: string;
|
|
30
|
+
tabBorderWidth?: string;
|
|
31
|
+
tabBorderStyle?: string;
|
|
32
|
+
tablistBorderWidth?: string;
|
|
33
|
+
tablistBorderStyle?: string;
|
|
34
|
+
tablistBorderColor?: string;
|
|
35
|
+
tabTextColor?: string;
|
|
27
36
|
default?: string;
|
|
28
37
|
success?: string;
|
|
29
38
|
error?: string;
|
|
@@ -48,6 +57,7 @@ export interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
|
48
57
|
|
|
49
58
|
export const BaseStyling = ({ children, properties = {} }: Props) => {
|
|
50
59
|
const defaultProperties: CSSProperties = {
|
|
60
|
+
colorFocus: '#0085f2',
|
|
51
61
|
colorPrimary: '#9e006b',
|
|
52
62
|
colorSecondary: '#003b5e',
|
|
53
63
|
colorTertiary: '#ff1e4e',
|
|
@@ -63,6 +73,7 @@ export const BaseStyling = ({ children, properties = {} }: Props) => {
|
|
|
63
73
|
inputBorderRadius: '8px',
|
|
64
74
|
inputBorderWidth: '1px',
|
|
65
75
|
inputBorderStyle: 'solid',
|
|
76
|
+
inputBackgroundColor: '#FFF',
|
|
66
77
|
modalShadowColor: 'rgba(0, 0, 0, 0.16)',
|
|
67
78
|
modalBackgroundColor: '#F5F8F8',
|
|
68
79
|
modalHeaderBackgroundColor: '#FFF',
|
|
@@ -71,6 +82,13 @@ export const BaseStyling = ({ children, properties = {} }: Props) => {
|
|
|
71
82
|
snackbarSuccessBackgroundColor: '#008a28',
|
|
72
83
|
snackbarErrorBackgroundColor: '#e22a1d',
|
|
73
84
|
snackbarBorderRadius: '8px',
|
|
85
|
+
tabsBackgroundColor: '#FFF',
|
|
86
|
+
tabBorderWidth: '2px',
|
|
87
|
+
tabBorderStyle: 'solid',
|
|
88
|
+
tablistBorderWidth: '1px',
|
|
89
|
+
tablistBorderStyle: 'solid',
|
|
90
|
+
tablistBorderColor: '#C3C3C7',
|
|
91
|
+
tabTextColor: '#0f0f1e',
|
|
74
92
|
default: '#0f0f1e',
|
|
75
93
|
success: '#008a28',
|
|
76
94
|
error: '#e22a1d',
|
|
@@ -94,7 +112,7 @@ export const BaseStyling = ({ children, properties = {} }: Props) => {
|
|
|
94
112
|
/** Set the actual CSS properties on the HTML :root object */
|
|
95
113
|
const setCSSProperties = (CSSPropertiesObject: CSSProperties) => {
|
|
96
114
|
for (const [key, value] of Object.entries(CSSPropertiesObject)) {
|
|
97
|
-
const formattedPropertyName = key.
|
|
115
|
+
const formattedPropertyName = key.replace(/([A-Z])/g, (val) => `-${val.toLowerCase()}`);
|
|
98
116
|
document.documentElement.style.setProperty(`--${formattedPropertyName}`, value);
|
|
99
117
|
}
|
|
100
118
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
1
|
+
import React, { Fragment, useRef } from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { ConfigObject, usePosition } from './usePosition';
|
|
4
4
|
import userEvent from '@testing-library/user-event';
|
|
@@ -30,7 +30,7 @@ const createUsePositionComponent = (
|
|
|
30
30
|
const { top, left, bottom, right, calculatePosition } = usePosition({ ...parameters });
|
|
31
31
|
|
|
32
32
|
return (
|
|
33
|
-
|
|
33
|
+
<Fragment>
|
|
34
34
|
<button data-testid="button" onClick={calculatePosition} ref={relativeElement}>
|
|
35
35
|
Test
|
|
36
36
|
</button>
|
|
@@ -41,7 +41,7 @@ const createUsePositionComponent = (
|
|
|
41
41
|
>
|
|
42
42
|
Test
|
|
43
43
|
</div>
|
|
44
|
-
|
|
44
|
+
</Fragment>
|
|
45
45
|
);
|
|
46
46
|
};
|
|
47
47
|
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
|
|
8
|
+
export interface RepeatedComponentProps {
|
|
9
|
+
onChange?: (state: { [key: string]: unknown }) => void;
|
|
10
|
+
identifier?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const ComponentToRepeat = ({ onChange, identifier }: RepeatedComponentProps) => {
|
|
14
|
+
const [inputState, setInputState] = useState({
|
|
15
|
+
errorMessage: 'random error',
|
|
16
|
+
error: false,
|
|
17
|
+
value: '',
|
|
18
|
+
identifier: identifier,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
onChange && onChange(inputState);
|
|
23
|
+
}, [inputState]);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<InputWrapper
|
|
27
|
+
helperText="Helper text for this field. Description should be short and not repeat the label"
|
|
28
|
+
name={`input_${identifier}`}
|
|
29
|
+
errorMessage={inputState.errorMessage}
|
|
30
|
+
type="text"
|
|
31
|
+
error={inputState.error}
|
|
32
|
+
value={inputState.value}
|
|
33
|
+
label="Label for this inputfield"
|
|
34
|
+
onChange={(event) => {
|
|
35
|
+
setInputState((prevState) => ({ ...prevState, value: event.target.value }));
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe('useRepeater should render', () => {
|
|
42
|
+
it('renders without crashing and repeats 1 item', () => {
|
|
43
|
+
const onChangeHandler = jest.fn();
|
|
44
|
+
|
|
45
|
+
const App = () => {
|
|
46
|
+
const { repeatedComponents } = useRepeater({
|
|
47
|
+
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler} />,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div>
|
|
52
|
+
{repeatedComponents.map((component, index) =>
|
|
53
|
+
React.cloneElement(component, {
|
|
54
|
+
identifier: `component_${index}`,
|
|
55
|
+
})
|
|
56
|
+
)}
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const renderedItems = render(<App />);
|
|
62
|
+
|
|
63
|
+
const inputWrappers = renderedItems.container.querySelectorAll('.wrapper.input-wrapper');
|
|
64
|
+
|
|
65
|
+
expect(inputWrappers.length).toBe(1);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should repeat 2 items', () => {
|
|
69
|
+
const onChangeHandler = jest.fn();
|
|
70
|
+
|
|
71
|
+
const App = () => {
|
|
72
|
+
const { repeatedComponents, repeat } = useRepeater({
|
|
73
|
+
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler} />,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
repeat();
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
{repeatedComponents.map((component, index) =>
|
|
83
|
+
React.cloneElement(component, {
|
|
84
|
+
identifier: `component_${index}`,
|
|
85
|
+
})
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const renderedItems = render(<App />);
|
|
92
|
+
|
|
93
|
+
const inputWrappers = renderedItems.container.querySelectorAll('.wrapper.input-wrapper');
|
|
94
|
+
|
|
95
|
+
expect(inputWrappers.length).toBe(2);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should repeat 3 items and remove the first index', () => {
|
|
99
|
+
const onChangeHandler = jest.fn();
|
|
100
|
+
|
|
101
|
+
const App = () => {
|
|
102
|
+
const { repeatedComponents, repeat, remove } = useRepeater({
|
|
103
|
+
componentToRepeat: <ComponentToRepeat onChange={onChangeHandler} />,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
repeat();
|
|
108
|
+
repeat();
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<div>
|
|
113
|
+
{repeatedComponents.map((component, index) => (
|
|
114
|
+
<Fragment key={index}>
|
|
115
|
+
{React.cloneElement(component, {
|
|
116
|
+
identifier: generateID(),
|
|
117
|
+
})}
|
|
118
|
+
<button id={`remove_input_${index}`} onClick={() => remove(component)}>
|
|
119
|
+
Remove
|
|
120
|
+
</button>
|
|
121
|
+
</Fragment>
|
|
122
|
+
))}
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const renderedItems = render(<App />);
|
|
128
|
+
|
|
129
|
+
const secondInputID = renderedItems.container.querySelectorAll('.input-wrapper input')[1].id;
|
|
130
|
+
|
|
131
|
+
const removeButton = renderedItems.container.querySelector('#remove_input_1');
|
|
132
|
+
|
|
133
|
+
userEvent.click(removeButton!);
|
|
134
|
+
|
|
135
|
+
expect(renderedItems.container.querySelector(`#${secondInputID}`)).toBeFalsy();
|
|
136
|
+
const inputWrappers = renderedItems.container.querySelectorAll('.wrapper.input-wrapper');
|
|
137
|
+
expect(inputWrappers.length).toBe(2);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { generateID } from '../util/helper';
|
|
3
|
+
|
|
4
|
+
interface Arguments {
|
|
5
|
+
componentToRepeat: React.ReactElement;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useRepeater = <T>({ componentToRepeat }: Arguments) => {
|
|
9
|
+
const [repeatedComponents, setRepeatedComponents] = useState<JSX.Element[]>([]);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
repeat();
|
|
13
|
+
}, []);
|
|
14
|
+
|
|
15
|
+
const repeat = () => {
|
|
16
|
+
const clonedComponent = React.cloneElement(componentToRepeat, { key: generateID(20) });
|
|
17
|
+
|
|
18
|
+
setRepeatedComponents((prevState) => [...prevState, clonedComponent]);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const remove = (componentToRemove: React.ReactElement<T>) => {
|
|
22
|
+
const newRepeatedComponents = repeatedComponents.filter(
|
|
23
|
+
(component) => component !== componentToRemove
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
setRepeatedComponents(newRepeatedComponents);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
repeatedComponents,
|
|
31
|
+
repeat,
|
|
32
|
+
remove,
|
|
33
|
+
};
|
|
34
|
+
};
|
package/src/hooks/useSpacing.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
2
|
|
|
3
|
-
type SpacingMultiplier = 0 | 0.5 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
3
|
+
export type SpacingMultiplier = 0 | 0.5 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
4
4
|
type SpacingMultiplierStringOrNumber = `${SpacingMultiplier}` | SpacingMultiplier;
|
|
5
5
|
type MultiValueSpacingMultiplier =
|
|
6
6
|
| `${SpacingMultiplier} ${SpacingMultiplier} ${SpacingMultiplier} ${SpacingMultiplier}`
|