@geneui/components 2.11.1

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 (154) hide show
  1. package/ActionableList.js +1761 -0
  2. package/AdvancedSearch.js +872 -0
  3. package/Alert.js +98 -0
  4. package/Avatar.js +77 -0
  5. package/Badge.js +76 -0
  6. package/Breadcrumb.js +128 -0
  7. package/BusyLoader.js +69 -0
  8. package/Button.js +130 -0
  9. package/CHANGELOG.md +424 -0
  10. package/Card.js +513 -0
  11. package/CardList.js +705 -0
  12. package/CellMeasurerCache-c11cec83.js +229 -0
  13. package/Charts.js +99 -0
  14. package/Checkbox.js +232 -0
  15. package/CheckboxGroup.js +206 -0
  16. package/CheckboxGroupWithSearch.js +279 -0
  17. package/Collapse.js +196 -0
  18. package/ColorPicker.js +210 -0
  19. package/ComboBox.js +99 -0
  20. package/Counter.js +99 -0
  21. package/DateFilter.js +179 -0
  22. package/DatePicker.js +1231 -0
  23. package/DatePickerInput.js +30 -0
  24. package/Divider.js +56 -0
  25. package/Drawer.js +264 -0
  26. package/Dropdown.js +99 -0
  27. package/Editor.js +22965 -0
  28. package/Empty.js +132 -0
  29. package/ExtendedInput.js +578 -0
  30. package/Form.js +116 -0
  31. package/FormContainer.js +189 -0
  32. package/FormableCheckbox.js +27 -0
  33. package/FormableDatePicker.js +39 -0
  34. package/FormableDropdown.js +105 -0
  35. package/FormableEditor.js +24 -0
  36. package/FormableHOC-21051057.js +83 -0
  37. package/FormableMultiSelectDropdown.js +105 -0
  38. package/FormableNumberInput.js +31 -0
  39. package/FormableRadio.js +23 -0
  40. package/FormableSwitcher.js +23 -0
  41. package/FormableTextInput.js +31 -0
  42. package/FormableUploader.js +40 -0
  43. package/GeneUIProvider.js +256 -0
  44. package/Grid.js +166 -0
  45. package/Holder.js +99 -0
  46. package/Icon.js +63 -0
  47. package/Image.js +130 -0
  48. package/ImagePreview.js +99 -0
  49. package/KeyValue.js +63 -0
  50. package/Label.js +58 -0
  51. package/LinkButton.js +104 -0
  52. package/Menu.js +277 -0
  53. package/MobileNavigation.js +95 -0
  54. package/MobilePopup.js +180 -0
  55. package/Modal.js +251 -0
  56. package/ModuleTitle.js +99 -0
  57. package/NavigationMenu.js +212 -0
  58. package/Notification.js +120 -0
  59. package/Option.js +186 -0
  60. package/Overlay.js +99 -0
  61. package/Overspread.js +343 -0
  62. package/Pagination.js +258 -0
  63. package/Paper.js +97 -0
  64. package/Popover-f4d1cac0.js +411 -0
  65. package/Popover.js +20 -0
  66. package/PopoverV2.js +19 -0
  67. package/Portal.js +58 -0
  68. package/Products.js +115 -0
  69. package/Profile.js +99 -0
  70. package/Progress.js +200 -0
  71. package/QRCode.js +816 -0
  72. package/README.md +90 -0
  73. package/Radio.js +152 -0
  74. package/RadioGroup.js +105 -0
  75. package/Range.js +14 -0
  76. package/RichEditor-b7928765.js +228 -0
  77. package/RichEditor.js +13 -0
  78. package/Scrollbar.js +1587 -0
  79. package/Search.js +72 -0
  80. package/SearchWithDropdown.js +195 -0
  81. package/Section.js +62 -0
  82. package/SkeletonLoader.js +82 -0
  83. package/Slider.js +256 -0
  84. package/Status.js +104 -0
  85. package/Steps.js +312 -0
  86. package/SuggestionList.js +15 -0
  87. package/Switcher.js +194 -0
  88. package/Table.js +102 -0
  89. package/TableCompositions.js +17028 -0
  90. package/Tabs.js +236 -0
  91. package/Tag.js +103 -0
  92. package/TextLink.js +22 -0
  93. package/Textarea.js +239 -0
  94. package/Time.js +63 -0
  95. package/TimePicker.js +99 -0
  96. package/Timeline.js +114 -0
  97. package/Title.js +66 -0
  98. package/Toaster.js +116 -0
  99. package/Tooltip.js +157 -0
  100. package/TransferList.js +502 -0
  101. package/Uploader.js +32 -0
  102. package/ValidatableCheckbox.js +126 -0
  103. package/ValidatableDatePicker.js +312 -0
  104. package/ValidatableDropdown.js +99 -0
  105. package/ValidatableElements.js +99 -0
  106. package/ValidatableMultiSelectDropdown.js +99 -0
  107. package/ValidatableNumberInput.js +194 -0
  108. package/ValidatableRadio.js +117 -0
  109. package/ValidatableSwitcher.js +94 -0
  110. package/ValidatableTextInput.js +164 -0
  111. package/ValidatableTimeInput.js +171 -0
  112. package/ValidatableUploader.js +94 -0
  113. package/Widget.js +99 -0
  114. package/_commonjsHelpers-24198af3.js +35 -0
  115. package/_rollupPluginBabelHelpers-e8fb2e5c.js +16 -0
  116. package/checkTimeValidation-e56771be.js +16 -0
  117. package/checkboxRadioSwitcher-5b69d7bd.js +4 -0
  118. package/clsx.m-2bb6df4b.js +3 -0
  119. package/configs-91c86664.js +96 -0
  120. package/configs.js +131 -0
  121. package/dateValidation-67caec66.js +225 -0
  122. package/debounce-4419bc2f.js +17 -0
  123. package/globalStyling-9c60a159.js +4 -0
  124. package/guid-8ddf77b3.js +16 -0
  125. package/index-00fe8887.js +193 -0
  126. package/index-0cf65939.js +30991 -0
  127. package/index-122432cd.js +270 -0
  128. package/index-262edd7a.js +77 -0
  129. package/index-5cea9a7d.js +407 -0
  130. package/index-5e722d91.js +867 -0
  131. package/index-67f4d4d1.js +6568 -0
  132. package/index-6ff23041.js +66 -0
  133. package/index-702bf24a.js +1938 -0
  134. package/index-a4635754.js +329 -0
  135. package/index-a59530cd.js +4 -0
  136. package/index-ac59cb10.js +169 -0
  137. package/index-b7a33c58.js +11 -0
  138. package/index-d9e8a888.js +987 -0
  139. package/index-e0af0caf.js +1182 -0
  140. package/index-e8776f3d.js +807 -0
  141. package/index.js +128 -0
  142. package/localization-4ba17032.js +46 -0
  143. package/objectWithoutPropertiesLoose-299691d8.js +78 -0
  144. package/package.json +190 -0
  145. package/rangeAndSlider-20599da4.js +8839 -0
  146. package/react-beautiful-dnd.esm-38c37304.js +10117 -0
  147. package/style-inject.es-746bb8ed.js +28 -0
  148. package/useClickOutside-5183e396.js +25 -0
  149. package/useDeviceType-dd51db38.js +15 -0
  150. package/useEllipsisDetection-ef536015.js +23 -0
  151. package/useKeyDown-38102ae7.js +21 -0
  152. package/useMount-6fef51a5.js +9 -0
  153. package/useWidth-9f4647f8.js +15 -0
  154. package/useWindowSize-80369d76.js +33 -0
@@ -0,0 +1,194 @@
1
+ import { _ as _extends } from './_rollupPluginBabelHelpers-e8fb2e5c.js';
2
+ import React__default, { forwardRef, useState, useCallback, useEffect } from 'react';
3
+ import { p as propTypesExports } from './index-e0af0caf.js';
4
+ import { n as noop } from './index-ac59cb10.js';
5
+ import { u as useMount } from './useMount-6fef51a5.js';
6
+ import './configs-91c86664.js';
7
+ import ExtendedInput from './ExtendedInput.js';
8
+ import './dateValidation-67caec66.js';
9
+ import './_commonjsHelpers-24198af3.js';
10
+ import 'react-dom';
11
+ import './index-6ff23041.js';
12
+ import './useDeviceType-dd51db38.js';
13
+ import './useWindowSize-80369d76.js';
14
+ import './index-5cea9a7d.js';
15
+ import './useKeyDown-38102ae7.js';
16
+ import './useClickOutside-5183e396.js';
17
+ import './Scrollbar.js';
18
+ import './globalStyling-9c60a159.js';
19
+ import './style-inject.es-746bb8ed.js';
20
+ import './Icon.js';
21
+ import './Tooltip.js';
22
+ import './Popover-f4d1cac0.js';
23
+ import './GeneUIProvider.js';
24
+
25
+ const validateMin = (value, min) => value >= min;
26
+ const validateMax = (value, max) => value <= max;
27
+ const validateFloat = (value, precisionMin, precisionMax) => {
28
+ const decimalPlaces = (value.split('.')[1] || []).length;
29
+ if (precisionMax && decimalPlaces > precisionMax) return false;
30
+ return true;
31
+ };
32
+ function checkValidation(required, isValid, min, max, numberType, precisionMin, precisionMax) {
33
+ let value = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : '';
34
+ const numberedValue = Number(value);
35
+ if (isValid === false) return {
36
+ key: 'customValidation',
37
+ isValid: false
38
+ };
39
+ if (numberType === 'integer' && !Number.isInteger(numberedValue)) return {
40
+ key: 'isInteger',
41
+ isValid: false
42
+ };
43
+ if (numberType === 'float' && !validateFloat(value, precisionMin, precisionMax)) return {
44
+ key: 'isFloat',
45
+ isValid: false
46
+ };
47
+ if (min != null && value && !validateMin(numberedValue, min)) return {
48
+ key: 'min',
49
+ isValid: false
50
+ };
51
+ if (max != null && value && !validateMax(numberedValue, max)) return {
52
+ key: 'max',
53
+ isValid: false
54
+ };
55
+ if (required && !value.length) return {
56
+ key: 'required',
57
+ isValid: false
58
+ };
59
+ return {
60
+ key: null,
61
+ isValid: true
62
+ };
63
+ }
64
+ const NumberInput = /*#__PURE__*/forwardRef((props, ref) => {
65
+ const {
66
+ onBlur,
67
+ required,
68
+ isValid,
69
+ numberType,
70
+ precisionMin,
71
+ precisionMax,
72
+ min,
73
+ max,
74
+ onChange,
75
+ value,
76
+ isFieldValid,
77
+ forceAllowValidation,
78
+ forceValidateDuringChange,
79
+ ...restProps
80
+ } = props;
81
+ const isControlled = 'value' in props && typeof value !== 'undefined';
82
+ const [validationState, setValidationState] = useState(true);
83
+ const [allowValidation, setAllowValidation] = useState(false);
84
+ const validate = useCallback(() => checkValidation(required, isValid, min, max, numberType, precisionMin, precisionMax, value || '').isValid, [required, isValid, min, max, value, numberType, precisionMin, precisionMax]);
85
+ const handleChange = useCallback(e => {
86
+ const {
87
+ value
88
+ } = e.target;
89
+ const validation = checkValidation(required, isValid, min, max, numberType, precisionMin, precisionMax, value);
90
+ setValidationState(validation.isValid);
91
+ onChange(e, validation.isValid, validation.key);
92
+ forceValidateDuringChange && setAllowValidation(true);
93
+ }, [onChange, min, max, required, isValid, numberType, precisionMin, precisionMax, forceValidateDuringChange]);
94
+
95
+ // we use this because need to show field validation after onBlur
96
+ const handleBlur = useCallback(e => {
97
+ onBlur(e);
98
+ setAllowValidation(true);
99
+ }, [onBlur]);
100
+ useEffect(() => {
101
+ isControlled && setValidationState(validate());
102
+ }, [isControlled, validate]);
103
+
104
+ // this for handling required prop changes
105
+ useEffect(() => {
106
+ setValidationState(validate());
107
+ }, [required]);
108
+
109
+ // need this for handling user's `isValid` prop
110
+ useEffect(() => {
111
+ setValidationState(isValid);
112
+ }, [isValid]);
113
+
114
+ // call function when validation state changes
115
+ useEffect(() => {
116
+ isFieldValid(validationState);
117
+ }, [validationState]);
118
+
119
+ // set Allow validation true if submit button clicked
120
+ useEffect(() => {
121
+ forceAllowValidation && setAllowValidation(true);
122
+ }, [forceAllowValidation]);
123
+ useMount(() => setValidationState(validate()));
124
+ return /*#__PURE__*/React__default.createElement(ExtendedInput, _extends({
125
+ min: min,
126
+ max: max,
127
+ ref: ref,
128
+ value: value,
129
+ isValid: !allowValidation || validationState,
130
+ onChange: handleChange,
131
+ onBlur: handleBlur,
132
+ required: required,
133
+ type: "number"
134
+ }, restProps));
135
+ });
136
+ NumberInput.propTypes = {
137
+ /**
138
+ * Maximum value
139
+ */
140
+ min: propTypesExports.number,
141
+ /**
142
+ * Minimum value
143
+ */
144
+ max: propTypesExports.number,
145
+ /**
146
+ * Value for number field
147
+ */
148
+ value: propTypesExports.oneOfType([propTypesExports.string, propTypesExports.number]),
149
+ /**
150
+ * Callback fires when field changes
151
+ */
152
+ onChange: propTypesExports.func,
153
+ /**
154
+ * Callback fires when input loose focus
155
+ */
156
+ onBlur: propTypesExports.func,
157
+ /**
158
+ * Callback fires when field validation state changes
159
+ */
160
+ isFieldValid: propTypesExports.func,
161
+ /**
162
+ * Additional validation state
163
+ */
164
+ isValid: propTypesExports.bool,
165
+ /**
166
+ * Allow validation without onBlur, validate field when mount
167
+ */
168
+ forceAllowValidation: propTypesExports.bool,
169
+ /**
170
+ * Define number type
171
+ */
172
+ numberType: propTypesExports.oneOf(['integer', 'float']),
173
+ /**
174
+ * Precision minimum count
175
+ */
176
+ precisionMin: propTypesExports.number,
177
+ /**
178
+ * Precision maximum count
179
+ */
180
+ precisionMax: propTypesExports.number,
181
+ /**
182
+ * We use this props if we need to show validation of a field during onChange
183
+ */
184
+ forceValidateDuringChange: propTypesExports.bool
185
+ };
186
+ NumberInput.defaultProps = {
187
+ isValid: true,
188
+ precisionMin: 0,
189
+ isFieldValid: noop,
190
+ onChange: noop,
191
+ onBlur: noop
192
+ };
193
+
194
+ export { NumberInput as default };
@@ -0,0 +1,117 @@
1
+ import { _ as _extends } from './_rollupPluginBabelHelpers-e8fb2e5c.js';
2
+ import React__default, { forwardRef, useState, useCallback, useEffect } from 'react';
3
+ import { p as propTypesExports } from './index-e0af0caf.js';
4
+ import { n as noop } from './index-ac59cb10.js';
5
+ import { u as useMount } from './useMount-6fef51a5.js';
6
+ import './configs-91c86664.js';
7
+ import RadioGroup from './RadioGroup.js';
8
+ import './dateValidation-67caec66.js';
9
+ import './_commonjsHelpers-24198af3.js';
10
+ import 'react-dom';
11
+ import './index-6ff23041.js';
12
+ import './Radio.js';
13
+ import './globalStyling-9c60a159.js';
14
+ import './style-inject.es-746bb8ed.js';
15
+ import './checkboxRadioSwitcher-5b69d7bd.js';
16
+ import './guid-8ddf77b3.js';
17
+
18
+ function checkValidation(required, isValid) {
19
+ let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
20
+ if (isValid === false) return {
21
+ key: 'customValidation',
22
+ isValid: false
23
+ };
24
+ if (required && (!value || value.length === 0)) return {
25
+ key: 'required',
26
+ isValid: false
27
+ };
28
+ return {
29
+ key: null,
30
+ isValid: true
31
+ };
32
+ }
33
+ const Radio = /*#__PURE__*/forwardRef((props, ref) => {
34
+ const {
35
+ onChange,
36
+ value,
37
+ isValid,
38
+ required,
39
+ isFieldValid,
40
+ forceAllowValidation,
41
+ ...restProps
42
+ } = props;
43
+ const isControlled = 'value' in props && typeof value !== 'undefined';
44
+ const [validationState, setValidationState] = useState(true);
45
+ const [allowValidation, setAllowValidation] = useState(false);
46
+ const validate = useCallback(() => checkValidation(required, isValid, value).isValid, [value, required, isValid]);
47
+ const handleChange = useCallback(e => {
48
+ const {
49
+ value
50
+ } = e.target;
51
+ const validation = checkValidation(required, isValid, value);
52
+ setValidationState(validation.isValid);
53
+ onChange(e, validation.isValid, validation.key);
54
+ }, [onChange, required, isValid]);
55
+
56
+ // we use this because need to show field validation after onBlur
57
+ const onBlur = useCallback(() => setAllowValidation(true), []);
58
+ useEffect(() => {
59
+ isControlled && setValidationState(validate());
60
+ }, [isControlled, validate]);
61
+
62
+ // need this for handling user's `isValid` prop
63
+ useEffect(() => {
64
+ setValidationState(isValid);
65
+ }, [isValid]);
66
+
67
+ // call function when validation state changes
68
+ useEffect(() => {
69
+ isFieldValid(validationState);
70
+ }, [validationState]);
71
+
72
+ // set Allow validation true if submit button clicked
73
+ useEffect(() => {
74
+ forceAllowValidation && setAllowValidation(true);
75
+ }, [forceAllowValidation]);
76
+ useMount(() => setValidationState(validate()));
77
+ return /*#__PURE__*/React__default.createElement(RadioGroup, _extends({
78
+ ref: ref,
79
+ value: value,
80
+ isValid: !allowValidation || validationState,
81
+ onChange: handleChange,
82
+ onBlur: onBlur
83
+ }, restProps));
84
+ });
85
+ Radio.propTypes = {
86
+ /**
87
+ * Value for radio field
88
+ */
89
+ value: propTypesExports.string,
90
+ /**
91
+ * Callback fires when radio field changes
92
+ */
93
+ onChange: propTypesExports.func,
94
+ /**
95
+ * Define is field required or no.
96
+ */
97
+ required: propTypesExports.bool,
98
+ /**
99
+ * Callback fires when field validation state changes
100
+ */
101
+ isFieldValid: propTypesExports.func,
102
+ /**
103
+ * Additional validation state
104
+ */
105
+ isValid: propTypesExports.bool,
106
+ /**
107
+ * Allow validation without onBlur, validate field when mount
108
+ */
109
+ forceAllowValidation: propTypesExports.bool
110
+ };
111
+ Radio.defaultProps = {
112
+ isValid: true,
113
+ isFieldValid: noop,
114
+ onChange: noop
115
+ };
116
+
117
+ export { Radio as default };
@@ -0,0 +1,94 @@
1
+ import { _ as _extends } from './_rollupPluginBabelHelpers-e8fb2e5c.js';
2
+ import React__default, { forwardRef, useState, useCallback, useEffect } from 'react';
3
+ import { p as propTypesExports } from './index-e0af0caf.js';
4
+ import { n as noop } from './index-ac59cb10.js';
5
+ import { u as useMount } from './useMount-6fef51a5.js';
6
+ import './configs-91c86664.js';
7
+ import Switcher from './Switcher.js';
8
+ import './dateValidation-67caec66.js';
9
+ import './_commonjsHelpers-24198af3.js';
10
+ import 'react-dom';
11
+ import './index-6ff23041.js';
12
+ import './useKeyDown-38102ae7.js';
13
+ import './globalStyling-9c60a159.js';
14
+ import './style-inject.es-746bb8ed.js';
15
+ import './checkboxRadioSwitcher-5b69d7bd.js';
16
+ import './guid-8ddf77b3.js';
17
+
18
+ function checkValidation(value, required, isValid) {
19
+ if (required && !value) return {
20
+ key: 'required',
21
+ isValid: false
22
+ };
23
+ if (isValid === false) return {
24
+ key: 'customValidation',
25
+ isValid: false
26
+ };
27
+ return {
28
+ key: null,
29
+ isValid: true
30
+ };
31
+ }
32
+ const SwitcherElement = /*#__PURE__*/forwardRef((props, ref) => {
33
+ const {
34
+ onChange,
35
+ isValid,
36
+ required,
37
+ isFieldValid,
38
+ forceAllowValidation,
39
+ ...restProps
40
+ } = props;
41
+ const isControlled = ('checked' in props);
42
+ const [validationState, setValidationState] = useState(true);
43
+ const [allowValidation, setAllowValidation] = useState(false);
44
+ const [value, setValue] = useState(false);
45
+ const localValue = isControlled ? props.checked : value;
46
+ const validate = useCallback(() => checkValidation(localValue, required, isValid).isValid, [localValue, required, isValid]);
47
+ const handleChange = useCallback(e => {
48
+ const validation = checkValidation(e.target.checked, required, isValid);
49
+ setAllowValidation(true);
50
+ !isControlled && setValidationState(validation.isValid);
51
+ setValue(e.target.checked);
52
+ onChange(e, validation.isValid, validation.key);
53
+ }, [required, isValid, isControlled, onChange]);
54
+ useEffect(() => {
55
+ isControlled && setValidationState(validate());
56
+ }, [isControlled, validate]);
57
+
58
+ // need this for handling user's `isValid` prop
59
+ useEffect(() => {
60
+ setValidationState(isValid);
61
+ }, [isValid]);
62
+
63
+ // call function when validation state changes
64
+ useEffect(() => {
65
+ isFieldValid(validationState);
66
+ }, [validationState]);
67
+
68
+ // set Allow validation true if submit button clicked
69
+ useEffect(() => {
70
+ forceAllowValidation && setAllowValidation(true);
71
+ }, [forceAllowValidation]);
72
+ useMount(() => setValidationState(validate()));
73
+ return /*#__PURE__*/React__default.createElement(Switcher, _extends({
74
+ ref: ref,
75
+ isValid: !allowValidation || validationState,
76
+ onChange: handleChange,
77
+ required: required
78
+ }, restProps));
79
+ });
80
+ SwitcherElement.propTypes = {
81
+ onChange: propTypesExports.func,
82
+ required: propTypesExports.bool,
83
+ checked: propTypesExports.bool,
84
+ isFieldValid: propTypesExports.func,
85
+ isValid: propTypesExports.bool,
86
+ forceAllowValidation: propTypesExports.bool
87
+ };
88
+ SwitcherElement.defaultProps = {
89
+ isValid: true,
90
+ isFieldValid: noop,
91
+ onChange: noop
92
+ };
93
+
94
+ export { SwitcherElement as default };
@@ -0,0 +1,164 @@
1
+ import { _ as _extends } from './_rollupPluginBabelHelpers-e8fb2e5c.js';
2
+ import React__default, { forwardRef, useState, useCallback, useEffect } from 'react';
3
+ import { p as propTypesExports } from './index-e0af0caf.js';
4
+ import { n as noop } from './index-ac59cb10.js';
5
+ import { u as useMount } from './useMount-6fef51a5.js';
6
+ import './configs-91c86664.js';
7
+ import ExtendedInput from './ExtendedInput.js';
8
+ import './dateValidation-67caec66.js';
9
+ import './_commonjsHelpers-24198af3.js';
10
+ import 'react-dom';
11
+ import './index-6ff23041.js';
12
+ import './useDeviceType-dd51db38.js';
13
+ import './useWindowSize-80369d76.js';
14
+ import './index-5cea9a7d.js';
15
+ import './useKeyDown-38102ae7.js';
16
+ import './useClickOutside-5183e396.js';
17
+ import './Scrollbar.js';
18
+ import './globalStyling-9c60a159.js';
19
+ import './style-inject.es-746bb8ed.js';
20
+ import './Icon.js';
21
+ import './Tooltip.js';
22
+ import './Popover-f4d1cac0.js';
23
+ import './GeneUIProvider.js';
24
+
25
+ const emailRegExp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
26
+ function checkValidation(required, isValid, maxLength, minLength, isEmail) {
27
+ let value = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '';
28
+ const valueWithoutSpaces = value ? value.toString().trim() : value;
29
+ if (isValid === false) return {
30
+ key: 'customValidation',
31
+ isValid: false
32
+ };
33
+ if (minLength && valueWithoutSpaces.length <= minLength) return {
34
+ key: 'minLength',
35
+ isValid: false
36
+ };
37
+ if (maxLength && valueWithoutSpaces.length >= maxLength) return {
38
+ key: 'maxLength',
39
+ isValid: false
40
+ };
41
+ if (valueWithoutSpaces.length > 0 && isEmail && !emailRegExp.test(valueWithoutSpaces)) return {
42
+ key: 'isEmail',
43
+ isValid: false
44
+ };
45
+ if (required && valueWithoutSpaces.length === 0) return {
46
+ key: 'required',
47
+ isValid: false
48
+ };
49
+ return {
50
+ key: null,
51
+ isValid: true
52
+ };
53
+ }
54
+ const TextInput = /*#__PURE__*/forwardRef((props, ref) => {
55
+ const {
56
+ onChange,
57
+ value,
58
+ isValid,
59
+ onBlur,
60
+ required,
61
+ maxLength,
62
+ minLength,
63
+ isEmail,
64
+ isFieldValid,
65
+ forceAllowValidation,
66
+ defaultValue,
67
+ ...restProps
68
+ } = props;
69
+ const isControlled = 'value' in props && typeof value !== 'undefined';
70
+ const [validationState, setValidationState] = useState(true);
71
+ const [allowValidation, setAllowValidation] = useState(false);
72
+ const validate = useCallback(defaultValue => checkValidation(required, isValid, maxLength, minLength, isEmail, value || defaultValue).isValid, [value, required, isValid, maxLength, minLength, isEmail]);
73
+ const handleChange = useCallback(e => {
74
+ const {
75
+ value
76
+ } = e.target;
77
+ const validation = checkValidation(required, isValid, maxLength, minLength, isEmail, value);
78
+ setValidationState(validation.isValid);
79
+ onChange && onChange(e, validation.isValid, validation.key);
80
+ }, [onChange, required, isValid, maxLength, minLength, isEmail]);
81
+
82
+ // we use this because need to show field validation after onBlur
83
+ const handleBlur = useCallback(e => {
84
+ setAllowValidation(true);
85
+ onBlur(e);
86
+ }, [onBlur]);
87
+ useEffect(() => {
88
+ isControlled && setValidationState(validate());
89
+ }, [isControlled, validate]);
90
+
91
+ // need this for handling user's `isValid` prop
92
+ useEffect(() => {
93
+ setValidationState(isValid);
94
+ }, [isValid]);
95
+
96
+ // call function when validation state changes
97
+ useEffect(() => {
98
+ isFieldValid(validationState);
99
+ }, [validationState]);
100
+
101
+ // set Allow validation true if submit button clicked
102
+ useEffect(() => {
103
+ forceAllowValidation && setAllowValidation(true);
104
+ }, [forceAllowValidation]);
105
+ useMount(() => setValidationState(validate(defaultValue)));
106
+ return /*#__PURE__*/React__default.createElement(ExtendedInput, _extends({}, restProps, {
107
+ ref: ref,
108
+ value: value,
109
+ isValid: !allowValidation || validationState,
110
+ onChange: handleChange,
111
+ required: required,
112
+ defaultValue: defaultValue,
113
+ onBlur: handleBlur
114
+ }));
115
+ });
116
+ TextInput.propTypes = {
117
+ /**
118
+ * Value for text input
119
+ */
120
+ value: propTypesExports.string,
121
+ /**
122
+ * Callback fires when field changes
123
+ */
124
+ onChange: propTypesExports.func,
125
+ /**
126
+ * Callback fires when field blured
127
+ */
128
+ onBlur: propTypesExports.func,
129
+ /**
130
+ * Define is field required or no.
131
+ */
132
+ required: propTypesExports.bool,
133
+ /**
134
+ * Is field accept only email or no
135
+ */
136
+ isEmail: propTypesExports.bool,
137
+ /**
138
+ * Maximum length of value
139
+ */
140
+ maxLength: propTypesExports.number,
141
+ /**
142
+ * Minimum length of value
143
+ */
144
+ minLength: propTypesExports.number,
145
+ /**
146
+ * Callback fires when field validation state changes
147
+ */
148
+ isFieldValid: propTypesExports.func,
149
+ /**
150
+ * Additional validation state
151
+ */
152
+ isValid: propTypesExports.bool,
153
+ /**
154
+ * Allow validation without onBlur, validate field when mount
155
+ */
156
+ forceAllowValidation: propTypesExports.bool
157
+ };
158
+ TextInput.defaultProps = {
159
+ isValid: true,
160
+ isFieldValid: noop,
161
+ onBlur: noop
162
+ };
163
+
164
+ export { TextInput as default };