@prom-ui/core 0.0.110 → 0.0.121

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 (67) hide show
  1. package/Avatar/package.json +1 -1
  2. package/Body/package.json +1 -1
  3. package/Box/package.json +1 -1
  4. package/Button/package.json +1 -1
  5. package/ButtonPageUp/package.json +1 -1
  6. package/Checkbox/package.json +1 -1
  7. package/Flex/package.json +1 -1
  8. package/Grid/package.json +1 -1
  9. package/Icon/cjs/index.development.js +2 -2
  10. package/Icon/cjs/index.development.v2.js +2 -2
  11. package/Icon/cjs/index.production.js +1 -1
  12. package/Icon/cjs/index.production.v2.js +1 -1
  13. package/Icon/cjs/style.development.css +1 -1
  14. package/Icon/cjs/style.development.v2.css +1 -1
  15. package/Icon/cjs/style.production.css +1 -1
  16. package/Icon/cjs/style.production.v2.css +1 -1
  17. package/Icon/index.d.ts +3 -1
  18. package/Icon/package.json +1 -1
  19. package/Image/package.json +1 -1
  20. package/ImageEmoji/package.json +1 -1
  21. package/Input/cjs/style.development.css +1 -1
  22. package/Input/cjs/style.development.v2.css +1 -1
  23. package/Input/cjs/style.production.css +1 -1
  24. package/Input/cjs/style.production.v2.css +1 -1
  25. package/Input/package.json +1 -1
  26. package/InputField/addons/AfterClearValue.d.ts +3 -0
  27. package/InputField/addons/AfterCorrectValue.d.ts +2 -0
  28. package/InputField/addons/AfterLoading.d.ts +2 -0
  29. package/InputField/addons/AfterTogglePassword.d.ts +6 -0
  30. package/InputField/addons/ErrorText.d.ts +5 -0
  31. package/InputField/cjs/index.development.js +427 -0
  32. package/InputField/cjs/index.development.v2.js +427 -0
  33. package/InputField/cjs/index.production.js +1 -0
  34. package/InputField/cjs/index.production.v2.js +1 -0
  35. package/InputField/cjs/style.development.css +1 -0
  36. package/InputField/cjs/style.development.v2.css +1 -0
  37. package/InputField/cjs/style.production.css +1 -0
  38. package/InputField/cjs/style.production.v2.css +1 -0
  39. package/InputField/index.d.ts +16 -0
  40. package/InputField/index.js +7 -0
  41. package/InputField/index.v2.js +7 -0
  42. package/InputField/package.json +9 -0
  43. package/InputField/utils.d.ts +6 -0
  44. package/KeyPress/package.json +1 -1
  45. package/Line/package.json +1 -1
  46. package/Link/package.json +1 -1
  47. package/List/package.json +1 -1
  48. package/Media/package.json +1 -1
  49. package/OutsideClick/package.json +1 -1
  50. package/Overlay/package.json +1 -1
  51. package/Picture/package.json +1 -1
  52. package/PortableOverlay/package.json +1 -1
  53. package/Portal/package.json +1 -1
  54. package/QRCode/package.json +1 -1
  55. package/Rating/package.json +1 -1
  56. package/SafeQuery/package.json +1 -1
  57. package/Scroll/package.json +1 -1
  58. package/ScrollControls/package.json +1 -1
  59. package/SideOverlay/package.json +1 -1
  60. package/SimpleSlider/package.json +1 -1
  61. package/Skeleton/package.json +1 -1
  62. package/Spinner/package.json +1 -1
  63. package/Text/package.json +1 -1
  64. package/TextEmoji/package.json +1 -1
  65. package/Tooltip/package.json +1 -1
  66. package/Tumbler/package.json +1 -1
  67. package/package.json +2 -2
@@ -0,0 +1,427 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var Input = require('@prom-ui/core/Input');
7
+ var Button = require('@prom-ui/core/Button');
8
+ var Icon = require('@prom-ui/core/Icon');
9
+ var EyeOpen = require('@prom-ui/icons/EyeOpen');
10
+ var EyeClose = require('@prom-ui/icons/EyeClose');
11
+ var Spinner = require('@prom-ui/core/Spinner');
12
+ var Ok = require('@prom-ui/icons/Ok');
13
+ var Cancel = require('@prom-ui/icons/Cancel');
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n["default"] = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
34
+
35
+ /******************************************************************************
36
+ Copyright (c) Microsoft Corporation.
37
+
38
+ Permission to use, copy, modify, and/or distribute this software for any
39
+ purpose with or without fee is hereby granted.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
42
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
43
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
44
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
45
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
46
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
47
+ PERFORMANCE OF THIS SOFTWARE.
48
+ ***************************************************************************** */
49
+
50
+ var __assign = function() {
51
+ __assign = Object.assign || function __assign(t) {
52
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
53
+ s = arguments[i];
54
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
55
+ }
56
+ return t;
57
+ };
58
+ return __assign.apply(this, arguments);
59
+ };
60
+
61
+ function __rest(s, e) {
62
+ var t = {};
63
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
64
+ t[p] = s[p];
65
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
66
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
67
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
68
+ t[p[i]] = s[p[i]];
69
+ }
70
+ return t;
71
+ }
72
+
73
+ var AfterTogglePassword = function (_a) {
74
+ var inputType = _a.inputType,
75
+ onChange = _a.onChange;
76
+
77
+ if (inputType === 'text') {
78
+ return React__namespace.createElement(Button.Button, {
79
+ type: 'button',
80
+ "button-height": '1-1',
81
+ "button-width": '1-1',
82
+ "button-padding": 'none',
83
+ onClick: function () {
84
+ return onChange('password');
85
+ },
86
+ title: '\u0421\u043A\u0440\u044B\u0442\u044C \u043F\u0430\u0440\u043E\u043B\u044C',
87
+ tabIndex: -1,
88
+ "data-qaid": 'input_field_hide_password',
89
+ "data-testid": 'input_field_hide_password'
90
+ }, React__namespace.createElement(Icon.Icon, {
91
+ "icon-as": EyeOpen.SvgEyeOpen,
92
+ "icon-color": 'black-700',
93
+ "icon-events": 'none',
94
+ style: {
95
+ width: 16,
96
+ height: 16
97
+ }
98
+ }));
99
+ }
100
+
101
+ return React__namespace.createElement(Button.Button, {
102
+ type: 'button',
103
+ "button-height": '1-1',
104
+ "button-width": '1-1',
105
+ "button-padding": 'none',
106
+ onClick: function () {
107
+ return onChange('text');
108
+ },
109
+ title: '\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u043F\u0430\u0440\u043E\u043B\u044C',
110
+ tabIndex: -1,
111
+ "data-qaid": 'input_field_show_password',
112
+ "data-testid": 'input_field_show_password'
113
+ }, React__namespace.createElement(Icon.Icon, {
114
+ "icon-as": EyeClose.SvgEyeClose,
115
+ "icon-color": 'black-600',
116
+ "icon-events": 'none',
117
+ style: {
118
+ width: 16,
119
+ height: 16
120
+ }
121
+ }));
122
+ };
123
+
124
+ var AfterLoading = function () {
125
+ return React__namespace.createElement(Spinner.Spinner, {
126
+ "spinner-color": 'violet-500',
127
+ width: 16,
128
+ height: 16,
129
+ "data-qaid": 'input_field_loading',
130
+ "data-testid": 'input_field_loading'
131
+ });
132
+ };
133
+
134
+ var AfterCorrectValue = function () {
135
+ return React__namespace.createElement(Icon.Icon, {
136
+ "icon-as": Ok.SvgOk,
137
+ "icon-color": 'green-800',
138
+ "icon-events": 'none',
139
+ "data-qaid": 'input_field_correct_value',
140
+ "data-testid": 'input_field_correct_value',
141
+ style: {
142
+ width: 16,
143
+ height: 16
144
+ }
145
+ });
146
+ };
147
+
148
+ var AfterClearValue = function (props) {
149
+ return React__namespace.createElement(Button.Button, __assign({
150
+ type: 'button',
151
+ "button-height": '1-1',
152
+ "button-width": '1-1',
153
+ "button-padding": 'none',
154
+ title: '\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C',
155
+ tabIndex: -1,
156
+ "data-qaid": 'input_field_clear_value',
157
+ "data-testid": 'input_field_clear_value'
158
+ }, props), React__namespace.createElement(Icon.Icon, {
159
+ "icon-as": Cancel.SvgCancel,
160
+ "icon-color": 'black-600',
161
+ "icon-events": 'none',
162
+ style: {
163
+ width: 16,
164
+ height: 16
165
+ }
166
+ }));
167
+ };
168
+
169
+ var css = {"root":"InputField__root___UnXum","input":"InputField__input___1Wl0O","beforeAndAfter":"InputField__beforeAndAfter___cUXq3","before":"InputField__before___-TbcG InputField__beforeAndAfter___cUXq3","after":"InputField__after___QmiGS InputField__beforeAndAfter___cUXq3","error":"InputField__error___7Fcq2","label":"InputField__label___uV711","labelRequired":"InputField__labelRequired___cxqrg"};
170
+
171
+ var ErrorText = function (_a) {
172
+ var children = _a.children;
173
+ return React__namespace.createElement("div", {
174
+ className: css.error,
175
+ "data-qaid": 'input_field_error',
176
+ "data-testid": 'input_field_error'
177
+ }, children);
178
+ };
179
+
180
+ function resolveOnChange(target, e, onChange, targetValue) {
181
+ if (!onChange) {
182
+ return;
183
+ }
184
+
185
+ var event = e;
186
+
187
+ if (e.type === 'click') {
188
+ // Clone a new target for event.
189
+ // Avoid the following usage, the setQuery method gets the original value.
190
+ //
191
+ // const [query, setQuery] = React.useState('');
192
+ // <InputField
193
+ // value={query}
194
+ // onChange={(e)=> {
195
+ // setQuery((prevStatus) => e.target.value);
196
+ // }}
197
+ // />
198
+ var currentTarget = target.cloneNode(true); // Click clear button
199
+
200
+ event = Object.create(e, {
201
+ target: {
202
+ value: currentTarget
203
+ },
204
+ currentTarget: {
205
+ value: currentTarget
206
+ }
207
+ });
208
+ currentTarget.value = '';
209
+ onChange(event);
210
+ return;
211
+ } // Trigger by composition event, this means we need force change the input value
212
+
213
+
214
+ if (targetValue !== undefined) {
215
+ event = Object.create(e, {
216
+ target: {
217
+ value: target
218
+ },
219
+ currentTarget: {
220
+ value: target
221
+ }
222
+ });
223
+ target.value = targetValue;
224
+ onChange(event);
225
+ return;
226
+ }
227
+
228
+ onChange(event);
229
+ }
230
+ function valueToString(value) {
231
+ if (Number.isInteger(value)) {
232
+ return "".concat(value);
233
+ }
234
+
235
+ if (!value) {
236
+ return '';
237
+ }
238
+
239
+ return "".concat(value);
240
+ }
241
+ function isNotEmptyArray(arr) {
242
+ return Array.isArray(arr) && arr.length > 0;
243
+ }
244
+ function getIsValueEmpty(value) {
245
+ return valueToString(value).length <= 0;
246
+ }
247
+ var useForwardRef = function (ref, initialValue) {
248
+ if (initialValue === void 0) {
249
+ initialValue = null;
250
+ }
251
+
252
+ var targetRef = React__namespace.useRef(initialValue);
253
+ React__namespace.useEffect(function () {
254
+ if (!ref) return;
255
+
256
+ if (typeof ref === 'function') {
257
+ ref(targetRef.current);
258
+ } else {
259
+ ref.current = targetRef.current;
260
+ }
261
+ }, [ref]);
262
+ return targetRef;
263
+ };
264
+
265
+ var InputField = React__namespace.forwardRef(function (_a, ref) {
266
+ var addonBefore = _a.addonBefore,
267
+ addonAfter = _a.addonAfter,
268
+ _b = _a.addonBeforeWidth,
269
+ addonBeforeWidth = _b === void 0 ? 40 : _b,
270
+ _c = _a.addonAfterWidth,
271
+ addonAfterWidth = _c === void 0 ? 40 : _c,
272
+ _d = _a.error,
273
+ error = _d === void 0 ? false : _d,
274
+ label = _a.label,
275
+ isLabelRequired = _a.isLabelRequired,
276
+ props = __rest(_a, ["addonBefore", "addonAfter", "addonBeforeWidth", "addonAfterWidth", "error", "label", "isLabelRequired"]);
277
+
278
+ var isMounted = React__namespace.useRef(false);
279
+ var isSkipOnFocus = React__namespace.useRef(false);
280
+ var isSkipOnBlur = React__namespace.useRef(false);
281
+ var inputRef = useForwardRef(ref, null);
282
+
283
+ var _e = React__namespace.useState(props.type),
284
+ localType = _e[0],
285
+ setLocalType = _e[1];
286
+
287
+ var _f = React__namespace.useState(getIsValueEmpty(props.value || props.defaultValue)),
288
+ isValueEmpty = _f[0],
289
+ setIsValueEmpty = _f[1];
290
+
291
+ React__namespace.useEffect(function () {
292
+ if (isMounted.current) {
293
+ var nextIsValueEmpty = getIsValueEmpty(props.value);
294
+
295
+ if (nextIsValueEmpty !== isValueEmpty) {
296
+ setIsValueEmpty(nextIsValueEmpty);
297
+ }
298
+ } else {
299
+ isMounted.current = true;
300
+ }
301
+ }, [props.value]);
302
+ var currentAddonAfter = null;
303
+
304
+ if (props.type === 'password' && addonAfter === 'togglePassword') {
305
+ currentAddonAfter = React__namespace.createElement(AfterTogglePassword, {
306
+ inputType: localType,
307
+ onChange: function (type) {
308
+ return setLocalType(type);
309
+ }
310
+ });
311
+ } else if (addonAfter === 'clearValue') {
312
+ currentAddonAfter = isValueEmpty ? null : React__namespace.createElement(AfterClearValue, {
313
+ onClick: function (e) {
314
+ var _a;
315
+
316
+ if (!getIsValueEmpty(props.value) && !props.onChange) {
317
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
318
+ return;
319
+ }
320
+
321
+ if (inputRef.current) {
322
+ setIsValueEmpty(true);
323
+ inputRef.current.focus();
324
+ resolveOnChange(inputRef.current, e, props.onChange);
325
+
326
+ if (getIsValueEmpty(props.value)) {
327
+ inputRef.current.value = '';
328
+ }
329
+ }
330
+ },
331
+ onMouseEnter: function () {
332
+ isSkipOnFocus.current = true;
333
+ isSkipOnBlur.current = true;
334
+ },
335
+ onTouchStart: function () {
336
+ isSkipOnFocus.current = true;
337
+ isSkipOnBlur.current = true;
338
+ },
339
+ onMouseLeave: function () {
340
+ isSkipOnFocus.current = false;
341
+ isSkipOnBlur.current = false;
342
+ },
343
+ onTouchEnd: function () {
344
+ isSkipOnFocus.current = false;
345
+ isSkipOnBlur.current = false;
346
+ }
347
+ });
348
+ } else if (addonAfter === 'correctValue') {
349
+ currentAddonAfter = React__namespace.createElement(AfterCorrectValue, null);
350
+ } else if (addonAfter === 'loading') {
351
+ currentAddonAfter = React__namespace.createElement(AfterLoading, null);
352
+ } else {
353
+ currentAddonAfter = addonAfter;
354
+ }
355
+
356
+ var isLabel = !!label;
357
+ var isBefore = !!addonBefore;
358
+ var isAfter = !!currentAddonAfter;
359
+ var isError = isNotEmptyArray(error) || !!error;
360
+ return React__namespace.createElement("div", {
361
+ className: props.className,
362
+ style: props.style,
363
+ "data-qaid": props['data-qaid'] || 'input_field',
364
+ "data-testid": props['data-testid'] || 'input_field'
365
+ }, isLabel && React__namespace.createElement("div", {
366
+ className: css.label
367
+ }, React__namespace.createElement("label", {
368
+ "data-qaid": 'input_field_label',
369
+ "data-testid": 'input_field_label',
370
+ htmlFor: props.id
371
+ }, label), !!isLabelRequired && React__namespace.createElement(React__namespace.Fragment, null, "\u00A0", React__namespace.createElement("span", {
372
+ className: css.labelRequired,
373
+ "data-qaid": 'input_field_label_required',
374
+ "data-testid": 'input_field_label_required'
375
+ }, "*"))), React__namespace.createElement("div", {
376
+ className: css.root
377
+ }, React__namespace.createElement(Input.Input, __assign({
378
+ ref: inputRef,
379
+ "input-theme": isError ? 'red' : 'white'
380
+ }, props, {
381
+ "data-qaid": 'input_field_textbox',
382
+ "data-testid": 'input_field_textbox',
383
+ style: {
384
+ paddingLeft: isBefore ? addonBeforeWidth : undefined,
385
+ paddingRight: isAfter ? addonAfterWidth : undefined
386
+ },
387
+ className: css.input,
388
+ type: localType,
389
+ onFocus: function (e) {
390
+ if (!isSkipOnFocus.current && props.onFocus) {
391
+ props.onFocus(e);
392
+ }
393
+
394
+ isSkipOnFocus.current = false;
395
+ },
396
+ onBlur: function (e) {
397
+ if (!isSkipOnBlur.current && props.onBlur) {
398
+ props.onBlur(e);
399
+ }
400
+
401
+ isSkipOnBlur.current = false;
402
+ },
403
+ onChange: function (e) {
404
+ setIsValueEmpty(getIsValueEmpty(e.target.value));
405
+ resolveOnChange(e.currentTarget, e, props.onChange);
406
+ }
407
+ })), isBefore && React__namespace.createElement("div", {
408
+ className: css.before,
409
+ style: {
410
+ width: addonBeforeWidth
411
+ }
412
+ }, addonBefore), isAfter && React__namespace.createElement("div", {
413
+ className: css.after,
414
+ style: {
415
+ width: addonAfterWidth
416
+ }
417
+ }, currentAddonAfter)), isError && (Array.isArray(error) ? error.map(function (errorItem) {
418
+ return React__namespace.createElement(ErrorText, {
419
+ key: errorItem
420
+ }, errorItem);
421
+ }) : error === true ? null : React__namespace.createElement(ErrorText, null, error)));
422
+ });
423
+ InputField.displayName = 'InputField';
424
+
425
+ exports.InputField = InputField;
426
+
427
+ require('./style.development.css');