@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
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@onewelcome/react-lib-components",
3
+ "version": "0.1.0-alpha",
4
+ "license": "Apache-2.0",
5
+ "author": "OneWelcome B.V.",
6
+ "main": "dist/index.js",
7
+ "module": "dist/react-lib-components.esm.js",
8
+ "typings": "dist/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "src"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "scripts": {
17
+ "analyze": "size-limit --why",
18
+ "build": "dts build",
19
+ "build-storybook": "build-storybook",
20
+ "lint": "dts lint",
21
+ "prepare": "husky install && dts build",
22
+ "size": "size-limit",
23
+ "start": "dts watch",
24
+ "prettier": "prettier --write --ignore-path .gitignore \"**/*.+(ts|tsx|scss|mdx)\"",
25
+ "storybook": "start-storybook -p 6006",
26
+ "test": "dts test --passWithNoTests"
27
+ },
28
+ "jest": {
29
+ "testEnvironment": "jsdom"
30
+ },
31
+ "peerDependencies": {
32
+ "react": ">=16"
33
+ },
34
+ "engines": {
35
+ "node": ">=12"
36
+ },
37
+ "size-limit": [
38
+ {
39
+ "path": "dist/react-lib-components.cjs.production.min.js",
40
+ "limit": "10 KB"
41
+ },
42
+ {
43
+ "path": "dist/react-lib-components.esm.js",
44
+ "limit": "10 KB"
45
+ }
46
+ ],
47
+ "devDependencies": {
48
+ "@babel/core": "^7.17.8",
49
+ "@size-limit/preset-small-lib": "^7.0.8",
50
+ "@storybook/addon-a11y": "^6.4.18",
51
+ "@storybook/addon-docs": "^6.4.19",
52
+ "@storybook/addon-essentials": "^6.4.18",
53
+ "@storybook/addon-links": "^6.4.18",
54
+ "@storybook/addons": "^6.4.17",
55
+ "@storybook/builder-webpack5": "^6.4.17",
56
+ "@storybook/manager-webpack5": "^6.4.18",
57
+ "@storybook/preset-scss": "^1.0.3",
58
+ "@storybook/react": "^6.4.13",
59
+ "@testing-library/dom": "^8.12.0",
60
+ "@testing-library/jest-dom": "^5.16.3",
61
+ "@testing-library/react": "^12.1.4",
62
+ "@testing-library/react-hooks": "^7.0.2",
63
+ "@testing-library/user-event": "^13.5.0",
64
+ "@tsconfig/create-react-app": "^1.0.2",
65
+ "@tsconfig/recommended": "^1.0.1",
66
+ "@types/mdx": "^2.0.1",
67
+ "@types/react": "^17.0.43",
68
+ "@types/react-dom": "^17.0.14",
69
+ "@types/react-router": "^5.1.18",
70
+ "@types/react-router-dom": "^5.3.3",
71
+ "babel-loader": "^8.2.4",
72
+ "dts-cli": "^1.4.0",
73
+ "html-webpack-plugin": "^5.5.0",
74
+ "husky": "^7.0.4",
75
+ "identity-obj-proxy": "^3.0.0",
76
+ "jest-junit": "^13.0.0",
77
+ "lint-staged": "^12.3.7",
78
+ "react": "^17.0.2",
79
+ "react-dom": "^17.0.2",
80
+ "react-is": "^17.0.2",
81
+ "react-router": "^6.3.0",
82
+ "rollup-plugin-styles": "^4.0.0",
83
+ "sass": "^1.49.10",
84
+ "size-limit": "^7.0.8",
85
+ "tslib": "^2.3.1",
86
+ "typescript": "^4.6.3"
87
+ }
88
+ }
@@ -0,0 +1,58 @@
1
+ $zIndex: 10;
2
+ $marginTop: 3.125rem;
3
+
4
+ .modal {
5
+ position: fixed;
6
+ z-index: $zIndex;
7
+ top: 0;
8
+ left: 0;
9
+ height: 100vh;
10
+ width: 100vw;
11
+
12
+ visibility: hidden;
13
+
14
+ display: flex;
15
+ align-items: flex-start;
16
+ justify-content: center;
17
+
18
+ .backdrop {
19
+ content: '';
20
+ position: absolute;
21
+ width: 100%;
22
+ height: 100%;
23
+ left: 0;
24
+ top: 0;
25
+ background-color: transparent;
26
+ transition: background-color 0.5s ease;
27
+ }
28
+
29
+ &.visible {
30
+ visibility: visible;
31
+
32
+ .backdrop {
33
+ background-color: var(--default);
34
+ opacity: 0.75;
35
+ }
36
+ }
37
+ }
38
+
39
+ .container {
40
+ background-color: var(--modal-background-color);
41
+ z-index: $zIndex + 1;
42
+ width: 100%;
43
+ height: 100%;
44
+
45
+ display: flex;
46
+ flex-direction: column;
47
+ }
48
+
49
+ @media only screen and (min-width: 50rem) {
50
+ .container {
51
+ margin-top: $marginTop;
52
+ width: 50rem;
53
+ height: auto;
54
+ max-height: calc(90% - $marginTop);
55
+ border-radius: 8px;
56
+ box-shadow: 0 30px 50px var(--modal-shadow-color);
57
+ }
58
+ }
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ import { BaseModal, Props } from './BaseModal';
3
+ import {
4
+ render,
5
+ getByRole,
6
+ getByText,
7
+ queryByText,
8
+ queryByRole,
9
+ fireEvent,
10
+ } from '@testing-library/react';
11
+ import userEvent from '@testing-library/user-event';
12
+
13
+ const classNames = ['class11', 'class12'];
14
+ const containerClassNames = ['class21', 'class22'];
15
+
16
+ const initParams: Props = {
17
+ id: 'modal',
18
+ open: true,
19
+ onClose: jest.fn(),
20
+ className: classNames.join(' '),
21
+ containerClassName: containerClassNames.join(' '),
22
+ children: 'This is example dialog content.',
23
+ };
24
+
25
+ describe('BaseModal', () => {
26
+ it('renders without crashing', () => {
27
+ const { container } = render(<BaseModal {...initParams} />);
28
+ const dialog = getByRole(container, 'dialog');
29
+ expect(dialog).toHaveAttribute('aria-modal', 'true');
30
+ expect(dialog).toHaveAttribute('aria-labelledby', 'modal-label');
31
+ expect(dialog).toHaveAttribute('aria-describedby', 'modal-description');
32
+ expect(dialog).toHaveAttribute('data-hidden', 'false');
33
+ expect(dialog).toHaveAttribute('aria-hidden', 'false');
34
+ expect(getByText(dialog, initParams.children as string)).toBeDefined();
35
+ expect(document.body).toHaveStyle('overflow: hidden');
36
+ });
37
+
38
+ it('should render close modal without content', () => {
39
+ const { container } = render(<BaseModal {...initParams} open={false} />);
40
+ const dialogByRole = queryByRole(container, 'dialog');
41
+ const dialog = container.children[0] as HTMLElement;
42
+ expect(dialogByRole).toBeNull();
43
+ expect(dialog).toHaveAttribute('aria-hidden', 'true');
44
+ expect(queryByText(dialog, initParams.children as string)).toBeNull();
45
+ });
46
+
47
+ it('should handle clicking on backdrop & ESC key', () => {
48
+ const { container } = render(<BaseModal {...initParams} />);
49
+ const modal = getByRole(container, 'dialog');
50
+ const backdrop = modal.querySelector('.backdrop') as HTMLElement;
51
+ expect(initParams.onClose).toHaveBeenCalledTimes(0);
52
+
53
+ userEvent.click(backdrop);
54
+ expect(initParams.onClose).toHaveBeenCalledTimes(1);
55
+
56
+ fireEvent.keyDown(modal, { key: 'Escape' });
57
+ expect(initParams.onClose).toHaveBeenCalledTimes(2);
58
+ });
59
+ });
@@ -0,0 +1,113 @@
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
+ };
@@ -0,0 +1,9 @@
1
+ .actions {
2
+ margin: 1.875rem 1.25rem 1.875rem 1.25rem;
3
+ display: flex;
4
+ justify-content: flex-end;
5
+
6
+ & * + * {
7
+ margin-left: 1.25rem;
8
+ }
9
+ }
@@ -0,0 +1,17 @@
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
+ });
@@ -0,0 +1,14 @@
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
+ };
@@ -0,0 +1,6 @@
1
+ .content {
2
+ padding: 1.5rem 1.25rem 0;
3
+ overflow-y: auto;
4
+ flex: 1;
5
+ outline: none;
6
+ }
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { BaseModalContent, Props } from './BaseModalContent';
3
+ import { render } from '@testing-library/react';
4
+ import { descriptionId } from '../BaseModalContext';
5
+
6
+ const classNames = ['class1', 'class2'];
7
+ const initParams: Props = {
8
+ id: descriptionId('modal'),
9
+ className: classNames.join(' '),
10
+ children: 'This is example dialog content.',
11
+ };
12
+
13
+ describe('BaseModalContent', () => {
14
+ it('renders without crashing', () => {
15
+ const { container } = render(<BaseModalContent {...initParams} />);
16
+
17
+ const dialogContentContainer = container.children[0];
18
+ expect(dialogContentContainer).toHaveClass('content', classNames[0], classNames[1]);
19
+ expect(dialogContentContainer).toHaveTextContent(initParams.children as string);
20
+ expect(dialogContentContainer).toEqual(document.activeElement);
21
+ });
22
+
23
+ it('should renders not focused div', () => {
24
+ const { container } = render(<BaseModalContent {...initParams} disableAutoFocus />);
25
+
26
+ const dialogContentContainer = container.children[0];
27
+ expect(dialogContentContainer).not.toEqual(document.activeElement);
28
+ });
29
+ });
@@ -0,0 +1,35 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ export const labelId = (id: string) => `${id}-label`;
2
+ export const descriptionId = (id: string) => `${id}-description`;
@@ -0,0 +1,17 @@
1
+ .header {
2
+ min-width: 80px;
3
+ padding: 1rem 1.25rem;
4
+ background-color: var(--modal-header-background-color);
5
+ border-top-left-radius: 8px;
6
+ border-top-right-radius: 8px;
7
+ }
8
+
9
+ .headline {
10
+ display: flex;
11
+ align-items: center;
12
+ }
13
+
14
+ .title {
15
+ flex: 1;
16
+ margin: 0 0 0 1.25rem;
17
+ }
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import { BaseModalHeader, Props } from './BaseModalHeader';
3
+ import { render, getByRole, getByTestId, getByText } from '@testing-library/react';
4
+ import { labelId } from '../BaseModalContext';
5
+ import userEvent from '@testing-library/user-event';
6
+
7
+ const additionalContent = 'Additional content';
8
+ const initParams: Props = {
9
+ id: labelId('modal'),
10
+ title: 'Example title',
11
+ onClose: jest.fn(),
12
+ children: <div data-testid="additional-content">{additionalContent}</div>,
13
+ };
14
+
15
+ describe('BaseModalHeader', () => {
16
+ it('renders without crashing', () => {
17
+ const { container } = render(<BaseModalHeader {...initParams} />);
18
+ const closeBtn = getByRole(container, 'button');
19
+ expect(initParams.onClose).toBeCalledTimes(0);
20
+
21
+ userEvent.click(closeBtn);
22
+
23
+ const dialogContentContainer = container.children[0];
24
+ const titleContainer = getByText(container, initParams.title);
25
+ expect(dialogContentContainer).toHaveClass('header');
26
+ expect(titleContainer).toHaveAttribute('id', 'modal-label');
27
+ expect(getByTestId(container, 'additional-content')).toHaveTextContent(additionalContent);
28
+ expect(initParams.onClose).toBeCalledTimes(1);
29
+ });
30
+ });
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,14 @@
1
+ .breadcrumbs {
2
+ .last {
3
+ color: var(--greyed-out);
4
+ margin: 0;
5
+ }
6
+
7
+ .icon {
8
+ color: var(--greyed-out);
9
+ font-size: 0.75rem;
10
+ line-height: 1.5rem;
11
+ margin-left: 0.375rem;
12
+ margin-right: 0.375rem;
13
+ }
14
+ }
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { Breadcrumbs, Props } from './Breadcrumbs';
3
+ import { render } from '@testing-library/react';
4
+ import { Link } from '../Link/Link';
5
+
6
+ const defaultParams: Props = {
7
+ 'aria-label': 'Breadcrumbs',
8
+ children: [
9
+ <Link key="0" to="#1" data-testid="link">
10
+ Test1
11
+ </Link>,
12
+ <Link key="1" to="#2" data-testid="link">
13
+ Test2
14
+ </Link>,
15
+ ],
16
+ };
17
+
18
+ const createBreadcrumbs = (params?: (defaultParams: Props) => Props) => {
19
+ let parameters: Props = defaultParams;
20
+ if (params) {
21
+ parameters = params(defaultParams);
22
+ }
23
+ const queries = render(<Breadcrumbs {...parameters} data-testid="breadcrumbs"></Breadcrumbs>);
24
+ const breadcrumbs = queries.getByTestId('breadcrumbs');
25
+
26
+ return {
27
+ ...queries,
28
+ breadcrumbs,
29
+ };
30
+ };
31
+
32
+ describe('Breadcrumbs should render', () => {
33
+ it('renders without crashing', () => {
34
+ const { breadcrumbs } = createBreadcrumbs();
35
+
36
+ expect(breadcrumbs).toBeDefined();
37
+ expect(breadcrumbs.firstChild).not.toHaveAttribute('aria-current');
38
+ expect((breadcrumbs.firstChild as HTMLElement).tagName).toEqual('A');
39
+ expect(breadcrumbs.lastChild).toHaveAttribute('aria-current', 'page');
40
+ expect((breadcrumbs.lastChild as HTMLElement).tagName).toEqual('SPAN');
41
+ });
42
+ });
@@ -0,0 +1,48 @@
1
+ import React, { Fragment, HTMLProps, ReactElement } from 'react';
2
+ import { Icon, Icons } from '../Icon/Icon';
3
+ import { Link, Props as LinkProps } from '../Link/Link';
4
+ import { Typography } from '../Typography/Typography';
5
+ import classes from './Breadcrumbs.module.scss';
6
+
7
+ type ChildrenType = ReactElement<LinkProps, typeof Link>;
8
+
9
+ export interface Props extends HTMLProps<HTMLElement> {
10
+ children: ChildrenType | ChildrenType[];
11
+ 'aria-label': string;
12
+ }
13
+
14
+ export const Breadcrumbs = ({
15
+ children,
16
+ 'aria-label': ariaLabel,
17
+ className = '',
18
+ ...rest
19
+ }: Props) => {
20
+ const items = React.Children.map(children, (child, index) => {
21
+ const isLastElement = Array.isArray(children) ? index === children.length - 1 : true;
22
+ if (isLastElement) {
23
+ return (
24
+ <Typography
25
+ key={child.key}
26
+ variant="body"
27
+ tag="span"
28
+ className={classes['last']}
29
+ aria-current="page"
30
+ >
31
+ {child.props.children}
32
+ </Typography>
33
+ );
34
+ } else {
35
+ return (
36
+ <Fragment key={child.key}>
37
+ {React.cloneElement(child)}
38
+ <Icon icon={Icons.ChevronRight} className={classes['icon']} />
39
+ </Fragment>
40
+ );
41
+ }
42
+ });
43
+ return (
44
+ <nav {...rest} aria-label={ariaLabel} className={`${classes['breadcrumbs']} ${className}`}>
45
+ {items}
46
+ </nav>
47
+ );
48
+ };
@@ -0,0 +1,20 @@
1
+ .button {
2
+ border-width: var(--button-border-width);
3
+ border-style: var(--button-border-style);
4
+ border-radius: var(--button-border-radius);
5
+ font-size: var(--button-font-size);
6
+ line-height: var(--button-font-size);
7
+ margin: 0;
8
+ padding: 0.5rem 1.25rem;
9
+ min-height: 2.5rem;
10
+ cursor: pointer;
11
+ transition-property: color, background-color, border-color;
12
+ transition-duration: 0.2s;
13
+ transition-timing-function: ease-in-out;
14
+ font-family: var(--font-family);
15
+
16
+ &:disabled {
17
+ color: var(--greyed-out);
18
+ cursor: not-allowed;
19
+ }
20
+ }