oolib 2.29.4 → 2.29.6
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.
|
@@ -3,12 +3,22 @@ export function PasswordInput({ enableValidation, ...props }: {
|
|
|
3
3
|
[x: string]: any;
|
|
4
4
|
enableValidation?: boolean;
|
|
5
5
|
}): any;
|
|
6
|
-
export function EmailInput(props
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export function EmailInput({ passValidationErrorToFormValidation, ...props }: {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
passValidationErrorToFormValidation: any;
|
|
9
|
+
}): any;
|
|
10
|
+
export function PhoneInput({ passValidationErrorToFormValidation, ...props }: {
|
|
11
|
+
[x: string]: any;
|
|
12
|
+
passValidationErrorToFormValidation: any;
|
|
13
|
+
}): any;
|
|
14
|
+
export function URLInput({ routesAreValidInputs, validationPlugin, passValidationErrorToFormValidation, content, ...props }: {
|
|
9
15
|
[x: string]: any;
|
|
10
16
|
routesAreValidInputs?: boolean;
|
|
11
17
|
validationPlugin: any;
|
|
12
|
-
|
|
18
|
+
passValidationErrorToFormValidation: any;
|
|
19
|
+
content: any;
|
|
20
|
+
}): any;
|
|
21
|
+
export function NumberInput({ passValidationErrorToFormValidation, ...props }: {
|
|
22
|
+
[x: string]: any;
|
|
23
|
+
passValidationErrorToFormValidation: any;
|
|
13
24
|
}): any;
|
|
14
|
-
export function NumberInput(props: any): any;
|
|
@@ -97,13 +97,13 @@ var DisplayIcon = function (_a) {
|
|
|
97
97
|
return (react_1.default.createElement("div", { style: { cursor: onClick ? 'pointer' : '', display: 'flex' }, onMouseDown: onClick || null }, IconComp && react_1.default.createElement(IconComp, { size: size, weight: "bold" })));
|
|
98
98
|
};
|
|
99
99
|
var TextInput = function (props) {
|
|
100
|
-
var id = props.id, invert = props.invert, disabled = props.disabled, icon = props.icon, type = props.type, _a = props.placeholder, placeholder = _a === void 0 ? 'Enter Text...' : _a, _b = props.value, value = _b === void 0 ? '' : _b, onChange = props.onChange, onFocus = props.onFocus, readOnly = props.readOnly, iconOnClick = props.iconOnClick, eyeIcon = props.eyeIcon, S = props.S, validateOnBlur = props.validateOnBlur, actionBtn = props.actionBtn, className = props.className, maxLength = props.maxLength, DEPRECATED_maxNumLimiter = props.maxNumLimiter, forceFocus = props.forceFocus //sometimes, when some other elem is clicked, we wanna trigger focus on the textinput. eg. when on mobile, the search icon is clicked on the listingpage
|
|
100
|
+
var id = props.id, invert = props.invert, disabled = props.disabled, icon = props.icon, type = props.type, _a = props.placeholder, placeholder = _a === void 0 ? 'Enter Text...' : _a, _b = props.value, value = _b === void 0 ? '' : _b, onChange = props.onChange, onFocus = props.onFocus, readOnly = props.readOnly, iconOnClick = props.iconOnClick, eyeIcon = props.eyeIcon, S = props.S, validateOnBlur = props.validateOnBlur, validateOnMount = props.validateOnMount, actionBtn = props.actionBtn, className = props.className, maxLength = props.maxLength, DEPRECATED_maxNumLimiter = props.maxNumLimiter, forceFocus = props.forceFocus //sometimes, when some other elem is clicked, we wanna trigger focus on the textinput. eg. when on mobile, the search icon is clicked on the listingpage
|
|
101
101
|
;
|
|
102
102
|
var _c = (0, react_1.useState)(''), inputStatus = _c[0], setInputStatus = _c[1];
|
|
103
103
|
var composition = icon && !eyeIcon ? 'icon+text' : 'textOnly';
|
|
104
104
|
var size = S ? 'S' : 'M';
|
|
105
105
|
var actionBtnEnabaled = !!value && (type !== 'url' ? true : inputStatus.type === 'success');
|
|
106
|
-
var
|
|
106
|
+
var handleValidate = function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
107
|
var value, res;
|
|
108
108
|
return __generator(this, function (_a) {
|
|
109
109
|
switch (_a.label) {
|
|
@@ -123,12 +123,17 @@ var TextInput = function (props) {
|
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
}); };
|
|
126
|
+
(0, react_1.useEffect)(function () {
|
|
127
|
+
if (validateOnMount) {
|
|
128
|
+
handleValidate({ target: { value: value } });
|
|
129
|
+
}
|
|
130
|
+
}, [validateOnMount]);
|
|
126
131
|
var handleOnChange = function (e) {
|
|
127
132
|
onChange(id, e.target.value);
|
|
128
133
|
if (inputStatus) {
|
|
129
134
|
if (type === 'url')
|
|
130
135
|
return setInputStatus('');
|
|
131
|
-
|
|
136
|
+
handleValidate(e);
|
|
132
137
|
}
|
|
133
138
|
};
|
|
134
139
|
var inputRef = (0, react_1.useRef)(null);
|
|
@@ -143,7 +148,7 @@ var TextInput = function (props) {
|
|
|
143
148
|
readOnly ? (react_1.default.createElement(Typo_1.SANS_3, { invert: invert }, type === 'password' ? '********' : value)) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
144
149
|
react_1.default.createElement(index_styled_1.InputContainerStyled, { invert: invert, type: type, disabled: disabled, status: inputStatus === null || inputStatus === void 0 ? void 0 : inputStatus.type, eyeIcon: eyeIcon, composition: composition, onClick: function () { return inputRef.current.focus(); } },
|
|
145
150
|
icon && (react_1.default.createElement(DisplayIcon, { icon: icon, size: S ? 15 : 20, onClick: iconOnClick || null })),
|
|
146
|
-
react_1.default.createElement(index_styled_1.InputStyled, { ref: inputRef, className: size === 'S' ? 'SANS_2' : 'SANS_3', id: id, type: type, name: type, placeholder: placeholder, value: value, onChange: handleOnChange, maxLength: maxLength || DEPRECATED_maxNumLimiter, onBlur:
|
|
151
|
+
react_1.default.createElement(index_styled_1.InputStyled, { ref: inputRef, className: size === 'S' ? 'SANS_2' : 'SANS_3', id: id, type: type, name: type, placeholder: placeholder, value: value, onChange: handleOnChange, maxLength: maxLength || DEPRECATED_maxNumLimiter, onBlur: handleValidate, onFocus: onFocus, size: size, autoComplete: 'off' }),
|
|
147
152
|
inputStatus === 'loading' && (react_1.default.createElement("div", null,
|
|
148
153
|
react_1.default.createElement(LoadersAndProgress_1.LoaderCircle, { S: true, invert: invert }))),
|
|
149
154
|
actionBtn && (react_1.default.createElement(Buttons_1.ButtonPrimary, { value: actionBtn.text, invert: actionBtn.invert, onClick: actionBtnEnabaled && actionBtn.onClick, disabled: !actionBtnEnabaled, style: { marginRight: '-2rem' } }))),
|
|
@@ -154,6 +159,7 @@ var TextInput = function (props) {
|
|
|
154
159
|
react_1.default.createElement(OKELink_1.OKELink, { style: { marginLeft: '1rem' }, to: inputStatus.link.to }, inputStatus.link.text)))))))));
|
|
155
160
|
};
|
|
156
161
|
exports.TextInput = TextInput;
|
|
162
|
+
//passValidationErrorToFormValidation is not being handled by PasswordInput, cuz i dont think we will need it here..
|
|
157
163
|
var PasswordInput = function (_a) {
|
|
158
164
|
var _b = _a.enableValidation, enableValidation = _b === void 0 ? true : _b, props = __rest(_a, ["enableValidation"]);
|
|
159
165
|
var _c = (0, react_1.useState)(false), showPassword = _c[0], setShowPassword = _c[1];
|
|
@@ -191,38 +197,54 @@ var PasswordInput = function (_a) {
|
|
|
191
197
|
return (react_1.default.createElement(exports.TextInput, __assign({ placeholder: 'Enter password...', type: showPassword ? 'text' : 'password', iconOnClick: toggleShowPassword, eyeIcon: true, icon: icon, validateOnBlur: enableValidation && handleValidation }, props)));
|
|
192
198
|
};
|
|
193
199
|
exports.PasswordInput = PasswordInput;
|
|
194
|
-
var EmailInput = function (
|
|
200
|
+
var EmailInput = function (_a) {
|
|
201
|
+
var passValidationErrorToFormValidation = _a.passValidationErrorToFormValidation, props = __rest(_a, ["passValidationErrorToFormValidation"]);
|
|
195
202
|
var handleValidation = function (value) {
|
|
196
203
|
var regEx = /^(([^<>()[\]\\.,;:\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,}))$/;
|
|
197
|
-
|
|
204
|
+
var errorObj = regEx.test(value)
|
|
198
205
|
? ''
|
|
199
206
|
: { type: 'error', msg: 'Enter a valid email address' };
|
|
207
|
+
if (passValidationErrorToFormValidation) {
|
|
208
|
+
passValidationErrorToFormValidation((errorObj === null || errorObj === void 0 ? void 0 : errorObj.type) || 'success');
|
|
209
|
+
}
|
|
210
|
+
return errorObj;
|
|
200
211
|
};
|
|
201
212
|
return (react_1.default.createElement(exports.TextInput, __assign({ type: "email", placeholder: 'Enter email...', validateOnBlur: handleValidation }, props)));
|
|
202
213
|
};
|
|
203
214
|
exports.EmailInput = EmailInput;
|
|
204
|
-
var PhoneInput = function (
|
|
215
|
+
var PhoneInput = function (_a) {
|
|
216
|
+
var passValidationErrorToFormValidation = _a.passValidationErrorToFormValidation, props = __rest(_a, ["passValidationErrorToFormValidation"]);
|
|
205
217
|
var handleValidation = function (value) {
|
|
218
|
+
var errorObj;
|
|
206
219
|
if (isNaN(value)) {
|
|
207
|
-
|
|
220
|
+
errorObj = { type: 'error', msg: 'Enter a valid phone number' };
|
|
221
|
+
if (passValidationErrorToFormValidation)
|
|
222
|
+
passValidationErrorToFormValidation(errorObj.type);
|
|
223
|
+
return errorObj;
|
|
208
224
|
}
|
|
209
225
|
if (value.length < 10) {
|
|
210
|
-
|
|
226
|
+
errorObj = { type: 'error', msg: 'Enter a valid phone number' };
|
|
227
|
+
if (passValidationErrorToFormValidation)
|
|
228
|
+
passValidationErrorToFormValidation(errorObj.type);
|
|
229
|
+
return errorObj;
|
|
211
230
|
}
|
|
231
|
+
//else
|
|
232
|
+
if (passValidationErrorToFormValidation)
|
|
233
|
+
passValidationErrorToFormValidation('success');
|
|
212
234
|
};
|
|
213
235
|
return (react_1.default.createElement(exports.TextInput, __assign({ type: "tel", placeholder: 'Enter Phone...', validateOnBlur: handleValidation, maxLength: 10 }, props)));
|
|
214
236
|
};
|
|
215
237
|
exports.PhoneInput = PhoneInput;
|
|
216
238
|
var URLInput = function (_a) {
|
|
217
239
|
var _b = _a.routesAreValidInputs, routesAreValidInputs = _b === void 0 ? false : _b, //if we want react route declarations to be considered as 'valid' then set this to true
|
|
218
|
-
validationPlugin = _a.validationPlugin,
|
|
240
|
+
validationPlugin = _a.validationPlugin, passValidationErrorToFormValidation = _a.passValidationErrorToFormValidation, content = _a.content, props = __rest(_a, ["routesAreValidInputs", "validationPlugin", "passValidationErrorToFormValidation", "content"]);
|
|
219
241
|
var handleValidation = function (value) { return __awaiter(void 0, void 0, void 0, function () {
|
|
220
|
-
var pluginResponse, response, err_1;
|
|
242
|
+
var pluginResponse, successObj, response, successObj, err_1, successObj, errorObj;
|
|
221
243
|
return __generator(this, function (_a) {
|
|
222
244
|
switch (_a.label) {
|
|
223
245
|
case 0:
|
|
224
246
|
if (!validationPlugin) return [3 /*break*/, 2];
|
|
225
|
-
return [4 /*yield*/, validationPlugin(value)];
|
|
247
|
+
return [4 /*yield*/, validationPlugin({ value: value, content: content, passValidationErrorToFormValidation: passValidationErrorToFormValidation })];
|
|
226
248
|
case 1:
|
|
227
249
|
pluginResponse = _a.sent();
|
|
228
250
|
if (pluginResponse)
|
|
@@ -232,7 +254,10 @@ var URLInput = function (_a) {
|
|
|
232
254
|
//else
|
|
233
255
|
//if routesAreValidInputs, then first validate for a route
|
|
234
256
|
if (routesAreValidInputs && value.substring(0, 1) === '/') {
|
|
235
|
-
|
|
257
|
+
successObj = { type: 'success', msg: 'valid route' };
|
|
258
|
+
if (passValidationErrorToFormValidation)
|
|
259
|
+
passValidationErrorToFormValidation(successObj.type);
|
|
260
|
+
return [2 /*return*/, successObj];
|
|
236
261
|
}
|
|
237
262
|
//else validate for a url
|
|
238
263
|
if (!/^https?:\/\//i.test(value)) {
|
|
@@ -246,37 +271,55 @@ var URLInput = function (_a) {
|
|
|
246
271
|
response = _a.sent();
|
|
247
272
|
if (response.status !== 200)
|
|
248
273
|
throw new Error('');
|
|
249
|
-
|
|
274
|
+
successObj = { type: 'success', msg: 'valid url' };
|
|
275
|
+
if (passValidationErrorToFormValidation)
|
|
276
|
+
passValidationErrorToFormValidation(successObj.type);
|
|
277
|
+
return [2 /*return*/, successObj];
|
|
250
278
|
case 5:
|
|
251
279
|
err_1 = _a.sent();
|
|
252
280
|
if (/[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/ig.test(value)) {
|
|
253
|
-
|
|
281
|
+
successObj = { type: 'success', msg: 'valid url' };
|
|
282
|
+
if (passValidationErrorToFormValidation)
|
|
283
|
+
passValidationErrorToFormValidation(successObj.type);
|
|
284
|
+
return [2 /*return*/, successObj];
|
|
254
285
|
}
|
|
255
|
-
|
|
286
|
+
errorObj = { type: 'error', msg: 'Enter a valid url...' };
|
|
287
|
+
if (passValidationErrorToFormValidation)
|
|
288
|
+
passValidationErrorToFormValidation(errorObj.type);
|
|
289
|
+
return [2 /*return*/, errorObj];
|
|
256
290
|
case 6: return [2 /*return*/];
|
|
257
291
|
}
|
|
258
292
|
});
|
|
259
293
|
}); };
|
|
260
|
-
(0, react_1.useEffect)(function () {
|
|
261
|
-
if (props.value && validateOnMount) {
|
|
262
|
-
handleValidation(props.value);
|
|
263
|
-
}
|
|
264
|
-
}, [validateOnMount, props.value]);
|
|
265
294
|
return (react_1.default.createElement(exports.TextInput, __assign({ type: "url", validateOnBlur: handleValidation, placeholder: "Enter a valid url..." }, props)));
|
|
266
295
|
};
|
|
267
296
|
exports.URLInput = URLInput;
|
|
268
|
-
var NumberInput = function (
|
|
297
|
+
var NumberInput = function (_a) {
|
|
298
|
+
var passValidationErrorToFormValidation = _a.passValidationErrorToFormValidation, props = __rest(_a, ["passValidationErrorToFormValidation"]);
|
|
269
299
|
var min = props.min, max = props.max;
|
|
270
300
|
var handleValidation = function (value) {
|
|
301
|
+
var errorObj;
|
|
271
302
|
if (isNaN(value)) {
|
|
272
|
-
|
|
303
|
+
errorObj = { type: 'error', msg: 'Enter a number' };
|
|
304
|
+
if (passValidationErrorToFormValidation)
|
|
305
|
+
passValidationErrorToFormValidation(errorObj.type);
|
|
306
|
+
return errorObj;
|
|
273
307
|
}
|
|
274
308
|
if (min && value < min) {
|
|
275
|
-
|
|
309
|
+
errorObj = { type: 'error', msg: "Enter value greater than ".concat(min) };
|
|
310
|
+
if (passValidationErrorToFormValidation)
|
|
311
|
+
passValidationErrorToFormValidation(errorObj.type);
|
|
312
|
+
return errorObj;
|
|
276
313
|
}
|
|
277
314
|
if (max && value > max) {
|
|
278
|
-
|
|
315
|
+
errorObj = { type: 'error', msg: "Enter value less than ".concat(max) };
|
|
316
|
+
if (passValidationErrorToFormValidation)
|
|
317
|
+
passValidationErrorToFormValidation(errorObj.type);
|
|
318
|
+
return errorObj;
|
|
279
319
|
}
|
|
320
|
+
//else
|
|
321
|
+
if (passValidationErrorToFormValidation)
|
|
322
|
+
passValidationErrorToFormValidation('success');
|
|
280
323
|
};
|
|
281
324
|
return (react_1.default.createElement(exports.TextInput
|
|
282
325
|
// type="number"
|