@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.
Files changed (240) hide show
  1. package/README.md +16 -1
  2. package/dist/Breadcrumbs/Breadcrumbs.d.ts +3 -3
  3. package/dist/Button/BaseButton.d.ts +3 -4
  4. package/dist/Button/Button.d.ts +3 -4
  5. package/dist/Button/IconButton.d.ts +4 -5
  6. package/dist/ContextMenu/ContextMenu.d.ts +3 -3
  7. package/dist/Form/Checkbox/Checkbox.d.ts +5 -5
  8. package/dist/Form/Fieldset/Fieldset.d.ts +9 -7
  9. package/dist/Form/FormControl/FormControl.d.ts +6 -5
  10. package/dist/Form/FormGroup/FormGroup.d.ts +4 -4
  11. package/dist/Form/FormHelperText/FormHelperText.d.ts +4 -5
  12. package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +8 -12
  13. package/dist/Form/Input/Input.d.ts +7 -6
  14. package/dist/Form/Label/Label.d.ts +4 -5
  15. package/dist/Form/Radio/Radio.d.ts +5 -5
  16. package/dist/Form/Select/Option.d.ts +3 -4
  17. package/dist/Form/Select/Select.d.ts +4 -4
  18. package/dist/Form/Textarea/Textarea.d.ts +9 -5
  19. package/dist/Form/Toggle/Toggle.d.ts +3 -3
  20. package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +4 -3
  21. package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +5 -5
  22. package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +4 -4
  23. package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +8 -4
  24. package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +3 -3
  25. package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +6 -6
  26. package/dist/Form/form.interfaces.d.ts +4 -3
  27. package/dist/Icon/Icon.d.ts +4 -4
  28. package/dist/Link/Link.d.ts +3 -5
  29. package/dist/Notifications/BaseModal/BaseModal.d.ts +17 -0
  30. package/dist/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +5 -0
  31. package/dist/Notifications/BaseModal/BaseModalContent/BaseModalContent.d.ts +8 -0
  32. package/dist/{BaseModal → Notifications/BaseModal}/BaseModalContext.d.ts +0 -0
  33. package/dist/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +8 -0
  34. package/dist/Notifications/Dialog/Dialog.d.ts +19 -0
  35. package/dist/Notifications/Dialog/DialogActions/DialogActions.d.ts +6 -0
  36. package/dist/Notifications/Dialog/DialogTitle/DialogTitle.d.ts +6 -0
  37. package/dist/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.d.ts +13 -0
  38. package/dist/Notifications/DiscardChangesModal/DiscardChangesModal.d.ts +13 -0
  39. package/dist/{Modal → Notifications/Modal}/Modal.d.ts +0 -0
  40. package/dist/{Modal → Notifications/Modal}/ModalActions/ModalActions.d.ts +0 -0
  41. package/dist/{Modal → Notifications/Modal}/ModalContent/ModalContent.d.ts +0 -0
  42. package/dist/{Modal → Notifications/Modal}/ModalHeader/ModalHeader.d.ts +0 -0
  43. package/dist/{Snackbar → Notifications/Snackbar}/SnackbarContainer/SnackbarContainer.d.ts +0 -0
  44. package/dist/{Snackbar → Notifications/Snackbar}/SnackbarItem/SnackbarItem.d.ts +0 -0
  45. package/dist/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarProvider.d.ts +1 -1
  46. package/dist/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarStateProvider.d.ts +0 -0
  47. package/dist/{Snackbar → Notifications/Snackbar}/interfaces.d.ts +0 -0
  48. package/dist/{Snackbar → Notifications/Snackbar}/useSnackbar.d.ts +0 -0
  49. package/dist/Pagination/Pagination.d.ts +19 -0
  50. package/dist/Popover/Popover.d.ts +3 -3
  51. package/dist/Tabs/Tab.d.ts +11 -0
  52. package/dist/Tabs/TabButton.d.ts +10 -0
  53. package/dist/Tabs/TabPanel.d.ts +8 -0
  54. package/dist/Tabs/Tabs.d.ts +9 -0
  55. package/dist/TextEllipsis/TextEllipsis.d.ts +6 -0
  56. package/dist/Tiles/Tile.d.ts +6 -7
  57. package/dist/Tiles/Tiles.d.ts +3 -3
  58. package/dist/Tooltip/Tooltip.d.ts +3 -3
  59. package/dist/Typography/Typography.d.ts +6 -4
  60. package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +3 -3
  61. package/dist/Wizard/WizardSteps/WizardSteps.d.ts +3 -3
  62. package/dist/_BaseStyling_/BaseStyling.d.ts +9 -0
  63. package/dist/hooks/useRepeater.d.ts +10 -0
  64. package/dist/hooks/useSpacing.d.ts +2 -2
  65. package/dist/hooks/useWrapper.d.ts +1 -1
  66. package/dist/index.d.ts +12 -7
  67. package/dist/interfaces.d.ts +2 -11
  68. package/dist/react-lib-components.cjs.development.js +1861 -1287
  69. package/dist/react-lib-components.cjs.development.js.map +1 -1
  70. package/dist/react-lib-components.cjs.production.min.js +1 -1
  71. package/dist/react-lib-components.cjs.production.min.js.map +1 -1
  72. package/dist/react-lib-components.esm.js +1858 -1289
  73. package/dist/react-lib-components.esm.js.map +1 -1
  74. package/dist/util/helper.d.ts +6 -1
  75. package/package.json +30 -24
  76. package/src/Breadcrumbs/Breadcrumbs.tsx +39 -37
  77. package/src/Button/BaseButton.test.tsx +65 -19
  78. package/src/Button/BaseButton.tsx +2 -3
  79. package/src/Button/Button.test.tsx +63 -17
  80. package/src/Button/Button.tsx +15 -4
  81. package/src/Button/IconButton.test.tsx +57 -22
  82. package/src/Button/IconButton.tsx +21 -12
  83. package/src/ContextMenu/ContextMenu.test.tsx +27 -1
  84. package/src/ContextMenu/ContextMenu.tsx +70 -65
  85. package/src/Form/Checkbox/Checkbox.module.scss +4 -0
  86. package/src/Form/Checkbox/Checkbox.test.tsx +28 -2
  87. package/src/Form/Checkbox/Checkbox.tsx +132 -117
  88. package/src/Form/Fieldset/Fieldset.module.scss +11 -1
  89. package/src/Form/Fieldset/Fieldset.test.tsx +30 -4
  90. package/src/Form/Fieldset/Fieldset.tsx +101 -43
  91. package/src/Form/FormControl/FormControl.test.tsx +27 -1
  92. package/src/Form/FormControl/FormControl.tsx +37 -37
  93. package/src/Form/FormGroup/FormGroup.test.tsx +27 -1
  94. package/src/Form/FormGroup/FormGroup.tsx +64 -58
  95. package/src/Form/FormHelperText/FormHelperText.test.tsx +27 -1
  96. package/src/Form/FormHelperText/FormHelperText.tsx +20 -16
  97. package/src/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +78 -0
  98. package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +61 -55
  99. package/src/Form/Input/Input.module.scss +34 -15
  100. package/src/Form/Input/Input.test.tsx +27 -1
  101. package/src/Form/Input/Input.tsx +88 -47
  102. package/src/Form/Label/Label.test.tsx +27 -1
  103. package/src/Form/Label/Label.tsx +18 -14
  104. package/src/Form/Radio/Radio.module.scss +4 -0
  105. package/src/Form/Radio/Radio.test.tsx +28 -2
  106. package/src/Form/Radio/Radio.tsx +98 -80
  107. package/src/Form/Select/Option.test.tsx +27 -1
  108. package/src/Form/Select/Option.tsx +49 -42
  109. package/src/Form/Select/Select.module.scss +5 -1
  110. package/src/Form/Select/Select.test.tsx +224 -30
  111. package/src/Form/Select/Select.tsx +248 -182
  112. package/src/Form/Textarea/Textarea.module.scss +2 -1
  113. package/src/Form/Textarea/Textarea.test.tsx +28 -2
  114. package/src/Form/Textarea/Textarea.tsx +44 -29
  115. package/src/Form/Toggle/Toggle.module.scss +9 -0
  116. package/src/Form/Toggle/Toggle.test.tsx +27 -1
  117. package/src/Form/Toggle/Toggle.tsx +25 -12
  118. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +28 -2
  119. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +45 -48
  120. package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +17 -1
  121. package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +89 -1
  122. package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +134 -74
  123. package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +1 -1
  124. package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +64 -59
  125. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.module.scss +1 -1
  126. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +43 -1
  127. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +55 -44
  128. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +5 -7
  129. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +43 -1
  130. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +100 -85
  131. package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +1 -1
  132. package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +27 -1
  133. package/src/Form/Wrapper/Wrapper/Wrapper.tsx +76 -71
  134. package/src/Form/form.interfaces.ts +4 -3
  135. package/src/Icon/Icon.module.scss +4 -0
  136. package/src/Icon/Icon.test.tsx +30 -2
  137. package/src/Icon/Icon.tsx +5 -5
  138. package/src/Link/Link.test.tsx +27 -1
  139. package/src/Link/Link.tsx +4 -6
  140. package/src/{BaseModal → Notifications/BaseModal}/BaseModal.module.scss +0 -0
  141. package/src/{BaseModal → Notifications/BaseModal}/BaseModal.test.tsx +35 -16
  142. package/src/Notifications/BaseModal/BaseModal.tsx +105 -0
  143. package/src/{BaseModal → Notifications/BaseModal}/BaseModalActions/BaseModalActions.module.scss +0 -0
  144. package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +42 -0
  145. package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +16 -0
  146. package/src/{BaseModal → Notifications/BaseModal}/BaseModalContent/BaseModalContent.module.scss +0 -0
  147. package/src/{BaseModal → Notifications/BaseModal}/BaseModalContent/BaseModalContent.test.tsx +27 -1
  148. package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +36 -0
  149. package/src/{BaseModal → Notifications/BaseModal}/BaseModalContext.ts +0 -0
  150. package/src/{BaseModal → Notifications/BaseModal}/BaseModalHeader/BaseModalHeader.module.scss +0 -0
  151. package/src/{BaseModal → Notifications/BaseModal}/BaseModalHeader/BaseModalHeader.test.tsx +29 -1
  152. package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +30 -0
  153. package/src/{Dialog → Notifications/Dialog}/Dialog.module.scss +0 -0
  154. package/src/{Dialog → Notifications/Dialog}/Dialog.test.tsx +52 -17
  155. package/src/Notifications/Dialog/Dialog.tsx +113 -0
  156. package/src/{Dialog → Notifications/Dialog}/DialogActions/DialogActions.module.scss +0 -0
  157. package/src/Notifications/Dialog/DialogActions/DialogActions.test.tsx +51 -0
  158. package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +24 -0
  159. package/src/{Dialog → Notifications/Dialog}/DialogTitle/DialogTitle.module.scss +0 -0
  160. package/src/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +44 -0
  161. package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +20 -0
  162. package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +95 -0
  163. package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +55 -0
  164. package/src/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +162 -0
  165. package/src/Notifications/DiscardChangesModal/DiscardChangesModal.tsx +61 -0
  166. package/src/{Modal → Notifications/Modal}/Modal.test.tsx +0 -0
  167. package/src/{Modal → Notifications/Modal}/Modal.tsx +0 -0
  168. package/src/{Modal → Notifications/Modal}/ModalActions/ModalActions.tsx +0 -0
  169. package/src/{Modal → Notifications/Modal}/ModalContent/ModalContent.tsx +0 -0
  170. package/src/{Modal → Notifications/Modal}/ModalHeader/ModalHeader.tsx +0 -0
  171. package/src/{Snackbar → Notifications/Snackbar}/SnackbarContainer/SnackbarContainer.module.scss +0 -0
  172. package/src/{Snackbar → Notifications/Snackbar}/SnackbarContainer/SnackbarContainer.test.tsx +0 -0
  173. package/src/{Snackbar → Notifications/Snackbar}/SnackbarContainer/SnackbarContainer.tsx +0 -0
  174. package/src/{Snackbar → Notifications/Snackbar}/SnackbarItem/SnackbarItem.module.scss +1 -1
  175. package/src/{Snackbar → Notifications/Snackbar}/SnackbarItem/SnackbarItem.test.tsx +0 -0
  176. package/src/{Snackbar → Notifications/Snackbar}/SnackbarItem/SnackbarItem.tsx +6 -7
  177. package/src/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarProvider.test.tsx +0 -0
  178. package/src/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarProvider.tsx +2 -2
  179. package/src/{Snackbar → Notifications/Snackbar}/SnackbarProvider/SnackbarStateProvider.tsx +0 -0
  180. package/src/{Snackbar → Notifications/Snackbar}/interfaces.ts +0 -0
  181. package/src/{Snackbar → Notifications/Snackbar}/useSnackbar.ts +0 -0
  182. package/src/Pagination/Pagination.module.scss +120 -0
  183. package/src/Pagination/Pagination.test.tsx +176 -0
  184. package/src/Pagination/Pagination.tsx +205 -0
  185. package/src/Popover/Popover.test.tsx +3 -3
  186. package/src/Popover/Popover.tsx +3 -3
  187. package/src/Tabs/Tab.test.tsx +71 -0
  188. package/src/Tabs/Tab.tsx +17 -0
  189. package/src/Tabs/TabButton.module.scss +36 -0
  190. package/src/Tabs/TabButton.test.tsx +77 -0
  191. package/src/Tabs/TabButton.tsx +58 -0
  192. package/src/Tabs/TabPanel.module.scss +7 -0
  193. package/src/Tabs/TabPanel.test.tsx +76 -0
  194. package/src/Tabs/TabPanel.tsx +27 -0
  195. package/src/Tabs/Tabs.module.scss +41 -0
  196. package/src/Tabs/Tabs.test.tsx +268 -0
  197. package/src/Tabs/Tabs.tsx +149 -0
  198. package/src/TextEllipsis/TextEllipsis.module.scss +18 -0
  199. package/src/TextEllipsis/TextEllipsis.test.tsx +80 -0
  200. package/src/TextEllipsis/TextEllipsis.tsx +55 -0
  201. package/src/Tiles/Tile.module.scss +1 -1
  202. package/src/Tiles/Tile.test.tsx +48 -12
  203. package/src/Tiles/Tile.tsx +68 -34
  204. package/src/Tiles/Tiles.test.tsx +38 -10
  205. package/src/Tiles/Tiles.tsx +42 -39
  206. package/src/Tooltip/Tooltip.test.tsx +27 -1
  207. package/src/Tooltip/Tooltip.tsx +104 -92
  208. package/src/Typography/Typography.test.tsx +27 -1
  209. package/src/Typography/Typography.tsx +66 -68
  210. package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +67 -62
  211. package/src/Wizard/Wizard.tsx +2 -2
  212. package/src/Wizard/WizardActions/WizardActions.tsx +3 -3
  213. package/src/Wizard/WizardSteps/WizardSteps.tsx +24 -21
  214. package/src/_BaseStyling_/BaseStyling.tsx +19 -1
  215. package/src/hooks/usePosition.test.tsx +3 -3
  216. package/src/hooks/useRepeater.test.tsx +139 -0
  217. package/src/hooks/useRepeater.ts +34 -0
  218. package/src/hooks/useSpacing.ts +1 -1
  219. package/src/hooks/useWrapper.ts +7 -2
  220. package/src/index.ts +20 -8
  221. package/src/interfaces.ts +2 -12
  222. package/src/util/helper.test.tsx +38 -1
  223. package/src/util/helper.tsx +21 -0
  224. package/dist/BaseModal/BaseModal.d.ts +0 -16
  225. package/dist/BaseModal/BaseModalActions/BaseModalActions.d.ts +0 -5
  226. package/dist/BaseModal/BaseModalContent/BaseModalContent.d.ts +0 -8
  227. package/dist/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +0 -8
  228. package/dist/Dialog/Dialog.d.ts +0 -18
  229. package/dist/Dialog/DialogActions/DialogActions.d.ts +0 -6
  230. package/dist/Dialog/DialogTitle/DialogTitle.d.ts +0 -6
  231. package/src/BaseModal/BaseModal.tsx +0 -113
  232. package/src/BaseModal/BaseModalActions/BaseModalActions.test.tsx +0 -17
  233. package/src/BaseModal/BaseModalActions/BaseModalActions.tsx +0 -14
  234. package/src/BaseModal/BaseModalContent/BaseModalContent.tsx +0 -35
  235. package/src/BaseModal/BaseModalHeader/BaseModalHeader.tsx +0 -28
  236. package/src/Dialog/Dialog.tsx +0 -96
  237. package/src/Dialog/DialogActions/DialogActions.test.tsx +0 -25
  238. package/src/Dialog/DialogActions/DialogActions.tsx +0 -21
  239. package/src/Dialog/DialogTitle/DialogTitle.test.tsx +0 -18
  240. package/src/Dialog/DialogTitle/DialogTitle.tsx +0 -18
@@ -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 (value?.length || placeholder || type === 'datetime-local' || type === 'time') {
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,14 +4,22 @@ 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
 
10
- export { Dialog } from './Dialog/Dialog';
11
- export { Modal } from './Modal/Modal';
12
- export { ModalActions } from './Modal/ModalActions/ModalActions';
13
- export { ModalContent } from './Modal/ModalContent/ModalContent';
14
- export { ModalHeader } from './Modal/ModalHeader/ModalHeader';
16
+ export { Dialog } from './Notifications/Dialog/Dialog';
17
+ export { Modal } from './Notifications/Modal/Modal';
18
+ export { ModalActions } from './Notifications/Modal/ModalActions/ModalActions';
19
+ export { ModalContent } from './Notifications/Modal/ModalContent/ModalContent';
20
+ export { ModalHeader } from './Notifications/Modal/ModalHeader/ModalHeader';
21
+ export { DiscardChangesModal } from './Notifications/DiscardChangesModal/DiscardChangesModal';
22
+ export { TextEllipsis, Props as TextEllipsisProps } from './TextEllipsis/TextEllipsis';
15
23
  export { Tooltip } from './Tooltip/Tooltip';
16
24
  export { Tiles } from './Tiles/Tiles';
17
25
  export { Tile } from './Tiles/Tile';
@@ -19,8 +27,12 @@ export { ContextMenu } from './ContextMenu/ContextMenu';
19
27
  export { ContextMenuItem } from './ContextMenu/ContextMenuItem';
20
28
  export { Breadcrumbs } from './Breadcrumbs/Breadcrumbs';
21
29
 
22
- export { SnackbarProvider } from './Snackbar/SnackbarProvider/SnackbarProvider';
23
- export { useSnackbar } from './Snackbar/useSnackbar';
30
+ export { SnackbarProvider } from './Notifications/Snackbar/SnackbarProvider/SnackbarProvider';
31
+ export { useSnackbar } from './Notifications/Snackbar/useSnackbar';
32
+
33
+ export { useRepeater } from './hooks/useRepeater';
34
+
35
+ export { generateID } from './util/helper';
24
36
 
25
37
  /** Form components */
26
38
  export { Form } from './Form/Form';
package/src/interfaces.ts CHANGED
@@ -1,15 +1,5 @@
1
- import React from 'react';
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
  }
@@ -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
+ });
@@ -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
+ };
@@ -1,16 +0,0 @@
1
- import React, { HTMLAttributes } from 'react';
2
- export interface Props extends HTMLAttributes<HTMLDivElement> {
3
- id: string;
4
- children: React.ReactNode;
5
- open: boolean;
6
- onClose?: (event?: React.MouseEvent<HTMLElement>) => unknown;
7
- className?: string;
8
- containerClassName?: string;
9
- labelledby?: string;
10
- describedby?: string;
11
- disableEscapeKeyDown?: boolean;
12
- disableBackdrop?: boolean;
13
- zIndex?: number;
14
- }
15
- export declare const useSetBodyScroll: (open: boolean) => void;
16
- export declare const BaseModal: ({ id, children, open, onClose, className, containerClassName, labelledby, describedby, disableEscapeKeyDown, disableBackdrop, zIndex, ...restProps }: Props) => JSX.Element;
@@ -1,5 +0,0 @@
1
- import React, { HTMLAttributes } from 'react';
2
- export interface Props extends HTMLAttributes<HTMLElement> {
3
- children?: React.ReactNode;
4
- }
5
- export declare const BaseModalActions: ({ children, className, ...restProps }: Props) => JSX.Element;
@@ -1,8 +0,0 @@
1
- import React, { HTMLAttributes } from 'react';
2
- export interface Props extends HTMLAttributes<HTMLDivElement> {
3
- id?: string;
4
- children: React.ReactNode;
5
- className?: string;
6
- disableAutoFocus?: boolean;
7
- }
8
- export declare const BaseModalContent: ({ id, children, className, disableAutoFocus, ...restProps }: Props) => JSX.Element;
@@ -1,8 +0,0 @@
1
- import React, { HTMLAttributes } from 'react';
2
- export interface Props extends HTMLAttributes<HTMLElement> {
3
- id: string;
4
- title: string;
5
- children?: React.ReactNode;
6
- onClose: (event: React.MouseEvent<HTMLButtonElement>) => void;
7
- }
8
- export declare const BaseModalHeader: ({ id, title, children, onClose, ...restProps }: Props) => JSX.Element;
@@ -1,18 +0,0 @@
1
- import React, { HTMLAttributes } from 'react';
2
- import { Props as ButtonProps } from '../Button/Button';
3
- export interface Props extends HTMLAttributes<HTMLDivElement> {
4
- id: string;
5
- open: boolean;
6
- children: React.ReactNode;
7
- alignActions: 'left' | 'right';
8
- onClose: () => void;
9
- title: string;
10
- primaryAction: Action;
11
- secondaryAction?: Action;
12
- zIndex?: number;
13
- }
14
- export interface Action extends Omit<ButtonProps, 'variant' | 'ref'> {
15
- label: string;
16
- onClick: (event?: React.MouseEvent<HTMLButtonElement>) => unknown;
17
- }
18
- export declare const Dialog: ({ id, open, children, alignActions, onClose, title, primaryAction, secondaryAction, zIndex, ...restProps }: Props) => JSX.Element;
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- import { Props as BaseModalActionsProps } from '../../BaseModal/BaseModalActions/BaseModalActions';
3
- export interface Props extends BaseModalActionsProps {
4
- align: 'left' | 'right';
5
- }
6
- export declare const DialogActions: ({ children, align, ...restProps }: Props) => JSX.Element;
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- export interface Props {
3
- id: string;
4
- title: string;
5
- }
6
- export declare const DialogTitle: ({ id, title }: Props) => JSX.Element;
@@ -1,113 +0,0 @@
1
- import React, { HTMLAttributes, useEffect, useRef } from 'react';
2
- import classes from './BaseModal.module.scss';
3
- import { labelId, descriptionId } from './BaseModalContext';
4
-
5
- const SCROLL_PROPERTY_NAME = 'overflow';
6
- const SCROLL_PROPERTY_VALUE = 'hidden';
7
-
8
- export interface Props extends HTMLAttributes<HTMLDivElement> {
9
- id: string;
10
- children: React.ReactNode;
11
- open: boolean;
12
- onClose?: (event?: React.MouseEvent<HTMLElement>) => unknown;
13
- className?: string;
14
- containerClassName?: string;
15
- labelledby?: string;
16
- describedby?: string;
17
- disableEscapeKeyDown?: boolean;
18
- disableBackdrop?: boolean;
19
- zIndex?: number;
20
- }
21
-
22
- const useBackdropOnCloseClick = (
23
- disableBackdrop: boolean,
24
- onClose?: (event?: React.MouseEvent<HTMLElement>) => unknown
25
- ) => {
26
- const backdropRef = useRef<HTMLDivElement>(null);
27
- const onBackdropClick = () => onClose && onClose();
28
-
29
- useEffect(() => {
30
- !disableBackdrop && backdropRef.current?.addEventListener('click', onBackdropClick);
31
- return () => {
32
- !disableBackdrop && backdropRef.current?.removeEventListener('click', onBackdropClick);
33
- };
34
- }, []);
35
-
36
- return {
37
- backdropRef,
38
- };
39
- };
40
-
41
- export const useSetBodyScroll = (open: boolean) => {
42
- const hideBodyScroll = () => {
43
- document.body.style[SCROLL_PROPERTY_NAME] = SCROLL_PROPERTY_VALUE;
44
- };
45
-
46
- const showBodyScroll = () => {
47
- const allModalsClosed =
48
- document.querySelectorAll('[role=dialog][data-hidden=false]').length === 0;
49
- if (allModalsClosed) {
50
- document.body.style.removeProperty(SCROLL_PROPERTY_NAME);
51
- }
52
- };
53
-
54
- useEffect(() => {
55
- if (open) {
56
- hideBodyScroll();
57
- } else {
58
- showBodyScroll();
59
- }
60
- }, [open]);
61
- };
62
-
63
- export const BaseModal = ({
64
- id,
65
- children,
66
- open,
67
- onClose,
68
- className = '',
69
- containerClassName = '',
70
- labelledby,
71
- describedby,
72
- disableEscapeKeyDown = false,
73
- disableBackdrop = false,
74
- zIndex,
75
- ...restProps
76
- }: Props) => {
77
- const { backdropRef } = useBackdropOnCloseClick(disableBackdrop, onClose);
78
- useSetBodyScroll(open);
79
-
80
- const handleEscKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {
81
- if (!disableEscapeKeyDown && event.key === 'Escape') {
82
- event.stopPropagation();
83
- onClose && onClose();
84
- }
85
- };
86
-
87
- return (
88
- <div
89
- {...restProps}
90
- id={id}
91
- className={`${classes['modal']} ${open && classes['visible']} ${className}`}
92
- role="dialog"
93
- aria-modal="true"
94
- aria-labelledby={labelledby || labelId(id)}
95
- aria-describedby={describedby || descriptionId(id)}
96
- aria-hidden={!open}
97
- tabIndex={-1}
98
- data-hidden={!open}
99
- onKeyDown={handleEscKeyPress}
100
- style={{ zIndex }}
101
- >
102
- <div ref={backdropRef} className={classes['backdrop']}></div>
103
- {open && (
104
- <div
105
- style={{ zIndex: zIndex && zIndex + 1 }}
106
- className={`${classes['container']} ${containerClassName}`}
107
- >
108
- {children}
109
- </div>
110
- )}
111
- </div>
112
- );
113
- };
@@ -1,17 +0,0 @@
1
- import React from 'react';
2
- import { BaseModalActions } from './BaseModalActions';
3
- import { render } from '@testing-library/react';
4
-
5
- describe('BaseModalActions', () => {
6
- it('renders without crashing', () => {
7
- const children = 'Content';
8
- const classNames = ['class1', 'class2'];
9
- const { container } = render(
10
- <BaseModalActions className={classNames.join(' ')}>{children}</BaseModalActions>
11
- );
12
-
13
- const dialogActionsContainer = container.children[0];
14
- expect(dialogActionsContainer).toHaveClass('actions', classNames[0], classNames[1]);
15
- expect(dialogActionsContainer).toHaveTextContent(children);
16
- });
17
- });
@@ -1,14 +0,0 @@
1
- import React, { HTMLAttributes } from 'react';
2
- import classes from './BaseModalActions.module.scss';
3
-
4
- export interface Props extends HTMLAttributes<HTMLElement> {
5
- children?: React.ReactNode;
6
- }
7
-
8
- export const BaseModalActions = ({ children, className = '', ...restProps }: Props) => {
9
- return (
10
- <footer {...restProps} className={`${classes['actions']} ${className}`}>
11
- {children}
12
- </footer>
13
- );
14
- };
@@ -1,35 +0,0 @@
1
- import React, { HTMLAttributes, useEffect, useRef } from 'react';
2
- import classes from './BaseModalContent.module.scss';
3
-
4
- export interface Props extends HTMLAttributes<HTMLDivElement> {
5
- id?: string;
6
- children: React.ReactNode;
7
- className?: string;
8
- disableAutoFocus?: boolean;
9
- }
10
-
11
- export const BaseModalContent = ({
12
- id,
13
- children,
14
- className = '',
15
- disableAutoFocus = false,
16
- ...restProps
17
- }: Props) => {
18
- const contentRef = useRef<HTMLDivElement>(null);
19
- useEffect(() => {
20
- !disableAutoFocus && contentRef.current?.focus();
21
- }, []);
22
-
23
- /**tabIndex is set to be able to do focus on that element which we need for catching keyDown events */
24
- return (
25
- <div
26
- {...restProps}
27
- ref={contentRef}
28
- id={id}
29
- className={`${classes['content']} ${className}`}
30
- tabIndex={-1}
31
- >
32
- {children}
33
- </div>
34
- );
35
- };
@@ -1,28 +0,0 @@
1
- import React, { HTMLAttributes } from 'react';
2
- import classes from './BaseModalHeader.module.scss';
3
- import { IconButton } from '../../Button/IconButton';
4
- import { Icon, Icons } from '../../Icon/Icon';
5
- import { Typography } from '../../Typography/Typography';
6
-
7
- export interface Props extends HTMLAttributes<HTMLElement> {
8
- id: string;
9
- title: string;
10
- children?: React.ReactNode;
11
- onClose: (event: React.MouseEvent<HTMLButtonElement>) => void;
12
- }
13
-
14
- export const BaseModalHeader = ({ id, title, children, onClose, ...restProps }: Props) => {
15
- return (
16
- <header {...restProps} className={classes['header']}>
17
- <div className={classes['headline']}>
18
- <Typography id={id} className={classes['title']} tag="h1" variant="h4">
19
- {title}
20
- </Typography>
21
- <IconButton onClick={onClose} className={classes['closeBtn']} title="close modal">
22
- <Icon icon={Icons.Times} />
23
- </IconButton>
24
- </div>
25
- {children}
26
- </header>
27
- );
28
- };
@@ -1,96 +0,0 @@
1
- import React, { HTMLAttributes } from 'react';
2
- import { BaseModal } from '../BaseModal/BaseModal';
3
- import { BaseModalContent } from '../BaseModal/BaseModalContent/BaseModalContent';
4
- import { DialogActions } from './DialogActions/DialogActions';
5
- import classes from './Dialog.module.scss';
6
- import { DialogTitle } from './DialogTitle/DialogTitle';
7
- import { Button, Props as ButtonProps } from '../Button/Button';
8
- import { labelId, descriptionId } from '../BaseModal/BaseModalContext';
9
-
10
- export interface Props extends HTMLAttributes<HTMLDivElement> {
11
- id: string;
12
- open: boolean;
13
- children: React.ReactNode;
14
- alignActions: 'left' | 'right';
15
- onClose: () => void;
16
- title: string;
17
- primaryAction: Action;
18
- secondaryAction?: Action;
19
- zIndex?: number;
20
- }
21
-
22
- export interface Action extends Omit<ButtonProps, 'variant' | 'ref'> {
23
- label: string;
24
- onClick: (event?: React.MouseEvent<HTMLButtonElement>) => unknown;
25
- }
26
-
27
- export const Dialog = ({
28
- id,
29
- open,
30
- children,
31
- alignActions,
32
- onClose,
33
- title,
34
- primaryAction,
35
- secondaryAction,
36
- zIndex,
37
- ...restProps
38
- }: Props) => {
39
- const { label: primaryLabel, ...restOfPrimaryAction } = primaryAction;
40
- const PrimaryButton = (
41
- <Button key="primary" {...restOfPrimaryAction}>
42
- {primaryLabel}
43
- </Button>
44
- );
45
- const TertiaryButton =
46
- secondaryAction &&
47
- (function () {
48
- const { label: secondaryLabel, ...restOfSecondaryAction } = secondaryAction;
49
- return (
50
- <Button key="tertiary" variant="text" {...restOfSecondaryAction}>
51
- {secondaryLabel}
52
- </Button>
53
- );
54
- })();
55
-
56
- const onHiddenInputKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => {
57
- /** It has to be here because then we will need to check if user doesn't click tab to select action button and want to do another action then primary one? */
58
- if (event.key === 'Enter') {
59
- primaryAction.onClick();
60
- }
61
- };
62
-
63
- return (
64
- <BaseModal
65
- {...restProps}
66
- id={id}
67
- className={classes['dialog']}
68
- containerClassName={classes['container']}
69
- open={open}
70
- disableBackdrop
71
- onClose={onClose}
72
- zIndex={zIndex}
73
- >
74
- <DialogTitle id={labelId(id)} title={title} />
75
- <BaseModalContent id={descriptionId(id)} className={classes['content']} disableAutoFocus>
76
- {children}
77
- </BaseModalContent>
78
- <DialogActions align={alignActions}>
79
- {alignActions === 'left'
80
- ? [PrimaryButton, TertiaryButton]
81
- : [TertiaryButton, PrimaryButton]}
82
- </DialogActions>
83
- <input
84
- autoFocus
85
- style={{
86
- position: 'absolute',
87
- width: 0,
88
- height: 0,
89
- opacity: 0,
90
- }}
91
- tabIndex={-1}
92
- onKeyPress={onHiddenInputKeyPress}
93
- />
94
- </BaseModal>
95
- );
96
- };
@@ -1,25 +0,0 @@
1
- import React from 'react';
2
- import { DialogActions, Props } from './DialogActions';
3
- import { render } from '@testing-library/react';
4
-
5
- const initParams: Props = {
6
- align: 'right',
7
- children: 'Content',
8
- };
9
-
10
- describe('DialogActions', () => {
11
- it('renders without crashing', () => {
12
- const { container } = render(<DialogActions {...initParams} />);
13
-
14
- const dialogActionsContainer = container.children[0];
15
- expect(dialogActionsContainer).toHaveClass('actions');
16
- expect(dialogActionsContainer).toHaveTextContent(initParams.children as string);
17
- });
18
-
19
- it('should align items to left', () => {
20
- const { container } = render(<DialogActions {...initParams} align="left" />);
21
-
22
- const dialogActionsContainer = container.children[0];
23
- expect(dialogActionsContainer).toHaveClass('actions', 'left');
24
- });
25
- });
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import {
3
- BaseModalActions,
4
- Props as BaseModalActionsProps,
5
- } from '../../BaseModal/BaseModalActions/BaseModalActions';
6
- import classes from './DialogActions.module.scss';
7
-
8
- export interface Props extends BaseModalActionsProps {
9
- align: 'left' | 'right';
10
- }
11
-
12
- export const DialogActions = ({ children, align, ...restProps }: Props) => {
13
- return (
14
- <BaseModalActions
15
- {...restProps}
16
- className={`${classes['actions']}${align === 'left' ? ' ' + classes['left'] : ''}`}
17
- >
18
- {children}
19
- </BaseModalActions>
20
- );
21
- };
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- import { DialogTitle, Props } from './DialogTitle';
3
- import { render, getByText } from '@testing-library/react';
4
-
5
- const initParams: Props = {
6
- id: 'dialog-label',
7
- title: 'Example title',
8
- };
9
-
10
- describe('DialogActions', () => {
11
- it('renders without crashing', () => {
12
- const { container } = render(<DialogTitle {...initParams} />);
13
-
14
- const dialogTitleContainer = container.children[0];
15
- expect(dialogTitleContainer).toHaveClass('header');
16
- expect(getByText(container, initParams.title));
17
- });
18
- });
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- import { Typography } from '../../Typography/Typography';
3
- import classes from './DialogTitle.module.scss';
4
-
5
- export interface Props {
6
- id: string;
7
- title: string;
8
- }
9
-
10
- export const DialogTitle = ({ id, title }: Props) => {
11
- return (
12
- <header className={classes['header']}>
13
- <Typography id={id} className={classes['title']} tag="h1" variant="h4">
14
- {title}
15
- </Typography>
16
- </header>
17
- );
18
- };