@telus-uds/components-base 1.28.0 → 1.30.0
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.
- package/CHANGELOG.md +20 -2
- package/component-docs.json +76 -2
- package/lib/TextInput/TextInputBase.js +34 -11
- package/lib/TextInput/dictionary.js +6 -2
- package/lib/TooltipButton/TooltipButton.js +4 -5
- package/lib/Validator/Validator.js +272 -0
- package/lib/Validator/index.js +13 -0
- package/lib/index.js +9 -0
- package/lib/utils/props/handlerProps.js +6 -1
- package/lib-module/TextInput/TextInputBase.js +34 -11
- package/lib-module/TextInput/dictionary.js +6 -2
- package/lib-module/TooltipButton/TooltipButton.js +4 -5
- package/lib-module/Validator/Validator.js +246 -0
- package/lib-module/Validator/index.js +2 -0
- package/lib-module/index.js +1 -0
- package/lib-module/utils/props/handlerProps.js +6 -1
- package/package.json +2 -2
- package/src/TextInput/TextInputBase.jsx +44 -9
- package/src/TextInput/dictionary.js +6 -2
- package/src/TooltipButton/TooltipButton.jsx +3 -3
- package/src/Validator/Validator.jsx +217 -0
- package/src/Validator/index.js +3 -0
- package/src/index.js +1 -0
- package/src/utils/props/handlerProps.js +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
# Change Log - @telus-uds/components-base
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 20 Mar 2023 19:41:55 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.30.0
|
|
8
|
+
|
|
9
|
+
Mon, 20 Mar 2023 19:41:55 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Password variant added to PM, koodo, Telus and Rebrand-PM (akshay.pandey1@telus.com)
|
|
14
|
+
- Bump @telus-uds/system-theme-tokens to v2.13.0
|
|
15
|
+
|
|
16
|
+
## 1.29.0
|
|
17
|
+
|
|
18
|
+
Tue, 07 Mar 2023 21:13:39 GMT
|
|
19
|
+
|
|
20
|
+
### Minor changes
|
|
21
|
+
|
|
22
|
+
- Tooltipbutton hover behavior and pressbehior fix + pm rebrand (akshay.pandey@telus.com)
|
|
23
|
+
- Bump @telus-uds/system-theme-tokens to v2.12.0
|
|
24
|
+
|
|
7
25
|
## 1.28.0
|
|
8
26
|
|
|
9
|
-
Thu, 02 Mar 2023 22:
|
|
27
|
+
Thu, 02 Mar 2023 22:33:01 GMT
|
|
10
28
|
|
|
11
29
|
### Minor changes
|
|
12
30
|
|
package/component-docs.json
CHANGED
|
@@ -192,6 +192,8 @@
|
|
|
192
192
|
"labelMarginLeft": "size"
|
|
193
193
|
},
|
|
194
194
|
"ChevronLink": {
|
|
195
|
+
"color": "color",
|
|
196
|
+
"outerBorderColor": "color",
|
|
195
197
|
"leftIcon": "icon",
|
|
196
198
|
"rightIcon": "icon",
|
|
197
199
|
"iconDisplace": "size",
|
|
@@ -884,6 +886,8 @@
|
|
|
884
886
|
"borderWidth": "border",
|
|
885
887
|
"borderColor": "color",
|
|
886
888
|
"borderRadius": "radius",
|
|
889
|
+
"passwordShowButtonIcon": "icon",
|
|
890
|
+
"passwordHideButtonIcon": "icon",
|
|
887
891
|
"buttonSize": "size",
|
|
888
892
|
"buttonsGap": "size",
|
|
889
893
|
"buttonsPaddingRight": "size",
|
|
@@ -1250,6 +1254,16 @@
|
|
|
1250
1254
|
}
|
|
1251
1255
|
},
|
|
1252
1256
|
"ChevronLink": {
|
|
1257
|
+
"focus": {
|
|
1258
|
+
"description": "Currently only web has good support for this. Applies when an interactive component's focus handler is triggered, such as keyboard tabbing or selection.",
|
|
1259
|
+
"values": [
|
|
1260
|
+
true
|
|
1261
|
+
],
|
|
1262
|
+
"type": "state",
|
|
1263
|
+
"platforms": [
|
|
1264
|
+
"rn"
|
|
1265
|
+
]
|
|
1266
|
+
},
|
|
1253
1267
|
"hover": {
|
|
1254
1268
|
"description": "Currently web only. Applies when an interactive component's hover handler is triggered, such as on mouseover.",
|
|
1255
1269
|
"values": [
|
|
@@ -1259,6 +1273,13 @@
|
|
|
1259
1273
|
"platforms": [
|
|
1260
1274
|
"rn"
|
|
1261
1275
|
]
|
|
1276
|
+
},
|
|
1277
|
+
"pressed": {
|
|
1278
|
+
"description": "Applies while an interactive component is being physically pressed. Most visible on touchscreen taps; in React Native Web, this is visible on web mouse clicks only if the pressable is held down.",
|
|
1279
|
+
"values": [
|
|
1280
|
+
true
|
|
1281
|
+
],
|
|
1282
|
+
"type": "state"
|
|
1262
1283
|
}
|
|
1263
1284
|
},
|
|
1264
1285
|
"ExpandCollapseControl": {
|
|
@@ -9697,6 +9718,55 @@
|
|
|
9697
9718
|
}
|
|
9698
9719
|
}
|
|
9699
9720
|
},
|
|
9721
|
+
"Validator": {
|
|
9722
|
+
"docs": {
|
|
9723
|
+
"description": "",
|
|
9724
|
+
"props": {
|
|
9725
|
+
"value": {
|
|
9726
|
+
"defaultValue": {
|
|
9727
|
+
"value": "''",
|
|
9728
|
+
"computed": false
|
|
9729
|
+
},
|
|
9730
|
+
"type": {
|
|
9731
|
+
"name": "string"
|
|
9732
|
+
},
|
|
9733
|
+
"required": false,
|
|
9734
|
+
"description": "The value is a 6-digit code, may be only numeric characters, non numeric character aren't renderize"
|
|
9735
|
+
},
|
|
9736
|
+
"tokens": {
|
|
9737
|
+
"defaultValue": {
|
|
9738
|
+
"value": "{}",
|
|
9739
|
+
"computed": false
|
|
9740
|
+
},
|
|
9741
|
+
"required": false
|
|
9742
|
+
},
|
|
9743
|
+
"variant": {
|
|
9744
|
+
"defaultValue": {
|
|
9745
|
+
"value": "{}",
|
|
9746
|
+
"computed": false
|
|
9747
|
+
},
|
|
9748
|
+
"required": false
|
|
9749
|
+
},
|
|
9750
|
+
"inactive": {
|
|
9751
|
+
"type": {
|
|
9752
|
+
"name": "bool"
|
|
9753
|
+
},
|
|
9754
|
+
"required": false,
|
|
9755
|
+
"description": "If true, the component is inactive and non editable."
|
|
9756
|
+
},
|
|
9757
|
+
"onChange": {
|
|
9758
|
+
"type": {
|
|
9759
|
+
"name": "func"
|
|
9760
|
+
},
|
|
9761
|
+
"required": false,
|
|
9762
|
+
"description": "Use to react upon input's value changes. Required when the `value` prop is set. Will receive the input's value as an argument."
|
|
9763
|
+
}
|
|
9764
|
+
},
|
|
9765
|
+
"attributes": {
|
|
9766
|
+
"acceptsRNA11yProps": false
|
|
9767
|
+
}
|
|
9768
|
+
}
|
|
9769
|
+
},
|
|
9700
9770
|
"ViewportProvider": {
|
|
9701
9771
|
"docs": {
|
|
9702
9772
|
"description": "Provides an up-to-date viewport value from system-constants, available via the `useViewport` hook",
|
|
@@ -12073,15 +12143,15 @@
|
|
|
12073
12143
|
"type": {
|
|
12074
12144
|
"name": "custom",
|
|
12075
12145
|
"raw": {
|
|
12146
|
+
"color": "color",
|
|
12147
|
+
"outerBorderColor": "color",
|
|
12076
12148
|
"leftIcon": "icon",
|
|
12077
12149
|
"rightIcon": "icon",
|
|
12078
12150
|
"iconDisplace": "size",
|
|
12079
12151
|
"iconSize": "size",
|
|
12080
12152
|
"iconSpace": "integer",
|
|
12081
12153
|
"textLine": "textLine",
|
|
12082
|
-
"color": "color",
|
|
12083
12154
|
"textLineStyle": "textLineStyle",
|
|
12084
|
-
"outerBorderColor": "color",
|
|
12085
12155
|
"outerBorderWidth": "border",
|
|
12086
12156
|
"outerBorderGap": "size",
|
|
12087
12157
|
"outerBorderOutline": "borderStyle",
|
|
@@ -13042,6 +13112,8 @@
|
|
|
13042
13112
|
"borderWidth": "border",
|
|
13043
13113
|
"borderColor": "color",
|
|
13044
13114
|
"borderRadius": "radius",
|
|
13115
|
+
"passwordShowButtonIcon": "icon",
|
|
13116
|
+
"passwordHideButtonIcon": "icon",
|
|
13045
13117
|
"buttonSize": "size",
|
|
13046
13118
|
"buttonsGap": "size",
|
|
13047
13119
|
"buttonsPaddingRight": "size",
|
|
@@ -13151,6 +13223,8 @@
|
|
|
13151
13223
|
"borderWidth": "border",
|
|
13152
13224
|
"borderColor": "color",
|
|
13153
13225
|
"borderRadius": "radius",
|
|
13226
|
+
"passwordShowButtonIcon": "icon",
|
|
13227
|
+
"passwordHideButtonIcon": "icon",
|
|
13154
13228
|
"buttonSize": "size",
|
|
13155
13229
|
"buttonsGap": "size",
|
|
13156
13230
|
"buttonsPaddingRight": "size",
|
|
@@ -183,6 +183,7 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
183
183
|
...rest
|
|
184
184
|
} = _ref6;
|
|
185
185
|
const [isFocused, setIsFocused] = (0, _react.useState)(false);
|
|
186
|
+
const [showPassword, setShowPassword] = (0, _react.useState)(false);
|
|
186
187
|
|
|
187
188
|
const handleFocus = event => {
|
|
188
189
|
setIsFocused(true);
|
|
@@ -244,27 +245,35 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
244
245
|
inactive
|
|
245
246
|
};
|
|
246
247
|
const themeTokens = (0, _ThemeProvider.useThemeTokens)('TextInput', tokens, variant, states);
|
|
248
|
+
|
|
249
|
+
const handleClear = event => {
|
|
250
|
+
var _inputRef$current;
|
|
251
|
+
|
|
252
|
+
onClear === null || onClear === void 0 ? void 0 : onClear(event);
|
|
253
|
+
resetValue(event);
|
|
254
|
+
inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const handleShowOrHide = () => {
|
|
258
|
+
if (!variant.inactive) setShowPassword(!showPassword);
|
|
259
|
+
};
|
|
260
|
+
|
|
247
261
|
const {
|
|
248
262
|
buttonsGap,
|
|
249
263
|
clearButtonIcon: ClearButtonIcon,
|
|
250
|
-
icon: IconComponent
|
|
264
|
+
icon: IconComponent,
|
|
265
|
+
passwordShowButtonIcon,
|
|
266
|
+
passwordHideButtonIcon
|
|
251
267
|
} = themeTokens;
|
|
252
268
|
const buttonsGapSize = (0, _utils.useSpacingScale)(buttonsGap);
|
|
253
269
|
const getCopy = (0, _utils.useCopy)({
|
|
254
270
|
dictionary: _dictionary.default,
|
|
255
271
|
copy
|
|
256
272
|
});
|
|
273
|
+
const textInputButtons = buttons;
|
|
257
274
|
|
|
258
275
|
if (onClear && isDirty) {
|
|
259
|
-
|
|
260
|
-
var _inputRef$current;
|
|
261
|
-
|
|
262
|
-
onClear === null || onClear === void 0 ? void 0 : onClear(event);
|
|
263
|
-
resetValue(event);
|
|
264
|
-
inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
buttons === null || buttons === void 0 ? void 0 : buttons.unshift( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
|
|
276
|
+
textInputButtons === null || textInputButtons === void 0 ? void 0 : textInputButtons.unshift( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
|
|
268
277
|
accessibilityLabel: getCopy('clearButtonAccessibilityLabel'),
|
|
269
278
|
icon: ClearButtonIcon,
|
|
270
279
|
onPress: handleClear,
|
|
@@ -274,6 +283,19 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
274
283
|
}, "clear"));
|
|
275
284
|
}
|
|
276
285
|
|
|
286
|
+
if (variant.password) {
|
|
287
|
+
textInputButtons === null || textInputButtons === void 0 ? void 0 : textInputButtons.unshift( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
|
|
288
|
+
accessibilityLabel: !showPassword ? getCopy('hidePasswordAccessibilityLabel') : getCopy('showPasswordAccessibilityLabel'),
|
|
289
|
+
icon: !showPassword ? passwordShowButtonIcon : passwordHideButtonIcon,
|
|
290
|
+
onPress: handleShowOrHide,
|
|
291
|
+
variant: {
|
|
292
|
+
compact: true,
|
|
293
|
+
password: true,
|
|
294
|
+
inactive: !!variant.inactive
|
|
295
|
+
}
|
|
296
|
+
}, !showPassword ? 'hide' : 'show'));
|
|
297
|
+
}
|
|
298
|
+
|
|
277
299
|
const inputProps = { ...selectProps(rest),
|
|
278
300
|
editable: !inactive,
|
|
279
301
|
onFocus: handleFocus,
|
|
@@ -297,6 +319,7 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
297
319
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_TextInput.default, {
|
|
298
320
|
ref: inputRef,
|
|
299
321
|
style: nativeInputStyle,
|
|
322
|
+
secureTextEntry: variant.password && !showPassword,
|
|
300
323
|
...inputProps
|
|
301
324
|
}), IconComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
302
325
|
pointerEvents: "none" // avoid hijacking input press events
|
|
@@ -311,7 +334,7 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
311
334
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_StackView.default, {
|
|
312
335
|
direction: "row",
|
|
313
336
|
space: buttonsGap,
|
|
314
|
-
children:
|
|
337
|
+
children: textInputButtons
|
|
315
338
|
})
|
|
316
339
|
})]
|
|
317
340
|
});
|
|
@@ -6,10 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _default = {
|
|
8
8
|
en: {
|
|
9
|
-
clearButtonAccessibilityLabel: 'Clear'
|
|
9
|
+
clearButtonAccessibilityLabel: 'Clear',
|
|
10
|
+
showPasswordAccessibilityLabel: 'Show Password',
|
|
11
|
+
hidePasswordAccessibilityLabel: 'Hide Password'
|
|
10
12
|
},
|
|
11
13
|
fr: {
|
|
12
|
-
clearButtonAccessibilityLabel: 'Effacer'
|
|
14
|
+
clearButtonAccessibilityLabel: 'Effacer',
|
|
15
|
+
showPasswordAccessibilityLabel: 'montrer le mot de passe',
|
|
16
|
+
hidePasswordAccessibilityLabel: 'masquer le mot de passe'
|
|
13
17
|
}
|
|
14
18
|
};
|
|
15
19
|
exports.default = _default;
|
|
@@ -37,14 +37,13 @@ const selectInnerContainerStyles = _ref => {
|
|
|
37
37
|
const selectIconTokens = _ref2 => {
|
|
38
38
|
let {
|
|
39
39
|
iconSize,
|
|
40
|
-
iconColor
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
iconColor,
|
|
41
|
+
iconScale = 1
|
|
43
42
|
} = _ref2;
|
|
44
43
|
return {
|
|
45
44
|
size: iconSize,
|
|
46
|
-
color: iconColor
|
|
47
|
-
|
|
45
|
+
color: iconColor,
|
|
46
|
+
scale: iconScale
|
|
48
47
|
};
|
|
49
48
|
};
|
|
50
49
|
/**
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
13
|
+
|
|
14
|
+
var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
|
|
15
|
+
|
|
16
|
+
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
17
|
+
|
|
18
|
+
var _utils = require("../utils");
|
|
19
|
+
|
|
20
|
+
var _TextInput = require("../TextInput");
|
|
21
|
+
|
|
22
|
+
var _StackView = _interopRequireDefault(require("../StackView"));
|
|
23
|
+
|
|
24
|
+
var _InputSupports = _interopRequireDefault(require("../InputSupports"));
|
|
25
|
+
|
|
26
|
+
var _ThemeProvider = require("../ThemeProvider");
|
|
27
|
+
|
|
28
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
+
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
|
+
|
|
34
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
+
|
|
36
|
+
const [selectProps, selectedSystemPropTypes] = (0, _utils.selectSystemProps)([_utils.inputSupportsProps]);
|
|
37
|
+
|
|
38
|
+
const selectCodeTextInputTokens = _ref => {
|
|
39
|
+
let {
|
|
40
|
+
outerBorderColor,
|
|
41
|
+
outerBackgroundColor
|
|
42
|
+
} = _ref;
|
|
43
|
+
return {
|
|
44
|
+
outerBorderColor,
|
|
45
|
+
outerBackgroundColor,
|
|
46
|
+
icon: null
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const Validator = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
|
|
51
|
+
let {
|
|
52
|
+
value = '',
|
|
53
|
+
inactive,
|
|
54
|
+
onChange,
|
|
55
|
+
tokens = {},
|
|
56
|
+
variant = {},
|
|
57
|
+
...rest
|
|
58
|
+
} = _ref2;
|
|
59
|
+
const defaultRef = (0, _react.useRef)();
|
|
60
|
+
const codeRef = ref !== null && ref !== void 0 ? ref : defaultRef;
|
|
61
|
+
const {
|
|
62
|
+
supportsProps
|
|
63
|
+
} = selectProps(rest);
|
|
64
|
+
const strValidation = supportsProps.validation;
|
|
65
|
+
const [individualCodes, setIndividualCodes] = (0, _react.useState)({});
|
|
66
|
+
const [text, setText] = (0, _react.useState)(value);
|
|
67
|
+
const validatorsLength = 6;
|
|
68
|
+
const prefix = 'code';
|
|
69
|
+
const sufixValidation = 'Validation';
|
|
70
|
+
const [isHover, setIsHover] = (0, _react.useState)(false);
|
|
71
|
+
|
|
72
|
+
const handleMouseOver = () => {
|
|
73
|
+
setIsHover(true);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleMouseOut = () => {
|
|
77
|
+
setIsHover(false);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const themeTokens = (0, _ThemeProvider.useThemeTokens)('TextInput', tokens, variant, {
|
|
81
|
+
hover: isHover
|
|
82
|
+
});
|
|
83
|
+
const [codeReferences, singleCodes] = (0, _react.useMemo)(() => {
|
|
84
|
+
const codes = [];
|
|
85
|
+
const valueCodes = {};
|
|
86
|
+
|
|
87
|
+
for (let i = 0; validatorsLength && i < validatorsLength; i += 1) {
|
|
88
|
+
codes[prefix + i] = /*#__PURE__*/(0, _react.createRef)();
|
|
89
|
+
valueCodes[prefix + i] = '';
|
|
90
|
+
valueCodes[prefix + i + sufixValidation] = '';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return [codes, valueCodes];
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
const handleSingleCodes = (codeId, val, validation) => {
|
|
97
|
+
singleCodes[codeId] = val;
|
|
98
|
+
singleCodes[codeId + sufixValidation] = validation;
|
|
99
|
+
/* eslint-disable no-unused-expressions */
|
|
100
|
+
|
|
101
|
+
setIndividualCodes({ ...individualCodes,
|
|
102
|
+
[codeId]: val
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const handleChangeCode = () => {
|
|
107
|
+
let code = '';
|
|
108
|
+
|
|
109
|
+
for (let i = 0; i < validatorsLength; i += 1) code += singleCodes[prefix + i];
|
|
110
|
+
|
|
111
|
+
if (typeof onChange === 'function') onChange(code, singleCodes);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const handleChangeCodeValues = (event, codeId, nextIndex) => {
|
|
115
|
+
var _codeReferences$codeI, _event$nativeEvent, _event$target, _codeElement$value, _codeElement$value2, _codeElement$value3;
|
|
116
|
+
|
|
117
|
+
const codeElement = (_codeReferences$codeI = codeReferences[codeId]) === null || _codeReferences$codeI === void 0 ? void 0 : _codeReferences$codeI.current;
|
|
118
|
+
const val = ((_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.value) || ((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value);
|
|
119
|
+
|
|
120
|
+
if (Number(val).toString() === 'NaN') {
|
|
121
|
+
var _singleCodes$codeId;
|
|
122
|
+
|
|
123
|
+
codeElement.value = (_singleCodes$codeId = singleCodes[codeId]) !== null && _singleCodes$codeId !== void 0 ? _singleCodes$codeId : '';
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if ((codeElement === null || codeElement === void 0 ? void 0 : (_codeElement$value = codeElement.value) === null || _codeElement$value === void 0 ? void 0 : _codeElement$value.length) > 1) {
|
|
128
|
+
const oldValue = singleCodes[codeId];
|
|
129
|
+
const newValue = codeElement.value.replace(oldValue, '');
|
|
130
|
+
codeElement.value = newValue;
|
|
131
|
+
handleSingleCodes(codeId, codeElement.value, 'success');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
handleSingleCodes(codeId, (_codeElement$value2 = codeElement === null || codeElement === void 0 ? void 0 : codeElement.value) !== null && _codeElement$value2 !== void 0 ? _codeElement$value2 : singleCodes[codeId], 'success');
|
|
135
|
+
handleChangeCode();
|
|
136
|
+
|
|
137
|
+
if (nextIndex === validatorsLength) {
|
|
138
|
+
codeElement.blur();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if ((codeElement === null || codeElement === void 0 ? void 0 : (_codeElement$value3 = codeElement.value) === null || _codeElement$value3 === void 0 ? void 0 : _codeElement$value3.length) > 0) codeReferences[prefix + nextIndex].current.focus();
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const handleKeyPress = (event, currentIndex, previousIndex) => {
|
|
146
|
+
if (!(event.keyCode === 8 || event.code === 'Backspace')) return;
|
|
147
|
+
|
|
148
|
+
if (currentIndex > 0) {
|
|
149
|
+
codeReferences[prefix + currentIndex].current.value = '';
|
|
150
|
+
codeReferences[prefix + previousIndex].current.focus();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
handleSingleCodes(prefix + currentIndex, '', '');
|
|
154
|
+
handleChangeCode();
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const getCodeComponents = () => {
|
|
158
|
+
const components = [];
|
|
159
|
+
|
|
160
|
+
for (let i = 0; validatorsLength && i < validatorsLength; i += 1) {
|
|
161
|
+
var _codeReferences$codeI2;
|
|
162
|
+
|
|
163
|
+
const codeId = prefix + i;
|
|
164
|
+
const codeInputProps = {
|
|
165
|
+
nativeID: codeId,
|
|
166
|
+
ref: (_codeReferences$codeI2 = codeReferences[codeId]) !== null && _codeReferences$codeI2 !== void 0 ? _codeReferences$codeI2 : null,
|
|
167
|
+
validation: strValidation || singleCodes[codeId + sufixValidation],
|
|
168
|
+
tokens: selectCodeTextInputTokens(themeTokens),
|
|
169
|
+
onFocus: () => codeReferences[codeId].current.select(),
|
|
170
|
+
onKeyPress: event => handleKeyPress(event, i, i - 1),
|
|
171
|
+
onMouseOver: handleMouseOver,
|
|
172
|
+
onMouseOut: handleMouseOut,
|
|
173
|
+
inactive
|
|
174
|
+
};
|
|
175
|
+
codeInputProps.validation || delete codeInputProps.validation;
|
|
176
|
+
components.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
177
|
+
style: staticStyles.codeInputWidth,
|
|
178
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextInput.TextInput, { ...codeInputProps
|
|
179
|
+
})
|
|
180
|
+
}, codeId));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return components;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
(0, _react.useEffect)(() => {
|
|
187
|
+
/* eslint-disable no-unused-expressions */
|
|
188
|
+
if (Number(value).toString() !== 'NaN') setText(value);
|
|
189
|
+
}, [value]);
|
|
190
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
191
|
+
|
|
192
|
+
(0, _react.useEffect)(() => {
|
|
193
|
+
for (let i = 0; i < validatorsLength; i += 1) {
|
|
194
|
+
var _text$i, _text$i2;
|
|
195
|
+
|
|
196
|
+
codeReferences[prefix + i].current.value = (_text$i = text[i]) !== null && _text$i !== void 0 ? _text$i : '';
|
|
197
|
+
handleSingleCodes(prefix + i, (_text$i2 = text[i]) !== null && _text$i2 !== void 0 ? _text$i2 : '', text[i] ? 'success' : '');
|
|
198
|
+
}
|
|
199
|
+
}, [text]);
|
|
200
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
201
|
+
|
|
202
|
+
(0, _react.useEffect)(() => {
|
|
203
|
+
const handlePasteCode = event => {
|
|
204
|
+
setText('');
|
|
205
|
+
const clipBoardText = event.clipboardData.getData('text');
|
|
206
|
+
if (Number(clipBoardText).toString() !== 'NaN') setText(clipBoardText);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const handleCopy = event => {
|
|
210
|
+
let clipBoardText = '';
|
|
211
|
+
|
|
212
|
+
for (let i = 0; i < validatorsLength; i += 1) singleCodes[prefix + i] && (clipBoardText += singleCodes[prefix + i]);
|
|
213
|
+
|
|
214
|
+
event.clipboardData.setData('text/plain', clipBoardText);
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
if (_Platform.default.OS === 'web') {
|
|
219
|
+
for (let i = 0; i < validatorsLength; i += 1) {
|
|
220
|
+
codeReferences[prefix + i].current.addEventListener('paste', handlePasteCode);
|
|
221
|
+
codeReferences[prefix + i].current.addEventListener('copy', handleCopy);
|
|
222
|
+
codeReferences[prefix + i].current.addEventListener('input', event => handleChangeCodeValues(event, prefix + i, i + 1));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return () => {
|
|
227
|
+
if (_Platform.default.oldValue === 'web') {
|
|
228
|
+
for (let i = 0; i < validatorsLength; i += 1) {
|
|
229
|
+
var _codeReferences, _codeReferences$curre, _codeReferences2, _codeReferences2$curr, _codeReferences3, _codeReferences3$curr;
|
|
230
|
+
|
|
231
|
+
(_codeReferences = codeReferences[prefix + i]) === null || _codeReferences === void 0 ? void 0 : (_codeReferences$curre = _codeReferences.current) === null || _codeReferences$curre === void 0 ? void 0 : _codeReferences$curre.removeEventListener('paste', handlePasteCode);
|
|
232
|
+
(_codeReferences2 = codeReferences[prefix + i]) === null || _codeReferences2 === void 0 ? void 0 : (_codeReferences2$curr = _codeReferences2.current) === null || _codeReferences2$curr === void 0 ? void 0 : _codeReferences2$curr.removeEventListener('copy', handleCopy);
|
|
233
|
+
(_codeReferences3 = codeReferences[prefix + i]) === null || _codeReferences3 === void 0 ? void 0 : (_codeReferences3$curr = _codeReferences3.current) === null || _codeReferences3$curr === void 0 ? void 0 : _codeReferences3$curr.removeEventListener('input', event => handleChangeCodeValues(event, prefix + i, i + 1));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}, []);
|
|
238
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputSupports.default, { ...supportsProps,
|
|
239
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_StackView.default, {
|
|
240
|
+
space: 2,
|
|
241
|
+
direction: "row",
|
|
242
|
+
ref: codeRef,
|
|
243
|
+
children: getCodeComponents()
|
|
244
|
+
})
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
Validator.displayName = 'Validator';
|
|
248
|
+
Validator.propTypes = { ...selectedSystemPropTypes,
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The value is a 6-digit code, may be only numeric characters, non numeric character aren't renderize
|
|
252
|
+
*/
|
|
253
|
+
value: _propTypes.default.string,
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* If true, the component is inactive and non editable.
|
|
257
|
+
*/
|
|
258
|
+
inactive: _propTypes.default.bool,
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Use to react upon input's value changes. Required when the `value` prop is set. Will receive the input's value as an argument.
|
|
262
|
+
*/
|
|
263
|
+
onChange: _propTypes.default.func
|
|
264
|
+
};
|
|
265
|
+
var _default = Validator;
|
|
266
|
+
exports.default = _default;
|
|
267
|
+
|
|
268
|
+
const staticStyles = _StyleSheet.default.create({
|
|
269
|
+
codeInputWidth: {
|
|
270
|
+
width: 43
|
|
271
|
+
}
|
|
272
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _Validator = _interopRequireDefault(require("./Validator"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var _default = _Validator.default;
|
|
13
|
+
exports.default = _default;
|
package/lib/index.js
CHANGED
|
@@ -52,6 +52,7 @@ var _exportNames = {
|
|
|
52
52
|
useA11yInfo: true,
|
|
53
53
|
BaseProvider: true,
|
|
54
54
|
useHydrationContext: true,
|
|
55
|
+
Validator: true,
|
|
55
56
|
ViewportProvider: true,
|
|
56
57
|
useViewport: true,
|
|
57
58
|
ViewportContext: true,
|
|
@@ -353,6 +354,12 @@ Object.defineProperty(exports, "Typography", {
|
|
|
353
354
|
return _Typography.default;
|
|
354
355
|
}
|
|
355
356
|
});
|
|
357
|
+
Object.defineProperty(exports, "Validator", {
|
|
358
|
+
enumerable: true,
|
|
359
|
+
get: function () {
|
|
360
|
+
return _Validator.default;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
356
363
|
Object.defineProperty(exports, "ViewportContext", {
|
|
357
364
|
enumerable: true,
|
|
358
365
|
get: function () {
|
|
@@ -654,6 +661,8 @@ var _BaseProvider = _interopRequireDefault(require("./BaseProvider"));
|
|
|
654
661
|
|
|
655
662
|
var _HydrationContext = require("./BaseProvider/HydrationContext");
|
|
656
663
|
|
|
664
|
+
var _Validator = _interopRequireDefault(require("./Validator"));
|
|
665
|
+
|
|
657
666
|
var _ViewportProvider = _interopRequireWildcard(require("./ViewportProvider"));
|
|
658
667
|
|
|
659
668
|
var _ThemeProvider = _interopRequireWildcard(require("./ThemeProvider"));
|
|
@@ -88,7 +88,12 @@ const textInputHandlerProps = {
|
|
|
88
88
|
/**
|
|
89
89
|
* onKeyDown handler (only supported on Web)
|
|
90
90
|
*/
|
|
91
|
-
|
|
91
|
+
onMouseOver: _propTypes.default.func,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* onKeyDown handler (only supported on Web)
|
|
95
|
+
*/
|
|
96
|
+
onMouseOut: _propTypes.default.func
|
|
92
97
|
}
|
|
93
98
|
};
|
|
94
99
|
exports.textInputHandlerProps = textInputHandlerProps;
|