sag_components 1.0.88 → 1.0.90
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.
|
@@ -53,10 +53,14 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
53
53
|
onInputChange = _ref.onInputChange,
|
|
54
54
|
_ref$labelColor = _ref.labelColor,
|
|
55
55
|
labelColor = _ref$labelColor === void 0 ? "#1B30AA" : _ref$labelColor,
|
|
56
|
-
required = _ref.required
|
|
56
|
+
required = _ref.required,
|
|
57
|
+
defaultValue = _ref.defaultValue,
|
|
58
|
+
_ref$allowedInput = _ref.allowedInput,
|
|
59
|
+
allowedInput = _ref$allowedInput === void 0 ? "all" : _ref$allowedInput;
|
|
57
60
|
/**
|
|
58
61
|
* SAG Dropdown
|
|
59
62
|
*/
|
|
63
|
+
|
|
60
64
|
var _useState = (0, _react.useState)(null),
|
|
61
65
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
62
66
|
currentInputValue = _useState2[0],
|
|
@@ -65,6 +69,15 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
65
69
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
66
70
|
currentOption = _useState4[0],
|
|
67
71
|
setCurrentOption = _useState4[1];
|
|
72
|
+
// const [valueState, setValueState] = useState(null);
|
|
73
|
+
|
|
74
|
+
// useEffect(() => {
|
|
75
|
+
// {
|
|
76
|
+
// if (defaultValue && getOptionByLabel(defaultValue) != null)
|
|
77
|
+
// setValueState(getOptionByLabel(defaultValue));
|
|
78
|
+
// }
|
|
79
|
+
// }, []);
|
|
80
|
+
|
|
68
81
|
(0, _react.useEffect)(function () {
|
|
69
82
|
var delayDebounceFn = setTimeout(function () {
|
|
70
83
|
onInputChange(currentInputValue);
|
|
@@ -131,6 +144,33 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
131
144
|
newValue: newValue
|
|
132
145
|
});
|
|
133
146
|
};
|
|
147
|
+
var getOptionByLabel = function getOptionByLabel(label) {
|
|
148
|
+
if (!label) return null;
|
|
149
|
+
if (!options) return null;
|
|
150
|
+
var foundOption = options.find(function (item) {
|
|
151
|
+
return item.label == label;
|
|
152
|
+
});
|
|
153
|
+
console.log(foundOption);
|
|
154
|
+
if (!foundOption) return null;
|
|
155
|
+
return foundOption;
|
|
156
|
+
};
|
|
157
|
+
var isInputAllowed = function isInputAllowed(inputChar) {
|
|
158
|
+
var NUMERIC_REGEX = /^[0-9-]+$/;
|
|
159
|
+
var ALPHA_REGEX = /^[a-zA-Z]+$/;
|
|
160
|
+
var ALPHA_NUMERIC_REGEX = /^[a-zA-Z0-9-]+$/;
|
|
161
|
+
switch (allowedInput) {
|
|
162
|
+
case "all":
|
|
163
|
+
return true;
|
|
164
|
+
case "alpha":
|
|
165
|
+
if (ALPHA_REGEX.test(inputChar)) return true;else return false;
|
|
166
|
+
case "numeric":
|
|
167
|
+
if (NUMERIC_REGEX.test(inputChar)) return true;else return false;
|
|
168
|
+
case "alphaNumeric":
|
|
169
|
+
if (ALPHA_NUMERIC_REGEX.test(inputChar)) return true;else return false;
|
|
170
|
+
default:
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
134
174
|
var getAutocompleteSingle = function getAutocompleteSingle() {
|
|
135
175
|
return /*#__PURE__*/_react.default.createElement(_styles.ThemeProvider, {
|
|
136
176
|
theme: theme
|
|
@@ -142,6 +182,7 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
142
182
|
onInputChangeHandler(event, newInputValue);
|
|
143
183
|
},
|
|
144
184
|
disablePortal: true,
|
|
185
|
+
defaultValue: getOptionByLabel(defaultValue),
|
|
145
186
|
id: "combo-box",
|
|
146
187
|
options: options,
|
|
147
188
|
sx: {
|
|
@@ -154,6 +195,11 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
154
195
|
forcePopupIcon: "auto",
|
|
155
196
|
renderInput: function renderInput(params) {
|
|
156
197
|
return /*#__PURE__*/_react.default.createElement(_TextField.default, Object.assign({}, params, {
|
|
198
|
+
onKeyDown: function onKeyDown(event) {
|
|
199
|
+
if (!isInputAllowed(event.key)) {
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
}
|
|
202
|
+
},
|
|
157
203
|
required: required,
|
|
158
204
|
label: text,
|
|
159
205
|
size: size,
|
|
@@ -233,6 +279,11 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
233
279
|
size: size,
|
|
234
280
|
sx: getTextFieldStyle(),
|
|
235
281
|
placeholder: placeHolder,
|
|
282
|
+
onKeyDown: function onKeyDown(event) {
|
|
283
|
+
if (!isInputAllowed(event.key)) {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
}
|
|
286
|
+
},
|
|
236
287
|
required: required,
|
|
237
288
|
InputProps: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.InputProps), {}, {
|
|
238
289
|
style: {
|
|
@@ -257,6 +308,11 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
257
308
|
size: size,
|
|
258
309
|
sx: getTextFieldStyle(),
|
|
259
310
|
placeholder: placeHolder,
|
|
311
|
+
onKeyDown: function onKeyDown(event) {
|
|
312
|
+
if (!isInputAllowed(event.key)) {
|
|
313
|
+
event.preventDefault();
|
|
314
|
+
}
|
|
315
|
+
},
|
|
260
316
|
required: required,
|
|
261
317
|
InputLabelProps: {
|
|
262
318
|
style: {
|