@codacy/ui-components 0.66.24 → 0.66.26
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.
- package/lib/Avatar/Avatar.js +20 -28
- package/lib/Avatar/Avatar.types.js +1 -5
- package/lib/Avatar/gravatar.js +14 -22
- package/lib/Avatar/index.js +1 -16
- package/lib/Banner/Banner.js +33 -50
- package/lib/Banner/Banner.styles.d.ts +1 -1
- package/lib/Banner/Banner.styles.js +11 -20
- package/lib/Banner/Banner.types.js +1 -5
- package/lib/Banner/index.js +2 -27
- package/lib/Bannerol/Bannerol.js +44 -61
- package/lib/Bannerol/Bannerol.styles.js +9 -18
- package/lib/Bannerol/Bannerol.types.js +1 -5
- package/lib/Bannerol/index.js +3 -38
- package/lib/BigTabs/BigTabs.js +39 -54
- package/lib/BigTabs/BigTabs.styles.js +79 -107
- package/lib/BigTabs/BigTabs.types.js +1 -5
- package/lib/BigTabs/index.js +1 -16
- package/lib/Button/Button.js +45 -67
- package/lib/Button/index.js +2 -27
- package/lib/Button/styles.js +101 -130
- package/lib/Button/types.js +1 -5
- package/lib/Checkbox/Checkbox.js +55 -68
- package/lib/Checkbox/CheckboxFilterList.js +33 -66
- package/lib/Checkbox/index.js +3 -38
- package/lib/Checkbox/styles.js +64 -86
- package/lib/Checkbox/types.js +1 -5
- package/lib/CloseButton/index.d.ts +1 -1
- package/lib/CloseButton/index.js +24 -36
- package/lib/Divider/Divider.js +14 -25
- package/lib/Divider/Divider.styles.d.ts +1 -1
- package/lib/Divider/Divider.styles.js +24 -38
- package/lib/Divider/Divider.types.js +1 -5
- package/lib/Divider/index.js +1 -16
- package/lib/Dropdown/Content/DropdownInput.js +10 -20
- package/lib/Dropdown/Content/DropdownItem.js +22 -36
- package/lib/Dropdown/Content/DropdownSeparator.js +8 -19
- package/lib/Dropdown/Content/DropdownTitle.js +8 -22
- package/lib/Dropdown/Content/index.js +4 -49
- package/lib/Dropdown/Dropdown.js +74 -102
- package/lib/Dropdown/Dropdown.styles.d.ts +1 -1
- package/lib/Dropdown/Dropdown.styles.js +60 -82
- package/lib/Dropdown/Dropdown.types.js +1 -5
- package/lib/Dropdown/Triggers/DropdownButtonTrigger.js +19 -32
- package/lib/Dropdown/Triggers/DropdownItemTrigger.js +18 -30
- package/lib/Dropdown/Triggers/FilterTrigger.js +66 -93
- package/lib/Dropdown/Triggers/InputTrigger.js +15 -24
- package/lib/Dropdown/Triggers/SelectTrigger.js +12 -21
- package/lib/Dropdown/Triggers/hooks.js +17 -26
- package/lib/Dropdown/Triggers/index.js +6 -71
- package/lib/Dropdown/Triggers/types.js +1 -5
- package/lib/Dropdown/index.js +4 -49
- package/lib/ExpandableBox/ExpandableBox.js +28 -43
- package/lib/ExpandableBox/ExpandableBox.styles.d.ts +2 -2
- package/lib/ExpandableBox/ExpandableBox.styles.js +27 -40
- package/lib/ExpandableBox/ExpandableBox.types.js +1 -5
- package/lib/ExpandableBox/index.js +1 -16
- package/lib/Flexbox/Flexbox.js +14 -21
- package/lib/Flexbox/index.js +1 -16
- package/lib/Group/Group.js +7 -18
- package/lib/Group/Group.styles.js +8 -16
- package/lib/Group/Group.types.js +1 -5
- package/lib/Group/index.js +1 -16
- package/lib/Icon/Icon.js +15 -26
- package/lib/Icon/Icon.styles.d.ts +1 -1
- package/lib/Icon/Icon.styles.js +57 -50
- package/lib/Icon/Icon.types.js +1 -5
- package/lib/Icon/index.js +1 -16
- package/lib/IconAndText/IconAndText.js +23 -36
- package/lib/IconAndText/IconAndText.styles.js +19 -29
- package/lib/IconAndText/IconAndText.types.js +1 -5
- package/lib/IconAndText/index.js +1 -16
- package/lib/Icons/Chevrons.js +45 -65
- package/lib/Icons/CodacyIcon.js +9 -20
- package/lib/Icons/Ellipsis.js +18 -29
- package/lib/Icons/Messages.js +58 -79
- package/lib/Icons/Search.js +8 -19
- package/lib/Icons/Severities.js +113 -149
- package/lib/Icons/Sorting.js +15 -29
- package/lib/Icons/Spinner.js +11 -22
- package/lib/Icons/Symbols.js +67 -90
- package/lib/Icons/index.js +8 -93
- package/lib/Img/Img.js +26 -45
- package/lib/Img/Img.styles.d.ts +2 -2
- package/lib/Img/Img.styles.js +21 -29
- package/lib/Img/Img.types.js +1 -5
- package/lib/Img/index.js +1 -16
- package/lib/InlineMessage/InlineMessage.js +43 -70
- package/lib/InlineMessage/index.js +1 -16
- package/lib/InlineMessage/types.js +1 -5
- package/lib/Input/Input.js +115 -143
- package/lib/Input/hooks.js +107 -208
- package/lib/Input/index.js +2 -27
- package/lib/Input/styles.d.ts +2 -2
- package/lib/Input/styles.js +116 -151
- package/lib/Input/types.js +1 -5
- package/lib/Labeled/Labeled.js +22 -35
- package/lib/Labeled/index.js +1 -16
- package/lib/Labeled/styles.js +23 -37
- package/lib/Labeled/types.js +1 -5
- package/lib/LeftMenu/LeftMenu.js +10 -21
- package/lib/LeftMenu/LeftMenu.styles.js +25 -43
- package/lib/LeftMenu/LeftMenu.types.js +1 -5
- package/lib/LeftMenu/index.js +1 -16
- package/lib/Link/Link.js +32 -50
- package/lib/Link/Link.styles.js +11 -23
- package/lib/Link/Link.types.js +1 -5
- package/lib/Link/index.js +3 -38
- package/lib/Message/Message.js +31 -42
- package/lib/Message/Message.styles.js +18 -31
- package/lib/Message/Message.types.js +1 -5
- package/lib/Message/index.js +1 -16
- package/lib/Modal/ConfirmationModal.js +40 -67
- package/lib/Modal/Modal.js +107 -137
- package/lib/Modal/index.js +2 -27
- package/lib/Modal/styles.js +44 -62
- package/lib/Modal/types.js +1 -5
- package/lib/MoreInfo/MoreInfo.js +41 -53
- package/lib/MoreInfo/index.js +1 -16
- package/lib/MoreInfo/types.js +1 -5
- package/lib/MultiSlider/MultiSlider.js +17 -31
- package/lib/MultiSlider/index.js +1 -16
- package/lib/MultiSlider/styles.js +18 -34
- package/lib/MultiSlider/types.js +1 -5
- package/lib/Panel/Panel.js +9 -19
- package/lib/Panel/Panel.styles.js +15 -22
- package/lib/Panel/Panel.types.js +1 -5
- package/lib/Panel/index.js +2 -27
- package/lib/PillLabel/PillLabel.js +35 -49
- package/lib/PillLabel/PillLabel.styles.js +33 -44
- package/lib/PillLabel/PillLabel.types.js +1 -5
- package/lib/PillLabel/index.js +1 -16
- package/lib/Popup/Popup.js +43 -61
- package/lib/Popup/index.js +1 -16
- package/lib/Popup/styles.js +22 -34
- package/lib/Popup/types.js +1 -5
- package/lib/ProgressBar/ProgressBar.js +19 -35
- package/lib/ProgressBar/index.js +2 -27
- package/lib/ProgressBar/styles.d.ts +2 -2
- package/lib/ProgressBar/styles.js +21 -37
- package/lib/ProgressBar/types.d.ts +0 -3
- package/lib/ProgressBar/types.js +1 -5
- package/lib/Radio/Radio.js +47 -59
- package/lib/Radio/index.js +1 -16
- package/lib/Radio/styles.js +48 -72
- package/lib/Radio/types.js +1 -5
- package/lib/ScrollableContent/ScrollableContent.js +27 -40
- package/lib/ScrollableContent/ScrollableContent.styles.js +22 -39
- package/lib/ScrollableContent/ScrollableContent.types.js +1 -5
- package/lib/ScrollableContent/index.js +2 -27
- package/lib/ScrollableContent/useScrollContainer.js +35 -50
- package/lib/Skeleton/Skeleton.js +25 -45
- package/lib/Skeleton/Skeleton.styles.js +28 -25
- package/lib/Skeleton/Skeleton.types.js +1 -5
- package/lib/Skeleton/index.js +2 -20
- package/lib/Slider/Slider.js +32 -56
- package/lib/Slider/index.js +1 -16
- package/lib/Slider/styles.js +41 -60
- package/lib/Slider/types.js +1 -5
- package/lib/StepNumber/StepNumber.js +26 -40
- package/lib/StepNumber/index.js +1 -16
- package/lib/StepNumber/styles.js +13 -24
- package/lib/StepNumber/types.js +1 -5
- package/lib/Stepper/Stepper.js +45 -62
- package/lib/Stepper/Stepper.styles.js +27 -44
- package/lib/Stepper/Stepper.types.js +1 -5
- package/lib/Stepper/index.js +1 -16
- package/lib/Switcher/Switcher.js +22 -34
- package/lib/Switcher/Switcher.styles.js +27 -42
- package/lib/Switcher/Switcher.types.js +1 -5
- package/lib/Switcher/index.js +1 -16
- package/lib/Tab/Tab.js +21 -33
- package/lib/Tab/Tab.styles.js +34 -50
- package/lib/Tab/Tab.types.js +1 -5
- package/lib/Tab/index.js +1 -16
- package/lib/Table/NewSelectableTable.js +59 -97
- package/lib/Table/SelectableTable.js +142 -189
- package/lib/Table/Table.js +110 -155
- package/lib/Table/Table.styles.js +67 -90
- package/lib/Table/Table.types.js +1 -5
- package/lib/Table/index.js +2 -27
- package/lib/TagsInput/TagsInput.js +32 -46
- package/lib/TagsInput/index.js +1 -16
- package/lib/TagsInput/style.js +45 -71
- package/lib/TagsInput/types.js +1 -5
- package/lib/Textarea/Textarea.js +52 -71
- package/lib/Textarea/Textarea.styles.js +91 -126
- package/lib/Textarea/Textarea.types.js +1 -5
- package/lib/Textarea/index.js +1 -16
- package/lib/ThemeProvider/ThemeProvider.js +41 -65
- package/lib/ThemeProvider/index.js +1 -16
- package/lib/Toast/Toast.js +53 -68
- package/lib/Toast/index.js +1 -16
- package/lib/Toast/styles.js +29 -49
- package/lib/Toast/types.js +1 -5
- package/lib/Toggle/Toggle.js +48 -65
- package/lib/Toggle/index.js +1 -16
- package/lib/Toggle/styles.d.ts +1 -1
- package/lib/Toggle/styles.js +66 -101
- package/lib/Toggle/types.js +1 -5
- package/lib/Tooltip/Tooltip.js +84 -121
- package/lib/Tooltip/index.js +2 -27
- package/lib/Tooltip/styles.js +63 -93
- package/lib/Tooltip/types.js +1 -5
- package/lib/Typography/Typography.js +78 -116
- package/lib/Typography/Typography.styles.js +61 -78
- package/lib/Typography/Typography.types.js +1 -5
- package/lib/Typography/index.js +3 -38
- package/lib/emotion.d.js +1 -3
- package/lib/hooks/index.js +3 -38
- package/lib/hooks/useForwardedRef.js +5 -11
- package/lib/hooks/useInfiniteScroll.js +13 -25
- package/lib/hooks/useStatefulRef.js +10 -23
- package/lib/index.js +49 -544
- package/lib/system-props/color.js +3 -9
- package/lib/system-props/index.js +2 -27
- package/lib/system-props/types.js +1 -5
- package/lib/theme/ColorSchemes/components/alerts.js +30 -38
- package/lib/theme/ColorSchemes/components/button.js +89 -97
- package/lib/theme/ColorSchemes/components/cards.js +16 -24
- package/lib/theme/ColorSchemes/components/charts.js +93 -101
- package/lib/theme/ColorSchemes/components/checkbox-input.js +13 -21
- package/lib/theme/ColorSchemes/components/divider.js +4 -12
- package/lib/theme/ColorSchemes/components/drawer.js +21 -29
- package/lib/theme/ColorSchemes/components/effects.js +5 -13
- package/lib/theme/ColorSchemes/components/filters.js +12 -20
- package/lib/theme/ColorSchemes/components/index.d.ts +2 -0
- package/lib/theme/ColorSchemes/components/index.js +23 -236
- package/lib/theme/ColorSchemes/components/input.js +38 -46
- package/lib/theme/ColorSchemes/components/issues.js +27 -35
- package/lib/theme/ColorSchemes/components/label.js +33 -41
- package/lib/theme/ColorSchemes/components/list-orb.js +8 -16
- package/lib/theme/ColorSchemes/components/loading.js +4 -12
- package/lib/theme/ColorSchemes/components/logo.js +6 -14
- package/lib/theme/ColorSchemes/components/modals.js +6 -14
- package/lib/theme/ColorSchemes/components/navigation.js +17 -25
- package/lib/theme/ColorSchemes/components/progress-bar.d.ts +5 -0
- package/lib/theme/ColorSchemes/components/progress-bar.js +5 -0
- package/lib/theme/ColorSchemes/components/selector.js +20 -28
- package/lib/theme/ColorSchemes/components/stepper.js +9 -17
- package/lib/theme/ColorSchemes/components/tables.js +12 -20
- package/lib/theme/ColorSchemes/components/tabs.js +13 -21
- package/lib/theme/ColorSchemes/components/tooltip.d.ts +6 -0
- package/lib/theme/ColorSchemes/components/tooltip.js +6 -0
- package/lib/theme/ColorSchemes/components/utils.js +1 -11
- package/lib/theme/ColorSchemes/dark/background.d.ts +27 -27
- package/lib/theme/ColorSchemes/dark/background.js +42 -50
- package/lib/theme/ColorSchemes/dark/border.d.ts +27 -27
- package/lib/theme/ColorSchemes/dark/border.js +37 -45
- package/lib/theme/ColorSchemes/dark/data.js +18 -24
- package/lib/theme/ColorSchemes/dark/icon.d.ts +27 -27
- package/lib/theme/ColorSchemes/dark/icon.js +40 -48
- package/lib/theme/ColorSchemes/dark/illustration.js +11 -17
- package/lib/theme/ColorSchemes/dark/index.js +60 -26
- package/lib/theme/ColorSchemes/dark/text.d.ts +27 -27
- package/lib/theme/ColorSchemes/dark/text.js +47 -54
- package/lib/theme/ColorSchemes/index.js +4 -49
- package/lib/theme/ColorSchemes/light/background.d.ts +27 -27
- package/lib/theme/ColorSchemes/light/background.js +42 -50
- package/lib/theme/ColorSchemes/light/border.d.ts +27 -27
- package/lib/theme/ColorSchemes/light/border.js +37 -45
- package/lib/theme/ColorSchemes/light/data.js +18 -24
- package/lib/theme/ColorSchemes/light/icon.d.ts +27 -27
- package/lib/theme/ColorSchemes/light/icon.js +40 -48
- package/lib/theme/ColorSchemes/light/illustration.js +11 -17
- package/lib/theme/ColorSchemes/light/index.d.ts +59 -54
- package/lib/theme/ColorSchemes/light/index.js +43 -19
- package/lib/theme/ColorSchemes/light/text.d.ts +27 -27
- package/lib/theme/ColorSchemes/light/text.js +47 -54
- package/lib/theme/ColorSchemes/primitives/blue.js +1 -7
- package/lib/theme/ColorSchemes/primitives/green.js +1 -7
- package/lib/theme/ColorSchemes/primitives/grey.js +1 -7
- package/lib/theme/ColorSchemes/primitives/index.d.ts +9 -9
- package/lib/theme/ColorSchemes/primitives/index.js +20 -18
- package/lib/theme/ColorSchemes/primitives/magenta.js +1 -7
- package/lib/theme/ColorSchemes/primitives/orange.js +1 -7
- package/lib/theme/ColorSchemes/primitives/purple.js +1 -7
- package/lib/theme/ColorSchemes/primitives/red.js +1 -7
- package/lib/theme/ColorSchemes/primitives/teal.js +1 -7
- package/lib/theme/ColorSchemes/primitives/yellow.js +1 -7
- package/lib/theme/ColorSchemes/semantics.js +7 -13
- package/lib/theme/index.js +2 -27
- package/lib/theme/theme.js +68 -77
- package/lib/types.js +1 -5
- package/lib/utils/hash.js +3 -9
- package/lib/utils/reactNodeToText.js +9 -17
- package/package.json +21 -11
package/lib/Input/hooks.js
CHANGED
|
@@ -1,159 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
32
|
-
setValue
|
|
33
|
-
onChange
|
|
34
|
-
onClear:
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
54
|
-
setValue
|
|
55
|
-
onChange
|
|
56
|
-
onClear:
|
|
25
|
+
value,
|
|
26
|
+
setValue,
|
|
27
|
+
onChange,
|
|
28
|
+
onClear: () => {
|
|
57
29
|
setValue(null);
|
|
58
30
|
},
|
|
59
31
|
type: 'number',
|
|
60
|
-
min
|
|
61
|
-
max
|
|
62
|
-
hasError
|
|
32
|
+
min,
|
|
33
|
+
max,
|
|
34
|
+
hasError
|
|
63
35
|
};
|
|
64
36
|
}
|
|
65
|
-
function useRequiredInput(initialValue, requiredMessage) {
|
|
66
|
-
|
|
67
|
-
|
|
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
|
|
43
|
+
return {
|
|
44
|
+
...inputProps,
|
|
75
45
|
onBlur: handleBlur,
|
|
76
|
-
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
|
-
|
|
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
|
|
95
|
-
setValue
|
|
61
|
+
value,
|
|
62
|
+
setValue,
|
|
96
63
|
onChange: handleChange
|
|
97
64
|
};
|
|
98
65
|
}
|
|
99
|
-
function useTagsInput(initialValue) {
|
|
100
|
-
|
|
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
|
|
109
|
-
setTags
|
|
72
|
+
tags,
|
|
73
|
+
setTags,
|
|
110
74
|
onChange: handleChange
|
|
111
75
|
};
|
|
112
76
|
}
|
|
113
|
-
function useDebounce(value, delay) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
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
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
99
|
+
const doValidation = () => {
|
|
148
100
|
if (didMountRef.current) {
|
|
149
|
-
|
|
101
|
+
const val = debouncedValue || '';
|
|
150
102
|
if (!val) {
|
|
151
103
|
setValid(isRequired ? false : null);
|
|
152
104
|
} else {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
115
|
+
useEffect(doValidation, [debouncedValue]);
|
|
165
116
|
return {
|
|
166
|
-
value
|
|
167
|
-
setValue
|
|
117
|
+
value,
|
|
118
|
+
setValue,
|
|
168
119
|
onChange: handleChange,
|
|
169
|
-
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:
|
|
179
|
-
return doValidation();
|
|
180
|
-
}
|
|
129
|
+
validate: () => doValidation()
|
|
181
130
|
};
|
|
182
131
|
};
|
|
183
132
|
}
|
|
184
133
|
function generateAsyncInputValidator(validations, inputType, hideSuccess) {
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
272
|
-
|
|
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
|
|
279
|
-
setValue
|
|
280
|
-
isLoading
|
|
181
|
+
value,
|
|
182
|
+
setValue,
|
|
183
|
+
isLoading,
|
|
281
184
|
onChange: handleChange,
|
|
282
|
-
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:
|
|
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:
|
|
300
|
-
return regex.test(value);
|
|
301
|
-
},
|
|
200
|
+
callback: value => regex.test(value),
|
|
302
201
|
errorMessage: errorMessage
|
|
303
202
|
}], inputType);
|
|
304
203
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
209
|
+
export const useValidatedInput = (validations, inputType, hideSuccess) => {
|
|
311
210
|
return generateInputValidator(validations, inputType, hideSuccess);
|
|
312
211
|
};
|
|
313
|
-
|
|
212
|
+
export const useAsyncValidatedInput = (validations, inputType, hideSuccess) => {
|
|
314
213
|
return generateAsyncInputValidator(validations, inputType, hideSuccess);
|
|
315
214
|
};
|
package/lib/Input/index.js
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
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';
|
package/lib/Input/styles.d.ts
CHANGED
|
@@ -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') => "
|
|
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" | "
|
|
7
|
+
} & Pick<InputProps, "disabled" | "isLoading" | "hasError" | "readOnly"> & {
|
|
8
8
|
hasLeftIcon: boolean;
|
|
9
9
|
hasRightIcon: boolean;
|
|
10
10
|
hasClearButton: boolean;
|