@widergy/energy-ui 3.24.0 → 3.26.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 +14 -0
- package/dist/components/UTActionCard/components/BottomActions/index.js +3 -0
- package/dist/components/UTAutocomplete/index.js +5 -0
- package/dist/components/UTBaseInputField/components/ActionAdornment/index.js +31 -0
- package/dist/components/UTBaseInputField/components/IconAdornment/constants.js +8 -0
- package/dist/components/UTBaseInputField/components/IconAdornment/index.js +48 -0
- package/dist/components/UTBaseInputField/components/IconAdornment/utils.js +17 -0
- package/dist/components/UTBaseInputField/components/PrefixAdornment/index.js +24 -0
- package/dist/components/UTBaseInputField/components/SuffixAdornment/index.js +22 -0
- package/dist/components/UTBaseInputField/components/TooltipAdornment/index.js +29 -0
- package/dist/components/UTBaseInputField/components/TooltipAdornment/styles.module.scss +3 -0
- package/dist/components/UTBaseInputField/index.js +169 -0
- package/dist/components/UTBaseInputField/styles.module.scss +29 -0
- package/dist/components/UTBaseInputField/theme.js +97 -0
- package/dist/components/UTButtonGroup/index.js +2 -0
- package/dist/components/UTCBUInput/index.js +21 -18
- package/dist/components/UTCard/index.js +6 -2
- package/dist/components/UTCheckbox/index.js +8 -0
- package/dist/components/UTCuit/index.js +51 -27
- package/dist/components/UTGoogleAutocomplete/index.js +2 -0
- package/dist/components/UTLabel/index.js +4 -1
- package/dist/components/UTOnboarding/index.js +15 -0
- package/dist/components/UTPasswordField/versions/V0/index.js +3 -0
- package/dist/components/UTPhoneInput/index.js +16 -277
- package/dist/components/UTPhoneInput/versions/V0/index.js +297 -0
- package/dist/components/UTPhoneInput/{styles.module.scss → versions/V0/styles.module.scss} +10 -10
- package/dist/components/UTPhoneInput/{theme.js → versions/V0/theme.js} +1 -1
- package/dist/components/UTPhoneInput/versions/V1/README.md +57 -0
- package/dist/components/UTPhoneInput/versions/V1/constants.js +910 -0
- package/dist/components/UTPhoneInput/versions/V1/index.js +166 -0
- package/dist/components/UTPhoneInput/versions/V1/styles.module.scss +20 -0
- package/dist/components/UTStatus/index.js +3 -0
- package/dist/components/UTTable/index.js +4 -1
- package/dist/components/UTTextArea/versions/V0/index.js +3 -0
- package/dist/components/UTTextInput/versions/V0/index.js +5 -0
- package/dist/components/UTTextInput/versions/V1/README.md +1 -1
- package/dist/components/UTTextInput/versions/V1/index.js +30 -87
- package/dist/components/UTTextInput/versions/V1/styles.module.scss +0 -24
- package/dist/constants/inputs.js +10 -0
- package/dist/types/googleMapsTypes.js +1 -0
- package/package.json +3 -2
- /package/dist/components/UTPhoneInput/{constants.js → versions/V0/constants.js} +0 -0
|
@@ -56,9 +56,10 @@ class UTCard extends _react.PureComponent {
|
|
|
56
56
|
classes: themeClasses,
|
|
57
57
|
classNames,
|
|
58
58
|
CustomFooter,
|
|
59
|
-
|
|
59
|
+
dataTestId,
|
|
60
60
|
ExpandedIcon,
|
|
61
61
|
expandText,
|
|
62
|
+
expandableIconProps,
|
|
62
63
|
flat,
|
|
63
64
|
footer,
|
|
64
65
|
header,
|
|
@@ -82,11 +83,13 @@ class UTCard extends _react.PureComponent {
|
|
|
82
83
|
});
|
|
83
84
|
return !isCollapsible ? /*#__PURE__*/_react.default.createElement("div", {
|
|
84
85
|
className: "".concat(classes.base, " ").concat(flat && classes.flat, " ").concat(!horizontal && _stylesModule.default.column, " ").concat(classes.base),
|
|
86
|
+
"data-testid": dataTestId,
|
|
85
87
|
style: style
|
|
86
88
|
}, header && /*#__PURE__*/_react.default.createElement("div", {
|
|
87
89
|
className: _stylesModule.default.headerContent
|
|
88
90
|
}, header), children, CustomFooter ? /*#__PURE__*/_react.default.createElement(CustomFooter, null) : Footer) : /*#__PURE__*/_react.default.createElement("div", {
|
|
89
91
|
className: "".concat(classes.base, " ").concat(flat && classes.flat, " ").concat(_stylesModule.default.column),
|
|
92
|
+
"data-testid": dataTestId,
|
|
90
93
|
style: style
|
|
91
94
|
}, /*#__PURE__*/_react.default.createElement(_UTTouchableWithoutFeedback.default, {
|
|
92
95
|
onClick: this.handleOnPress,
|
|
@@ -118,9 +121,10 @@ UTCard.propTypes = {
|
|
|
118
121
|
classes: (0, _propTypes.objectOf)(_propTypes.string),
|
|
119
122
|
classNames: (0, _propTypes.objectOf)(_propTypes.string),
|
|
120
123
|
CustomFooter: (0, _propTypes.oneOfType)([_propTypes.element, _propTypes.func]),
|
|
121
|
-
|
|
124
|
+
dataTestId: _propTypes.string,
|
|
122
125
|
ExpandedIcon: (0, _propTypes.oneOfType)([_propTypes.func, _propTypes.element]),
|
|
123
126
|
expandText: _propTypes.string,
|
|
127
|
+
expandableIconProps: _propTypes.object,
|
|
124
128
|
flat: _propTypes.bool,
|
|
125
129
|
footer: _types.cardActionsTypes.footer,
|
|
126
130
|
header: _types.cardActionsTypes.header,
|
|
@@ -36,6 +36,7 @@ const UTCheckbox = _ref => {
|
|
|
36
36
|
classes: themeClasses = {},
|
|
37
37
|
classNames,
|
|
38
38
|
color = 'primary',
|
|
39
|
+
checkboxDataTestId,
|
|
39
40
|
CustomCheckedIcon = Checked,
|
|
40
41
|
customRowLabel: CustomRowLabel,
|
|
41
42
|
CustomUncheckedIcon = _ref2 => {
|
|
@@ -51,6 +52,7 @@ const UTCheckbox = _ref => {
|
|
|
51
52
|
input,
|
|
52
53
|
item,
|
|
53
54
|
label,
|
|
55
|
+
labelDataTestId,
|
|
54
56
|
labelProps = {},
|
|
55
57
|
meta,
|
|
56
58
|
onChange,
|
|
@@ -82,6 +84,9 @@ const UTCheckbox = _ref => {
|
|
|
82
84
|
checkedIcon: useCustomIcons && /*#__PURE__*/_react.default.createElement(CustomCheckedIcon, {
|
|
83
85
|
className: classes.checkedIcon
|
|
84
86
|
}),
|
|
87
|
+
inputProps: {
|
|
88
|
+
'data-testid': checkboxDataTestId
|
|
89
|
+
},
|
|
85
90
|
icon: useCustomIcons && /*#__PURE__*/_react.default.createElement(CustomUncheckedIcon, {
|
|
86
91
|
className: classes.uncheckedIcon
|
|
87
92
|
}),
|
|
@@ -96,6 +101,7 @@ const UTCheckbox = _ref => {
|
|
|
96
101
|
item: item
|
|
97
102
|
}) : /*#__PURE__*/_react.default.createElement(_UTLabel.default, _extends({
|
|
98
103
|
className: classes.label,
|
|
104
|
+
dataTestId: labelDataTestId,
|
|
99
105
|
variant: "small",
|
|
100
106
|
withMarkdown: true
|
|
101
107
|
}, labelProps), label),
|
|
@@ -115,6 +121,7 @@ UTCheckbox.propTypes = {
|
|
|
115
121
|
}),
|
|
116
122
|
classNames: (0, _propTypes.objectOf)(_propTypes.string),
|
|
117
123
|
color: _propTypes.string,
|
|
124
|
+
checkboxDataTestId: _propTypes.string,
|
|
118
125
|
CustomCheckedIcon: _propTypes.node,
|
|
119
126
|
customRowLabel: (0, _propTypes.oneOfType)([_propTypes.func, _propTypes.element, _propTypes.string]),
|
|
120
127
|
CustomUncheckedIcon: _propTypes.node,
|
|
@@ -123,6 +130,7 @@ UTCheckbox.propTypes = {
|
|
|
123
130
|
input: _formTypes.inputPropTypes,
|
|
124
131
|
item: (0, _propTypes.oneOfType)([_propTypes.string, _propTypes.object]),
|
|
125
132
|
label: (0, _propTypes.oneOfType)([_propTypes.number, _propTypes.string]),
|
|
133
|
+
labelDataTestId: _propTypes.string,
|
|
126
134
|
labelProps: _propTypes.object,
|
|
127
135
|
meta: _formTypes.metaPropTypes,
|
|
128
136
|
onChange: _propTypes.func,
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));
|
|
9
9
|
var _form = require("@widergy/web-utils/lib/form");
|
|
10
|
+
var _propTypes = require("prop-types");
|
|
10
11
|
var _UTLabel = _interopRequireDefault(require("../UTLabel"));
|
|
11
12
|
var _WithTheme = _interopRequireDefault(require("../WithTheme"));
|
|
12
13
|
var _formTypes = require("../../types/formTypes");
|
|
@@ -93,55 +94,75 @@ class UTCuit extends _react.PureComponent {
|
|
|
93
94
|
document,
|
|
94
95
|
verificationCode
|
|
95
96
|
} = this.state;
|
|
97
|
+
const {
|
|
98
|
+
documentDataTestId,
|
|
99
|
+
prefixDataTestId,
|
|
100
|
+
verificationCodeDataTestId
|
|
101
|
+
} = this.props;
|
|
96
102
|
this.handleFocus();
|
|
97
103
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
98
104
|
className: _stylesModule.default.container
|
|
99
105
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
100
106
|
className: _stylesModule.default.fieldContainer
|
|
101
107
|
}, /*#__PURE__*/_react.default.createElement(_TextField.default, {
|
|
102
|
-
className: _stylesModule.default.fieldCuit,
|
|
103
|
-
name: "prefix",
|
|
104
|
-
label: this.props.field.label,
|
|
105
108
|
autoComplete: "off",
|
|
106
|
-
|
|
109
|
+
autoFocus: this.props.field.configuration.auto_focus,
|
|
110
|
+
className: _stylesModule.default.fieldCuit,
|
|
111
|
+
error: (0, _form.shouldShowErrors)(this.props.meta) ? this.props.meta.error : '',
|
|
112
|
+
fullWidth: true,
|
|
107
113
|
InputLabelProps: {
|
|
108
114
|
shrink: this.props.input.value !== 0
|
|
109
115
|
},
|
|
116
|
+
InputProps: {
|
|
117
|
+
type: 'input',
|
|
118
|
+
inputProps: {
|
|
119
|
+
'data-testid': prefixDataTestId
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
label: this.props.field.label,
|
|
123
|
+
margin: "none",
|
|
124
|
+
name: "prefix",
|
|
110
125
|
onChange: this.handleOnChangePrefix,
|
|
111
126
|
onKeyPress: this.handleKeyPress,
|
|
112
|
-
|
|
113
|
-
value: prefix
|
|
114
|
-
InputProps: "input",
|
|
115
|
-
fullWidth: true,
|
|
116
|
-
margin: "none",
|
|
117
|
-
autoFocus: this.props.field.configuration.auto_focus
|
|
127
|
+
placeholder: "XX",
|
|
128
|
+
value: prefix
|
|
118
129
|
}), /*#__PURE__*/_react.default.createElement(_TextField.default, {
|
|
119
|
-
name: "document",
|
|
120
|
-
className: _stylesModule.default.fieldDocument,
|
|
121
130
|
autoComplete: "off",
|
|
122
|
-
|
|
123
|
-
onKeyPress: this.handleKeyPress,
|
|
131
|
+
className: _stylesModule.default.fieldDocument,
|
|
124
132
|
disabled: this.props.field.configuration.disable_document,
|
|
125
133
|
error: (0, _form.shouldShowErrors)(this.props.meta) ? this.props.meta.error : '',
|
|
126
|
-
value: document,
|
|
127
|
-
onChange: this.handleOnChangeDocument,
|
|
128
134
|
fullWidth: true,
|
|
129
|
-
InputProps:
|
|
135
|
+
InputProps: {
|
|
136
|
+
type: 'text',
|
|
137
|
+
inputProps: {
|
|
138
|
+
'data-testid': documentDataTestId
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
inputRef: this.documentRef,
|
|
130
142
|
margin: "none",
|
|
131
|
-
|
|
143
|
+
name: "document",
|
|
144
|
+
onChange: this.handleOnChangeDocument,
|
|
145
|
+
onKeyPress: this.handleKeyPress,
|
|
146
|
+
placeholder: "XXXXXXXX",
|
|
147
|
+
value: document
|
|
132
148
|
}), /*#__PURE__*/_react.default.createElement(_TextField.default, {
|
|
133
149
|
autoComplete: "off",
|
|
134
150
|
className: _stylesModule.default.fieldCuit,
|
|
135
|
-
name: "verificationCode",
|
|
136
|
-
placeholder: "X",
|
|
137
|
-
fullWidth: true,
|
|
138
|
-
onKeyPress: this.handleKeyPress,
|
|
139
151
|
error: (0, _form.shouldShowErrors)(this.props.meta) ? this.props.meta.error : '',
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
InputProps:
|
|
152
|
+
fullWidth: true,
|
|
153
|
+
inputRef: this.verificationCodeRef,
|
|
154
|
+
InputProps: {
|
|
155
|
+
type: 'input',
|
|
156
|
+
inputProps: {
|
|
157
|
+
'data-testid': verificationCodeDataTestId
|
|
158
|
+
}
|
|
159
|
+
},
|
|
143
160
|
margin: "none",
|
|
144
|
-
|
|
161
|
+
name: "verificationCode",
|
|
162
|
+
onChange: this.handleOnChangeVerificationCode,
|
|
163
|
+
onKeyPress: this.handleKeyPress,
|
|
164
|
+
placeholder: "X",
|
|
165
|
+
value: verificationCode
|
|
145
166
|
})), /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
|
|
146
167
|
variant: "small",
|
|
147
168
|
colorTheme: "error"
|
|
@@ -149,8 +170,11 @@ class UTCuit extends _react.PureComponent {
|
|
|
149
170
|
}
|
|
150
171
|
}
|
|
151
172
|
UTCuit.propTypes = {
|
|
173
|
+
documentDataTestId: _propTypes.string,
|
|
174
|
+
field: _formTypes.fieldType,
|
|
152
175
|
input: _formTypes.inputPropTypes,
|
|
153
176
|
meta: _formTypes.metaPropTypes,
|
|
154
|
-
|
|
177
|
+
prefixDataTestId: _propTypes.string,
|
|
178
|
+
verificationCodeDataTestId: _propTypes.string
|
|
155
179
|
};
|
|
156
180
|
var _default = exports.default = (0, _WithTheme.default)(null, _theme.retrieveMuiTheme)(UTCuit);
|
|
@@ -25,6 +25,7 @@ const UTGoogleAutocomplete = _ref => {
|
|
|
25
25
|
let {
|
|
26
26
|
alert,
|
|
27
27
|
classes,
|
|
28
|
+
dataTestId,
|
|
28
29
|
detailErrorLabel = 'Hubo un error al intentar recuperar el detalle de la dirección seleccionada',
|
|
29
30
|
inputProps,
|
|
30
31
|
minChar = 3,
|
|
@@ -90,6 +91,7 @@ const UTGoogleAutocomplete = _ref => {
|
|
|
90
91
|
}, /*#__PURE__*/_react.default.createElement(_UTAlert.default, {
|
|
91
92
|
content: alert
|
|
92
93
|
}), /*#__PURE__*/_react.default.createElement(_UTTextInput.default, _extends({
|
|
94
|
+
dataTestId: dataTestId,
|
|
93
95
|
input: {
|
|
94
96
|
value: searchInputValue,
|
|
95
97
|
onChange: handleInputChange
|
|
@@ -22,8 +22,9 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
22
22
|
const UTLabel = _ref => {
|
|
23
23
|
let {
|
|
24
24
|
children,
|
|
25
|
-
classes: theme,
|
|
26
25
|
className,
|
|
26
|
+
classes: theme,
|
|
27
|
+
dataTestId,
|
|
27
28
|
markdownRenderers,
|
|
28
29
|
title,
|
|
29
30
|
variant,
|
|
@@ -36,6 +37,7 @@ const UTLabel = _ref => {
|
|
|
36
37
|
}), [theme, className]);
|
|
37
38
|
return /*#__PURE__*/_react.default.createElement(_UTSkeleton.default, null, /*#__PURE__*/_react.default.createElement(Component, {
|
|
38
39
|
className: "".concat(classes.root, " ").concat(classes.className).trim(),
|
|
40
|
+
"data-testid": dataTestId,
|
|
39
41
|
title: title
|
|
40
42
|
}, withMarkdown && /*#__PURE__*/_react.default.createElement(_reactMarkdown.default, {
|
|
41
43
|
children: children,
|
|
@@ -51,6 +53,7 @@ UTLabel.defaultProps = _constants.DEFAULT_PROPS;
|
|
|
51
53
|
UTLabel.propTypes = {
|
|
52
54
|
classes: (0, _propTypes.objectOf)(_propTypes.string),
|
|
53
55
|
className: _propTypes.string,
|
|
56
|
+
dataTestId: _propTypes.string,
|
|
54
57
|
markdownRenderers: (0, _propTypes.objectOf)(_propTypes.func),
|
|
55
58
|
title: _propTypes.string,
|
|
56
59
|
variant: _propTypes.string,
|
|
@@ -21,12 +21,14 @@ const UTOnboarding = _ref => {
|
|
|
21
21
|
var _steps$currentStep$is, _steps$currentStep, _steps$currentStep$hi, _steps$currentStep2, _steps$currentStep3, _steps$currentStep4;
|
|
22
22
|
let {
|
|
23
23
|
classes: themeClasses,
|
|
24
|
+
closeButtonDataTestId,
|
|
24
25
|
classNames,
|
|
25
26
|
enabled,
|
|
26
27
|
handleComplete,
|
|
27
28
|
handleOnClose,
|
|
28
29
|
options,
|
|
29
30
|
steps,
|
|
31
|
+
titleDataTestId,
|
|
30
32
|
variant
|
|
31
33
|
} = _ref;
|
|
32
34
|
const classes = (0, _react.useMemo)(() => (0, _classesUtils.mergeClasses)(themeClasses, classNames), [themeClasses, classNames]) || {};
|
|
@@ -35,6 +37,17 @@ const UTOnboarding = _ref => {
|
|
|
35
37
|
const currentStepIsSuggestion = (_steps$currentStep$is = (_steps$currentStep = steps[currentStep]) === null || _steps$currentStep === void 0 ? void 0 : _steps$currentStep.isSuggestion) !== null && _steps$currentStep$is !== void 0 ? _steps$currentStep$is : false;
|
|
36
38
|
const hideFooter = (_steps$currentStep$hi = (_steps$currentStep2 = steps[currentStep]) === null || _steps$currentStep2 === void 0 ? void 0 : _steps$currentStep2.hideFooter) !== null && _steps$currentStep$hi !== void 0 ? _steps$currentStep$hi : false;
|
|
37
39
|
const totalSteps = steps.length;
|
|
40
|
+
|
|
41
|
+
// This timeout is here only to get the querySelectors out of the call-stack order, giving the Step component time to render every child inside. This
|
|
42
|
+
// is necessary to find the html element searched by the selectors.
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
var _skipButton$attribute, _stepTitle$attributes, _skipButton$setAttrib, _stepTitle$setAttribu;
|
|
45
|
+
const skipButton = document.querySelector('.introjs-skipbutton');
|
|
46
|
+
const stepTitle = document.querySelector('.introjs-tooltip-title');
|
|
47
|
+
if (skipButton !== null && skipButton !== void 0 && (_skipButton$attribute = skipButton.attributes) !== null && _skipButton$attribute !== void 0 && _skipButton$attribute['data-testid'] && stepTitle !== null && stepTitle !== void 0 && (_stepTitle$attributes = stepTitle.attributes) !== null && _stepTitle$attributes !== void 0 && _stepTitle$attributes['data-testid']) return;
|
|
48
|
+
skipButton === null || skipButton === void 0 || (_skipButton$setAttrib = skipButton.setAttribute) === null || _skipButton$setAttrib === void 0 || _skipButton$setAttrib.call(skipButton, 'data-testid', closeButtonDataTestId);
|
|
49
|
+
stepTitle === null || stepTitle === void 0 || (_stepTitle$setAttribu = stepTitle.setAttribute) === null || _stepTitle$setAttribu === void 0 || _stepTitle$setAttribu.call(stepTitle, 'data-testid', titleDataTestId);
|
|
50
|
+
}, 1);
|
|
38
51
|
(0, _react.useEffect)(() => {
|
|
39
52
|
setLoading(false);
|
|
40
53
|
}, [steps]);
|
|
@@ -113,11 +126,13 @@ const UTOnboarding = _ref => {
|
|
|
113
126
|
UTOnboarding.propTypes = {
|
|
114
127
|
classes: (0, _propTypes.objectOf)(_propTypes.string),
|
|
115
128
|
classNames: (0, _propTypes.objectOf)(_propTypes.string),
|
|
129
|
+
closeButtonDataTestId: _propTypes.string,
|
|
116
130
|
enabled: _propTypes.bool,
|
|
117
131
|
handleComplete: _propTypes.func,
|
|
118
132
|
handleOnClose: _propTypes.func,
|
|
119
133
|
options: _propTypes.object,
|
|
120
134
|
steps: _propTypes.array,
|
|
135
|
+
titleDataTestId: _propTypes.string,
|
|
121
136
|
variant: _propTypes.string
|
|
122
137
|
};
|
|
123
138
|
var _default = exports.default = (0, _WithTheme.default)(_theme.retrieveStyle)(UTOnboarding);
|
|
@@ -19,6 +19,7 @@ const UTPasswordField = _ref => {
|
|
|
19
19
|
field,
|
|
20
20
|
input,
|
|
21
21
|
classes = {},
|
|
22
|
+
dataTestId,
|
|
22
23
|
ValidationPassedIcon,
|
|
23
24
|
ValidationFailedIcon,
|
|
24
25
|
NoValueIcon,
|
|
@@ -40,6 +41,7 @@ const UTPasswordField = _ref => {
|
|
|
40
41
|
validationContainer
|
|
41
42
|
} = classes;
|
|
42
43
|
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_UTTextInput.default, _extends({
|
|
44
|
+
dataTestId: dataTestId,
|
|
43
45
|
field: field,
|
|
44
46
|
input: input,
|
|
45
47
|
meta: !showValidations ? meta : undefined,
|
|
@@ -70,6 +72,7 @@ UTPasswordField.propTypes = {
|
|
|
70
72
|
field: _formTypes.fieldType,
|
|
71
73
|
input: _formTypes.inputPropTypes,
|
|
72
74
|
classes: (0, _propTypes.objectOf)(_propTypes.string),
|
|
75
|
+
dataTestId: _propTypes.string,
|
|
73
76
|
variant: _propTypes.string,
|
|
74
77
|
ValidationPassedIcon: _propTypes.elementType,
|
|
75
78
|
ValidationFailedIcon: _propTypes.elementType,
|
|
@@ -4,284 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _propTypes = require("prop-types");
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var _form = require("@widergy/web-utils/lib/form");
|
|
12
|
-
var _array = require("@widergy/web-utils/lib/array");
|
|
13
|
-
var _UTTooltip = _interopRequireDefault(require("../UTTooltip"));
|
|
14
|
-
var _UTLabel = _interopRequireDefault(require("../UTLabel"));
|
|
15
|
-
var _WithTheme = _interopRequireDefault(require("../WithTheme"));
|
|
16
|
-
var _formTypes = require("../../types/formTypes");
|
|
17
|
-
var _classesUtils = require("../../utils/classesUtils");
|
|
18
|
-
var _theme = require("./theme");
|
|
19
|
-
var _constants = require("./constants");
|
|
20
|
-
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
9
|
+
var _V = _interopRequireDefault(require("./versions/V0"));
|
|
10
|
+
var _V2 = _interopRequireDefault(require("./versions/V1"));
|
|
21
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
areaCode: '',
|
|
33
|
-
phoneNumber: ''
|
|
34
|
-
}));
|
|
35
|
-
_defineProperty(this, "handleInitializeField", () => {
|
|
36
|
-
let areaCode;
|
|
37
|
-
let phoneNumber;
|
|
38
|
-
const {
|
|
39
|
-
value
|
|
40
|
-
} = this.props.input;
|
|
41
|
-
if (typeof value === 'object' && this.props.childKeys) {
|
|
42
|
-
areaCode = value[this.props.childKeys[0]];
|
|
43
|
-
areaCode = typeof areaCode === 'number' ? areaCode.toString() : areaCode;
|
|
44
|
-
phoneNumber = value[this.props.childKeys[1]];
|
|
45
|
-
phoneNumber = typeof phoneNumber === 'number' ? phoneNumber.toString() : phoneNumber;
|
|
46
|
-
} else {
|
|
47
|
-
const stringValue = value.toString();
|
|
48
|
-
areaCode = stringValue.slice(0, stringValue.indexOf('-'));
|
|
49
|
-
phoneNumber = stringValue.slice(stringValue.indexOf('-') + 1);
|
|
50
|
-
}
|
|
51
|
-
this.setState({
|
|
52
|
-
initialized: true
|
|
53
|
-
});
|
|
54
|
-
this.setState({
|
|
55
|
-
areaCode,
|
|
56
|
-
phoneNumber
|
|
57
|
-
}, () => this.handleValidateAreaCode(this.state.areaCode));
|
|
58
|
-
});
|
|
59
|
-
_defineProperty(this, "handleValidateAreaCode", areaCode => {
|
|
60
|
-
if (areaCode.slice(0, 1) === '0') {
|
|
61
|
-
this.setState({
|
|
62
|
-
error: this.props.errors.codeWithZero,
|
|
63
|
-
city: undefined
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
const code = _constants.AREA_CODES.find(element => element.code === areaCode);
|
|
67
|
-
const error = areaCode.length && !code && this.props.errors.invalidCode;
|
|
68
|
-
this.setState({
|
|
69
|
-
error,
|
|
70
|
-
city: code && code.city
|
|
71
|
-
}, () => {
|
|
72
|
-
if (this.state.city && !error) this.handleValidatePhoneNumber(this.state.phoneNumber);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
_defineProperty(this, "handleCleanPhoneNumber", () => this.setState({
|
|
77
|
-
phoneNumber: ''
|
|
78
|
-
}));
|
|
79
|
-
_defineProperty(this, "handleValidatePhoneNumber", phoneNumber => {
|
|
80
|
-
if (phoneNumber.slice(0, 1) === '0') {
|
|
81
|
-
this.setState({
|
|
82
|
-
error: this.props.errors.phoneWithZero
|
|
83
|
-
});
|
|
84
|
-
} else if (phoneNumber.slice(0, 2) === '15') {
|
|
85
|
-
this.setState({
|
|
86
|
-
error: this.props.errors.phoneWithFifteen
|
|
87
|
-
});
|
|
88
|
-
} else if (phoneNumber.length === 0) {
|
|
89
|
-
this.setState({
|
|
90
|
-
error: this.props.errors.numberNotEmpty
|
|
91
|
-
});
|
|
92
|
-
} else this.setState({
|
|
93
|
-
error: undefined
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
_defineProperty(this, "handleChangeAreaCode", event => {
|
|
97
|
-
this.setState({
|
|
98
|
-
initialized: true
|
|
99
|
-
});
|
|
100
|
-
const areaCode = event.target.value.slice(0, 4);
|
|
101
|
-
if (!areaCode) {
|
|
102
|
-
this.setState({
|
|
103
|
-
areaCode
|
|
104
|
-
}, () => {
|
|
105
|
-
this.handleChange("".concat(this.state.areaCode).concat(this.state.phoneNumber));
|
|
106
|
-
});
|
|
107
|
-
} else {
|
|
108
|
-
this.setState({
|
|
109
|
-
areaCode
|
|
110
|
-
}, () => {
|
|
111
|
-
this.handleChange("".concat(this.state.areaCode, "-").concat(this.state.phoneNumber));
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
this.handleCleanPhoneNumber();
|
|
115
|
-
this.handleValidateAreaCode(areaCode);
|
|
116
|
-
});
|
|
117
|
-
_defineProperty(this, "handleChangePhone", event => {
|
|
118
|
-
const phoneNumber = event.target.value.slice(0, 10 - this.state.areaCode.length);
|
|
119
|
-
this.setState({
|
|
120
|
-
phoneNumber
|
|
121
|
-
}, () => {
|
|
122
|
-
this.handleChange("".concat(this.state.areaCode, "-").concat(this.state.phoneNumber));
|
|
123
|
-
});
|
|
124
|
-
this.handleValidatePhoneNumber(phoneNumber);
|
|
125
|
-
});
|
|
126
|
-
_defineProperty(this, "handleKeyPress", event => {
|
|
127
|
-
const regexp = /[0-9]+/g;
|
|
128
|
-
if (!regexp.test(event.key)) {
|
|
129
|
-
event.preventDefault();
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
_defineProperty(this, "handleChange", initialValue => {
|
|
133
|
-
let value = initialValue;
|
|
134
|
-
const {
|
|
135
|
-
childKeys,
|
|
136
|
-
field,
|
|
137
|
-
input
|
|
138
|
-
} = this.props;
|
|
139
|
-
if (childKeys) {
|
|
140
|
-
const splittedPhone = value.split('-');
|
|
141
|
-
value = {
|
|
142
|
-
...(!(0, _array.isEmpty)(splittedPhone[0]) && {
|
|
143
|
-
[childKeys[0]]: splittedPhone[0]
|
|
144
|
-
}),
|
|
145
|
-
...(!(0, _array.isEmpty)(splittedPhone[1]) && {
|
|
146
|
-
[childKeys[1]]: splittedPhone[1]
|
|
147
|
-
})
|
|
148
|
-
};
|
|
149
|
-
} else if (field.configuration && field.configuration.without_dash) {
|
|
150
|
-
value = initialValue.replace('-', '');
|
|
151
|
-
}
|
|
152
|
-
input.onChange(value);
|
|
153
|
-
});
|
|
154
|
-
this.state = {
|
|
155
|
-
areaCode: '',
|
|
156
|
-
phoneNumber: '',
|
|
157
|
-
city: null,
|
|
158
|
-
initialized: false
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
componentDidMount() {
|
|
162
|
-
if (this.props.input && this.props.input.value && !this.state.initialized) {
|
|
163
|
-
this.handleInitializeField();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
componentDidUpdate(prevProps) {
|
|
167
|
-
if (this.props.input && this.props.input.value && !this.state.areaCode && !this.state.initialized) {
|
|
168
|
-
this.handleInitializeField();
|
|
169
|
-
}
|
|
170
|
-
if (this.state.initialized && prevProps.input && prevProps.input.value && this.props.input && (!this.props.input.value || this.props.input.value.length === 0)) {
|
|
171
|
-
this.cleanField();
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
render() {
|
|
175
|
-
var _field$configuration, _field$configuration2;
|
|
176
|
-
const {
|
|
177
|
-
areaCodeFieldProps,
|
|
178
|
-
phoneNumberFieldProps,
|
|
179
|
-
field,
|
|
180
|
-
input,
|
|
181
|
-
disabled,
|
|
182
|
-
meta,
|
|
183
|
-
classes: themeClasses = {},
|
|
184
|
-
placeholder,
|
|
185
|
-
label,
|
|
186
|
-
variant,
|
|
187
|
-
inputClassName,
|
|
188
|
-
classNames
|
|
189
|
-
} = this.props;
|
|
190
|
-
const {
|
|
191
|
-
areaCode,
|
|
192
|
-
city,
|
|
193
|
-
error,
|
|
194
|
-
phoneNumber
|
|
195
|
-
} = this.state;
|
|
196
|
-
const classes = (0, _classesUtils.mergeClasses)(themeClasses, classNames);
|
|
197
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
198
|
-
className: "".concat(_stylesModule.default.container, " ").concat(this.props.style)
|
|
199
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
200
|
-
className: _stylesModule.default.inputContainer
|
|
201
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
202
|
-
className: "".concat(_stylesModule.default.areaCode, " ").concat(_stylesModule.default["".concat(variant, "AreaCode")], " ").concat(classes.areaCodeContainer)
|
|
203
|
-
}, /*#__PURE__*/_react.default.createElement(_TextField.default, _extends({
|
|
204
|
-
name: "area_code",
|
|
205
|
-
type: "tel",
|
|
206
|
-
label: ((_field$configuration = field.configuration) === null || _field$configuration === void 0 ? void 0 : _field$configuration.area_code_label) || _constants.AREA_CODE_LABEL,
|
|
207
|
-
placeholder: ((_field$configuration2 = field.configuration) === null || _field$configuration2 === void 0 ? void 0 : _field$configuration2.area_code_placeholder) || _constants.AREA_CODE_PLACEHOLDER,
|
|
208
|
-
autoComplete: "off",
|
|
209
|
-
fullWidth: true,
|
|
210
|
-
margin: "none",
|
|
211
|
-
onKeyPress: this.handleKeyPress,
|
|
212
|
-
onFocus: this.handleFocus,
|
|
213
|
-
onChange: this.handleChangeAreaCode,
|
|
214
|
-
onBlur: this.handleBlur,
|
|
215
|
-
value: areaCode,
|
|
216
|
-
error: Boolean(error || (0, _form.shouldShowErrors)(meta)),
|
|
217
|
-
disabled: disabled,
|
|
218
|
-
variant: variant,
|
|
219
|
-
InputProps: {
|
|
220
|
-
classes: {
|
|
221
|
-
input: inputClassName
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}, areaCodeFieldProps)), /*#__PURE__*/_react.default.createElement(_UTTooltip.default, {
|
|
225
|
-
stringContentClassName: classes.tooltip,
|
|
226
|
-
content: city || ' '
|
|
227
|
-
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
228
|
-
className: "".concat(_stylesModule.default.icon, " ").concat(_stylesModule.default["".concat(variant, "Icon")], " ").concat(city && _stylesModule.default.showCheckedIcon)
|
|
229
|
-
}, /*#__PURE__*/_react.default.createElement(_CheckCircleOutline.default, {
|
|
230
|
-
tabIndex: "-1",
|
|
231
|
-
className: "".concat(_stylesModule.default.checkedIcon, " ").concat(classes.areaCodeIcon)
|
|
232
|
-
})))), /*#__PURE__*/_react.default.createElement("div", {
|
|
233
|
-
className: "".concat(_stylesModule.default.phoneNumber, " ").concat(classes.phoneNumberContainer)
|
|
234
|
-
}, /*#__PURE__*/_react.default.createElement(_TextField.default, _extends({
|
|
235
|
-
name: "phone_number",
|
|
236
|
-
type: "tel",
|
|
237
|
-
margin: "none",
|
|
238
|
-
placeholder: placeholder,
|
|
239
|
-
label: label,
|
|
240
|
-
onKeyPress: this.handleKeyPress,
|
|
241
|
-
autoComplete: "off",
|
|
242
|
-
fullWidth: true,
|
|
243
|
-
error: Boolean(error || (0, _form.shouldShowErrors)(meta)),
|
|
244
|
-
onFocus: input.onFocus,
|
|
245
|
-
onChange: this.handleChangePhone,
|
|
246
|
-
disabled: !city || disabled,
|
|
247
|
-
value: phoneNumber,
|
|
248
|
-
variant: variant,
|
|
249
|
-
InputProps: {
|
|
250
|
-
classes: {
|
|
251
|
-
input: inputClassName
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}, phoneNumberFieldProps)))), (error || (0, _form.shouldShowErrors)(meta)) && /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
|
|
255
|
-
colorTheme: "error",
|
|
256
|
-
variant: "small"
|
|
257
|
-
}, error || meta.error));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
UTPhoneInput.propTypes = {
|
|
261
|
-
input: _formTypes.inputPropTypes,
|
|
262
|
-
meta: _formTypes.metaPropTypes,
|
|
263
|
-
placeholder: _propTypes.string,
|
|
264
|
-
disabled: _propTypes.bool,
|
|
265
|
-
label: _propTypes.string,
|
|
266
|
-
classes: (0, _propTypes.objectOf)(_propTypes.string),
|
|
267
|
-
classNames: (0, _propTypes.objectOf)(_propTypes.string),
|
|
268
|
-
errors: (0, _propTypes.shape)({
|
|
269
|
-
codeWithZero: _propTypes.string,
|
|
270
|
-
invalidCode: _propTypes.string,
|
|
271
|
-
phoneWithFifteen: _propTypes.string,
|
|
272
|
-
phoneWithZero: _propTypes.string,
|
|
273
|
-
numberNotEmpty: _propTypes.string
|
|
274
|
-
}),
|
|
275
|
-
childKeys: (0, _propTypes.arrayOf)(_propTypes.string),
|
|
276
|
-
field: _formTypes.fieldType,
|
|
277
|
-
variant: _propTypes.string,
|
|
278
|
-
inputClassName: _propTypes.string,
|
|
279
|
-
areaCodeFieldProps: _propTypes.object,
|
|
280
|
-
phoneNumberFieldProps: _propTypes.object
|
|
12
|
+
const UTPhoneInput = _ref => {
|
|
13
|
+
let {
|
|
14
|
+
version = 'V0',
|
|
15
|
+
...props
|
|
16
|
+
} = _ref;
|
|
17
|
+
const Component = {
|
|
18
|
+
V0: _V.default,
|
|
19
|
+
V1: _V2.default
|
|
20
|
+
}[version];
|
|
21
|
+
return /*#__PURE__*/_react.default.createElement(Component, props);
|
|
281
22
|
};
|
|
282
|
-
UTPhoneInput.
|
|
283
|
-
|
|
284
|
-
areaCodeFieldProps: {},
|
|
285
|
-
phoneNumberFieldProps: {}
|
|
23
|
+
UTPhoneInput.propTypes = {
|
|
24
|
+
version: _propTypes.string
|
|
286
25
|
};
|
|
287
|
-
var _default = exports.default =
|
|
26
|
+
var _default = exports.default = UTPhoneInput;
|