@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.
Files changed (42) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/components/UTActionCard/components/BottomActions/index.js +3 -0
  3. package/dist/components/UTAutocomplete/index.js +5 -0
  4. package/dist/components/UTBaseInputField/components/ActionAdornment/index.js +31 -0
  5. package/dist/components/UTBaseInputField/components/IconAdornment/constants.js +8 -0
  6. package/dist/components/UTBaseInputField/components/IconAdornment/index.js +48 -0
  7. package/dist/components/UTBaseInputField/components/IconAdornment/utils.js +17 -0
  8. package/dist/components/UTBaseInputField/components/PrefixAdornment/index.js +24 -0
  9. package/dist/components/UTBaseInputField/components/SuffixAdornment/index.js +22 -0
  10. package/dist/components/UTBaseInputField/components/TooltipAdornment/index.js +29 -0
  11. package/dist/components/UTBaseInputField/components/TooltipAdornment/styles.module.scss +3 -0
  12. package/dist/components/UTBaseInputField/index.js +169 -0
  13. package/dist/components/UTBaseInputField/styles.module.scss +29 -0
  14. package/dist/components/UTBaseInputField/theme.js +97 -0
  15. package/dist/components/UTButtonGroup/index.js +2 -0
  16. package/dist/components/UTCBUInput/index.js +21 -18
  17. package/dist/components/UTCard/index.js +6 -2
  18. package/dist/components/UTCheckbox/index.js +8 -0
  19. package/dist/components/UTCuit/index.js +51 -27
  20. package/dist/components/UTGoogleAutocomplete/index.js +2 -0
  21. package/dist/components/UTLabel/index.js +4 -1
  22. package/dist/components/UTOnboarding/index.js +15 -0
  23. package/dist/components/UTPasswordField/versions/V0/index.js +3 -0
  24. package/dist/components/UTPhoneInput/index.js +16 -277
  25. package/dist/components/UTPhoneInput/versions/V0/index.js +297 -0
  26. package/dist/components/UTPhoneInput/{styles.module.scss → versions/V0/styles.module.scss} +10 -10
  27. package/dist/components/UTPhoneInput/{theme.js → versions/V0/theme.js} +1 -1
  28. package/dist/components/UTPhoneInput/versions/V1/README.md +57 -0
  29. package/dist/components/UTPhoneInput/versions/V1/constants.js +910 -0
  30. package/dist/components/UTPhoneInput/versions/V1/index.js +166 -0
  31. package/dist/components/UTPhoneInput/versions/V1/styles.module.scss +20 -0
  32. package/dist/components/UTStatus/index.js +3 -0
  33. package/dist/components/UTTable/index.js +4 -1
  34. package/dist/components/UTTextArea/versions/V0/index.js +3 -0
  35. package/dist/components/UTTextInput/versions/V0/index.js +5 -0
  36. package/dist/components/UTTextInput/versions/V1/README.md +1 -1
  37. package/dist/components/UTTextInput/versions/V1/index.js +30 -87
  38. package/dist/components/UTTextInput/versions/V1/styles.module.scss +0 -24
  39. package/dist/constants/inputs.js +10 -0
  40. package/dist/types/googleMapsTypes.js +1 -0
  41. package/package.json +3 -2
  42. /package/dist/components/UTPhoneInput/{constants.js → versions/V0/constants.js} +0 -0
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _propTypes = require("prop-types");
9
+ var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));
10
+ var _CheckCircleOutline = _interopRequireDefault(require("@material-ui/icons/CheckCircleOutline"));
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"));
21
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
23
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
24
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
25
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
26
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
27
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
28
+ class UTPhoneInput extends _react.PureComponent {
29
+ constructor(props) {
30
+ super(props);
31
+ _defineProperty(this, "cleanField", () => this.setState({
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
+ areaCodeDataTestId,
178
+ areaCodeFieldProps,
179
+ phoneNumberFieldProps,
180
+ field,
181
+ input,
182
+ disabled,
183
+ meta,
184
+ classes: themeClasses = {},
185
+ phoneNumberDataTestId,
186
+ placeholder,
187
+ label,
188
+ variant,
189
+ inputClassName,
190
+ classNames
191
+ } = this.props;
192
+ const {
193
+ areaCode,
194
+ city,
195
+ error,
196
+ phoneNumber
197
+ } = this.state;
198
+ const classes = (0, _classesUtils.mergeClasses)(themeClasses, classNames);
199
+ return /*#__PURE__*/_react.default.createElement("div", {
200
+ className: "".concat(_stylesModule.default.container, " ").concat(this.props.style)
201
+ }, /*#__PURE__*/_react.default.createElement("div", {
202
+ className: _stylesModule.default.inputContainer
203
+ }, /*#__PURE__*/_react.default.createElement("div", {
204
+ className: "".concat(_stylesModule.default.areaCode, " ").concat(_stylesModule.default["".concat(variant, "AreaCode")], " ").concat(classes.areaCodeContainer)
205
+ }, /*#__PURE__*/_react.default.createElement(_TextField.default, _extends({
206
+ name: "area_code",
207
+ type: "tel",
208
+ label: ((_field$configuration = field.configuration) === null || _field$configuration === void 0 ? void 0 : _field$configuration.area_code_label) || _constants.AREA_CODE_LABEL,
209
+ placeholder: ((_field$configuration2 = field.configuration) === null || _field$configuration2 === void 0 ? void 0 : _field$configuration2.area_code_placeholder) || _constants.AREA_CODE_PLACEHOLDER,
210
+ autoComplete: "off",
211
+ fullWidth: true,
212
+ margin: "none",
213
+ onKeyPress: this.handleKeyPress,
214
+ onFocus: this.handleFocus,
215
+ onChange: this.handleChangeAreaCode,
216
+ onBlur: this.handleBlur,
217
+ value: areaCode,
218
+ error: Boolean(error || (0, _form.shouldShowErrors)(meta)),
219
+ disabled: disabled,
220
+ variant: variant,
221
+ InputProps: {
222
+ classes: {
223
+ input: inputClassName
224
+ },
225
+ inputProps: {
226
+ 'data-testid': areaCodeDataTestId
227
+ }
228
+ }
229
+ }, areaCodeFieldProps)), /*#__PURE__*/_react.default.createElement(_UTTooltip.default, {
230
+ stringContentClassName: classes.tooltip,
231
+ content: city || ' '
232
+ }, /*#__PURE__*/_react.default.createElement("span", {
233
+ className: "".concat(_stylesModule.default.icon, " ").concat(_stylesModule.default["".concat(variant, "Icon")], " ").concat(city && _stylesModule.default.showCheckedIcon)
234
+ }, /*#__PURE__*/_react.default.createElement(_CheckCircleOutline.default, {
235
+ tabIndex: "-1",
236
+ className: "".concat(_stylesModule.default.checkedIcon, " ").concat(classes.areaCodeIcon)
237
+ })))), /*#__PURE__*/_react.default.createElement("div", {
238
+ className: "".concat(_stylesModule.default.phoneNumber, " ").concat(classes.phoneNumberContainer)
239
+ }, /*#__PURE__*/_react.default.createElement(_TextField.default, _extends({
240
+ name: "phone_number",
241
+ type: "tel",
242
+ margin: "none",
243
+ placeholder: placeholder,
244
+ label: label,
245
+ onKeyPress: this.handleKeyPress,
246
+ autoComplete: "off",
247
+ fullWidth: true,
248
+ error: Boolean(error || (0, _form.shouldShowErrors)(meta)),
249
+ onFocus: input.onFocus,
250
+ onChange: this.handleChangePhone,
251
+ disabled: !city || disabled,
252
+ value: phoneNumber,
253
+ variant: variant,
254
+ InputProps: {
255
+ classes: {
256
+ input: inputClassName
257
+ },
258
+ inputProps: {
259
+ 'data-testid': phoneNumberDataTestId
260
+ }
261
+ }
262
+ }, phoneNumberFieldProps)))), (error || (0, _form.shouldShowErrors)(meta)) && /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
263
+ colorTheme: "error",
264
+ variant: "small"
265
+ }, error || meta.error));
266
+ }
267
+ }
268
+ UTPhoneInput.propTypes = {
269
+ input: _formTypes.inputPropTypes,
270
+ meta: _formTypes.metaPropTypes,
271
+ placeholder: _propTypes.string,
272
+ disabled: _propTypes.bool,
273
+ label: _propTypes.string,
274
+ classes: (0, _propTypes.objectOf)(_propTypes.string),
275
+ classNames: (0, _propTypes.objectOf)(_propTypes.string),
276
+ errors: (0, _propTypes.shape)({
277
+ codeWithZero: _propTypes.string,
278
+ invalidCode: _propTypes.string,
279
+ phoneWithFifteen: _propTypes.string,
280
+ phoneWithZero: _propTypes.string,
281
+ numberNotEmpty: _propTypes.string
282
+ }),
283
+ childKeys: (0, _propTypes.arrayOf)(_propTypes.string),
284
+ field: _formTypes.fieldType,
285
+ variant: _propTypes.string,
286
+ inputClassName: _propTypes.string,
287
+ areaCodeFieldProps: _propTypes.object,
288
+ phoneNumberFieldProps: _propTypes.object,
289
+ areaCodeDataTestId: _propTypes.string,
290
+ phoneNumberDataTestId: _propTypes.string
291
+ };
292
+ UTPhoneInput.defaultProps = {
293
+ classes: {},
294
+ areaCodeFieldProps: {},
295
+ phoneNumberFieldProps: {}
296
+ };
297
+ var _default = exports.default = (0, _WithTheme.default)(_theme.retrieveStyle, _theme.retrieveMuiTheme)(UTPhoneInput);
@@ -1,5 +1,5 @@
1
- @import '../../scss/variables/colors.module.scss';
2
- @import '../../scss/variables/fontSizes.module.scss';
1
+ @import '../../../../scss/variables/colors.module.scss';
2
+ @import '../../../../scss/variables/fontSizes.module.scss';
3
3
 
4
4
  .container {
5
5
  align-items: flex-start;
@@ -7,7 +7,7 @@
7
7
  flex-direction: column;
8
8
  flex-shrink: 0;
9
9
  width: 100%;
10
- };
10
+ }
11
11
 
12
12
  .inputContainer {
13
13
  align-items: flex-end;
@@ -15,21 +15,21 @@
15
15
  justify-content: space-between;
16
16
  margin-bottom: 8px;
17
17
  width: 100%;
18
- };
18
+ }
19
19
 
20
20
  .areaCode {
21
21
  align-items: flex-end;
22
22
  display: flex;
23
23
  position: relative;
24
- };
24
+ }
25
25
 
26
26
  .outlinedAreaCode {
27
27
  align-items: center;
28
- };
28
+ }
29
29
 
30
30
  .phoneNumber {
31
31
  width: calc(100% - 30px - 70px);
32
- };
32
+ }
33
33
 
34
34
  .input {
35
35
  appearance: none;
@@ -40,15 +40,15 @@
40
40
  margin-top: auto;
41
41
  outline: 0;
42
42
  width: 100%;
43
- };
43
+ }
44
44
 
45
45
  .activeInput {
46
46
  border-color: 1px solid $input-primary;
47
- };
47
+ }
48
48
 
49
49
  .error {
50
50
  height: 19px;
51
- };
51
+ }
52
52
 
53
53
  .smallText {
54
54
  font-size: $small;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.retrieveStyle = exports.retrieveMuiTheme = void 0;
7
7
  var _seamlessImmutable = require("seamless-immutable");
8
8
  var _styles = require("@material-ui/core/styles");
9
- var _colorsModule = _interopRequireDefault(require("../../scss/variables/colors.module.scss"));
9
+ var _colorsModule = _interopRequireDefault(require("../../../../scss/variables/colors.module.scss"));
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  const retrieveStyle = _ref => {
12
12
  let {
@@ -0,0 +1,57 @@
1
+ # UTPhoneInput
2
+
3
+ ## Description
4
+
5
+ `UTPhoneInput` is a configurable phone input component that allows users to input phone numbers, optionally including an area code. It supports various customization options such as icons, validation messages, and configurable error handling. The component also handles validation for specific area codes and can work with or without them.
6
+
7
+ ## Props
8
+
9
+ | Name | Type | Default | Description |
10
+ | --------------------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
11
+ | areaCodeDataTestId | string | | Identifier for the area code input field, useful for testing. |
12
+ | areaCodePlaceholder | string | | Placeholder for the area code input field. |
13
+ | countryCode | string | | Prefix for the phone number, typically used to display the country code (e.g., "+1" for the US). |
14
+ | disabled | bool | false | Disables both the area code and phone number input fields. |
15
+ | error | string | | Error message displayed below the input fields. |
16
+ | helpText | string | | Help text displayed below the input fields. |
17
+ | maxLength | number | 10 | Maximum number of characters allowed in the phone number input (excluding the area code). |
18
+ | onBlur | func | | Function called when either the area code or phone number input loses focus. |
19
+ | onChange | func | | Function called when either the area code or phone number value changes. Should handle concatenated values (`areaCode-phoneNumber`). |
20
+ | onFocus | func | | Function called when either the area code or phone number input gains focus. |
21
+ | phoneNumberDataTestId | string | | Identifier for the phone number input field, useful for testing. |
22
+ | placeholder | string | | Placeholder text displayed in the phone number input when it's empty. |
23
+ | readOnly | bool | false | Makes the area code and phone number input fields read-only. |
24
+ | required | bool | false | Marks the input fields as required. |
25
+ | RightIcon | elementType | | Icon displayed on the right side of both the area code and phone number input fields. |
26
+ | title | string | | Title displayed above the input fields. |
27
+ | titleVariant | string | 'large' | Variant of the title, can be `small` or `large`. |
28
+ | translations | shape({ areaCodeWithoutZeroError: string, invalidAreaCodeError: string }) | `{ areaCodeWithoutZeroError: 'Ingrese el código sin 0', invalidAreaCodeError: 'Código de área inválido' }` | Translation strings used for error messages related to area code validation. |
29
+ | validations | object | | Object containing validation rules to be applied to the input fields. |
30
+ | value | string | | Current value of the phone input in the format `areaCode-phoneNumber`. |
31
+ | withAreaCode | bool | true | If `true`, displays the area code input field. If `false`, only the phone number input is shown. |
32
+
33
+ ### Translations
34
+
35
+ The `translations` prop allows you to customize the error messages displayed when the area code is invalid. It supports the following keys:
36
+
37
+ - **areaCodeWithoutZeroError**: Error message displayed when the area code starts with a `0`.
38
+ - **invalidAreaCodeError**: Error message displayed when the area code is invalid.
39
+
40
+ ### titleVariant
41
+
42
+ The value of `titleVariant` must be one of the following:
43
+
44
+ - "small"
45
+ - "large"
46
+
47
+ ### Handling Errors
48
+
49
+ Errors related to the area code or phone number input can be displayed using the `error` prop or through the `validations` prop, which allows more complex validation rules. The component also provides built-in area code validation, which can be customized through the `translations` prop.
50
+
51
+ ### Validations
52
+
53
+ The `validations` prop allows you to pass an object with validation rules to be applied to both the area code and phone number inputs. For more information on the structure of `validations`, refer to the **UTValidation** component documentation.
54
+
55
+ ### Combining the Area Code and Phone Number
56
+
57
+ When the `onChange` handler is called, it returns the concatenated value of the area code and phone number in the format: `areaCode-phoneNumber`. If the `withAreaCode` prop is set to `false`, only the phone number will be returned.