oolib 2.29.4 → 2.29.5

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: any): any;
7
- export function PhoneInput(props: any): any;
8
- export function URLInput({ routesAreValidInputs, validationPlugin, validateOnMount, ...props }: {
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
- validateOnMount: any;
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 handleValidateOnBlur = function (e) { return __awaiter(void 0, void 0, void 0, function () {
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
- handleValidateOnBlur(e);
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: handleValidateOnBlur, onFocus: onFocus, size: size, autoComplete: 'off' }),
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,23 +197,35 @@ 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 (props) {
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
- return regEx.test(value)
204
+ var errorObj = regEx.test(value)
198
205
  ? ''
199
206
  : { type: 'error', msg: 'Enter a valid email address' };
207
+ if (errorObj && passValidationErrorToFormValidation)
208
+ passValidationErrorToFormValidation(errorObj);
209
+ return errorObj;
200
210
  };
201
211
  return (react_1.default.createElement(exports.TextInput, __assign({ type: "email", placeholder: 'Enter email...', validateOnBlur: handleValidation }, props)));
202
212
  };
203
213
  exports.EmailInput = EmailInput;
204
- var PhoneInput = function (props) {
214
+ var PhoneInput = function (_a) {
215
+ var passValidationErrorToFormValidation = _a.passValidationErrorToFormValidation, props = __rest(_a, ["passValidationErrorToFormValidation"]);
205
216
  var handleValidation = function (value) {
217
+ var errorObj;
206
218
  if (isNaN(value)) {
207
- return { type: 'error', msg: 'Enter a valid phone number' };
219
+ errorObj = { type: 'error', msg: 'Enter a valid phone number' };
220
+ if (passValidationErrorToFormValidation)
221
+ passValidationErrorToFormValidation(errorObj);
222
+ return errorObj;
208
223
  }
209
224
  if (value.length < 10) {
210
- return { type: 'error', msg: 'Enter a valid phone number' };
225
+ errorObj = { type: 'error', msg: 'Enter a valid phone number' };
226
+ if (passValidationErrorToFormValidation)
227
+ passValidationErrorToFormValidation(errorObj);
228
+ return errorObj;
211
229
  }
212
230
  };
213
231
  return (react_1.default.createElement(exports.TextInput, __assign({ type: "tel", placeholder: 'Enter Phone...', validateOnBlur: handleValidation, maxLength: 10 }, props)));
@@ -215,14 +233,14 @@ var PhoneInput = function (props) {
215
233
  exports.PhoneInput = PhoneInput;
216
234
  var URLInput = function (_a) {
217
235
  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, validateOnMount = _a.validateOnMount, props = __rest(_a, ["routesAreValidInputs", "validationPlugin", "validateOnMount"]);
236
+ validationPlugin = _a.validationPlugin, passValidationErrorToFormValidation = _a.passValidationErrorToFormValidation, content = _a.content, props = __rest(_a, ["routesAreValidInputs", "validationPlugin", "passValidationErrorToFormValidation", "content"]);
219
237
  var handleValidation = function (value) { return __awaiter(void 0, void 0, void 0, function () {
220
- var pluginResponse, response, err_1;
238
+ var pluginResponse, response, err_1, errorObj;
221
239
  return __generator(this, function (_a) {
222
240
  switch (_a.label) {
223
241
  case 0:
224
242
  if (!validationPlugin) return [3 /*break*/, 2];
225
- return [4 /*yield*/, validationPlugin(value)];
243
+ return [4 /*yield*/, validationPlugin({ value: value, content: content, passValidationErrorToFormValidation: passValidationErrorToFormValidation })];
226
244
  case 1:
227
245
  pluginResponse = _a.sent();
228
246
  if (pluginResponse)
@@ -252,30 +270,39 @@ var URLInput = function (_a) {
252
270
  if (/[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/ig.test(value)) {
253
271
  return [2 /*return*/, { type: 'success', msg: 'valid url' }];
254
272
  }
255
- return [2 /*return*/, { type: 'error', msg: 'Enter a valid url...' }];
273
+ errorObj = { type: 'error', msg: 'Enter a valid url...' };
274
+ if (passValidationErrorToFormValidation)
275
+ passValidationErrorToFormValidation(errorObj);
276
+ return [2 /*return*/, errorObj];
256
277
  case 6: return [2 /*return*/];
257
278
  }
258
279
  });
259
280
  }); };
260
- (0, react_1.useEffect)(function () {
261
- if (props.value && validateOnMount) {
262
- handleValidation(props.value);
263
- }
264
- }, [validateOnMount, props.value]);
265
281
  return (react_1.default.createElement(exports.TextInput, __assign({ type: "url", validateOnBlur: handleValidation, placeholder: "Enter a valid url..." }, props)));
266
282
  };
267
283
  exports.URLInput = URLInput;
268
- var NumberInput = function (props) {
284
+ var NumberInput = function (_a) {
285
+ var passValidationErrorToFormValidation = _a.passValidationErrorToFormValidation, props = __rest(_a, ["passValidationErrorToFormValidation"]);
269
286
  var min = props.min, max = props.max;
270
287
  var handleValidation = function (value) {
288
+ var errorObj;
271
289
  if (isNaN(value)) {
272
- return { type: 'error', msg: 'Enter a number' };
290
+ errorObj = { type: 'error', msg: 'Enter a number' };
291
+ if (passValidationErrorToFormValidation)
292
+ passValidationErrorToFormValidation(errorObj);
293
+ return errorObj;
273
294
  }
274
295
  if (min && value < min) {
275
- return { type: 'error', msg: "Enter value greater than ".concat(min) };
296
+ errorObj = { type: 'error', msg: "Enter value greater than ".concat(min) };
297
+ if (passValidationErrorToFormValidation)
298
+ passValidationErrorToFormValidation(errorObj);
299
+ return errorObj;
276
300
  }
277
301
  if (max && value > max) {
278
- return { type: 'error', msg: "Enter value less than ".concat(max) };
302
+ errorObj = { type: 'error', msg: "Enter value less than ".concat(max) };
303
+ if (passValidationErrorToFormValidation)
304
+ passValidationErrorToFormValidation(errorObj);
305
+ return errorObj;
279
306
  }
280
307
  };
281
308
  return (react_1.default.createElement(exports.TextInput
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.29.4",
3
+ "version": "2.29.5",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",