@codacy/ui-components 0.66.25 → 0.66.27

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/lib/Avatar/Avatar.js +20 -28
  2. package/lib/Avatar/Avatar.types.js +1 -5
  3. package/lib/Avatar/gravatar.js +14 -22
  4. package/lib/Avatar/index.js +1 -16
  5. package/lib/Banner/Banner.js +33 -50
  6. package/lib/Banner/Banner.styles.d.ts +1 -1
  7. package/lib/Banner/Banner.styles.js +11 -20
  8. package/lib/Banner/Banner.types.js +1 -5
  9. package/lib/Banner/index.js +2 -27
  10. package/lib/Bannerol/Bannerol.js +44 -61
  11. package/lib/Bannerol/Bannerol.styles.js +9 -18
  12. package/lib/Bannerol/Bannerol.types.js +1 -5
  13. package/lib/Bannerol/index.js +3 -38
  14. package/lib/BigTabs/BigTabs.js +39 -54
  15. package/lib/BigTabs/BigTabs.styles.js +79 -107
  16. package/lib/BigTabs/BigTabs.types.js +1 -5
  17. package/lib/BigTabs/index.js +1 -16
  18. package/lib/Button/Button.js +45 -67
  19. package/lib/Button/index.js +2 -27
  20. package/lib/Button/styles.js +101 -130
  21. package/lib/Button/types.js +1 -5
  22. package/lib/Checkbox/Checkbox.js +55 -68
  23. package/lib/Checkbox/CheckboxFilterList.js +33 -66
  24. package/lib/Checkbox/index.js +3 -38
  25. package/lib/Checkbox/styles.js +64 -86
  26. package/lib/Checkbox/types.js +1 -5
  27. package/lib/CloseButton/index.d.ts +1 -1
  28. package/lib/CloseButton/index.js +24 -36
  29. package/lib/Divider/Divider.js +14 -25
  30. package/lib/Divider/Divider.styles.d.ts +1 -1
  31. package/lib/Divider/Divider.styles.js +24 -38
  32. package/lib/Divider/Divider.types.js +1 -5
  33. package/lib/Divider/index.js +1 -16
  34. package/lib/Dropdown/Content/DropdownInput.js +10 -20
  35. package/lib/Dropdown/Content/DropdownItem.js +22 -36
  36. package/lib/Dropdown/Content/DropdownSeparator.js +8 -19
  37. package/lib/Dropdown/Content/DropdownTitle.js +8 -22
  38. package/lib/Dropdown/Content/index.js +4 -49
  39. package/lib/Dropdown/Dropdown.js +74 -102
  40. package/lib/Dropdown/Dropdown.styles.d.ts +1 -1
  41. package/lib/Dropdown/Dropdown.styles.js +60 -82
  42. package/lib/Dropdown/Dropdown.types.js +1 -5
  43. package/lib/Dropdown/Triggers/DropdownButtonTrigger.js +19 -32
  44. package/lib/Dropdown/Triggers/DropdownItemTrigger.js +18 -30
  45. package/lib/Dropdown/Triggers/FilterTrigger.js +66 -93
  46. package/lib/Dropdown/Triggers/InputTrigger.js +15 -24
  47. package/lib/Dropdown/Triggers/SelectTrigger.js +12 -21
  48. package/lib/Dropdown/Triggers/hooks.js +17 -26
  49. package/lib/Dropdown/Triggers/index.js +6 -71
  50. package/lib/Dropdown/Triggers/types.js +1 -5
  51. package/lib/Dropdown/index.js +4 -49
  52. package/lib/ExpandableBox/ExpandableBox.js +28 -43
  53. package/lib/ExpandableBox/ExpandableBox.styles.d.ts +2 -2
  54. package/lib/ExpandableBox/ExpandableBox.styles.js +27 -40
  55. package/lib/ExpandableBox/ExpandableBox.types.js +1 -5
  56. package/lib/ExpandableBox/index.js +1 -16
  57. package/lib/Flexbox/Flexbox.js +14 -21
  58. package/lib/Flexbox/index.js +1 -16
  59. package/lib/Group/Group.js +7 -18
  60. package/lib/Group/Group.styles.js +8 -16
  61. package/lib/Group/Group.types.js +1 -5
  62. package/lib/Group/index.js +1 -16
  63. package/lib/Icon/Icon.js +15 -26
  64. package/lib/Icon/Icon.styles.d.ts +1 -1
  65. package/lib/Icon/Icon.styles.js +57 -50
  66. package/lib/Icon/Icon.types.js +1 -5
  67. package/lib/Icon/index.js +1 -16
  68. package/lib/IconAndText/IconAndText.js +23 -36
  69. package/lib/IconAndText/IconAndText.styles.js +19 -29
  70. package/lib/IconAndText/IconAndText.types.js +1 -5
  71. package/lib/IconAndText/index.js +1 -16
  72. package/lib/Icons/Chevrons.js +45 -65
  73. package/lib/Icons/CodacyIcon.js +9 -20
  74. package/lib/Icons/Ellipsis.js +18 -29
  75. package/lib/Icons/Messages.js +58 -79
  76. package/lib/Icons/Search.js +8 -19
  77. package/lib/Icons/Severities.js +113 -149
  78. package/lib/Icons/Sorting.js +15 -29
  79. package/lib/Icons/Spinner.js +11 -22
  80. package/lib/Icons/Symbols.js +67 -90
  81. package/lib/Icons/index.js +8 -93
  82. package/lib/Img/Img.js +26 -45
  83. package/lib/Img/Img.styles.d.ts +2 -2
  84. package/lib/Img/Img.styles.js +21 -29
  85. package/lib/Img/Img.types.js +1 -5
  86. package/lib/Img/index.js +1 -16
  87. package/lib/InlineMessage/InlineMessage.js +43 -70
  88. package/lib/InlineMessage/index.js +1 -16
  89. package/lib/InlineMessage/types.js +1 -5
  90. package/lib/Input/Input.js +115 -143
  91. package/lib/Input/hooks.js +107 -208
  92. package/lib/Input/index.js +2 -27
  93. package/lib/Input/styles.d.ts +2 -2
  94. package/lib/Input/styles.js +116 -151
  95. package/lib/Input/types.js +1 -5
  96. package/lib/Labeled/Labeled.js +22 -35
  97. package/lib/Labeled/index.js +1 -16
  98. package/lib/Labeled/styles.js +23 -37
  99. package/lib/Labeled/types.js +1 -5
  100. package/lib/LeftMenu/LeftMenu.js +10 -21
  101. package/lib/LeftMenu/LeftMenu.styles.js +25 -43
  102. package/lib/LeftMenu/LeftMenu.types.js +1 -5
  103. package/lib/LeftMenu/index.js +1 -16
  104. package/lib/Link/Link.js +32 -50
  105. package/lib/Link/Link.styles.js +11 -23
  106. package/lib/Link/Link.types.js +1 -5
  107. package/lib/Link/index.js +3 -38
  108. package/lib/Message/Message.js +31 -42
  109. package/lib/Message/Message.styles.js +18 -31
  110. package/lib/Message/Message.types.js +1 -5
  111. package/lib/Message/index.js +1 -16
  112. package/lib/Modal/ConfirmationModal.js +40 -67
  113. package/lib/Modal/Modal.js +107 -137
  114. package/lib/Modal/index.js +2 -27
  115. package/lib/Modal/styles.js +44 -62
  116. package/lib/Modal/types.js +1 -5
  117. package/lib/MoreInfo/MoreInfo.js +41 -53
  118. package/lib/MoreInfo/index.js +1 -16
  119. package/lib/MoreInfo/types.js +1 -5
  120. package/lib/MultiSlider/MultiSlider.js +17 -31
  121. package/lib/MultiSlider/index.js +1 -16
  122. package/lib/MultiSlider/styles.js +18 -34
  123. package/lib/MultiSlider/types.js +1 -5
  124. package/lib/Panel/Panel.js +9 -19
  125. package/lib/Panel/Panel.styles.js +15 -26
  126. package/lib/Panel/Panel.types.js +1 -5
  127. package/lib/Panel/index.js +2 -27
  128. package/lib/PillLabel/PillLabel.js +35 -49
  129. package/lib/PillLabel/PillLabel.styles.js +33 -44
  130. package/lib/PillLabel/PillLabel.types.js +1 -5
  131. package/lib/PillLabel/index.js +1 -16
  132. package/lib/Popup/Popup.js +43 -61
  133. package/lib/Popup/index.js +1 -16
  134. package/lib/Popup/styles.js +22 -37
  135. package/lib/Popup/types.js +1 -5
  136. package/lib/ProgressBar/ProgressBar.js +19 -34
  137. package/lib/ProgressBar/index.js +2 -27
  138. package/lib/ProgressBar/styles.js +21 -35
  139. package/lib/ProgressBar/types.js +1 -5
  140. package/lib/Radio/Radio.js +47 -59
  141. package/lib/Radio/index.js +1 -16
  142. package/lib/Radio/styles.js +48 -72
  143. package/lib/Radio/types.js +1 -5
  144. package/lib/ScrollableContent/ScrollableContent.js +27 -40
  145. package/lib/ScrollableContent/ScrollableContent.styles.js +22 -39
  146. package/lib/ScrollableContent/ScrollableContent.types.js +1 -5
  147. package/lib/ScrollableContent/index.js +2 -27
  148. package/lib/ScrollableContent/useScrollContainer.js +35 -50
  149. package/lib/Skeleton/Skeleton.js +25 -45
  150. package/lib/Skeleton/Skeleton.styles.js +28 -25
  151. package/lib/Skeleton/Skeleton.types.js +1 -5
  152. package/lib/Skeleton/index.js +2 -20
  153. package/lib/Slider/Slider.js +32 -56
  154. package/lib/Slider/index.js +1 -16
  155. package/lib/Slider/styles.js +41 -60
  156. package/lib/Slider/types.js +1 -5
  157. package/lib/StepNumber/StepNumber.js +26 -40
  158. package/lib/StepNumber/index.js +1 -16
  159. package/lib/StepNumber/styles.js +13 -24
  160. package/lib/StepNumber/types.js +1 -5
  161. package/lib/Stepper/Stepper.js +45 -62
  162. package/lib/Stepper/Stepper.styles.js +27 -44
  163. package/lib/Stepper/Stepper.types.js +1 -5
  164. package/lib/Stepper/index.js +1 -16
  165. package/lib/Switcher/Switcher.js +22 -34
  166. package/lib/Switcher/Switcher.styles.js +27 -42
  167. package/lib/Switcher/Switcher.types.js +1 -5
  168. package/lib/Switcher/index.js +1 -16
  169. package/lib/Tab/Tab.js +21 -33
  170. package/lib/Tab/Tab.styles.js +34 -50
  171. package/lib/Tab/Tab.types.js +1 -5
  172. package/lib/Tab/index.js +1 -16
  173. package/lib/Table/NewSelectableTable.js +59 -97
  174. package/lib/Table/SelectableTable.js +142 -189
  175. package/lib/Table/Table.js +110 -155
  176. package/lib/Table/Table.styles.js +67 -90
  177. package/lib/Table/Table.types.js +1 -5
  178. package/lib/Table/index.js +2 -27
  179. package/lib/TagsInput/TagsInput.js +32 -46
  180. package/lib/TagsInput/index.js +1 -16
  181. package/lib/TagsInput/style.js +45 -71
  182. package/lib/TagsInput/types.js +1 -5
  183. package/lib/Textarea/Textarea.js +52 -71
  184. package/lib/Textarea/Textarea.styles.js +91 -126
  185. package/lib/Textarea/Textarea.types.js +1 -5
  186. package/lib/Textarea/index.js +1 -16
  187. package/lib/ThemeProvider/ThemeProvider.js +41 -65
  188. package/lib/ThemeProvider/index.js +1 -16
  189. package/lib/Toast/Toast.js +53 -68
  190. package/lib/Toast/index.js +1 -16
  191. package/lib/Toast/styles.js +29 -49
  192. package/lib/Toast/types.js +1 -5
  193. package/lib/Toggle/Toggle.js +48 -65
  194. package/lib/Toggle/index.js +1 -16
  195. package/lib/Toggle/styles.d.ts +1 -1
  196. package/lib/Toggle/styles.js +66 -101
  197. package/lib/Toggle/types.js +1 -5
  198. package/lib/Tooltip/Tooltip.js +84 -121
  199. package/lib/Tooltip/index.js +2 -27
  200. package/lib/Tooltip/styles.js +61 -91
  201. package/lib/Tooltip/types.js +1 -5
  202. package/lib/Typography/Typography.js +78 -116
  203. package/lib/Typography/Typography.styles.js +61 -78
  204. package/lib/Typography/Typography.types.js +1 -5
  205. package/lib/Typography/index.js +3 -38
  206. package/lib/emotion.d.js +1 -3
  207. package/lib/hooks/index.d.ts +1 -0
  208. package/lib/hooks/index.js +4 -38
  209. package/lib/hooks/useForwardedRef.js +5 -11
  210. package/lib/hooks/useInfiniteScroll.js +13 -25
  211. package/lib/hooks/useStatefulRef.js +10 -23
  212. package/lib/index.js +49 -544
  213. package/lib/system-props/color.js +3 -9
  214. package/lib/system-props/index.js +2 -27
  215. package/lib/system-props/types.js +1 -5
  216. package/lib/theme/ColorSchemes/components/alerts.js +30 -38
  217. package/lib/theme/ColorSchemes/components/button.js +89 -97
  218. package/lib/theme/ColorSchemes/components/cards.js +16 -24
  219. package/lib/theme/ColorSchemes/components/charts.js +93 -101
  220. package/lib/theme/ColorSchemes/components/checkbox-input.js +13 -21
  221. package/lib/theme/ColorSchemes/components/divider.js +4 -12
  222. package/lib/theme/ColorSchemes/components/drawer.js +21 -29
  223. package/lib/theme/ColorSchemes/components/effects.js +5 -13
  224. package/lib/theme/ColorSchemes/components/filters.js +12 -20
  225. package/lib/theme/ColorSchemes/components/index.js +23 -258
  226. package/lib/theme/ColorSchemes/components/input.js +38 -46
  227. package/lib/theme/ColorSchemes/components/issues.js +27 -35
  228. package/lib/theme/ColorSchemes/components/label.js +33 -41
  229. package/lib/theme/ColorSchemes/components/list-orb.js +8 -16
  230. package/lib/theme/ColorSchemes/components/loading.js +4 -12
  231. package/lib/theme/ColorSchemes/components/logo.js +6 -14
  232. package/lib/theme/ColorSchemes/components/modals.js +6 -14
  233. package/lib/theme/ColorSchemes/components/navigation.js +17 -25
  234. package/lib/theme/ColorSchemes/components/progress-bar.js +5 -13
  235. package/lib/theme/ColorSchemes/components/selector.js +20 -28
  236. package/lib/theme/ColorSchemes/components/stepper.js +9 -17
  237. package/lib/theme/ColorSchemes/components/tables.js +12 -20
  238. package/lib/theme/ColorSchemes/components/tabs.js +13 -21
  239. package/lib/theme/ColorSchemes/components/tooltip.js +6 -14
  240. package/lib/theme/ColorSchemes/components/utils.js +1 -11
  241. package/lib/theme/ColorSchemes/dark/background.d.ts +27 -27
  242. package/lib/theme/ColorSchemes/dark/background.js +42 -50
  243. package/lib/theme/ColorSchemes/dark/border.d.ts +27 -27
  244. package/lib/theme/ColorSchemes/dark/border.js +37 -45
  245. package/lib/theme/ColorSchemes/dark/data.js +18 -24
  246. package/lib/theme/ColorSchemes/dark/icon.d.ts +27 -27
  247. package/lib/theme/ColorSchemes/dark/icon.js +40 -48
  248. package/lib/theme/ColorSchemes/dark/illustration.js +11 -17
  249. package/lib/theme/ColorSchemes/dark/index.js +60 -31
  250. package/lib/theme/ColorSchemes/dark/text.d.ts +27 -27
  251. package/lib/theme/ColorSchemes/dark/text.js +47 -54
  252. package/lib/theme/ColorSchemes/index.js +4 -49
  253. package/lib/theme/ColorSchemes/light/background.d.ts +27 -27
  254. package/lib/theme/ColorSchemes/light/background.js +42 -50
  255. package/lib/theme/ColorSchemes/light/border.d.ts +27 -27
  256. package/lib/theme/ColorSchemes/light/border.js +37 -45
  257. package/lib/theme/ColorSchemes/light/data.js +18 -24
  258. package/lib/theme/ColorSchemes/light/icon.d.ts +27 -27
  259. package/lib/theme/ColorSchemes/light/icon.js +40 -48
  260. package/lib/theme/ColorSchemes/light/illustration.js +11 -17
  261. package/lib/theme/ColorSchemes/light/index.d.ts +54 -54
  262. package/lib/theme/ColorSchemes/light/index.js +43 -19
  263. package/lib/theme/ColorSchemes/light/text.d.ts +27 -27
  264. package/lib/theme/ColorSchemes/light/text.js +47 -54
  265. package/lib/theme/ColorSchemes/primitives/blue.js +1 -7
  266. package/lib/theme/ColorSchemes/primitives/green.js +1 -7
  267. package/lib/theme/ColorSchemes/primitives/grey.js +1 -7
  268. package/lib/theme/ColorSchemes/primitives/index.d.ts +9 -9
  269. package/lib/theme/ColorSchemes/primitives/index.js +20 -18
  270. package/lib/theme/ColorSchemes/primitives/magenta.js +1 -7
  271. package/lib/theme/ColorSchemes/primitives/orange.js +1 -7
  272. package/lib/theme/ColorSchemes/primitives/purple.js +1 -7
  273. package/lib/theme/ColorSchemes/primitives/red.js +1 -7
  274. package/lib/theme/ColorSchemes/primitives/teal.js +1 -7
  275. package/lib/theme/ColorSchemes/primitives/yellow.js +1 -7
  276. package/lib/theme/ColorSchemes/semantics.js +7 -13
  277. package/lib/theme/index.js +2 -27
  278. package/lib/theme/theme.js +68 -77
  279. package/lib/types.js +1 -5
  280. package/lib/utils/hash.js +3 -9
  281. package/lib/utils/reactNodeToText.js +9 -17
  282. package/package.json +21 -11
@@ -1,159 +1,110 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.useAsyncValidatedInput = void 0;
8
- exports.useDebounce = useDebounce;
9
- exports.useEmailInput = void 0;
10
- exports.useInput = useInput;
11
- exports.useNumberInput = useNumberInput;
12
- exports.useRegexInput = void 0;
13
- exports.useRequiredInput = useRequiredInput;
14
- exports.useTagsInput = useTagsInput;
15
- exports.useTextarea = useTextarea;
16
- exports.useValidatedInput = exports.useUrlInput = void 0;
17
- var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/regeneratorRuntime"));
18
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
19
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
20
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
21
- var _react = require("react");
22
- function useInput(initialValue) {
23
- var _useState = (0, _react.useState)(initialValue),
24
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
25
- value = _useState2[0],
26
- setValue = _useState2[1];
27
- var onChange = (0, _react.useCallback)(function (e) {
28
- return setValue(e.currentTarget.value);
29
- }, []);
1
+ import { useState, useCallback, useEffect, useRef } from 'react';
2
+ export function useInput(initialValue) {
3
+ const [value, setValue] = useState(initialValue);
4
+ const onChange = useCallback(e => setValue(e.currentTarget.value), []);
30
5
  return {
31
- value: value,
32
- setValue: setValue,
33
- onChange: onChange,
34
- onClear: function onClear(e) {
6
+ value,
7
+ setValue,
8
+ onChange,
9
+ onClear: e => {
35
10
  e.stopPropagation();
36
11
  setValue('');
37
12
  }
38
13
  };
39
14
  }
40
- function useNumberInput(initialValue, min, max) {
41
- var _useState3 = (0, _react.useState)(initialValue),
42
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
43
- value = _useState4[0],
44
- setValue = _useState4[1];
45
- var onChange = (0, _react.useCallback)(function (e) {
15
+ export function useNumberInput(initialValue, min, max) {
16
+ const [value, setValue] = useState(initialValue);
17
+ const onChange = useCallback(e => {
46
18
  setValue(e.currentTarget.value === '' ? null : Number(e.currentTarget.value));
47
19
  }, []);
48
- var hasValue = value !== null && value !== undefined;
49
- var hasMin = min !== undefined;
50
- var hasMax = max !== undefined;
51
- var hasError = hasValue && (hasMin && value < min || hasMax && value > max);
20
+ const hasValue = value !== null && value !== undefined;
21
+ const hasMin = min !== undefined;
22
+ const hasMax = max !== undefined;
23
+ const hasError = hasValue && (hasMin && value < min || hasMax && value > max);
52
24
  return {
53
- value: value,
54
- setValue: setValue,
55
- onChange: onChange,
56
- onClear: function onClear() {
25
+ value,
26
+ setValue,
27
+ onChange,
28
+ onClear: () => {
57
29
  setValue(null);
58
30
  },
59
31
  type: 'number',
60
- min: min,
61
- max: max,
62
- hasError: hasError
32
+ min,
33
+ max,
34
+ hasError
63
35
  };
64
36
  }
65
- function useRequiredInput(initialValue, requiredMessage) {
66
- var inputProps = useInput(initialValue);
67
- var _useState5 = (0, _react.useState)(null),
68
- _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
69
- valid = _useState6[0],
70
- setValid = _useState6[1];
37
+ export function useRequiredInput(initialValue, requiredMessage) {
38
+ const inputProps = useInput(initialValue);
39
+ const [valid, setValid] = useState(null);
71
40
  function handleBlur() {
72
41
  setValid(!!inputProps.value && inputProps.value.trim() !== '');
73
42
  }
74
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, inputProps), {}, {
43
+ return {
44
+ ...inputProps,
75
45
  onBlur: handleBlur,
76
- onClear: function onClear() {
46
+ onClear: () => {
77
47
  inputProps.setValue('');
78
48
  setValid(false);
79
49
  },
80
50
  required: true,
81
51
  hasError: valid !== null && !valid,
82
52
  errorMessage: !valid ? requiredMessage || 'Please, enter a value' : undefined
83
- });
53
+ };
84
54
  }
85
- function useTextarea(initialValue) {
86
- var _useState7 = (0, _react.useState)(initialValue),
87
- _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
88
- value = _useState8[0],
89
- setValue = _useState8[1];
55
+ export function useTextarea(initialValue) {
56
+ const [value, setValue] = useState(initialValue);
90
57
  function handleChange(e) {
91
58
  setValue(e.currentTarget.value);
92
59
  }
93
60
  return {
94
- value: value,
95
- setValue: setValue,
61
+ value,
62
+ setValue,
96
63
  onChange: handleChange
97
64
  };
98
65
  }
99
- function useTagsInput(initialValue) {
100
- var _useState9 = (0, _react.useState)(initialValue),
101
- _useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
102
- tags = _useState10[0],
103
- setTags = _useState10[1];
66
+ export function useTagsInput(initialValue) {
67
+ const [tags, setTags] = useState(initialValue);
104
68
  function handleChange(value) {
105
69
  setTags(value);
106
70
  }
107
71
  return {
108
- tags: tags,
109
- setTags: setTags,
72
+ tags,
73
+ setTags,
110
74
  onChange: handleChange
111
75
  };
112
76
  }
113
- function useDebounce(value, delay) {
114
- var _useState11 = (0, _react.useState)(value),
115
- _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
116
- debouncedValue = _useState12[0],
117
- setDebouncedValue = _useState12[1];
118
- (0, _react.useEffect)(function () {
119
- var handler = setTimeout(function () {
77
+ export function useDebounce(value, delay) {
78
+ const [debouncedValue, setDebouncedValue] = useState(value);
79
+ useEffect(() => {
80
+ const handler = setTimeout(() => {
120
81
  setDebouncedValue(value);
121
82
  }, delay);
122
- return function () {
83
+ return () => {
123
84
  clearTimeout(handler);
124
85
  };
125
86
  }, [value, delay]);
126
87
  return debouncedValue;
127
88
  }
128
89
  function generateInputValidator(validations, inputType, hideSuccess) {
129
- return function (initialValue, isRequired) {
130
- var didMountRef = (0, _react.useRef)(false);
131
- var _useState13 = (0, _react.useState)(initialValue),
132
- _useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
133
- value = _useState14[0],
134
- setValue = _useState14[1];
135
- var _useState15 = (0, _react.useState)(null),
136
- _useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
137
- valid = _useState16[0],
138
- setValid = _useState16[1];
139
- var _useState17 = (0, _react.useState)(),
140
- _useState18 = (0, _slicedToArray2["default"])(_useState17, 2),
141
- errorMessage = _useState18[0],
142
- setErrorMessage = _useState18[1];
143
- var debouncedValue = useDebounce(value, 500);
144
- var handleChange = (0, _react.useCallback)(function (e) {
90
+ return (initialValue, isRequired) => {
91
+ const didMountRef = useRef(false);
92
+ const [value, setValue] = useState(initialValue);
93
+ const [valid, setValid] = useState(null);
94
+ const [errorMessage, setErrorMessage] = useState();
95
+ const debouncedValue = useDebounce(value, 500);
96
+ const handleChange = useCallback(e => {
145
97
  setValue(e.currentTarget.value || '');
146
98
  }, []);
147
- var doValidation = function doValidation() {
99
+ const doValidation = () => {
148
100
  if (didMountRef.current) {
149
- var val = debouncedValue || '';
101
+ const val = debouncedValue || '';
150
102
  if (!val) {
151
103
  setValid(isRequired ? false : null);
152
104
  } else {
153
- var validationFailed = validations.find(function (_ref) {
154
- var callback = _ref.callback;
155
- return !callback(val);
156
- });
105
+ const validationFailed = validations.find(({
106
+ callback
107
+ }) => !callback(val));
157
108
  setErrorMessage(validationFailed === null || validationFailed === void 0 ? void 0 : validationFailed.errorMessage);
158
109
  setValid(!validationFailed);
159
110
  }
@@ -161,12 +112,12 @@ function generateInputValidator(validations, inputType, hideSuccess) {
161
112
  didMountRef.current = true;
162
113
  }
163
114
  };
164
- (0, _react.useEffect)(doValidation, [debouncedValue]);
115
+ useEffect(doValidation, [debouncedValue]);
165
116
  return {
166
- value: value,
167
- setValue: setValue,
117
+ value,
118
+ setValue,
168
119
  onChange: handleChange,
169
- onClear: function onClear() {
120
+ onClear: () => {
170
121
  setValue('');
171
122
  doValidation();
172
123
  },
@@ -175,111 +126,63 @@ function generateInputValidator(validations, inputType, hideSuccess) {
175
126
  hasSuccess: !hideSuccess && valid !== null && !!valid,
176
127
  errorMessage: !valid && !!errorMessage ? errorMessage : undefined,
177
128
  type: inputType || 'text',
178
- validate: function validate() {
179
- return doValidation();
180
- }
129
+ validate: () => doValidation()
181
130
  };
182
131
  };
183
132
  }
184
133
  function generateAsyncInputValidator(validations, inputType, hideSuccess) {
185
- return function (initialValue, isRequired) {
186
- var didMountRef = (0, _react.useRef)(false);
187
- var _useState19 = (0, _react.useState)(initialValue),
188
- _useState20 = (0, _slicedToArray2["default"])(_useState19, 2),
189
- value = _useState20[0],
190
- setValue = _useState20[1];
191
- var _useState21 = (0, _react.useState)(null),
192
- _useState22 = (0, _slicedToArray2["default"])(_useState21, 2),
193
- valid = _useState22[0],
194
- setValid = _useState22[1];
195
- var _useState23 = (0, _react.useState)(),
196
- _useState24 = (0, _slicedToArray2["default"])(_useState23, 2),
197
- isLoading = _useState24[0],
198
- setIsLoading = _useState24[1];
199
- var _useState25 = (0, _react.useState)(),
200
- _useState26 = (0, _slicedToArray2["default"])(_useState25, 2),
201
- errorMessage = _useState26[0],
202
- setErrorMessage = _useState26[1];
203
- var debouncedValue = useDebounce(value, 500);
204
- var doValidation = /*#__PURE__*/function () {
205
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
206
- var val, _validationFailed, index, validationFailed, isValid;
207
- return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
208
- while (1) switch (_context.prev = _context.next) {
209
- case 0:
210
- if (!didMountRef.current) {
211
- _context.next = 28;
212
- break;
213
- }
214
- val = debouncedValue || '';
215
- if (val) {
216
- _context.next = 7;
217
- break;
218
- }
219
- setValid(isRequired ? false : null);
220
- setIsLoading(false);
221
- _context.next = 26;
222
- break;
223
- case 7:
224
- setIsLoading(true);
225
- _context.prev = 8;
226
- index = 0;
227
- case 10:
228
- _context.next = 12;
229
- return validations[index].callback(val);
230
- case 12:
231
- isValid = _context.sent;
134
+ return (initialValue, isRequired) => {
135
+ const didMountRef = useRef(false);
136
+ const [value, setValue] = useState(initialValue);
137
+ const [valid, setValid] = useState(null);
138
+ const [isLoading, setIsLoading] = useState();
139
+ const [errorMessage, setErrorMessage] = useState();
140
+ const debouncedValue = useDebounce(value, 500);
141
+ const doValidation = async () => {
142
+ if (didMountRef.current) {
143
+ const val = debouncedValue || '';
144
+ if (!val) {
145
+ setValid(isRequired ? false : null);
146
+ setIsLoading(false);
147
+ } else {
148
+ setIsLoading(true);
149
+ try {
150
+ var _validationFailed;
151
+ let index = 0;
152
+ let validationFailed;
153
+ do {
154
+ const isValid = await validations[index].callback(val);
232
155
  if (isValid) index++;else validationFailed = validations[index];
233
- case 14:
234
- if (index < validations.length && !validationFailed) {
235
- _context.next = 10;
236
- break;
237
- }
238
- case 15:
239
- setValid(!validationFailed);
240
- setErrorMessage((_validationFailed = validationFailed) === null || _validationFailed === void 0 ? void 0 : _validationFailed.errorMessage);
241
- _context.next = 23;
242
- break;
243
- case 19:
244
- _context.prev = 19;
245
- _context.t0 = _context["catch"](8);
246
- setValid(false);
247
- setErrorMessage(_context.t0.message);
248
- case 23:
249
- _context.prev = 23;
250
- setIsLoading(false);
251
- return _context.finish(23);
252
- case 26:
253
- _context.next = 29;
254
- break;
255
- case 28:
256
- didMountRef.current = true;
257
- case 29:
258
- case "end":
259
- return _context.stop();
156
+ } while (index < validations.length && !validationFailed);
157
+ setValid(!validationFailed);
158
+ setErrorMessage((_validationFailed = validationFailed) === null || _validationFailed === void 0 ? void 0 : _validationFailed.errorMessage);
159
+ } catch (err) {
160
+ setValid(false);
161
+ setErrorMessage(err.message);
162
+ } finally {
163
+ setIsLoading(false);
260
164
  }
261
- }, _callee, null, [[8, 19, 23, 26]]);
262
- }));
263
- return function doValidation() {
264
- return _ref2.apply(this, arguments);
265
- };
266
- }();
267
- (0, _react.useEffect)(function () {
165
+ }
166
+ } else {
167
+ didMountRef.current = true;
168
+ }
169
+ };
170
+ useEffect(() => {
268
171
  doValidation();
269
172
  // eslint-disable-next-line react-hooks/exhaustive-deps
270
173
  }, [debouncedValue]);
271
- var handleChange = (0, _react.useCallback)(function (e) {
272
- var value = e.currentTarget.value || '';
174
+ const handleChange = useCallback(e => {
175
+ const value = e.currentTarget.value || '';
273
176
  setValue(value);
274
177
  if (!isLoading) setIsLoading(true);
275
178
  // eslint-disable-next-line react-hooks/exhaustive-deps
276
179
  }, []);
277
180
  return {
278
- value: value,
279
- setValue: setValue,
280
- isLoading: isLoading,
181
+ value,
182
+ setValue,
183
+ isLoading,
281
184
  onChange: handleChange,
282
- onClear: function onClear() {
185
+ onClear: () => {
283
186
  setValue('');
284
187
  doValidation();
285
188
  },
@@ -288,28 +191,24 @@ function generateAsyncInputValidator(validations, inputType, hideSuccess) {
288
191
  hasSuccess: !hideSuccess && valid !== null && !!valid,
289
192
  errorMessage: !valid && !!errorMessage ? errorMessage : undefined,
290
193
  type: inputType || 'text',
291
- validate: function validate() {
292
- return doValidation();
293
- }
194
+ validate: () => doValidation()
294
195
  };
295
196
  };
296
197
  }
297
198
  function generateRegexInputValidator(regex, errorMessage, inputType) {
298
199
  return generateInputValidator([{
299
- callback: function callback(value) {
300
- return regex.test(value);
301
- },
200
+ callback: value => regex.test(value),
302
201
  errorMessage: errorMessage
303
202
  }], inputType);
304
203
  }
305
- var useEmailInput = exports.useEmailInput = generateRegexInputValidator(/^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5})$/, 'Insert a valid email address', 'email');
306
- var useUrlInput = exports.useUrlInput = generateRegexInputValidator(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w\-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/, 'Insert a valid URL', 'url');
307
- var useRegexInput = exports.useRegexInput = function useRegexInput(regex, errorMessage, inputType) {
204
+ export const useEmailInput = generateRegexInputValidator(/^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5})$/, 'Insert a valid email address', 'email');
205
+ export const useUrlInput = generateRegexInputValidator(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w\-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/, 'Insert a valid URL', 'url');
206
+ export const useRegexInput = (regex, errorMessage, inputType) => {
308
207
  return generateRegexInputValidator(regex, errorMessage, inputType);
309
208
  };
310
- var useValidatedInput = exports.useValidatedInput = function useValidatedInput(validations, inputType, hideSuccess) {
209
+ export const useValidatedInput = (validations, inputType, hideSuccess) => {
311
210
  return generateInputValidator(validations, inputType, hideSuccess);
312
211
  };
313
- var useAsyncValidatedInput = exports.useAsyncValidatedInput = function useAsyncValidatedInput(validations, inputType, hideSuccess) {
212
+ export const useAsyncValidatedInput = (validations, inputType, hideSuccess) => {
314
213
  return generateAsyncInputValidator(validations, inputType, hideSuccess);
315
214
  };
@@ -1,27 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _Input = require("./Input");
7
- Object.keys(_Input).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _Input[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _Input[key];
14
- }
15
- });
16
- });
17
- var _hooks = require("./hooks");
18
- Object.keys(_hooks).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _hooks[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function get() {
24
- return _hooks[key];
25
- }
26
- });
27
- });
1
+ export * from './Input';
2
+ export * from './hooks';
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { InputProps } from './types';
3
- export declare const getState: (hasError?: boolean, disabled?: boolean, state?: 'focus' | 'hover' | 'enabled') => "error" | "focus" | "disabled" | "enabled" | "hover";
3
+ export declare const getState: (hasError?: boolean, disabled?: boolean, state?: 'focus' | 'hover' | 'enabled') => "enabled" | "hover" | "focus" | "disabled" | "error";
4
4
  export declare const InputElement: import("@emotion/styled").StyledComponent<{
5
5
  theme?: import("@emotion/react").Theme | undefined;
6
6
  as?: import("react").ElementType<any> | undefined;
7
- } & Pick<InputProps, "disabled" | "readOnly" | "isLoading" | "hasError"> & {
7
+ } & Pick<InputProps, "disabled" | "isLoading" | "hasError" | "readOnly"> & {
8
8
  hasLeftIcon: boolean;
9
9
  hasRightIcon: boolean;
10
10
  hasClearButton: boolean;