@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,129 @@
1
+ import React from 'react';
2
+ import { Tile, Props } from './Tile';
3
+ import { render, getByRole } from '@testing-library/react';
4
+ import { Icon, Icons } from '../Icon/Icon';
5
+ import { ContextMenu } from '../ContextMenu/ContextMenu';
6
+ import { IconButton } from '../Button/IconButton';
7
+ import { ContextMenuItem } from '../ContextMenu/ContextMenuItem';
8
+ import userEvent from '@testing-library/user-event';
9
+
10
+ const onShow = jest.fn();
11
+ const onClose = jest.fn();
12
+ const contextMenuItemOnClick = jest.fn();
13
+ const iconClick = jest.fn();
14
+
15
+ const contextMenu = (
16
+ <ContextMenu
17
+ id="context_menu"
18
+ data-testid="contextmenu"
19
+ onShow={onShow}
20
+ onClose={onClose}
21
+ trigger={
22
+ <IconButton data-testid="contextmenu-trigger" title="context menu">
23
+ <Icon icon={Icons.EllipsisAlt} />
24
+ </IconButton>
25
+ }
26
+ >
27
+ <ContextMenuItem data-testid="item1" onClick={contextMenuItemOnClick}>
28
+ Item 1
29
+ </ContextMenuItem>
30
+ <ContextMenuItem data-testid="item2" onClick={contextMenuItemOnClick}>
31
+ Item 2
32
+ </ContextMenuItem>
33
+ <ContextMenuItem data-testid="item3" onClick={contextMenuItemOnClick}>
34
+ Item 3
35
+ </ContextMenuItem>
36
+ </ContextMenu>
37
+ );
38
+
39
+ const defaultParams: Props = {
40
+ title: 'tile',
41
+ iconProps: { icon: Icons.Bell, onClick: iconClick, 'data-testid': 'icon' },
42
+ menu: contextMenu,
43
+ };
44
+
45
+ const createTile = (params?: (defaultParams: Props) => Props) => {
46
+ let parameters: Props = defaultParams;
47
+ if (params) {
48
+ parameters = params(defaultParams);
49
+ }
50
+ const queries = render(
51
+ <Tile {...parameters} data-testid="tile">
52
+ tile content
53
+ </Tile>
54
+ );
55
+ const tile = queries.getByTestId('tile');
56
+ const menutrigger = queries.getByTestId('contextmenu-trigger');
57
+ const icon = queries.getByTestId('icon');
58
+
59
+ return {
60
+ ...queries,
61
+ tile,
62
+ menutrigger,
63
+ icon,
64
+ };
65
+ };
66
+
67
+ describe('Tile should render', () => {
68
+ it('renders without crashing', () => {
69
+ const { tile, icon } = createTile();
70
+
71
+ userEvent.click(icon);
72
+
73
+ expect(iconClick).toHaveBeenCalled();
74
+ expect(tile).toBeDefined();
75
+ });
76
+ });
77
+
78
+ describe("should throw errors since we don't pass props", () => {
79
+ it('throws because of missing id', () => {
80
+ // Prevent throwing an error in the console when this test is executed. We fix this and the end of this test.
81
+ const err = console.error;
82
+ console.error = jest.fn();
83
+
84
+ let actual;
85
+
86
+ try {
87
+ // @ts-ignore: mandatory props (test for non-typescript react projects)
88
+ render(<Tile imageProps={{ src: 'test', alt: 'test' }} />);
89
+ } catch (e: any) {
90
+ actual = e.message;
91
+ }
92
+
93
+ const expected = 'Please make sure to pass a title prop to your Tile component.';
94
+
95
+ expect(actual).toEqual(expected);
96
+
97
+ console.error = err;
98
+ });
99
+ });
100
+
101
+ describe('contextmenu', () => {
102
+ it('should render everything correctly', () => {
103
+ const { menutrigger, getByTestId } = createTile();
104
+
105
+ const contextMenu = getByTestId('contextmenu');
106
+ const menuitem1 = getByTestId('item1');
107
+ const menuitem2 = getByTestId('item2');
108
+ const menuitem3 = getByTestId('item3');
109
+ const popover = document.querySelector('.popover');
110
+
111
+ expect(popover).toHaveStyle({ opacity: '0;' });
112
+ expect(menutrigger).toBeTruthy();
113
+ expect(contextMenu).toBeTruthy();
114
+ expect(menuitem1).toBeTruthy();
115
+ expect(menuitem2).toBeTruthy();
116
+ expect(menuitem3).toBeTruthy();
117
+
118
+ userEvent.click(menutrigger);
119
+ expect(onShow).toHaveBeenCalled();
120
+ expect(popover).toHaveClass('show');
121
+ expect(popover).toHaveStyle({ opacity: '1;' });
122
+
123
+ userEvent.click(getByRole(menuitem1, 'button'));
124
+ userEvent.click(getByRole(menuitem2, 'button'));
125
+ userEvent.click(getByRole(menuitem3, 'button'));
126
+
127
+ expect(contextMenuItemOnClick).toHaveBeenCalledTimes(3);
128
+ });
129
+ });
@@ -0,0 +1,48 @@
1
+ import React, { HTMLProps, ReactElement } from 'react';
2
+ import { Icon, Icons, Props as IconProps } from '../Icon/Icon';
3
+ import classes from './Tile.module.scss';
4
+
5
+ import { Props as ContextMenuProps } from '../ContextMenu/ContextMenu';
6
+
7
+ interface ImageProps {
8
+ src: string;
9
+ alt: string;
10
+ }
11
+
12
+ export interface Props extends Omit<HTMLProps<HTMLDivElement>, 'contextMenu'> {
13
+ title: string;
14
+ imageProps?: ImageProps;
15
+ iconProps?: IconProps;
16
+ loading?: boolean;
17
+ menu?: ReactElement<ContextMenuProps>;
18
+ }
19
+
20
+ export const Tile = ({
21
+ title,
22
+ imageProps,
23
+ iconProps,
24
+ className,
25
+ loading,
26
+ menu,
27
+ ...rest
28
+ }: Props) => {
29
+ if (!title) {
30
+ throw new Error('Please make sure to pass a title prop to your Tile component.');
31
+ }
32
+
33
+ return (
34
+ <div {...rest} className={`${classes['tile']} ${loading ? classes['loading'] : ''}`}>
35
+ <header>
36
+ {iconProps && <Icon {...iconProps} className={`${classes['icon']} ${className ?? ''}`} />}
37
+ {menu ?? null}
38
+ </header>
39
+ <div className={classes['content']}>
40
+ {imageProps && imageProps.src && imageProps.alt && (
41
+ <figure className={classes['image']}>{!loading && <img {...imageProps} />}</figure>
42
+ )}
43
+ {!imageProps && <Icon className={classes['placeholder']} icon={Icons.Image} />}
44
+ <span className={classes['title']}>{title}</span>
45
+ </div>
46
+ </div>
47
+ );
48
+ };
@@ -0,0 +1,11 @@
1
+ .tiles {
2
+ display: grid;
3
+ grid-gap: 1rem;
4
+ grid-template-columns: repeat(1, 1fr);
5
+ }
6
+
7
+ @media screen and (min-width: 30em) {
8
+ .tiles {
9
+ grid-template-columns: repeat(auto-fit, minmax(14.5rem, 1fr));
10
+ }
11
+ }
@@ -0,0 +1,118 @@
1
+ import React from 'react';
2
+ import { Tiles, Props } from './Tiles';
3
+ import { Tile } from './Tile';
4
+ import { render } from '@testing-library/react';
5
+ import { Icon, Icons } from '../Icon/Icon';
6
+ import { ContextMenu } from '../ContextMenu/ContextMenu';
7
+ import { ContextMenuItem } from '../ContextMenu/ContextMenuItem';
8
+ import { IconButton } from '../Button/IconButton';
9
+
10
+ const onShow = jest.fn();
11
+ const onClose = jest.fn();
12
+ const contextMenuItemOnClick = jest.fn();
13
+
14
+ const contextMenu = (
15
+ <ContextMenu
16
+ id="context_menu"
17
+ onShow={onShow}
18
+ onClose={onClose}
19
+ trigger={
20
+ <IconButton title="context menu">
21
+ <Icon icon={Icons.EllipsisAlt} />
22
+ </IconButton>
23
+ }
24
+ >
25
+ <ContextMenuItem data-testid="item1" onClick={contextMenuItemOnClick}>
26
+ Item 1
27
+ </ContextMenuItem>
28
+ <ContextMenuItem data-testid="item2" onClick={contextMenuItemOnClick}>
29
+ Item 2
30
+ </ContextMenuItem>
31
+ <ContextMenuItem data-testid="item3" onClick={contextMenuItemOnClick}>
32
+ Item 3
33
+ </ContextMenuItem>
34
+ </ContextMenu>
35
+ );
36
+
37
+ const defaultParams: Props = {
38
+ children: [
39
+ <Tile
40
+ data-testid="tile"
41
+ key="tile1"
42
+ title="Tile1"
43
+ imageProps={{
44
+ src: 'https://www.onegini.com/hubfs/OneWelcome_Beeldmerk.svg',
45
+ alt: 'OneWelcome logo',
46
+ }}
47
+ iconProps={{ icon: Icons.Checkmark }}
48
+ menu={contextMenu}
49
+ />,
50
+ <Tile
51
+ data-testid="tile"
52
+ key="tile2"
53
+ title="Tile2"
54
+ imageProps={{
55
+ src: 'https://www.onegini.com/hubfs/OneWelcome_Beeldmerk.svg',
56
+ alt: 'OneWelcome logo',
57
+ }}
58
+ iconProps={{ icon: Icons.Forbidden }}
59
+ menu={contextMenu}
60
+ />,
61
+ <Tile
62
+ data-testid="tile"
63
+ key="tile3"
64
+ title="Tile3"
65
+ imageProps={{
66
+ src: 'https://www.onegini.com/hubfs/OneWelcome_Beeldmerk.svg',
67
+ alt: 'OneWelcome logo',
68
+ }}
69
+ iconProps={{ icon: Icons.Checkmark }}
70
+ menu={contextMenu}
71
+ />,
72
+ ],
73
+ className: 'example-classname',
74
+ };
75
+
76
+ const createTiles = (params?: (defaultParams: Props) => Props) => {
77
+ let parameters: Props = defaultParams;
78
+ if (params) {
79
+ parameters = params(defaultParams);
80
+ }
81
+ const queries = render(<Tiles {...parameters} data-testid="tiles" />);
82
+ const tiles = queries.getByTestId('tiles');
83
+
84
+ let individualTiles;
85
+
86
+ if (!parameters.loading) {
87
+ individualTiles = queries.getAllByTestId('tile');
88
+ }
89
+
90
+ return {
91
+ ...queries,
92
+ tiles,
93
+ individualTiles,
94
+ };
95
+ };
96
+
97
+ describe('Tiles should render', () => {
98
+ it('renders without crashing', () => {
99
+ const { tiles, individualTiles } = createTiles();
100
+
101
+ individualTiles?.forEach((tile, index) => {
102
+ expect(tile.querySelector('.title')).toHaveTextContent('Tile' + (index + 1).toFixed(0));
103
+ expect(tile.querySelector('img')).toBeTruthy();
104
+ });
105
+
106
+ expect(tiles).toHaveClass('example-classname');
107
+ expect(tiles).toBeDefined();
108
+ });
109
+ });
110
+
111
+ describe('loading state should be handled properly', () => {
112
+ it('is loading', () => {
113
+ const { tiles } = createTiles((defaultParams) => ({ ...defaultParams, loading: true }));
114
+
115
+ expect(tiles).toHaveAttribute('aria-busy', 'true');
116
+ expect(tiles.querySelectorAll('.tile.loading').length).toBe(3);
117
+ });
118
+ });
@@ -0,0 +1,48 @@
1
+ import React, { HTMLProps, ReactNode } from 'react';
2
+ import classes from './Tiles.module.scss';
3
+ import { Tile } from './Tile';
4
+
5
+ export interface Props extends HTMLProps<HTMLDivElement> {
6
+ children: ReactNode;
7
+ loading?: boolean;
8
+ }
9
+
10
+ export const Tiles = ({ children, className, loading = false, ...rest }: Props) => {
11
+ const renderChildren = () => {
12
+ if (loading) {
13
+ return [
14
+ <Tile
15
+ key="placeholder1"
16
+ title="placeholder"
17
+ imageProps={{ src: 'placeholder', alt: 'placeholder' }}
18
+ loading={true}
19
+ />,
20
+ <Tile
21
+ key="placeholder2"
22
+ title="placeholder"
23
+ imageProps={{ src: 'placeholder', alt: 'placeholder' }}
24
+ loading={true}
25
+ />,
26
+ <Tile
27
+ key="placeholder3"
28
+ title="placeholder"
29
+ imageProps={{ src: 'placeholder', alt: 'placeholder' }}
30
+ loading={true}
31
+ />,
32
+ ];
33
+ }
34
+
35
+ return children;
36
+ };
37
+
38
+ return (
39
+ <div
40
+ {...rest}
41
+ className={`${classes['tiles']} ${className ?? ''}`}
42
+ aria-live="polite"
43
+ aria-busy={loading}
44
+ >
45
+ {renderChildren()}
46
+ </div>
47
+ );
48
+ };
@@ -0,0 +1,42 @@
1
+ .wrapper {
2
+ display: flex;
3
+ align-items: center;
4
+ }
5
+
6
+ .tooltip-wrapper {
7
+ .icon {
8
+ margin-left: 0.5rem;
9
+ transition: all 0.2s ease-in-out;
10
+ color: var(--greyed-out);
11
+
12
+ &:hover {
13
+ color: var(--default);
14
+ }
15
+ }
16
+ }
17
+
18
+ .tooltip {
19
+ position: fixed;
20
+ background-color: var(--default);
21
+ padding: 0.1875rem 0.5rem;
22
+ color: #fff;
23
+ max-width: 330px;
24
+ opacity: 0;
25
+ transform: scale(0);
26
+ transition-duration: 0.2s;
27
+ transition-timing-function: ease-in-out;
28
+ transition-property: opacity, transform;
29
+ transform-origin: center left;
30
+ pointer-events: none;
31
+
32
+ &.visible {
33
+ opacity: 1;
34
+ transform: scale(1);
35
+ }
36
+ }
37
+
38
+ .label {
39
+ &:focus-visible {
40
+ outline: 0.5px dashed var(--color-primary);
41
+ }
42
+ }
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+ import { Tooltip, Props } from './Tooltip';
3
+ import { render } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+
6
+ const defaultParams: Props = {
7
+ children: 'This is a test message',
8
+ label: 'Label',
9
+ };
10
+
11
+ const createTooltip = (params?: (defaultParams: Props) => Props) => {
12
+ let parameters: Props = defaultParams;
13
+ if (params) {
14
+ parameters = params(defaultParams);
15
+ }
16
+ const queries = render(<Tooltip {...parameters} data-testid="tooltip" />);
17
+ const tooltip = queries.getByTestId('tooltip');
18
+
19
+ return {
20
+ ...queries,
21
+ tooltip,
22
+ };
23
+ };
24
+
25
+ describe('Tooltip should render', () => {
26
+ it('renders without crashing', () => {
27
+ const { tooltip, getByText } = createTooltip((defaultParams) => ({
28
+ ...defaultParams,
29
+ className: 'testing',
30
+ }));
31
+
32
+ const tooltipText = getByText('This is a test message');
33
+ const label = getByText('Label');
34
+
35
+ expect(tooltip).toHaveClass('testing');
36
+ expect(tooltipText).toHaveStyle({ top: '0px', left: '16px' });
37
+ expect(label).toBeTruthy();
38
+ expect(tooltipText).toBeTruthy();
39
+ expect(tooltip).toBeTruthy();
40
+ });
41
+
42
+ it('should override the default placement and offset values', () => {
43
+ const { tooltip, getByText } = createTooltip((defaultParams) => ({
44
+ ...defaultParams,
45
+ placement: { horizontal: 'center', vertical: 'center' },
46
+ offset: { top: 0, right: 16, left: 0, bottom: 16 },
47
+ transformOrigin: { horizontal: 'right', vertical: 'bottom' },
48
+ }));
49
+
50
+ const tooltipText = getByText('This is a test message');
51
+ expect(tooltipText).toHaveStyle({ right: '1024px', bottom: '768px' });
52
+ expect(tooltip).toBeTruthy();
53
+ });
54
+ });
55
+
56
+ describe('It opens the tooltip', () => {
57
+ it('opens', () => {
58
+ const { tooltip, getByText } = createTooltip();
59
+
60
+ const icon = tooltip.querySelector('.icon')!;
61
+ const tooltipHover = getByText('This is a test message');
62
+ userEvent.hover(icon);
63
+
64
+ expect(tooltipHover).toHaveClass('visible');
65
+ expect(tooltipHover).toHaveAttribute('aria-hidden', 'false');
66
+
67
+ userEvent.keyboard('{escape}');
68
+
69
+ expect(tooltipHover).not.toHaveClass('visible');
70
+ expect(tooltipHover).toHaveAttribute('aria-hidden', 'true');
71
+ });
72
+ });
@@ -0,0 +1,130 @@
1
+ import React, { HTMLProps, ReactNode, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import { Icon, Icons } from '../Icon/Icon';
3
+ import classes from './Tooltip.module.scss';
4
+ import { generateID } from '../util/helper';
5
+ import { Offset, Placement, usePosition } from '../hooks/usePosition';
6
+ import { createPortal } from 'react-dom';
7
+
8
+ export interface Props extends Omit<HTMLProps<HTMLDivElement>, 'label'> {
9
+ label: string | ReactNode;
10
+ children: string;
11
+ placement?: Placement;
12
+ offset?: Offset;
13
+ transformOrigin?: Placement;
14
+ domRoot?: HTMLElement;
15
+ }
16
+
17
+ interface DefaultPosition {
18
+ placement: Placement;
19
+ offset: Offset;
20
+ transformOrigin: Placement;
21
+ }
22
+
23
+ const defaultPosition: DefaultPosition = {
24
+ placement: { horizontal: 'right', vertical: 'center' },
25
+ offset: { left: 16, right: 0, top: 0, bottom: 0 },
26
+ transformOrigin: { horizontal: 'left', vertical: 'center' },
27
+ };
28
+
29
+ export const Tooltip = ({
30
+ children,
31
+ className,
32
+ placement = defaultPosition.placement,
33
+ offset = defaultPosition.offset,
34
+ transformOrigin = defaultPosition.transformOrigin,
35
+ domRoot = document.body,
36
+ label,
37
+ ...rest
38
+ }: Props) => {
39
+ const [identifier] = useState(generateID());
40
+ const [visible, setVisible] = useState(false);
41
+
42
+ const relativeElement = useRef<HTMLOrSVGElement>(null);
43
+ const elementToBePositioned = useRef<HTMLDivElement>(null);
44
+
45
+ const { top, bottom, right, left, calculatePosition } = usePosition({
46
+ relativeElement: relativeElement,
47
+ elementToBePositioned: elementToBePositioned,
48
+ placement: placement,
49
+ offset: offset,
50
+ transformOrigin: transformOrigin,
51
+ });
52
+
53
+ useEffect(() => {
54
+ if (!visible) return;
55
+
56
+ function escapePressHandler(event: KeyboardEvent) {
57
+ if (event.key === 'Escape') {
58
+ setVisible(false);
59
+ }
60
+ }
61
+
62
+ document.addEventListener('keyup', escapePressHandler);
63
+
64
+ return () => {
65
+ document.removeEventListener('keyup', escapePressHandler);
66
+ };
67
+ }, [visible]);
68
+
69
+ useLayoutEffect(() => {
70
+ calculatePosition();
71
+ }, [visible]);
72
+
73
+ const renderChildren = () => {
74
+ if (React.isValidElement(label)) {
75
+ return React.cloneElement(label, {
76
+ onFocus: () => setVisible(true),
77
+ onBlur: () => setVisible(false),
78
+ 'aria-describedby': identifier,
79
+ tabIndex: 0,
80
+ className: classes['label'],
81
+ });
82
+ }
83
+
84
+ return (
85
+ <span
86
+ className={classes['label']}
87
+ tabIndex={0}
88
+ onFocus={() => setVisible(true)}
89
+ onBlur={() => setVisible(false)}
90
+ aria-describedby={identifier}
91
+ >
92
+ {label}
93
+ </span>
94
+ );
95
+ };
96
+
97
+ return (
98
+ <div {...rest} className={`${classes.wrapper} ${className ?? ''}`}>
99
+ {renderChildren()}
100
+ <div className={`${classes['tooltip-wrapper']}`}>
101
+ <Icon
102
+ ref={relativeElement}
103
+ tag="div"
104
+ onMouseEnter={() => setVisible(true)}
105
+ onMouseLeave={() => setVisible(false)}
106
+ icon={Icons.InfoCircle}
107
+ className={classes.icon}
108
+ />
109
+ {createPortal(
110
+ <div
111
+ ref={elementToBePositioned}
112
+ style={{
113
+ ...rest.style,
114
+ top: top,
115
+ left: left,
116
+ right: right,
117
+ bottom: bottom,
118
+ }}
119
+ aria-hidden={!visible}
120
+ id={identifier}
121
+ className={`${classes.tooltip} ${visible ? classes.visible : ''}`}
122
+ >
123
+ {children}
124
+ </div>,
125
+ domRoot
126
+ )}
127
+ </div>
128
+ </div>
129
+ );
130
+ };
@@ -0,0 +1,46 @@
1
+ @mixin fontProperties($fontFamily, $fontSize, $fontWeight, $lineHeight) {
2
+ font-family: $fontFamily;
3
+ font-size: $fontSize;
4
+ font-style: normal;
5
+ font-variant: normal;
6
+ line-height: $lineHeight;
7
+ font-weight: $fontWeight;
8
+ text-transform: none;
9
+ letter-spacing: 0;
10
+ color: var(--default);
11
+ margin: 0 0 1rem 0;
12
+ }
13
+
14
+ .typography_style_ {
15
+ &h1 {
16
+ @include fontProperties(var(--font-family), var(--font-size-h1), 700, 1.2);
17
+ }
18
+
19
+ &h2 {
20
+ @include fontProperties(var(--font-family), var(--font-size-h2), 700, 1.42857);
21
+ }
22
+
23
+ &h3 {
24
+ @include fontProperties(var(--font-family), var(--font-size-h3), 500, 1.16666);
25
+ }
26
+
27
+ &h4 {
28
+ @include fontProperties(var(--font-family), var(--font-size-h4), 700, 1.2);
29
+ }
30
+
31
+ &body {
32
+ @include fontProperties(var(--font-family), var(--font-size), 400, 1.5);
33
+ }
34
+
35
+ &body-bold {
36
+ @include fontProperties(var(--font-family), var(--font-size), 700, 1.5);
37
+ }
38
+
39
+ &sub-text {
40
+ @include fontProperties(var(--font-family), var(--font-size-sub), 400, 1.333);
41
+ }
42
+
43
+ &code {
44
+ @include fontProperties(var(--font-family-code), var(--font-size-code), 400, 1.5);
45
+ }
46
+ }