@onewelcome/react-lib-components 0.2.0 → 0.2.3

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 (282) hide show
  1. package/dist/Breadcrumbs/Breadcrumbs.d.ts +4 -4
  2. package/dist/Button/BaseButton.d.ts +4 -4
  3. package/dist/Button/Button.d.ts +3 -3
  4. package/dist/Button/IconButton.d.ts +4 -4
  5. package/dist/ContextMenu/ContextMenu.d.ts +5 -5
  6. package/dist/ContextMenu/ContextMenuItem.d.ts +2 -2
  7. package/dist/DataGrid/DataGrid.d.ts +6 -6
  8. package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +4 -4
  9. package/dist/DataGrid/DataGridActions/DataGridColumnsToggle.d.ts +3 -3
  10. package/dist/DataGrid/DataGridBody/DataGridBody.d.ts +3 -3
  11. package/dist/DataGrid/DataGridBody/DataGridCell.d.ts +2 -2
  12. package/dist/DataGrid/DataGridBody/DataGridRow.d.ts +3 -3
  13. package/dist/DataGrid/DataGridHeader/DataGridHeader.d.ts +3 -3
  14. package/dist/DataGrid/DataGridHeader/DataGridHeaderCell.d.ts +3 -3
  15. package/dist/DataGrid/datagrid.interfaces.d.ts +1 -1
  16. package/dist/Form/Checkbox/Checkbox.d.ts +5 -5
  17. package/dist/Form/Fieldset/Fieldset.d.ts +3 -3
  18. package/dist/Form/Form.d.ts +1 -1
  19. package/dist/Form/FormControl/FormControl.d.ts +3 -3
  20. package/dist/Form/FormGroup/FormGroup.d.ts +5 -5
  21. package/dist/Form/FormHelperText/FormHelperText.d.ts +3 -3
  22. package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +6 -6
  23. package/dist/Form/Input/Input.d.ts +5 -5
  24. package/dist/Form/Label/Label.d.ts +2 -2
  25. package/dist/Form/Radio/Radio.d.ts +5 -5
  26. package/dist/Form/Select/Option.d.ts +2 -2
  27. package/dist/Form/Select/Select.d.ts +5 -5
  28. package/dist/Form/Textarea/Textarea.d.ts +6 -6
  29. package/dist/Form/Toggle/Toggle.d.ts +3 -3
  30. package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +4 -4
  31. package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +4 -4
  32. package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +4 -4
  33. package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +4 -4
  34. package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +4 -4
  35. package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +6 -6
  36. package/dist/Form/form.interfaces.d.ts +1 -1
  37. package/dist/Icon/Icon.d.ts +3 -3
  38. package/dist/Link/Link.d.ts +7 -7
  39. package/dist/Notifications/BaseModal/BaseModal.d.ts +4 -4
  40. package/dist/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +2 -2
  41. package/dist/Notifications/BaseModal/BaseModalContent/BaseModalContent.d.ts +2 -2
  42. package/dist/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +2 -2
  43. package/dist/Notifications/Dialog/Dialog.d.ts +5 -5
  44. package/dist/Notifications/Dialog/DialogActions/DialogActions.d.ts +3 -3
  45. package/dist/Notifications/Dialog/DialogTitle/DialogTitle.d.ts +2 -2
  46. package/dist/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.d.ts +3 -3
  47. package/dist/Notifications/DiscardChangesModal/DiscardChangesModal.d.ts +7 -7
  48. package/dist/Notifications/Modal/Modal.d.ts +1 -1
  49. package/dist/Notifications/Modal/ModalActions/ModalActions.d.ts +1 -1
  50. package/dist/Notifications/Modal/ModalContent/ModalContent.d.ts +1 -1
  51. package/dist/Notifications/Modal/ModalHeader/ModalHeader.d.ts +1 -1
  52. package/dist/Notifications/SlideInModal/SlideInModal.d.ts +3 -3
  53. package/dist/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +3 -3
  54. package/dist/Notifications/Snackbar/SnackbarItem/SnackbarItem.d.ts +2 -2
  55. package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +3 -3
  56. package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +2 -2
  57. package/dist/Notifications/Snackbar/interfaces.d.ts +2 -2
  58. package/dist/Pagination/Pagination.d.ts +3 -3
  59. package/dist/Popover/Popover.d.ts +3 -3
  60. package/dist/Skeleton/Skeleton.d.ts +3 -3
  61. package/dist/StatusIndicator/StatusIndicator.d.ts +5 -5
  62. package/dist/Tabs/Tab.d.ts +1 -1
  63. package/dist/Tabs/TabButton.d.ts +2 -2
  64. package/dist/Tabs/TabPanel.d.ts +2 -2
  65. package/dist/Tabs/Tabs.d.ts +4 -4
  66. package/dist/TextEllipsis/TextEllipsis.d.ts +2 -2
  67. package/dist/Tiles/Tile.d.ts +5 -5
  68. package/dist/Tiles/Tiles.d.ts +2 -2
  69. package/dist/Tooltip/Tooltip.d.ts +3 -3
  70. package/dist/Typography/Typography.d.ts +3 -3
  71. package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +2 -2
  72. package/dist/Wizard/Wizard.d.ts +3 -3
  73. package/dist/Wizard/WizardActions/WizardActions.d.ts +2 -2
  74. package/dist/Wizard/WizardStateProvider.d.ts +2 -2
  75. package/dist/Wizard/WizardSteps/WizardSteps.d.ts +2 -2
  76. package/dist/Wizard/wizardStateReducer.d.ts +5 -5
  77. package/dist/_BaseStyling_/BaseStyling.d.ts +1 -1
  78. package/dist/hooks/usePosition.d.ts +4 -4
  79. package/dist/hooks/useRepeater.d.ts +1 -1
  80. package/dist/hooks/useScroll.d.ts +1 -1
  81. package/dist/hooks/useSpacing.d.ts +1 -1
  82. package/dist/hooks/useWrapper.d.ts +1 -1
  83. package/dist/index.d.ts +55 -55
  84. package/dist/react-lib-components.cjs.development.js +676 -578
  85. package/dist/react-lib-components.cjs.development.js.map +1 -1
  86. package/dist/react-lib-components.cjs.production.min.js +1 -1
  87. package/dist/react-lib-components.cjs.production.min.js.map +1 -1
  88. package/dist/react-lib-components.esm.js +676 -578
  89. package/dist/react-lib-components.esm.js.map +1 -1
  90. package/package.json +27 -16
  91. package/src/Breadcrumbs/Breadcrumbs.test.tsx +15 -15
  92. package/src/Breadcrumbs/Breadcrumbs.tsx +11 -11
  93. package/src/Button/BaseButton.module.scss +1 -1
  94. package/src/Button/BaseButton.test.tsx +27 -27
  95. package/src/Button/BaseButton.tsx +8 -8
  96. package/src/Button/Button.module.scss +5 -5
  97. package/src/Button/Button.test.tsx +39 -39
  98. package/src/Button/Button.tsx +10 -10
  99. package/src/Button/IconButton.module.scss +5 -5
  100. package/src/Button/IconButton.test.tsx +29 -29
  101. package/src/Button/IconButton.tsx +11 -11
  102. package/src/ContextMenu/ContextMenu.test.tsx +97 -76
  103. package/src/ContextMenu/ContextMenu.tsx +48 -42
  104. package/src/ContextMenu/ContextMenuItem.module.scss +1 -1
  105. package/src/ContextMenu/ContextMenuItem.tsx +7 -5
  106. package/src/DataGrid/DataGrid.test.tsx +193 -193
  107. package/src/DataGrid/DataGrid.tsx +26 -26
  108. package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +63 -63
  109. package/src/DataGrid/DataGridActions/DataGridActions.tsx +15 -15
  110. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss +1 -1
  111. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +21 -21
  112. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +20 -20
  113. package/src/DataGrid/DataGridBody/DataGridBody.test.tsx +40 -40
  114. package/src/DataGrid/DataGridBody/DataGridBody.tsx +10 -10
  115. package/src/DataGrid/DataGridBody/DataGridCell.module.scss +1 -1
  116. package/src/DataGrid/DataGridBody/DataGridCell.test.tsx +25 -25
  117. package/src/DataGrid/DataGridBody/DataGridCell.tsx +6 -6
  118. package/src/DataGrid/DataGridBody/DataGridRow.test.tsx +38 -38
  119. package/src/DataGrid/DataGridBody/DataGridRow.tsx +8 -8
  120. package/src/DataGrid/DataGridHeader/DataGridHeader.module.scss +1 -2
  121. package/src/DataGrid/DataGridHeader/DataGridHeader.test.tsx +119 -119
  122. package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +13 -13
  123. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +2 -0
  124. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +51 -51
  125. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +14 -14
  126. package/src/DataGrid/datagrid.interfaces.ts +1 -1
  127. package/src/Form/Checkbox/Checkbox.test.tsx +74 -74
  128. package/src/Form/Checkbox/Checkbox.tsx +27 -27
  129. package/src/Form/Fieldset/Fieldset.module.scss +1 -1
  130. package/src/Form/Fieldset/Fieldset.test.tsx +35 -35
  131. package/src/Form/Fieldset/Fieldset.tsx +27 -27
  132. package/src/Form/Form.test.tsx +18 -18
  133. package/src/Form/Form.tsx +3 -3
  134. package/src/Form/FormControl/FormControl.test.tsx +22 -22
  135. package/src/Form/FormControl/FormControl.tsx +10 -10
  136. package/src/Form/FormGroup/FormGroup.test.tsx +37 -37
  137. package/src/Form/FormGroup/FormGroup.tsx +16 -16
  138. package/src/Form/FormHelperText/FormHelperText.test.tsx +18 -18
  139. package/src/Form/FormHelperText/FormHelperText.tsx +7 -7
  140. package/src/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +15 -15
  141. package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +14 -14
  142. package/src/Form/Input/Input.module.scss +20 -44
  143. package/src/Form/Input/Input.test.tsx +121 -73
  144. package/src/Form/Input/Input.tsx +96 -35
  145. package/src/Form/Label/Label.test.tsx +13 -13
  146. package/src/Form/Label/Label.tsx +6 -6
  147. package/src/Form/Radio/Radio.test.tsx +35 -35
  148. package/src/Form/Radio/Radio.tsx +17 -17
  149. package/src/Form/Select/Option.test.tsx +10 -10
  150. package/src/Form/Select/Option.tsx +8 -8
  151. package/src/Form/Select/Select.module.scss +7 -9
  152. package/src/Form/Select/Select.test.tsx +144 -141
  153. package/src/Form/Select/Select.tsx +79 -78
  154. package/src/Form/Textarea/Textarea.module.scss +8 -18
  155. package/src/Form/Textarea/Textarea.test.tsx +27 -27
  156. package/src/Form/Textarea/Textarea.tsx +33 -13
  157. package/src/Form/Toggle/Toggle.module.scss +1 -1
  158. package/src/Form/Toggle/Toggle.test.tsx +22 -22
  159. package/src/Form/Toggle/Toggle.tsx +10 -10
  160. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +39 -39
  161. package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +12 -12
  162. package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +2 -8
  163. package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +55 -55
  164. package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +30 -35
  165. package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +35 -35
  166. package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +12 -12
  167. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +55 -55
  168. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +12 -12
  169. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +2 -11
  170. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +50 -50
  171. package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +22 -22
  172. package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +2 -2
  173. package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +11 -11
  174. package/src/Form/Wrapper/Wrapper/Wrapper.tsx +17 -17
  175. package/src/Form/form.interfaces.ts +1 -1
  176. package/src/Icon/Icon.module.scss +71 -71
  177. package/src/Icon/Icon.test.tsx +18 -18
  178. package/src/Icon/Icon.tsx +70 -70
  179. package/src/Link/Link.module.scss +5 -5
  180. package/src/Link/Link.test.tsx +76 -76
  181. package/src/Link/Link.tsx +27 -27
  182. package/src/Link/types.d.ts +1 -1
  183. package/src/Notifications/BaseModal/BaseModal.module.scss +1 -1
  184. package/src/Notifications/BaseModal/BaseModal.test.tsx +53 -53
  185. package/src/Notifications/BaseModal/BaseModal.tsx +16 -16
  186. package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +13 -13
  187. package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +5 -5
  188. package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +16 -16
  189. package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +5 -5
  190. package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +19 -19
  191. package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +10 -10
  192. package/src/Notifications/Dialog/Dialog.test.tsx +35 -35
  193. package/src/Notifications/Dialog/Dialog.tsx +19 -19
  194. package/src/Notifications/Dialog/DialogActions/DialogActions.test.tsx +14 -14
  195. package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +6 -6
  196. package/src/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +12 -12
  197. package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +6 -6
  198. package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +20 -20
  199. package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +7 -7
  200. package/src/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +36 -36
  201. package/src/Notifications/DiscardChangesModal/DiscardChangesModal.tsx +8 -8
  202. package/src/Notifications/Modal/Modal.test.tsx +6 -6
  203. package/src/Notifications/Modal/Modal.tsx +1 -1
  204. package/src/Notifications/Modal/ModalActions/ModalActions.tsx +2 -2
  205. package/src/Notifications/Modal/ModalContent/ModalContent.tsx +2 -2
  206. package/src/Notifications/Modal/ModalHeader/ModalHeader.tsx +2 -2
  207. package/src/Notifications/SlideInModal/SlideInModal.test.tsx +16 -16
  208. package/src/Notifications/SlideInModal/SlideInModal.tsx +16 -11
  209. package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +16 -16
  210. package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.tsx +6 -6
  211. package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +2 -2
  212. package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +17 -17
  213. package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +23 -23
  214. package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +32 -32
  215. package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +18 -18
  216. package/src/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +3 -3
  217. package/src/Notifications/Snackbar/interfaces.ts +2 -2
  218. package/src/Notifications/Snackbar/useSnackbar.ts +2 -2
  219. package/src/Pagination/Pagination.module.scss +2 -0
  220. package/src/Pagination/Pagination.test.tsx +47 -47
  221. package/src/Pagination/Pagination.tsx +35 -35
  222. package/src/Popover/Popover.test.tsx +19 -19
  223. package/src/Popover/Popover.tsx +7 -7
  224. package/src/Skeleton/Skeleton.module.scss +2 -2
  225. package/src/Skeleton/Skeleton.test.tsx +29 -29
  226. package/src/Skeleton/Skeleton.tsx +10 -10
  227. package/src/StatusIndicator/StatusIndicator.test.tsx +38 -38
  228. package/src/StatusIndicator/StatusIndicator.tsx +9 -9
  229. package/src/Tabs/Tab.test.tsx +13 -13
  230. package/src/Tabs/Tab.tsx +1 -1
  231. package/src/Tabs/TabButton.test.tsx +28 -28
  232. package/src/Tabs/TabButton.tsx +7 -7
  233. package/src/Tabs/TabPanel.test.tsx +30 -30
  234. package/src/Tabs/TabPanel.tsx +4 -4
  235. package/src/Tabs/Tabs.test.tsx +93 -93
  236. package/src/Tabs/Tabs.tsx +25 -25
  237. package/src/TextEllipsis/TextEllipsis.test.tsx +22 -22
  238. package/src/TextEllipsis/TextEllipsis.tsx +6 -6
  239. package/src/Tiles/Tile.module.scss +1 -1
  240. package/src/Tiles/Tile.test.tsx +42 -42
  241. package/src/Tiles/Tile.tsx +22 -22
  242. package/src/Tiles/Tiles.test.tsx +30 -30
  243. package/src/Tiles/Tiles.tsx +9 -9
  244. package/src/Tooltip/Tooltip.test.tsx +35 -35
  245. package/src/Tooltip/Tooltip.tsx +21 -21
  246. package/src/Typography/Typography.module.scss +1 -1
  247. package/src/Typography/Typography.test.tsx +49 -49
  248. package/src/Typography/Typography.tsx +42 -42
  249. package/src/Wizard/BaseWizardSteps/BaseWizardSteps.module.scss +1 -1
  250. package/src/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +26 -26
  251. package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +24 -24
  252. package/src/Wizard/Wizard.test.tsx +56 -56
  253. package/src/Wizard/Wizard.tsx +6 -6
  254. package/src/Wizard/WizardActions/WizardActions.test.tsx +34 -34
  255. package/src/Wizard/WizardActions/WizardActions.tsx +14 -14
  256. package/src/Wizard/WizardStateProvider.tsx +3 -3
  257. package/src/Wizard/WizardSteps/WizardSteps.test.tsx +27 -27
  258. package/src/Wizard/WizardSteps/WizardSteps.tsx +7 -7
  259. package/src/Wizard/wizardStateReducer.ts +9 -9
  260. package/src/_BaseStyling_/BaseStyling.test.tsx +14 -14
  261. package/src/_BaseStyling_/BaseStyling.tsx +50 -50
  262. package/src/hooks/useAnimation.test.tsx +12 -12
  263. package/src/hooks/useAnimation.ts +4 -4
  264. package/src/hooks/useBodyClick.test.tsx +8 -8
  265. package/src/hooks/useBodyClick.ts +3 -3
  266. package/src/hooks/useFormSelector.test.ts +17 -17
  267. package/src/hooks/useFormSelector.ts +4 -4
  268. package/src/hooks/usePosition.test.tsx +215 -215
  269. package/src/hooks/usePosition.ts +68 -68
  270. package/src/hooks/useRepeater.test.tsx +26 -26
  271. package/src/hooks/useRepeater.ts +5 -5
  272. package/src/hooks/useScroll.test.tsx +5 -5
  273. package/src/hooks/useScroll.ts +3 -3
  274. package/src/hooks/useSpacing.test.ts +40 -40
  275. package/src/hooks/useSpacing.ts +3 -3
  276. package/src/hooks/useWrapper.test.ts +12 -12
  277. package/src/hooks/useWrapper.ts +14 -7
  278. package/src/index.ts +67 -67
  279. package/src/mixins.module.scss +76 -27
  280. package/src/types.d.ts +1 -1
  281. package/src/util/helper.test.tsx +25 -25
  282. package/src/util/helper.tsx +64 -64
@@ -1,11 +1,12 @@
1
- import React, { useEffect, useRef } from 'react';
2
- import { Input, Props } from './Input';
3
- import { render } from '@testing-library/react';
4
- import userEvent from '@testing-library/user-event';
1
+ import React, { useEffect, useRef, useState, Fragment } from "react";
2
+ import { Input, Props, Type } from "./Input";
3
+ import { fireEvent, render } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+ import { Label } from "../Label/Label";
5
6
 
6
7
  const defaultParams: Props = {
7
- name: 'input',
8
- type: 'text',
8
+ name: "input",
9
+ type: "text"
9
10
  };
10
11
 
11
12
  const createInput = (params?: (defaultParams: Props) => Props) => {
@@ -14,25 +15,54 @@ const createInput = (params?: (defaultParams: Props) => Props) => {
14
15
  parameters = params(defaultParams);
15
16
  }
16
17
  const queries = render(<Input {...parameters} data-testid="input" />);
17
- const input = queries.getByTestId('input');
18
+ const input = queries.getByTestId("input");
18
19
 
19
20
  return {
20
21
  ...queries,
21
- input,
22
+ input
22
23
  };
23
24
  };
24
25
 
25
- describe('Input should render', () => {
26
- it('renders without crashing and has a name and type', () => {
26
+ const CreateInputComponent = ({
27
+ onValueChange,
28
+ type
29
+ }: {
30
+ onValueChange: (value: string) => void;
31
+ type: Type;
32
+ }) => {
33
+ const [inputValue, setInputValue] = useState("");
34
+
35
+ useEffect(() => {
36
+ if (inputValue !== "") {
37
+ onValueChange(inputValue);
38
+ }
39
+ }, [inputValue]);
40
+
41
+ return (
42
+ <Fragment>
43
+ <Label htmlFor="sample-input">Test</Label>
44
+ <Input
45
+ name="sample_input"
46
+ type={type}
47
+ id="sample-input"
48
+ value={inputValue}
49
+ onChange={e => setInputValue(e.target.value)}
50
+ />
51
+ </Fragment>
52
+ );
53
+ };
54
+
55
+ describe("Input should render", () => {
56
+ it("renders without crashing and has a name and type", () => {
27
57
  const { input } = createInput();
28
58
  expect(input).toBeTruthy();
29
59
  });
30
60
  });
31
61
 
32
- describe('ref should work', () => {
33
- it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
62
+ describe("ref should work", () => {
63
+ it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
34
64
  const ExampleComponent = ({
35
- propagateRef,
65
+ propagateRef
36
66
  }: {
37
67
  propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
38
68
  }) => {
@@ -48,114 +78,132 @@ describe('ref should work', () => {
48
78
  };
49
79
 
50
80
  const refCheck = (ref: React.RefObject<HTMLElement>) => {
51
- expect(ref.current).toHaveAttribute('data-ref', 'testing');
81
+ expect(ref.current).toHaveAttribute("data-ref", "testing");
52
82
  };
53
83
 
54
84
  render(<ExampleComponent propagateRef={refCheck} />);
55
85
  });
56
86
  });
57
87
 
58
- describe('Should have the appropriate attributes', () => {
59
- it('is disabled and has a class', () => {
60
- const { input } = createInput((defaultParams) => ({
88
+ describe("Should have the appropriate attributes", () => {
89
+ it("is disabled and has a class", () => {
90
+ const { input } = createInput(defaultParams => ({
61
91
  ...defaultParams,
62
92
  disabled: true,
63
- className: 'classname',
93
+ className: "classname"
64
94
  }));
65
95
 
66
- expect(input).toHaveAttribute('disabled');
67
- expect(input).toHaveClass('classname');
96
+ expect(input).toHaveAttribute("disabled");
97
+ expect(input).toHaveClass("classname");
68
98
  });
69
99
  });
70
100
 
71
- describe('Should render all different types of inputs', () => {
72
- it('should render a text input', () => {
73
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'text' }));
101
+ describe("Should render all different types of inputs", () => {
102
+ it.each([
103
+ ["text", "testing", "testing"],
104
+ ["email", "testing@testing.com", "testing@testing.com"],
105
+ ["tel", "06123456789", "06123456789"],
106
+ ["number", "1234567890", "1234567890"],
107
+ ["search", "example", "example"],
108
+ ["time", "1234", "12:34"],
109
+ ["url", "https://www.onewelcome.com", "https://www.onewelcome.com"]
110
+ ])(
111
+ "renders a %p input with %p as a value",
112
+ async (type: string, value: string, result: string) => {
113
+ let changedValue = "";
74
114
 
75
- expect(input).toHaveAttribute('type', 'text');
76
- });
115
+ const { findByLabelText } = render(
116
+ <CreateInputComponent type={type as Type} onValueChange={value => (changedValue = value)} />
117
+ );
77
118
 
78
- it('should render a email input', () => {
79
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'email' }));
119
+ const input = await findByLabelText(/Test/);
80
120
 
81
- expect(input).toHaveAttribute('type', 'email');
82
- });
83
-
84
- it('should render a tel input', () => {
85
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'tel' }));
86
-
87
- expect(input).toHaveAttribute('type', 'tel');
88
- });
121
+ input.focus();
89
122
 
90
- it('should render a number input', () => {
91
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'number' }));
123
+ userEvent.keyboard(value);
92
124
 
93
- expect(input).toHaveAttribute('type', 'number');
94
- });
125
+ expect(changedValue).toBe(result);
126
+ }
127
+ );
95
128
 
96
- it('should render a password input', () => {
97
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'password' }));
129
+ it("should render a password input", () => {
130
+ const { input } = createInput(defaultParams => ({ ...defaultParams, type: "password" }));
98
131
 
99
- expect(input).toHaveAttribute('type', 'password');
132
+ expect(input).toHaveAttribute("type", "password");
100
133
  });
101
134
 
102
- it('should render a search input', () => {
103
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'search' }));
104
-
105
- expect(input).toHaveAttribute('type', 'search');
106
- });
135
+ it("should render a datetime input", async () => {
136
+ let changedValue = "";
107
137
 
108
- it('should render a time input', () => {
109
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'time' }));
138
+ const { findByLabelText } = render(
139
+ <CreateInputComponent type="datetime-local" onValueChange={value => (changedValue = value)} />
140
+ );
110
141
 
111
- expect(input).toHaveAttribute('type', 'time');
112
- });
142
+ const input = await findByLabelText(/Test/);
113
143
 
114
- it('should render a url input', () => {
115
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'url' }));
144
+ const testValue = "2019-03-29T12:34";
145
+ fireEvent.change(input, { target: { value: testValue } });
116
146
 
117
- expect(input).toHaveAttribute('type', 'url');
147
+ expect(changedValue).toBe(testValue);
118
148
  });
119
149
 
120
- it('should render a datetime input', () => {
121
- const { input } = createInput((defaultParams) => ({
122
- ...defaultParams,
123
- type: 'datetime-local',
124
- }));
150
+ it("should be hidden", () => {
151
+ const { input } = createInput(defaultParams => ({ ...defaultParams, type: "hidden" }));
125
152
 
126
- expect(input).toHaveAttribute('type', 'datetime-local');
127
- });
128
-
129
- it('should be hidden', () => {
130
- const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'hidden' }));
131
-
132
- expect(input.parentElement).toHaveClass('hidden');
133
- expect(input).toHaveAttribute('type', 'hidden');
153
+ expect(input.parentElement).toHaveClass("hidden");
154
+ expect(input).toHaveAttribute("type", "hidden");
134
155
  });
135
156
  });
136
157
 
137
- describe('It should execute the listeners', () => {
138
- it('fires event handlers', () => {
158
+ describe("It should execute the listeners", () => {
159
+ it("fires event handlers", () => {
139
160
  const onChangeHandler = jest.fn();
140
161
  const onKeyUpHandler = jest.fn();
141
162
  const onKeyDownHandler = jest.fn();
142
163
 
143
- const { input } = createInput((defaultParams) => ({
164
+ const { input } = createInput(defaultParams => ({
144
165
  ...defaultParams,
145
- type: 'text',
166
+ type: "text",
146
167
  onKeyUp: onKeyUpHandler,
147
168
  onKeyDown: onKeyDownHandler,
148
- onChange: onChangeHandler,
169
+ onChange: onChangeHandler
149
170
  }));
150
171
 
151
172
  input.focus();
152
173
 
153
174
  expect(input).toHaveFocus();
154
175
 
155
- userEvent.keyboard('test');
176
+ userEvent.keyboard("test");
156
177
 
157
178
  expect(onKeyUpHandler).toHaveBeenCalled();
158
179
  expect(onKeyDownHandler).toHaveBeenCalled();
159
180
  expect(onChangeHandler).toHaveBeenCalled();
160
181
  });
161
182
  });
183
+
184
+ describe("It should render prefix and suffix ", () => {
185
+ it("renders prefix and suffix", () => {
186
+ const prefix = "http://";
187
+ const suffix = ".com";
188
+ const { getByText } = createInput(defaultParams => ({
189
+ ...defaultParams,
190
+ prefix,
191
+ suffix
192
+ }));
193
+
194
+ expect(getByText(prefix)).toBeDefined();
195
+ expect(getByText(suffix)).toBeDefined();
196
+ });
197
+
198
+ it("error icon should be visible with suffix", () => {
199
+ const suffix = ".com";
200
+ const { input, getByText } = createInput(defaultParams => ({
201
+ ...defaultParams,
202
+ error: true,
203
+ suffix
204
+ }));
205
+
206
+ expect(input.querySelector("icon-warning")).toBeDefined();
207
+ expect(getByText(suffix)).toBeDefined();
208
+ });
209
+ });
@@ -1,31 +1,69 @@
1
- import React, { ComponentPropsWithRef, Ref, useEffect, useState } from 'react';
2
- import classes from './Input.module.scss';
3
- import readyclasses from '../../readyclasses.module.scss';
4
- import { Icon, Icons } from '../../Icon/Icon';
5
- import { FormElement } from '../form.interfaces';
1
+ import React, { ComponentPropsWithRef, Ref, useEffect, useRef, useState } from "react";
2
+ import classes from "./Input.module.scss";
3
+ import readyclasses from "../../readyclasses.module.scss";
4
+ import { Icon, Icons } from "../../Icon/Icon";
5
+ import { FormElement } from "../form.interfaces";
6
6
 
7
- const dateTypes = ['date', 'time', 'datetime-local'] as const;
7
+ const dateTypes = ["date", "time", "datetime-local"] as const;
8
8
 
9
9
  export type Type =
10
- | 'text'
11
- | 'email'
12
- | 'file'
13
- | 'number'
14
- | 'password'
15
- | 'search'
16
- | 'tel'
17
- | 'url'
18
- | 'hidden'
10
+ | "text"
11
+ | "email"
12
+ | "file"
13
+ | "number"
14
+ | "password"
15
+ | "search"
16
+ | "tel"
17
+ | "url"
18
+ | "hidden"
19
19
  | typeof dateTypes[number];
20
20
 
21
- export interface Props extends ComponentPropsWithRef<'input'>, FormElement {
22
- wrapperProps?: ComponentPropsWithRef<'div'>;
21
+ export interface Props extends ComponentPropsWithRef<"input">, FormElement {
22
+ wrapperProps?: ComponentPropsWithRef<"div">;
23
23
  labeledBy?: string;
24
24
  type: Type;
25
25
  suffix?: string;
26
26
  prefix?: string;
27
27
  }
28
28
 
29
+ const useErrorOffset = (
30
+ suffix: React.RefObject<HTMLDivElement>,
31
+ errorIcon: React.RefObject<HTMLDivElement>,
32
+ inputWrapper: React.RefObject<HTMLDivElement>,
33
+ error: boolean,
34
+ type: Type,
35
+ suffixContent: string = ""
36
+ ) => {
37
+ const [errorOffset, setErrorOffset] = useState({});
38
+ const [defaultErrorOffset, setDefaultErrorOffset] = useState<number | null>(null);
39
+
40
+ const getErrorIconOffset = () => parseFloat(getComputedStyle(errorIcon.current!).right);
41
+ const getInputPaddingRight = (input: HTMLDivElement) =>
42
+ (dateTypes as ReadonlyArray<string>).includes(type)
43
+ ? 0
44
+ : parseFloat(getComputedStyle(input).paddingRight);
45
+
46
+ useEffect(() => {
47
+ if (errorIcon.current && inputWrapper.current) {
48
+ let defaultOffset = defaultErrorOffset;
49
+ if (!defaultOffset) {
50
+ defaultOffset = getErrorIconOffset();
51
+ setDefaultErrorOffset(defaultOffset);
52
+ }
53
+
54
+ if (suffix.current && suffixContent) {
55
+ const inputPaddingRight = getInputPaddingRight(inputWrapper.current);
56
+ const prefixDifference = suffix.current.offsetWidth + inputPaddingRight + defaultOffset;
57
+ setErrorOffset({ right: `${prefixDifference}px` });
58
+ } else {
59
+ setErrorOffset({ right: `${defaultOffset}px` });
60
+ }
61
+ }
62
+ }, [suffix.current, errorIcon.current, inputWrapper.current, error, type, suffixContent]);
63
+
64
+ return { errorOffset };
65
+ };
66
+
29
67
  export const Input = React.forwardRef(
30
68
  (
31
69
  {
@@ -46,6 +84,17 @@ export const Input = React.forwardRef(
46
84
  ref: Ref<HTMLInputElement>
47
85
  ) => {
48
86
  const [focus, setFocus] = useState(false);
87
+ const inputWrapperRef = useRef<HTMLDivElement>(null);
88
+ const errorIconRef = useRef<HTMLDivElement>(null);
89
+ const suffixRef = useRef<HTMLDivElement>(null);
90
+ const { errorOffset } = useErrorOffset(
91
+ suffixRef,
92
+ errorIconRef,
93
+ inputWrapperRef,
94
+ error,
95
+ type,
96
+ suffix
97
+ );
49
98
 
50
99
  useEffect(() => {
51
100
  if (name === undefined) {
@@ -53,45 +102,49 @@ export const Input = React.forwardRef(
53
102
  }
54
103
  }, []);
55
104
 
56
- const inputClassNames = [classes['input']];
105
+ const inputClassNames = [classes["input"]];
57
106
 
58
107
  (dateTypes as ReadonlyArray<string>).includes(type) &&
59
- inputClassNames.push(classes['remove-extra-indent']);
108
+ inputClassNames.push(classes["remove-extra-indent"]);
60
109
  className && inputClassNames.push(className);
61
110
 
62
- const iconClassNames = [classes['warning']];
111
+ const iconClassNames = [classes["warning"]];
63
112
  (dateTypes as ReadonlyArray<string>).includes(type) &&
64
- iconClassNames.push(classes['extra-indent']);
113
+ iconClassNames.push(classes["extra-indent"]);
65
114
 
66
- const wrapperClasses = [classes['input-wrapper']];
115
+ const wrapperClasses = [classes["input-wrapper"]];
116
+ const outlineClasses = [classes["outline"]];
67
117
 
68
118
  wrapperProps?.className && wrapperClasses.push(wrapperProps.className);
69
- type === 'hidden' && wrapperClasses.push(readyclasses['hidden']);
70
- prefix && wrapperClasses.push(classes['prefix']);
71
- suffix && wrapperClasses.push(classes['suffix']);
72
- disabled && wrapperClasses.push(classes['disabled']);
73
- error && wrapperClasses.push(classes['error']);
74
- focus && wrapperClasses.push(classes['focus']);
119
+ type === "hidden" && wrapperClasses.push(readyclasses["hidden"]);
120
+ prefix && wrapperClasses.push(classes["prefix"]);
121
+ suffix && wrapperClasses.push(classes["suffix"]);
122
+ disabled &&
123
+ wrapperClasses.push(classes["disabled"]) &&
124
+ outlineClasses.push(classes["disabled"]);
125
+ error && wrapperClasses.push(classes["error"]) && outlineClasses.push(classes["error"]);
126
+ focus && wrapperClasses.push(classes["focus"]) && outlineClasses.push(classes["focus"]);
75
127
 
76
128
  return (
77
129
  <div
130
+ ref={inputWrapperRef}
78
131
  {...wrapperProps}
79
132
  style={{ ...style }}
80
- className={`${classes['input-wrapper']} ${wrapperClasses.join(' ')}`}
133
+ className={`${classes["input-wrapper"]} ${wrapperClasses.join(" ")}`}
81
134
  >
82
135
  {prefix && (
83
- <div data-prefix className={classes['prefix']}>
136
+ <div data-prefix className={classes["prefix"]}>
84
137
  <span>{prefix}</span>
85
138
  </div>
86
139
  )}
87
140
  <input
88
141
  {...rest}
89
142
  ref={ref}
90
- onFocus={(event) => {
143
+ onFocus={event => {
91
144
  setFocus(true);
92
145
  onFocus && onFocus(event);
93
146
  }}
94
- onBlur={(event) => {
147
+ onBlur={event => {
95
148
  setFocus(false);
96
149
  onBlur && onBlur(event);
97
150
  }}
@@ -99,14 +152,22 @@ export const Input = React.forwardRef(
99
152
  type={type}
100
153
  name={name}
101
154
  disabled={disabled}
102
- className={inputClassNames.join(' ')}
155
+ className={inputClassNames.join(" ")}
103
156
  />
104
157
  {suffix && (
105
- <div data-suffix className={classes['suffix']}>
158
+ <div ref={suffixRef} data-suffix className={classes["suffix"]}>
106
159
  <span>{suffix}</span>
107
160
  </div>
108
161
  )}
109
- {error && <Icon className={iconClassNames.join(' ')} icon={Icons.Error} />}
162
+ {error && (
163
+ <Icon
164
+ style={errorOffset}
165
+ ref={errorIconRef}
166
+ className={iconClassNames.join(" ")}
167
+ icon={Icons.Error}
168
+ />
169
+ )}
170
+ <span className={outlineClasses.join(" ")}></span>
110
171
  </div>
111
172
  );
112
173
  }
@@ -1,34 +1,34 @@
1
- import React, { useEffect, useRef } from 'react';
2
- import { Label } from './Label';
3
- import { render } from '@testing-library/react';
1
+ import React, { useEffect, useRef } from "react";
2
+ import { Label } from "./Label";
3
+ import { render } from "@testing-library/react";
4
4
 
5
- describe('Label should render', () => {
6
- it('renders without crashing', () => {
5
+ describe("Label should render", () => {
6
+ it("renders without crashing", () => {
7
7
  const { getByTestId } = render(
8
8
  <Label htmlFor="input-name" data-testid="component">
9
9
  Label
10
10
  </Label>
11
11
  );
12
- const component = getByTestId('component');
12
+ const component = getByTestId("component");
13
13
  expect(component).toBeDefined();
14
14
  });
15
15
 
16
- it('adds htmlFor attribute', () => {
16
+ it("adds htmlFor attribute", () => {
17
17
  const { getByTestId } = render(
18
18
  <Label htmlFor="input-name" data-testid="component">
19
19
  Label
20
20
  </Label>
21
21
  );
22
22
 
23
- const component = getByTestId('component');
24
- expect(component.getAttribute('for')).toBe('input-name');
23
+ const component = getByTestId("component");
24
+ expect(component.getAttribute("for")).toBe("input-name");
25
25
  });
26
26
  });
27
27
 
28
- describe('ref should work', () => {
29
- it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
28
+ describe("ref should work", () => {
29
+ it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
30
30
  const ExampleComponent = ({
31
- propagateRef,
31
+ propagateRef
32
32
  }: {
33
33
  propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
34
34
  }) => {
@@ -44,7 +44,7 @@ describe('ref should work', () => {
44
44
  };
45
45
 
46
46
  const refCheck = (ref: React.RefObject<HTMLElement>) => {
47
- expect(ref.current).toHaveAttribute('data-ref', 'testing');
47
+ expect(ref.current).toHaveAttribute("data-ref", "testing");
48
48
  };
49
49
 
50
50
  render(<ExampleComponent propagateRef={refCheck} />);
@@ -1,8 +1,8 @@
1
- import React, { ComponentPropsWithRef, ReactNode } from 'react';
2
- import classes from './Label.module.scss';
3
- import readyclasses from '../../readyclasses.module.scss';
1
+ import React, { ComponentPropsWithRef, ReactNode } from "react";
2
+ import classes from "./Label.module.scss";
3
+ import readyclasses from "../../readyclasses.module.scss";
4
4
 
5
- export interface Props extends ComponentPropsWithRef<'label'> {
5
+ export interface Props extends ComponentPropsWithRef<"label"> {
6
6
  children?: ReactNode;
7
7
  }
8
8
 
@@ -12,8 +12,8 @@ export const Label = React.forwardRef<HTMLLabelElement, Props>(
12
12
  <label
13
13
  {...rest}
14
14
  ref={ref}
15
- className={`${hidden ? readyclasses['sr-only'] : ''} ${classes['label']} ${
16
- className ?? ''
15
+ className={`${hidden ? readyclasses["sr-only"] : ""} ${classes["label"]} ${
16
+ className ?? ""
17
17
  }`}
18
18
  >
19
19
  {children}