@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
@@ -1,48 +1,82 @@
1
- import React, { HTMLProps, ReactElement } from 'react';
2
- import { Icon, Icons, Props as IconProps } from '../Icon/Icon';
1
+ import React, { ComponentPropsWithRef, ReactElement, useState } from 'react';
2
+ import { Icon, Icons } from '../Icon/Icon';
3
3
  import classes from './Tile.module.scss';
4
+ import readyClasses from '../readyclasses.module.scss';
4
5
 
5
6
  import { Props as ContextMenuProps } from '../ContextMenu/ContextMenu';
7
+ import { generateID } from '../util/helper';
8
+ import { Props as IconButtonProps } from '../Button/IconButton';
6
9
 
7
10
  interface ImageProps {
8
11
  src: string;
9
- alt: string;
10
12
  }
11
13
 
12
- export interface Props extends Omit<HTMLProps<HTMLDivElement>, 'contextMenu'> {
14
+ export interface Props extends ComponentPropsWithRef<'div'> {
13
15
  title: string;
14
16
  imageProps?: ImageProps;
15
- iconProps?: IconProps;
17
+ enabled?: boolean;
16
18
  loading?: boolean;
17
- menu?: ReactElement<ContextMenuProps>;
19
+ tileAction?: ReactElement<ContextMenuProps> | ReactElement<IconButtonProps>;
18
20
  }
19
21
 
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
- }
22
+ export const Tile = React.forwardRef<HTMLDivElement, Props>(
23
+ ({ title, imageProps, enabled, className, loading, tileAction, ...rest }: Props, ref) => {
24
+ const [tileDescriptionID] = useState(generateID(20));
25
+
26
+ if (!title) {
27
+ throw new Error('Please make sure to pass a title prop to your Tile component.');
28
+ }
29
+
30
+ const statusMessage = () => {
31
+ if (enabled) {
32
+ return 'Status: enabled';
33
+ }
32
34
 
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
- };
35
+ return 'Status: disabled';
36
+ };
37
+
38
+ return (
39
+ <article
40
+ {...rest}
41
+ tabIndex={0}
42
+ aria-labelledby={tileDescriptionID}
43
+ ref={ref}
44
+ className={`${classes['tile']} ${loading ? classes['loading'] : ''}`}
45
+ >
46
+ <header style={{ justifyContent: enabled === undefined ? 'flex-end' : 'space-between' }}>
47
+ {enabled === true && (
48
+ <Icon
49
+ color="var(--success)"
50
+ icon={Icons.Checkmark}
51
+ className={`${classes['icon']} ${className ?? ''}`}
52
+ />
53
+ )}
54
+ {enabled === false && (
55
+ <Icon
56
+ color="var(--greyed-out)"
57
+ icon={Icons.Forbidden}
58
+ className={`${classes['icon']} ${className ?? ''}`}
59
+ />
60
+ )}
61
+ {enabled !== undefined && (
62
+ <span id={tileDescriptionID} className={readyClasses['sr-only']}>
63
+ {`${title}. ${statusMessage()}`}
64
+ </span>
65
+ )}
66
+ {tileAction ?? null}
67
+ </header>
68
+ <div className={classes['content']}>
69
+ {imageProps && imageProps.src.length > 0 && (
70
+ <figure className={classes['image']}>
71
+ {!loading && <img {...imageProps} alt="" />}
72
+ </figure>
73
+ )}
74
+ {(!imageProps || imageProps.src.length === 0) && (
75
+ <Icon className={classes['placeholder']} icon={Icons.Image} />
76
+ )}
77
+ <span className={classes['title']}>{title}</span>
78
+ </div>
79
+ </article>
80
+ );
81
+ }
82
+ );
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect, useRef } from 'react';
2
2
  import { Tiles, Props } from './Tiles';
3
3
  import { Tile } from './Tile';
4
4
  import { render } from '@testing-library/react';
@@ -34,6 +34,12 @@ const contextMenu = (
34
34
  </ContextMenu>
35
35
  );
36
36
 
37
+ const addToFavoriteButton = (
38
+ <IconButton title="Add to favorite">
39
+ <Icon icon={Icons.Star} />
40
+ </IconButton>
41
+ );
42
+
37
43
  const defaultParams: Props = {
38
44
  children: [
39
45
  <Tile
@@ -42,10 +48,9 @@ const defaultParams: Props = {
42
48
  title="Tile1"
43
49
  imageProps={{
44
50
  src: 'https://www.onegini.com/hubfs/OneWelcome_Beeldmerk.svg',
45
- alt: 'OneWelcome logo',
46
51
  }}
47
- iconProps={{ icon: Icons.Checkmark }}
48
- menu={contextMenu}
52
+ enabled={true}
53
+ tileAction={contextMenu}
49
54
  />,
50
55
  <Tile
51
56
  data-testid="tile"
@@ -53,10 +58,9 @@ const defaultParams: Props = {
53
58
  title="Tile2"
54
59
  imageProps={{
55
60
  src: 'https://www.onegini.com/hubfs/OneWelcome_Beeldmerk.svg',
56
- alt: 'OneWelcome logo',
57
61
  }}
58
- iconProps={{ icon: Icons.Forbidden }}
59
- menu={contextMenu}
62
+ enabled={false}
63
+ tileAction={addToFavoriteButton}
60
64
  />,
61
65
  <Tile
62
66
  data-testid="tile"
@@ -64,10 +68,8 @@ const defaultParams: Props = {
64
68
  title="Tile3"
65
69
  imageProps={{
66
70
  src: 'https://www.onegini.com/hubfs/OneWelcome_Beeldmerk.svg',
67
- alt: 'OneWelcome logo',
68
71
  }}
69
- iconProps={{ icon: Icons.Checkmark }}
70
- menu={contextMenu}
72
+ tileAction={contextMenu}
71
73
  />,
72
74
  ],
73
75
  className: 'example-classname',
@@ -116,3 +118,29 @@ describe('loading state should be handled properly', () => {
116
118
  expect(tiles.querySelectorAll('.tile.loading').length).toBe(3);
117
119
  });
118
120
  });
121
+
122
+ describe('ref should work', () => {
123
+ it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
124
+ const ExampleComponent = ({
125
+ propagateRef,
126
+ }: {
127
+ propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
128
+ }) => {
129
+ const ref = useRef(null);
130
+
131
+ useEffect(() => {
132
+ if (ref.current) {
133
+ propagateRef && propagateRef(ref);
134
+ }
135
+ }, [ref]);
136
+
137
+ return <Tiles {...defaultParams} data-ref="testing" ref={ref} />;
138
+ };
139
+
140
+ const refCheck = (ref: React.RefObject<HTMLElement>) => {
141
+ expect(ref.current).toHaveAttribute('data-ref', 'testing');
142
+ };
143
+
144
+ render(<ExampleComponent propagateRef={refCheck} />);
145
+ });
146
+ });
@@ -1,48 +1,51 @@
1
- import React, { HTMLProps, ReactNode } from 'react';
1
+ import React, { ComponentPropsWithRef, ReactNode } from 'react';
2
2
  import classes from './Tiles.module.scss';
3
3
  import { Tile } from './Tile';
4
4
 
5
- export interface Props extends HTMLProps<HTMLDivElement> {
5
+ export interface Props extends ComponentPropsWithRef<'div'> {
6
6
  children: ReactNode;
7
7
  loading?: boolean;
8
8
  }
9
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
- }
10
+ export const Tiles = React.forwardRef<HTMLDivElement, Props>(
11
+ ({ children, className, loading = false, ...rest }: Props, ref) => {
12
+ const renderChildren = () => {
13
+ if (loading) {
14
+ return [
15
+ <Tile
16
+ key="placeholder1"
17
+ title="placeholder"
18
+ imageProps={{ src: 'placeholder' }}
19
+ loading={true}
20
+ />,
21
+ <Tile
22
+ key="placeholder2"
23
+ title="placeholder"
24
+ imageProps={{ src: 'placeholder' }}
25
+ loading={true}
26
+ />,
27
+ <Tile
28
+ key="placeholder3"
29
+ title="placeholder"
30
+ imageProps={{ src: 'placeholder' }}
31
+ loading={true}
32
+ />,
33
+ ];
34
+ }
34
35
 
35
- return children;
36
- };
36
+ return children;
37
+ };
37
38
 
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
- };
39
+ return (
40
+ <div
41
+ {...rest}
42
+ ref={ref}
43
+ className={`${classes['tiles']} ${className ?? ''}`}
44
+ aria-live="polite"
45
+ aria-busy={loading}
46
+ >
47
+ {renderChildren()}
48
+ </div>
49
+ );
50
+ }
51
+ );
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect, useRef } from 'react';
2
2
  import { Tooltip, Props } from './Tooltip';
3
3
  import { render } from '@testing-library/react';
4
4
  import userEvent from '@testing-library/user-event';
@@ -70,3 +70,29 @@ describe('It opens the tooltip', () => {
70
70
  expect(tooltipHover).toHaveAttribute('aria-hidden', 'true');
71
71
  });
72
72
  });
73
+
74
+ describe('ref should work', () => {
75
+ it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
76
+ const ExampleComponent = ({
77
+ propagateRef,
78
+ }: {
79
+ propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
80
+ }) => {
81
+ const ref = useRef(null);
82
+
83
+ useEffect(() => {
84
+ if (ref.current) {
85
+ propagateRef && propagateRef(ref);
86
+ }
87
+ }, [ref]);
88
+
89
+ return <Tooltip {...defaultParams} data-ref="testing" ref={ref} />;
90
+ };
91
+
92
+ const refCheck = (ref: React.RefObject<HTMLElement>) => {
93
+ expect(ref.current).toHaveAttribute('data-ref', 'testing');
94
+ };
95
+
96
+ render(<ExampleComponent propagateRef={refCheck} />);
97
+ });
98
+ });
@@ -1,11 +1,18 @@
1
- import React, { HTMLProps, ReactNode, useEffect, useLayoutEffect, useRef, useState } from 'react';
1
+ import React, {
2
+ ComponentPropsWithRef,
3
+ ReactNode,
4
+ useEffect,
5
+ useLayoutEffect,
6
+ useRef,
7
+ useState,
8
+ } from 'react';
2
9
  import { Icon, Icons } from '../Icon/Icon';
3
10
  import classes from './Tooltip.module.scss';
4
11
  import { generateID } from '../util/helper';
5
12
  import { Offset, Placement, usePosition } from '../hooks/usePosition';
6
13
  import { createPortal } from 'react-dom';
7
14
 
8
- export interface Props extends Omit<HTMLProps<HTMLDivElement>, 'label'> {
15
+ export interface Props extends ComponentPropsWithRef<'div'> {
9
16
  label: string | ReactNode;
10
17
  children: string;
11
18
  placement?: Placement;
@@ -26,105 +33,110 @@ const defaultPosition: DefaultPosition = {
26
33
  transformOrigin: { horizontal: 'left', vertical: 'center' },
27
34
  };
28
35
 
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);
36
+ export const Tooltip = React.forwardRef<HTMLDivElement, Props>(
37
+ (
38
+ {
39
+ children,
40
+ className,
41
+ placement = defaultPosition.placement,
42
+ offset = defaultPosition.offset,
43
+ transformOrigin = defaultPosition.transformOrigin,
44
+ domRoot = document.body,
45
+ label,
46
+ ...rest
47
+ }: Props,
48
+ ref
49
+ ) => {
50
+ const [identifier] = useState(generateID());
51
+ const [visible, setVisible] = useState(false);
41
52
 
42
- const relativeElement = useRef<HTMLOrSVGElement>(null);
43
- const elementToBePositioned = useRef<HTMLDivElement>(null);
53
+ const relativeElement = useRef<HTMLDivElement>(null);
54
+ const elementToBePositioned = useRef<HTMLDivElement>(null);
44
55
 
45
- const { top, bottom, right, left, calculatePosition } = usePosition({
46
- relativeElement: relativeElement,
47
- elementToBePositioned: elementToBePositioned,
48
- placement: placement,
49
- offset: offset,
50
- transformOrigin: transformOrigin,
51
- });
56
+ const { top, bottom, right, left, calculatePosition } = usePosition({
57
+ relativeElement: relativeElement,
58
+ elementToBePositioned: elementToBePositioned,
59
+ placement: placement,
60
+ offset: offset,
61
+ transformOrigin: transformOrigin,
62
+ });
52
63
 
53
- useEffect(() => {
54
- if (!visible) return;
64
+ useEffect(() => {
65
+ if (!visible) return;
55
66
 
56
- function escapePressHandler(event: KeyboardEvent) {
57
- if (event.key === 'Escape') {
58
- setVisible(false);
67
+ function escapePressHandler(event: KeyboardEvent) {
68
+ if (event.key === 'Escape') {
69
+ setVisible(false);
70
+ }
59
71
  }
60
- }
61
72
 
62
- document.addEventListener('keyup', escapePressHandler);
73
+ document.addEventListener('keyup', escapePressHandler);
63
74
 
64
- return () => {
65
- document.removeEventListener('keyup', escapePressHandler);
66
- };
67
- }, [visible]);
75
+ return () => {
76
+ document.removeEventListener('keyup', escapePressHandler);
77
+ };
78
+ }, [visible]);
68
79
 
69
- useLayoutEffect(() => {
70
- calculatePosition();
71
- }, [visible]);
80
+ useLayoutEffect(() => {
81
+ calculatePosition();
82
+ }, [visible]);
72
83
 
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
- }
84
+ const renderChildren = () => {
85
+ if (React.isValidElement(label)) {
86
+ return React.cloneElement(label, {
87
+ onFocus: () => setVisible(true),
88
+ onBlur: () => setVisible(false),
89
+ 'aria-describedby': identifier,
90
+ tabIndex: 0,
91
+ className: classes['label'],
92
+ });
93
+ }
83
94
 
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
- };
95
+ return (
96
+ <span
97
+ className={classes['label']}
98
+ tabIndex={0}
99
+ onFocus={() => setVisible(true)}
100
+ onBlur={() => setVisible(false)}
101
+ aria-describedby={identifier}
102
+ >
103
+ {label}
104
+ </span>
105
+ );
106
+ };
96
107
 
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
- )}
108
+ return (
109
+ <div {...rest} ref={ref} className={`${classes.wrapper} ${className ?? ''}`}>
110
+ {renderChildren()}
111
+ <div className={`${classes['tooltip-wrapper']}`}>
112
+ <Icon
113
+ ref={relativeElement}
114
+ tag="div"
115
+ onMouseEnter={() => setVisible(true)}
116
+ onMouseLeave={() => setVisible(false)}
117
+ icon={Icons.InfoCircle}
118
+ className={classes.icon}
119
+ />
120
+ {createPortal(
121
+ <div
122
+ ref={elementToBePositioned}
123
+ style={{
124
+ ...rest.style,
125
+ top: top,
126
+ left: left,
127
+ right: right,
128
+ bottom: bottom,
129
+ }}
130
+ aria-hidden={!visible}
131
+ id={identifier}
132
+ className={`${classes.tooltip} ${visible ? classes.visible : ''}`}
133
+ >
134
+ {children}
135
+ </div>,
136
+ domRoot
137
+ )}
138
+ </div>
127
139
  </div>
128
- </div>
129
- );
130
- };
140
+ );
141
+ }
142
+ );
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect, useRef } from 'react';
2
2
  import { Typography, Props } from './Typography';
3
3
  import { render } from '@testing-library/react';
4
4
  import { Spacing } from '../hooks/useSpacing';
@@ -112,3 +112,29 @@ describe('Should override styling', () => {
112
112
  expect(typography.style).toHaveProperty('margin', '1rem 1rem 2rem 1rem');
113
113
  });
114
114
  });
115
+
116
+ describe('ref should work', () => {
117
+ it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
118
+ const ExampleComponent = ({
119
+ propagateRef,
120
+ }: {
121
+ propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
122
+ }) => {
123
+ const ref = useRef(null);
124
+
125
+ useEffect(() => {
126
+ if (ref.current) {
127
+ propagateRef && propagateRef(ref);
128
+ }
129
+ }, [ref]);
130
+
131
+ return <Typography variant="body" data-ref="testing" ref={ref} />;
132
+ };
133
+
134
+ const refCheck = (ref: React.RefObject<HTMLElement>) => {
135
+ expect(ref.current).toHaveAttribute('data-ref', 'testing');
136
+ };
137
+
138
+ render(<ExampleComponent propagateRef={refCheck} />);
139
+ });
140
+ });