@onewelcome/react-lib-components 0.1.0-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.
Files changed (248) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -0
  3. package/dist/BaseModal/BaseModal.d.ts +16 -0
  4. package/dist/BaseModal/BaseModalActions/BaseModalActions.d.ts +5 -0
  5. package/dist/BaseModal/BaseModalContent/BaseModalContent.d.ts +8 -0
  6. package/dist/BaseModal/BaseModalContext.d.ts +2 -0
  7. package/dist/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +8 -0
  8. package/dist/Breadcrumbs/Breadcrumbs.d.ts +9 -0
  9. package/dist/Button/BaseButton.d.ts +8 -0
  10. package/dist/Button/Button.d.ts +10 -0
  11. package/dist/Button/IconButton.d.ts +10 -0
  12. package/dist/ContextMenu/ContextMenu.d.ts +18 -0
  13. package/dist/ContextMenu/ContextMenuItem.d.ts +6 -0
  14. package/dist/Dialog/Dialog.d.ts +18 -0
  15. package/dist/Dialog/DialogActions/DialogActions.d.ts +6 -0
  16. package/dist/Dialog/DialogTitle/DialogTitle.d.ts +6 -0
  17. package/dist/Form/Checkbox/Checkbox.d.ts +13 -0
  18. package/dist/Form/Fieldset/Fieldset.d.ts +13 -0
  19. package/dist/Form/Form.d.ts +5 -0
  20. package/dist/Form/FormControl/FormControl.d.ts +8 -0
  21. package/dist/Form/FormGroup/FormGroup.d.ts +18 -0
  22. package/dist/Form/FormHelperText/FormHelperText.d.ts +7 -0
  23. package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +18 -0
  24. package/dist/Form/Input/Input.d.ts +12 -0
  25. package/dist/Form/Label/Label.d.ts +6 -0
  26. package/dist/Form/Radio/Radio.d.ts +11 -0
  27. package/dist/Form/Select/Option.d.ts +12 -0
  28. package/dist/Form/Select/Select.d.ts +15 -0
  29. package/dist/Form/Textarea/Textarea.d.ts +7 -0
  30. package/dist/Form/Toggle/Toggle.d.ts +6 -0
  31. package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +8 -0
  32. package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +17 -0
  33. package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +10 -0
  34. package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +12 -0
  35. package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +14 -0
  36. package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +28 -0
  37. package/dist/Form/form.interfaces.d.ts +12 -0
  38. package/dist/Icon/Icon.d.ts +75 -0
  39. package/dist/Link/Link.d.ts +15 -0
  40. package/dist/Modal/Modal.d.ts +1 -0
  41. package/dist/Modal/ModalActions/ModalActions.d.ts +1 -0
  42. package/dist/Modal/ModalContent/ModalContent.d.ts +1 -0
  43. package/dist/Modal/ModalHeader/ModalHeader.d.ts +1 -0
  44. package/dist/Popover/Popover.d.ts +11 -0
  45. package/dist/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +12 -0
  46. package/dist/Snackbar/SnackbarItem/SnackbarItem.d.ts +13 -0
  47. package/dist/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +18 -0
  48. package/dist/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +14 -0
  49. package/dist/Snackbar/interfaces.d.ts +10 -0
  50. package/dist/Snackbar/useSnackbar.d.ts +1 -0
  51. package/dist/Tiles/Tile.d.ts +16 -0
  52. package/dist/Tiles/Tiles.d.ts +6 -0
  53. package/dist/Tooltip/Tooltip.d.ts +11 -0
  54. package/dist/Typography/Typography.d.ts +12 -0
  55. package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +13 -0
  56. package/dist/Wizard/Wizard.d.ts +12 -0
  57. package/dist/Wizard/WizardActions/WizardActions.d.ts +12 -0
  58. package/dist/Wizard/WizardStateProvider.d.ts +12 -0
  59. package/dist/Wizard/WizardSteps/WizardSteps.d.ts +5 -0
  60. package/dist/Wizard/wizardStateReducer.d.ts +26 -0
  61. package/dist/_BaseStyling_/BaseStyling.d.ts +47 -0
  62. package/dist/hooks/useAnimation.d.ts +6 -0
  63. package/dist/hooks/useBodyClick.d.ts +1 -0
  64. package/dist/hooks/useFormSelector.d.ts +13 -0
  65. package/dist/hooks/usePosition.d.ts +36 -0
  66. package/dist/hooks/useScroll.d.ts +2 -0
  67. package/dist/hooks/useSpacing.d.ts +18 -0
  68. package/dist/hooks/useWrapper.d.ts +11 -0
  69. package/dist/index.d.ts +43 -0
  70. package/dist/index.js +8 -0
  71. package/dist/interfaces.d.ts +13 -0
  72. package/dist/react-lib-components.cjs.development.js +3282 -0
  73. package/dist/react-lib-components.cjs.development.js.map +1 -0
  74. package/dist/react-lib-components.cjs.production.min.js +2 -0
  75. package/dist/react-lib-components.cjs.production.min.js.map +1 -0
  76. package/dist/react-lib-components.esm.js +3235 -0
  77. package/dist/react-lib-components.esm.js.map +1 -0
  78. package/dist/util/helper.d.ts +1 -0
  79. package/package.json +88 -0
  80. package/src/BaseModal/BaseModal.module.scss +58 -0
  81. package/src/BaseModal/BaseModal.test.tsx +59 -0
  82. package/src/BaseModal/BaseModal.tsx +113 -0
  83. package/src/BaseModal/BaseModalActions/BaseModalActions.module.scss +9 -0
  84. package/src/BaseModal/BaseModalActions/BaseModalActions.test.tsx +17 -0
  85. package/src/BaseModal/BaseModalActions/BaseModalActions.tsx +14 -0
  86. package/src/BaseModal/BaseModalContent/BaseModalContent.module.scss +6 -0
  87. package/src/BaseModal/BaseModalContent/BaseModalContent.test.tsx +29 -0
  88. package/src/BaseModal/BaseModalContent/BaseModalContent.tsx +35 -0
  89. package/src/BaseModal/BaseModalContext.ts +2 -0
  90. package/src/BaseModal/BaseModalHeader/BaseModalHeader.module.scss +17 -0
  91. package/src/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +30 -0
  92. package/src/BaseModal/BaseModalHeader/BaseModalHeader.tsx +28 -0
  93. package/src/Breadcrumbs/Breadcrumbs.module.scss +14 -0
  94. package/src/Breadcrumbs/Breadcrumbs.test.tsx +42 -0
  95. package/src/Breadcrumbs/Breadcrumbs.tsx +48 -0
  96. package/src/Button/BaseButton.module.scss +20 -0
  97. package/src/Button/BaseButton.test.tsx +59 -0
  98. package/src/Button/BaseButton.tsx +31 -0
  99. package/src/Button/Button.module.scss +336 -0
  100. package/src/Button/Button.test.tsx +76 -0
  101. package/src/Button/Button.tsx +44 -0
  102. package/src/Button/IconButton.module.scss +161 -0
  103. package/src/Button/IconButton.test.tsx +47 -0
  104. package/src/Button/IconButton.tsx +29 -0
  105. package/src/ContextMenu/ContextMenu.module.scss +20 -0
  106. package/src/ContextMenu/ContextMenu.test.tsx +93 -0
  107. package/src/ContextMenu/ContextMenu.tsx +91 -0
  108. package/src/ContextMenu/ContextMenuItem.module.scss +31 -0
  109. package/src/ContextMenu/ContextMenuItem.tsx +15 -0
  110. package/src/Dialog/Dialog.module.scss +16 -0
  111. package/src/Dialog/Dialog.test.tsx +79 -0
  112. package/src/Dialog/Dialog.tsx +96 -0
  113. package/src/Dialog/DialogActions/DialogActions.module.scss +11 -0
  114. package/src/Dialog/DialogActions/DialogActions.test.tsx +25 -0
  115. package/src/Dialog/DialogActions/DialogActions.tsx +21 -0
  116. package/src/Dialog/DialogTitle/DialogTitle.module.scss +7 -0
  117. package/src/Dialog/DialogTitle/DialogTitle.test.tsx +18 -0
  118. package/src/Dialog/DialogTitle/DialogTitle.tsx +18 -0
  119. package/src/Form/Checkbox/Checkbox.module.scss +65 -0
  120. package/src/Form/Checkbox/Checkbox.test.tsx +119 -0
  121. package/src/Form/Checkbox/Checkbox.tsx +145 -0
  122. package/src/Form/Fieldset/Fieldset.module.scss +19 -0
  123. package/src/Form/Fieldset/Fieldset.test.tsx +85 -0
  124. package/src/Form/Fieldset/Fieldset.tsx +55 -0
  125. package/src/Form/Form.module.scss +3 -0
  126. package/src/Form/Form.test.tsx +47 -0
  127. package/src/Form/Form.tsx +14 -0
  128. package/src/Form/FormControl/FormControl.module.scss +67 -0
  129. package/src/Form/FormControl/FormControl.test.tsx +56 -0
  130. package/src/Form/FormControl/FormControl.tsx +47 -0
  131. package/src/Form/FormGroup/FormGroup.module.scss +29 -0
  132. package/src/Form/FormGroup/FormGroup.test.tsx +61 -0
  133. package/src/Form/FormGroup/FormGroup.tsx +78 -0
  134. package/src/Form/FormHelperText/FormHelperText.module.scss +8 -0
  135. package/src/Form/FormHelperText/FormHelperText.test.tsx +42 -0
  136. package/src/Form/FormHelperText/FormHelperText.tsx +22 -0
  137. package/src/Form/FormSelectorWrapper/FormSelectorWrapper.module.scss +33 -0
  138. package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +65 -0
  139. package/src/Form/Input/Input.module.scss +65 -0
  140. package/src/Form/Input/Input.test.tsx +135 -0
  141. package/src/Form/Input/Input.tsx +72 -0
  142. package/src/Form/Label/Label.module.scss +5 -0
  143. package/src/Form/Label/Label.test.tsx +26 -0
  144. package/src/Form/Label/Label.tsx +19 -0
  145. package/src/Form/Radio/Radio.module.scss +100 -0
  146. package/src/Form/Radio/Radio.test.tsx +88 -0
  147. package/src/Form/Radio/Radio.tsx +98 -0
  148. package/src/Form/Select/Option.test.tsx +15 -0
  149. package/src/Form/Select/Option.tsx +57 -0
  150. package/src/Form/Select/Select.module.scss +189 -0
  151. package/src/Form/Select/Select.test.tsx +96 -0
  152. package/src/Form/Select/Select.tsx +217 -0
  153. package/src/Form/Textarea/Textarea.module.scss +53 -0
  154. package/src/Form/Textarea/Textarea.test.tsx +76 -0
  155. package/src/Form/Textarea/Textarea.tsx +33 -0
  156. package/src/Form/Toggle/Toggle.module.scss +58 -0
  157. package/src/Form/Toggle/Toggle.test.tsx +29 -0
  158. package/src/Form/Toggle/Toggle.tsx +20 -0
  159. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.module.scss +12 -0
  160. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +99 -0
  161. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +62 -0
  162. package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +24 -0
  163. package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +93 -0
  164. package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +92 -0
  165. package/src/Form/Wrapper/RadioWrapper/RadioWrapper.module.scss +12 -0
  166. package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +101 -0
  167. package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +74 -0
  168. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.module.scss +14 -0
  169. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +101 -0
  170. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +59 -0
  171. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +65 -0
  172. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +125 -0
  173. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +105 -0
  174. package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +35 -0
  175. package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +17 -0
  176. package/src/Form/Wrapper/Wrapper/Wrapper.tsx +101 -0
  177. package/src/Form/form.interfaces.ts +14 -0
  178. package/src/Icon/Icon.module.scss +278 -0
  179. package/src/Icon/Icon.test.tsx +39 -0
  180. package/src/Icon/Icon.tsx +94 -0
  181. package/src/Link/Link.module.scss +46 -0
  182. package/src/Link/Link.test.tsx +122 -0
  183. package/src/Link/Link.tsx +80 -0
  184. package/src/Link/types.d.ts +9 -0
  185. package/src/Modal/Modal.test.tsx +16 -0
  186. package/src/Modal/Modal.tsx +1 -0
  187. package/src/Modal/ModalActions/ModalActions.tsx +4 -0
  188. package/src/Modal/ModalContent/ModalContent.tsx +4 -0
  189. package/src/Modal/ModalHeader/ModalHeader.tsx +4 -0
  190. package/src/Popover/Popover.module.scss +18 -0
  191. package/src/Popover/Popover.test.tsx +84 -0
  192. package/src/Popover/Popover.tsx +46 -0
  193. package/src/Snackbar/SnackbarContainer/SnackbarContainer.module.scss +35 -0
  194. package/src/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +37 -0
  195. package/src/Snackbar/SnackbarContainer/SnackbarContainer.tsx +28 -0
  196. package/src/Snackbar/SnackbarItem/SnackbarItem.module.scss +135 -0
  197. package/src/Snackbar/SnackbarItem/SnackbarItem.test.tsx +47 -0
  198. package/src/Snackbar/SnackbarItem/SnackbarItem.tsx +105 -0
  199. package/src/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +179 -0
  200. package/src/Snackbar/SnackbarProvider/SnackbarProvider.tsx +127 -0
  201. package/src/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +25 -0
  202. package/src/Snackbar/interfaces.ts +11 -0
  203. package/src/Snackbar/useSnackbar.ts +4 -0
  204. package/src/Tiles/Tile.module.scss +72 -0
  205. package/src/Tiles/Tile.test.tsx +129 -0
  206. package/src/Tiles/Tile.tsx +48 -0
  207. package/src/Tiles/Tiles.module.scss +11 -0
  208. package/src/Tiles/Tiles.test.tsx +118 -0
  209. package/src/Tiles/Tiles.tsx +48 -0
  210. package/src/Tooltip/Tooltip.module.scss +42 -0
  211. package/src/Tooltip/Tooltip.test.tsx +72 -0
  212. package/src/Tooltip/Tooltip.tsx +130 -0
  213. package/src/Typography/Typography.module.scss +46 -0
  214. package/src/Typography/Typography.test.tsx +114 -0
  215. package/src/Typography/Typography.tsx +84 -0
  216. package/src/Wizard/BaseWizardSteps/BaseWizardSteps.module.scss +192 -0
  217. package/src/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +75 -0
  218. package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +86 -0
  219. package/src/Wizard/Wizard.test.tsx +198 -0
  220. package/src/Wizard/Wizard.tsx +49 -0
  221. package/src/Wizard/WizardActions/WizardActions.test.tsx +168 -0
  222. package/src/Wizard/WizardActions/WizardActions.tsx +100 -0
  223. package/src/Wizard/WizardStateProvider.tsx +26 -0
  224. package/src/Wizard/WizardSteps/WizardSteps.test.tsx +110 -0
  225. package/src/Wizard/WizardSteps/WizardSteps.tsx +30 -0
  226. package/src/Wizard/wizardStateReducer.ts +51 -0
  227. package/src/_BaseStyling_/BaseStyling.test.tsx +39 -0
  228. package/src/_BaseStyling_/BaseStyling.tsx +115 -0
  229. package/src/hooks/useAnimation.test.tsx +45 -0
  230. package/src/hooks/useAnimation.ts +20 -0
  231. package/src/hooks/useBodyClick.test.tsx +39 -0
  232. package/src/hooks/useBodyClick.ts +20 -0
  233. package/src/hooks/useFormSelector.test.ts +40 -0
  234. package/src/hooks/useFormSelector.ts +47 -0
  235. package/src/hooks/usePosition.test.tsx +494 -0
  236. package/src/hooks/usePosition.ts +347 -0
  237. package/src/hooks/useScroll.test.tsx +20 -0
  238. package/src/hooks/useScroll.ts +16 -0
  239. package/src/hooks/useSpacing.test.ts +70 -0
  240. package/src/hooks/useSpacing.ts +42 -0
  241. package/src/hooks/useWrapper.test.ts +49 -0
  242. package/src/hooks/useWrapper.ts +35 -0
  243. package/src/index.ts +52 -0
  244. package/src/interfaces.ts +15 -0
  245. package/src/readyclasses.module.scss +77 -0
  246. package/src/types.d.ts +4 -0
  247. package/src/util/helper.test.tsx +15 -0
  248. package/src/util/helper.tsx +80 -0
@@ -0,0 +1,51 @@
1
+ import { Reducer } from 'react';
2
+ import { Step } from './BaseWizardSteps/BaseWizardSteps';
3
+ import { WizardMode } from './Wizard';
4
+
5
+ type WizardStateType = {
6
+ steps: Step[];
7
+ currentStepNo: number;
8
+ mode: WizardMode;
9
+ stepScreenReaderLabel: string;
10
+ };
11
+
12
+ interface SetWizardStateAction {
13
+ type: 'SET_STATE';
14
+ payload: {
15
+ steps: Step[];
16
+ mode: WizardMode;
17
+ stepScreenReaderLabel: string;
18
+ };
19
+ }
20
+
21
+ interface ChangeCurrentStepNoAction {
22
+ type: 'CHANGE_CURRENT_STEP_NO';
23
+ payload: number;
24
+ }
25
+
26
+ const setWizardState = (
27
+ steps: Step[],
28
+ mode: WizardMode,
29
+ stepScreenReaderLabel: string
30
+ ): SetWizardStateAction => {
31
+ return { type: 'SET_STATE', payload: { steps, mode, stepScreenReaderLabel } };
32
+ };
33
+
34
+ const changeCurrentStepNo = (currentStepNo: number): ChangeCurrentStepNoAction => {
35
+ return { type: 'CHANGE_CURRENT_STEP_NO', payload: currentStepNo };
36
+ };
37
+
38
+ type WizardActions = SetWizardStateAction | ChangeCurrentStepNoAction;
39
+
40
+ const reducer: Reducer<WizardStateType, WizardActions> = (state, action) => {
41
+ switch (action.type) {
42
+ case 'SET_STATE':
43
+ return { ...state, ...action.payload };
44
+ case 'CHANGE_CURRENT_STEP_NO':
45
+ return { ...state, currentStepNo: action.payload };
46
+ default:
47
+ return state;
48
+ }
49
+ };
50
+
51
+ export { setWizardState, changeCurrentStepNo, reducer, WizardActions, WizardStateType };
@@ -0,0 +1,39 @@
1
+ import React, { Fragment } from 'react';
2
+ import { BaseStyling } from './BaseStyling';
3
+ import { Button } from '../Button/Button';
4
+ import { render } from '@testing-library/react';
5
+
6
+ describe('BaseStyling should render', () => {
7
+ it('renders without crashing', async () => {
8
+ const { container, findByTestId } = render(
9
+ <Fragment>
10
+ <BaseStyling>
11
+ <Button data-testid="button">Test</Button>
12
+ </BaseStyling>
13
+ </Fragment>
14
+ );
15
+
16
+ const button = await findByTestId('button');
17
+ expect(button).toHaveStyle({ backgroundColor: 'rgb(158, 0, 107);' });
18
+ expect(container.querySelector('#child')).toBeDefined();
19
+ });
20
+ });
21
+
22
+ describe('Should override default color', () => {
23
+ it('overrides primary color', async () => {
24
+ const { findByTestId } = render(
25
+ <Fragment>
26
+ <BaseStyling
27
+ properties={{
28
+ colorPrimary: 'rgb(255, 255, 255);',
29
+ }}
30
+ >
31
+ <Button data-testid="button">Test</Button>
32
+ </BaseStyling>
33
+ </Fragment>
34
+ );
35
+
36
+ const button = await findByTestId('button');
37
+ expect(button).toHaveStyle({ backgroundColor: 'rgb(255, 255, 255);' });
38
+ });
39
+ });
@@ -0,0 +1,115 @@
1
+ import React, { Fragment, HTMLAttributes, ReactChild, useEffect, useState } from 'react';
2
+
3
+ interface CSSProperties {
4
+ colorPrimary?: string;
5
+ colorSecondary?: string;
6
+ colorTertiary?: string;
7
+ defaultLineHeight?: string;
8
+ buttonBorderRadius?: string;
9
+ buttonBorderWidth?: string;
10
+ buttonFontSize?: string;
11
+ buttonBorderStyle?: string;
12
+ buttonFillTextColor?: string;
13
+ buttonFillBackgroundColor?: string;
14
+ buttonOutlineHoverTextColor?: string;
15
+ inputBorderColor?: string;
16
+ inputBorderRadius?: string;
17
+ inputBorderWidth?: string;
18
+ inputBorderStyle?: string;
19
+ modalShadowColor?: string;
20
+ modalBackgroundColor?: string;
21
+ modalHeaderBackgroundColor?: string;
22
+ snackbarTextColor?: string;
23
+ snackbarInfoBackgroundColor?: string;
24
+ snackbarSuccessBackgroundColor?: string;
25
+ snackbarErrorBackgroundColor?: string;
26
+ snackbarBorderRadius?: string;
27
+ default?: string;
28
+ success?: string;
29
+ error?: string;
30
+ disabled?: string;
31
+ greyedOut?: string;
32
+ warning?: string;
33
+ fontFamily?: string;
34
+ fontFamilyCode?: string;
35
+ fontSize?: string;
36
+ fontSizeH1?: string;
37
+ fontSizeH2?: string;
38
+ fontSizeH3?: string;
39
+ fontSizeH4?: string;
40
+ fontSizeSub?: string;
41
+ fontSizeCode?: string;
42
+ }
43
+
44
+ export interface Props extends HTMLAttributes<HTMLDivElement> {
45
+ children?: ReactChild;
46
+ properties?: CSSProperties;
47
+ }
48
+
49
+ export const BaseStyling = ({ children, properties = {} }: Props) => {
50
+ const defaultProperties: CSSProperties = {
51
+ colorPrimary: '#9e006b',
52
+ colorSecondary: '#003b5e',
53
+ colorTertiary: '#ff1e4e',
54
+ defaultLineHeight: '26px',
55
+ buttonBorderRadius: '20px',
56
+ buttonBorderWidth: '2px',
57
+ buttonFontSize: '1rem',
58
+ buttonBorderStyle: 'solid',
59
+ buttonFillTextColor: '#FFF',
60
+ buttonFillBackgroundColor: '#FFF',
61
+ buttonOutlineHoverTextColor: '#FFF',
62
+ inputBorderColor: '#e9e9eb',
63
+ inputBorderRadius: '8px',
64
+ inputBorderWidth: '1px',
65
+ inputBorderStyle: 'solid',
66
+ modalShadowColor: 'rgba(0, 0, 0, 0.16)',
67
+ modalBackgroundColor: '#F5F8F8',
68
+ modalHeaderBackgroundColor: '#FFF',
69
+ snackbarTextColor: '#fff',
70
+ snackbarInfoBackgroundColor: '#003b5e',
71
+ snackbarSuccessBackgroundColor: '#008a28',
72
+ snackbarErrorBackgroundColor: '#e22a1d',
73
+ snackbarBorderRadius: '8px',
74
+ default: '#0f0f1e',
75
+ success: '#008a28',
76
+ error: '#e22a1d',
77
+ disabled: '#e9e9eb',
78
+ greyedOut: '#6f6f76',
79
+ warning: '#ff6105',
80
+ fontFamily: "'Red Hat Display', sans-serif",
81
+ fontFamilyCode: "'Red Hat Mono', sans-serif",
82
+ fontSize: '1rem',
83
+ fontSizeH1: '2.5rem',
84
+ fontSizeH2: '1.625rem',
85
+ fontSizeH3: '1.5rem',
86
+ fontSizeH4: '1.25rem',
87
+ fontSizeSub: '.75rem',
88
+ fontSizeCode: '1rem',
89
+ };
90
+
91
+ /** We need a loading state, because otherwise you see the colors flash from the default to the possible overridden ones. */
92
+ const [isLoading, setIsLoading] = useState(true);
93
+
94
+ /** Set the actual CSS properties on the HTML :root object */
95
+ const setCSSProperties = (CSSPropertiesObject: CSSProperties) => {
96
+ for (const [key, value] of Object.entries(CSSPropertiesObject)) {
97
+ const formattedPropertyName = key.replaceAll(/([A-Z])/g, (val) => `-${val.toLowerCase()}`);
98
+ document.documentElement.style.setProperty(`--${formattedPropertyName}`, value);
99
+ }
100
+ };
101
+
102
+ /** Check if the properties prop object is filled with anything. If it is, we want to shallow merge it with the default BaseStyling. */
103
+ useEffect(() => {
104
+ if (Object.keys(properties).length !== 0) {
105
+ const mergedState = { ...defaultProperties, ...properties };
106
+ setCSSProperties(mergedState);
107
+ } else {
108
+ setCSSProperties(defaultProperties);
109
+ }
110
+ setIsLoading(false);
111
+ }, [properties]);
112
+
113
+ /** Only render if we're not loading */
114
+ return !isLoading ? <Fragment>{children}</Fragment> : null;
115
+ };
@@ -0,0 +1,45 @@
1
+ import React, { Fragment } from 'react';
2
+ import { render, fireEvent } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { useAnimation } from './useAnimation';
5
+
6
+ describe('useAnimation', () => {
7
+ it('should execute', () => {
8
+ const callback = jest.fn();
9
+
10
+ const Component = () => {
11
+ const { ref, animationStarted, startAnimation } = useAnimation<HTMLDivElement>(callback);
12
+
13
+ return (
14
+ <Fragment>
15
+ <button data-testid="button" onClick={() => startAnimation()}>
16
+ start animation
17
+ </button>
18
+ <div
19
+ data-testid="animated-div"
20
+ ref={ref}
21
+ className={animationStarted ? 'animation-started' : ''}
22
+ >
23
+ animated div
24
+ </div>
25
+ </Fragment>
26
+ );
27
+ };
28
+
29
+ const { getByTestId } = render(<Component />);
30
+
31
+ const animatedDiv = getByTestId('animated-div');
32
+ const startButton = getByTestId('button');
33
+
34
+ expect(animatedDiv).not.toHaveClass('animation-started');
35
+ expect(callback).not.toBeCalled();
36
+
37
+ userEvent.click(startButton);
38
+ expect(animatedDiv).toHaveClass('animation-started');
39
+ expect(callback).not.toBeCalled();
40
+
41
+ fireEvent.animationEnd(animatedDiv);
42
+ expect(animatedDiv).toHaveClass('animation-started');
43
+ expect(callback).toBeCalled();
44
+ });
45
+ });
@@ -0,0 +1,20 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+
3
+ export const useAnimation = <RefElement extends HTMLElement>(callback: () => void) => {
4
+ const animatedObjectRef = useRef<RefElement>(null);
5
+ /** We need to store flag that says us when to call the callback */
6
+ const [animationStarted, setAnimationStarted] = useState(false);
7
+
8
+ const onAnimationEnd = () => animationStarted && callback();
9
+
10
+ useEffect(() => {
11
+ animatedObjectRef.current?.addEventListener('animationend', onAnimationEnd);
12
+ return () => animatedObjectRef.current?.removeEventListener('animationend', onAnimationEnd);
13
+ }, [animationStarted]);
14
+
15
+ return {
16
+ ref: animatedObjectRef,
17
+ animationStarted,
18
+ startAnimation: () => setAnimationStarted(true),
19
+ };
20
+ };
@@ -0,0 +1,39 @@
1
+ import React, { Fragment, useState } from 'react';
2
+ import { useBodyClick } from './useBodyClick';
3
+ import { render } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+
6
+ describe('function should be executed', () => {
7
+ it('should execute', () => {
8
+ const clickHandler = jest.fn();
9
+ const validateFunction = jest.fn(() => true);
10
+
11
+ const Component = () => {
12
+ const [variable, setVariable] = useState(true);
13
+ const [variable2, setvariable2] = useState(true);
14
+ useBodyClick(validateFunction, clickHandler, [variable, variable2]);
15
+
16
+ return (
17
+ <Fragment>
18
+ <button data-testid="button1" onClick={() => setVariable(!variable)}>
19
+ Test
20
+ </button>
21
+ <button data-testid="button2" onClick={() => setvariable2(!variable2)}>
22
+ Test
23
+ </button>
24
+ </Fragment>
25
+ );
26
+ };
27
+
28
+ const { getByTestId } = render(<Component></Component>);
29
+
30
+ const button1 = getByTestId('button1');
31
+ const button2 = getByTestId('button2');
32
+
33
+ userEvent.click(button1);
34
+ userEvent.click(button2);
35
+
36
+ expect(clickHandler).toHaveBeenCalledTimes(2);
37
+ expect(validateFunction).toHaveBeenCalledTimes(2);
38
+ });
39
+ });
@@ -0,0 +1,20 @@
1
+ import { useEffect } from 'react';
2
+
3
+ export const useBodyClick = (
4
+ checkFunction: (event: MouseEvent) => boolean,
5
+ callbackFunction: (...args: unknown[]) => unknown,
6
+ dependingStateVariable: React.ComponentState | React.ComponentState[]
7
+ ) => {
8
+ function bodyClickListener(event: MouseEvent) {
9
+ if (checkFunction(event)) {
10
+ callbackFunction();
11
+ }
12
+ }
13
+ useEffect(() => {
14
+ window.addEventListener('click', bodyClickListener);
15
+
16
+ return () => {
17
+ window.removeEventListener('click', bodyClickListener);
18
+ };
19
+ }, [dependingStateVariable]);
20
+ };
@@ -0,0 +1,40 @@
1
+ import { useFormSelector } from './useFormSelector';
2
+ import { renderHook } from '@testing-library/react-hooks';
3
+
4
+ describe('we should get the correct return values and describedBy is the same as identifier', () => {
5
+ it('should return correct values', () => {
6
+ const { result } = renderHook(() =>
7
+ useFormSelector({
8
+ name: 'test',
9
+ errorMessage: 'errormessage',
10
+ error: false,
11
+ parentErrorId: 'parenterrorid',
12
+ helperText: 'helpertext',
13
+ parentHelperId: 'parenthelperid',
14
+ })
15
+ );
16
+
17
+ expect(result.current.describedBy).toHaveLength(15);
18
+ expect(result.current.errorId).toHaveLength(15);
19
+ expect(result.current.identifier).toHaveLength(15);
20
+
21
+ expect(result.current.describedBy).toBe(result.current.identifier);
22
+ });
23
+ });
24
+
25
+ describe('describedBy should be the parenterrorid', () => {
26
+ it('should be linked correctly', () => {
27
+ const { result } = renderHook(() =>
28
+ useFormSelector({
29
+ name: 'test',
30
+ errorMessage: 'errormessage',
31
+ error: true,
32
+ parentErrorId: 'parenterrorid',
33
+ helperText: 'helpertext',
34
+ parentHelperId: 'parenthelperid',
35
+ })
36
+ );
37
+
38
+ expect(result.current.describedBy).toBe('parenterrorid');
39
+ });
40
+ });
@@ -0,0 +1,47 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { generateID } from '../util/helper';
3
+
4
+ export interface ConfigObject {
5
+ name: string | undefined;
6
+ errorMessage?: string;
7
+ error?: boolean;
8
+ parentErrorId?: string;
9
+ helperText?: string;
10
+ parentHelperId?: string;
11
+ }
12
+
13
+ export const useFormSelector = (configObject: ConfigObject) => {
14
+ const [identifier] = useState(generateID(15, configObject.name));
15
+ const [describedBy, setDescribedBy] = useState('');
16
+ const [errorId] = useState(generateID(15, configObject.errorMessage));
17
+
18
+ useEffect(() => {
19
+ if (configObject.error && configObject.parentErrorId) {
20
+ setDescribedBy(configObject.parentErrorId);
21
+ }
22
+
23
+ if (
24
+ (!configObject.error && configObject.helperText) ||
25
+ (!configObject.parentErrorId && !configObject.errorMessage && configObject.helperText)
26
+ ) {
27
+ setDescribedBy(`${identifier}`);
28
+ }
29
+
30
+ if (
31
+ (!configObject.error && !configObject.helperText && configObject.parentHelperId) ||
32
+ (!configObject.parentErrorId && !configObject.errorMessage && configObject.parentHelperId)
33
+ ) {
34
+ setDescribedBy(`${configObject.parentHelperId}`);
35
+ }
36
+
37
+ if (configObject.errorMessage && !configObject.parentErrorId && configObject.error) {
38
+ setDescribedBy(errorId);
39
+ }
40
+ }, [identifier, configObject.error, configObject.parentErrorId]);
41
+
42
+ return {
43
+ describedBy,
44
+ errorId,
45
+ identifier,
46
+ };
47
+ };