@onewelcome/react-lib-components 0.1.1-alpha → 0.1.4-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 +3 -4
- package/dist/ContextMenu/ContextMenu.d.ts +3 -3
- package/dist/Form/Checkbox/Checkbox.d.ts +5 -5
- package/dist/Form/Fieldset/Fieldset.d.ts +4 -4
- package/dist/Form/FormControl/FormControl.d.ts +5 -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 +7 -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 +4 -6
- package/dist/Notifications/BaseModal/BaseModal.d.ts +3 -4
- package/dist/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +3 -3
- package/dist/Notifications/BaseModal/BaseModalContent/BaseModalContent.d.ts +3 -3
- package/dist/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +3 -3
- package/dist/Notifications/Dialog/Dialog.d.ts +3 -3
- package/dist/Notifications/Dialog/DialogActions/DialogActions.d.ts +3 -3
- package/dist/Notifications/Dialog/DialogTitle/DialogTitle.d.ts +3 -3
- package/dist/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.d.ts +5 -4
- package/dist/Notifications/DiscardChangesModal/DiscardChangesModal.d.ts +3 -1
- 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 +3 -3
- 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 +6 -0
- package/dist/interfaces.d.ts +2 -11
- package/dist/react-lib-components.cjs.development.js +2395 -1696
- 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 +2391 -1698
- 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 +14 -9
- package/src/ContextMenu/ContextMenu.test.tsx +27 -1
- package/src/ContextMenu/ContextMenu.tsx +70 -65
- package/src/Form/Checkbox/Checkbox.test.tsx +28 -2
- package/src/Form/Checkbox/Checkbox.tsx +132 -122
- package/src/Form/Fieldset/Fieldset.test.tsx +28 -2
- package/src/Form/Fieldset/Fieldset.tsx +96 -50
- package/src/Form/FormControl/FormControl.test.tsx +27 -1
- package/src/Form/FormControl/FormControl.tsx +36 -39
- package/src/Form/FormGroup/FormGroup.test.tsx +51 -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.test.tsx +28 -2
- package/src/Form/Radio/Radio.tsx +98 -90
- 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 +27 -1
- 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.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 +54 -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 +10 -7
- package/src/Notifications/BaseModal/BaseModal.test.tsx +27 -1
- package/src/Notifications/BaseModal/BaseModal.tsx +59 -54
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +26 -1
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +11 -9
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +27 -1
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +27 -26
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +29 -1
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +18 -16
- package/src/Notifications/Dialog/Dialog.test.tsx +39 -1
- package/src/Notifications/Dialog/Dialog.tsx +84 -78
- package/src/Notifications/Dialog/DialogActions/DialogActions.test.tsx +27 -1
- package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +15 -12
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +28 -2
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +13 -11
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +41 -1
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +43 -36
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +52 -1
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.tsx +8 -3
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +1 -1
- 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.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.test.tsx +27 -1
- package/src/Tiles/Tile.tsx +59 -62
- package/src/Tiles/Tiles.test.tsx +27 -1
- 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/WizardSteps/WizardSteps.tsx +24 -21
- package/src/_BaseStyling_/BaseStyling.tsx +19 -1
- 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 +15 -1
- package/src/interfaces.ts +2 -12
- package/src/util/helper.test.tsx +38 -1
- package/src/util/helper.tsx +21 -0
|
@@ -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
|
};
|
|
@@ -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}`
|
package/src/hooks/useWrapper.ts
CHANGED
|
@@ -10,13 +10,18 @@ export const useWrapper = (value?: string, placeholder?: string, type?: InputTyp
|
|
|
10
10
|
const [hasFocus, setHasFocus] = useState(false);
|
|
11
11
|
|
|
12
12
|
useEffect(() => {
|
|
13
|
-
if (
|
|
13
|
+
if (
|
|
14
|
+
(value?.length && value.length > 0) ||
|
|
15
|
+
placeholder ||
|
|
16
|
+
type === 'datetime-local' ||
|
|
17
|
+
type === 'time'
|
|
18
|
+
) {
|
|
14
19
|
setFloatingLabelActive(true);
|
|
15
20
|
}
|
|
16
21
|
}, []);
|
|
17
22
|
|
|
18
23
|
useEffect(() => {
|
|
19
|
-
if (value?.length || hasFocus) {
|
|
24
|
+
if ((value?.length && value.length > 0) || hasFocus) {
|
|
20
25
|
setFloatingLabelActive(true);
|
|
21
26
|
} else if (!placeholder && !hasFocus && type !== 'datetime-local' && type !== 'time') {
|
|
22
27
|
setFloatingLabelActive(false);
|
package/src/index.ts
CHANGED
|
@@ -4,15 +4,25 @@ export { Typography } from './Typography/Typography';
|
|
|
4
4
|
export { Button } from './Button/Button';
|
|
5
5
|
export { Link } from './Link/Link';
|
|
6
6
|
export { IconButton } from './Button/IconButton';
|
|
7
|
-
|
|
7
|
+
export {
|
|
8
|
+
Pagination,
|
|
9
|
+
Props as PaginationProps,
|
|
10
|
+
PageChangeLabels,
|
|
11
|
+
PaginationTranslations,
|
|
12
|
+
PageSize,
|
|
13
|
+
} from './Pagination/Pagination';
|
|
8
14
|
export { Icon, Icons } from './Icon/Icon';
|
|
9
15
|
|
|
16
|
+
export { Tabs, Props as TabsProps } from './Tabs/Tabs';
|
|
17
|
+
export { Tab, Props as TabProps } from './Tabs/Tab';
|
|
18
|
+
|
|
10
19
|
export { Dialog } from './Notifications/Dialog/Dialog';
|
|
11
20
|
export { Modal } from './Notifications/Modal/Modal';
|
|
12
21
|
export { ModalActions } from './Notifications/Modal/ModalActions/ModalActions';
|
|
13
22
|
export { ModalContent } from './Notifications/Modal/ModalContent/ModalContent';
|
|
14
23
|
export { ModalHeader } from './Notifications/Modal/ModalHeader/ModalHeader';
|
|
15
24
|
export { DiscardChangesModal } from './Notifications/DiscardChangesModal/DiscardChangesModal';
|
|
25
|
+
export { TextEllipsis, Props as TextEllipsisProps } from './TextEllipsis/TextEllipsis';
|
|
16
26
|
export { Tooltip } from './Tooltip/Tooltip';
|
|
17
27
|
export { Tiles } from './Tiles/Tiles';
|
|
18
28
|
export { Tile } from './Tiles/Tile';
|
|
@@ -23,6 +33,10 @@ export { Breadcrumbs } from './Breadcrumbs/Breadcrumbs';
|
|
|
23
33
|
export { SnackbarProvider } from './Notifications/Snackbar/SnackbarProvider/SnackbarProvider';
|
|
24
34
|
export { useSnackbar } from './Notifications/Snackbar/useSnackbar';
|
|
25
35
|
|
|
36
|
+
export { useRepeater } from './hooks/useRepeater';
|
|
37
|
+
|
|
38
|
+
export { generateID } from './util/helper';
|
|
39
|
+
|
|
26
40
|
/** Form components */
|
|
27
41
|
export { Form } from './Form/Form';
|
|
28
42
|
export { Fieldset } from './Form/Fieldset/Fieldset';
|
package/src/interfaces.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export type DataAttributeKey = `data-${string}`;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* By default typescript does not allow data-* attributes on HTMLAttributes interface. We extend the default React.HTMLAttributes interface here and add the dataAttribute possibility into it.
|
|
5
|
-
* An example of this can be found in Checkbox.tsx. We assign wrapperProps to the HTMLAttributes interface below, and are now able to add a test-id inside of Checkbox.test.tsx on line 77.
|
|
6
|
-
*/
|
|
7
|
-
type DataAttributeKey = `data-${string}`;
|
|
8
|
-
|
|
9
|
-
export interface HTMLProps<T> extends React.HTMLProps<T> {
|
|
10
|
-
[dataAttribute: DataAttributeKey]: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface HTMLAttributes<T> extends React.HTMLAttributes<T> {
|
|
3
|
+
export interface KeyValuePair {
|
|
14
4
|
[dataAttribute: DataAttributeKey]: any;
|
|
15
5
|
}
|
package/src/util/helper.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generateID } from './helper';
|
|
1
|
+
import { generateID, filterProps } from './helper';
|
|
2
2
|
|
|
3
3
|
/* Generate an ID of 20 characters with a string woven in */
|
|
4
4
|
|
|
@@ -13,3 +13,40 @@ describe('generateID should correctly generate IDs in the correct way', () => {
|
|
|
13
13
|
expect(ID2.length).toBe(20);
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
|
+
|
|
17
|
+
describe('filterprops should return the correct object', () => {
|
|
18
|
+
it('gives back the props we told it to filter', () => {
|
|
19
|
+
const propsObject = {
|
|
20
|
+
'data-filter': true,
|
|
21
|
+
'data-test': false,
|
|
22
|
+
'aria-hidden': false,
|
|
23
|
+
'aria-expanded': true,
|
|
24
|
+
title: 'test',
|
|
25
|
+
className: 'example-classname',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const returnedPropsObject = filterProps(propsObject, /^data-/);
|
|
29
|
+
|
|
30
|
+
expect(returnedPropsObject).toStrictEqual({ 'data-filter': true, 'data-test': false });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('gives back the propsObject without the props we told it to filter', () => {
|
|
34
|
+
const propsObject = {
|
|
35
|
+
'data-filter': true,
|
|
36
|
+
'data-test': false,
|
|
37
|
+
'aria-hidden': false,
|
|
38
|
+
'aria-expanded': true,
|
|
39
|
+
title: 'test',
|
|
40
|
+
className: 'example-classname',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const returnedPropsObject = filterProps(propsObject, /^data-/, false);
|
|
44
|
+
|
|
45
|
+
expect(returnedPropsObject).toStrictEqual({
|
|
46
|
+
'aria-hidden': false,
|
|
47
|
+
'aria-expanded': true,
|
|
48
|
+
title: 'test',
|
|
49
|
+
className: 'example-classname',
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
package/src/util/helper.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type KeyValuePair = { [key: string]: unknown };
|
|
2
|
+
|
|
1
3
|
export const generateID = (length = 15, stringToWeaveIn?: string) => {
|
|
2
4
|
/** We will make sure to mesh the generate id and name property together to basically create a unique ID */
|
|
3
5
|
let hashCharacters = [
|
|
@@ -78,3 +80,22 @@ export const generateID = (length = 15, stringToWeaveIn?: string) => {
|
|
|
78
80
|
|
|
79
81
|
return id.slice(0, length);
|
|
80
82
|
};
|
|
83
|
+
|
|
84
|
+
export const filterProps = (props: any, regexPattern: RegExp, returnFiltered: boolean = true) => {
|
|
85
|
+
if (returnFiltered) {
|
|
86
|
+
return Object.keys(props).reduce((acc: KeyValuePair, key) => {
|
|
87
|
+
if (regexPattern.test(key)) {
|
|
88
|
+
acc[key] = props[key];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return acc;
|
|
92
|
+
}, {});
|
|
93
|
+
} else {
|
|
94
|
+
return Object.entries(props)
|
|
95
|
+
.filter(([key]) => !regexPattern.test(key))
|
|
96
|
+
.reduce(
|
|
97
|
+
(prevObj, currKeyValPair) => ({ ...prevObj, [currKeyValPair[0]]: currKeyValPair[1] }),
|
|
98
|
+
{}
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
};
|