@widergy/energy-ui 3.92.0 → 3.94.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/UTCheckList/versions/V1/index.js +4 -1
- package/dist/components/UTCheckbox/versions/V1/index.js +3 -0
- package/dist/components/UTDataCategory/index.js +1 -1
- package/dist/components/UTDataElement/components/MainAction/index.js +6 -20
- package/dist/components/UTFieldLabel/index.js +9 -2
- package/dist/components/UTFieldLabel/styles.module.scss +6 -0
- package/dist/components/UTIcon/components/Flag/index.js +34 -0
- package/dist/components/UTIcon/components/Flag/styles.module.scss +10 -0
- package/dist/components/UTIcon/index.js +1 -3
- package/dist/components/UTIcon/theme.js +18 -3
- package/dist/components/UTPhoneInput/versions/V1/README.md +38 -6
- package/dist/components/UTPhoneInput/versions/V1/index.js +66 -18
- package/dist/components/UTPhoneInput/versions/V1/styles.module.scss +14 -1
- package/dist/components/UTSelect/versions/V1/index.js +10 -5
- package/dist/components/UTSelect/versions/V1/utils.js +8 -1
- package/dist/components/UTSwitch/index.js +12 -87
- package/dist/components/UTSwitch/versions/V0/index.js +101 -0
- package/dist/components/UTSwitch/{theme.js → versions/V0/theme.js} +1 -1
- package/dist/components/UTSwitch/versions/V1/constants.js +12 -0
- package/dist/components/UTSwitch/versions/V1/index.js +102 -0
- package/dist/components/UTSwitch/versions/V1/styles.module.scss +71 -0
- package/dist/components/UTSwitch/versions/V1/theme.js +51 -0
- package/dist/constants/countries.js +975 -0
- package/dist/constants/testIds.js +1 -1
- package/package.json +2 -1
- package/dist/components/UTDataElement/components/MainAction/styles.module.scss +0 -23
- /package/dist/components/UTSwitch/{constants.js → versions/V0/constants.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [3.94.0](https://github.com/widergy/energy-ui/compare/v3.93.0...v3.94.0) (2025-07-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* [PROMI] phone input ([#638](https://github.com/widergy/energy-ui/issues/638)) ([6f4c2a8](https://github.com/widergy/energy-ui/commit/6f4c2a846cc5d1b1c6490d5bae9467604a0a4b48))
|
|
7
|
+
|
|
8
|
+
# [3.93.0](https://github.com/widergy/energy-ui/compare/v3.92.0...v3.93.0) (2025-07-29)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add switch version v1 ([#647](https://github.com/widergy/energy-ui/issues/647)) ([e8b39d7](https://github.com/widergy/energy-ui/commit/e8b39d77b71b9d8cb2361ff9c13a17d5f8cff7e6))
|
|
14
|
+
|
|
1
15
|
# [3.92.0](https://github.com/widergy/energy-ui/compare/v3.91.1...v3.92.0) (2025-07-22)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -115,9 +115,10 @@ const UTCheckList = _ref => {
|
|
|
115
115
|
version: "V1"
|
|
116
116
|
}), categorizedOptions.map((_ref5, catIndex) => {
|
|
117
117
|
let [category, categoryOptions] = _ref5;
|
|
118
|
+
const categoryKey = "".concat(category, "-").concat(categoryOptions.map(opt => opt.value).join('-'));
|
|
118
119
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
119
120
|
className: "".concat(_stylesModule.default.categoryContainer, " ").concat(smallVerticalSpacingClass),
|
|
120
|
-
key:
|
|
121
|
+
key: categoryKey
|
|
121
122
|
}, category !== _constants2.NO_CATEGORY && /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
|
|
122
123
|
className: _stylesModule.default.categoryTitle,
|
|
123
124
|
colorTheme: "gray",
|
|
@@ -133,6 +134,7 @@ const UTCheckList = _ref => {
|
|
|
133
134
|
disabled: item.disabled || disabled,
|
|
134
135
|
isSimple: isSimple,
|
|
135
136
|
key: item.value,
|
|
137
|
+
icon: item.icon,
|
|
136
138
|
onChange: () => handleChange(item.value),
|
|
137
139
|
reversed: isSimple ? reversedBasedOnVariant : reversed,
|
|
138
140
|
spacing: horizontalSpacing,
|
|
@@ -157,6 +159,7 @@ UTCheckList.propTypes = {
|
|
|
157
159
|
options: (0, _propTypes.arrayOf)((0, _propTypes.shape)({
|
|
158
160
|
checked: _propTypes.bool,
|
|
159
161
|
disabled: _propTypes.bool,
|
|
162
|
+
icon: _propTypes.string,
|
|
160
163
|
name: _propTypes.string,
|
|
161
164
|
value: _propTypes.string,
|
|
162
165
|
category: _propTypes.string
|
|
@@ -36,6 +36,7 @@ const UTCheckbox = _ref => {
|
|
|
36
36
|
meta,
|
|
37
37
|
onChange = () => {},
|
|
38
38
|
required,
|
|
39
|
+
icon,
|
|
39
40
|
title,
|
|
40
41
|
value = false,
|
|
41
42
|
variant = 'default',
|
|
@@ -88,6 +89,7 @@ const UTCheckbox = _ref => {
|
|
|
88
89
|
})))), CustomComponent || /*#__PURE__*/_react.default.createElement(_UTFieldLabel.default, {
|
|
89
90
|
className: classes.title,
|
|
90
91
|
highlighted: shouldHighlightLabel,
|
|
92
|
+
icon: icon,
|
|
91
93
|
required: required
|
|
92
94
|
}, title), error && /*#__PURE__*/_react.default.createElement(_UTValidation.default, {
|
|
93
95
|
className: classes.validation,
|
|
@@ -110,6 +112,7 @@ UTCheckbox.propTypes = {
|
|
|
110
112
|
meta: _formTypes.metaPropTypes.isRequired,
|
|
111
113
|
onChange: _propTypes.func,
|
|
112
114
|
required: _propTypes.bool,
|
|
115
|
+
icon: _propTypes.string,
|
|
113
116
|
reversed: _propTypes.bool,
|
|
114
117
|
spacing: _propTypes.string,
|
|
115
118
|
title: _propTypes.string,
|
|
@@ -71,7 +71,7 @@ const UTDataCategory = _ref => {
|
|
|
71
71
|
} = element;
|
|
72
72
|
return /*#__PURE__*/_react.default.createElement(_UTDataElement.default, _extends({
|
|
73
73
|
key: key || index,
|
|
74
|
-
dataTestId: dataTestId ? "".concat(dataTestId, ".
|
|
74
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(index) : "".concat(dataCategory.item, ".").concat(index),
|
|
75
75
|
classNames: classes.element
|
|
76
76
|
}, elementsProps, dataElementProps));
|
|
77
77
|
}))));
|
|
@@ -10,7 +10,6 @@ var _testIds = require("../../../../constants/testIds");
|
|
|
10
10
|
var _UTSwitch = _interopRequireDefault(require("../../../UTSwitch"));
|
|
11
11
|
var _UTButton = _interopRequireDefault(require("../../../UTButton"));
|
|
12
12
|
var _constants = require("../../constants");
|
|
13
|
-
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
14
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
14
|
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); }
|
|
16
15
|
const {
|
|
@@ -23,28 +22,15 @@ const MainAction = _ref => {
|
|
|
23
22
|
value,
|
|
24
23
|
onClick,
|
|
25
24
|
dataTestId,
|
|
26
|
-
id,
|
|
27
25
|
...props
|
|
28
26
|
} = _ref;
|
|
29
|
-
return type === _constants.ACTION_TYPE.SWITCH && onChange ? /*#__PURE__*/_react.default.createElement(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(dataElement.switchAction) : undefined,
|
|
33
|
-
input: {
|
|
34
|
-
onChange,
|
|
35
|
-
value
|
|
36
|
-
},
|
|
37
|
-
field: {
|
|
38
|
-
key: "".concat(id)
|
|
39
|
-
}
|
|
27
|
+
return type === _constants.ACTION_TYPE.SWITCH && onChange ? /*#__PURE__*/_react.default.createElement(_UTSwitch.default, _extends({
|
|
28
|
+
onChange: onChange,
|
|
29
|
+
value: value
|
|
40
30
|
}, props, {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
sliderContainer: _stylesModule.default.sliderContainer,
|
|
45
|
-
sliderHover: _stylesModule.default.sliderHover
|
|
46
|
-
}
|
|
47
|
-
}))) : type === _constants.ACTION_TYPE.BUTTON && onClick ? /*#__PURE__*/_react.default.createElement(_UTButton.default, _extends({
|
|
31
|
+
dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(dataElement.switchAction) : undefined,
|
|
32
|
+
version: "V1"
|
|
33
|
+
})) : type === _constants.ACTION_TYPE.BUTTON && onClick ? /*#__PURE__*/_react.default.createElement(_UTButton.default, _extends({
|
|
48
34
|
dataTestId: dataTestId ? "".concat(dataTestId, ".").concat(dataElement.buttonAction) : undefined,
|
|
49
35
|
variant: "text",
|
|
50
36
|
onClick: onClick
|
|
@@ -12,6 +12,7 @@ var _UTLabel = _interopRequireDefault(require("../UTLabel"));
|
|
|
12
12
|
var _UTButton = _interopRequireDefault(require("../UTButton"));
|
|
13
13
|
var _UTTooltip = _interopRequireDefault(require("../UTTooltip"));
|
|
14
14
|
var _inputs = require("../../constants/inputs");
|
|
15
|
+
var _UTIcon = _interopRequireDefault(require("../UTIcon"));
|
|
15
16
|
var _constants = require("./constants");
|
|
16
17
|
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
17
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -22,6 +23,7 @@ const UTFieldLabel = _ref => {
|
|
|
22
23
|
className,
|
|
23
24
|
dataTestId,
|
|
24
25
|
highlighted,
|
|
26
|
+
icon,
|
|
25
27
|
readOnly,
|
|
26
28
|
required,
|
|
27
29
|
size = 'large',
|
|
@@ -31,12 +33,16 @@ const UTFieldLabel = _ref => {
|
|
|
31
33
|
className: "".concat(!(0, _isEmpty.default)(actions) ? _stylesModule.default.labelWithActions : '')
|
|
32
34
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
33
35
|
className: "".concat(_stylesModule.default.label, " ").concat(className)
|
|
34
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
36
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
37
|
+
className: _stylesModule.default.labelContent
|
|
38
|
+
}, icon && /*#__PURE__*/_react.default.createElement(_UTIcon.default, {
|
|
39
|
+
name: icon
|
|
40
|
+
}), /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
|
|
35
41
|
colorTheme: readOnly ? 'gray' : highlighted ? 'accent' : 'dark',
|
|
36
42
|
dataTestId: dataTestId,
|
|
37
43
|
variant: _inputs.TITLE_VARIANTS[size],
|
|
38
44
|
withMarkdown: true
|
|
39
|
-
}, children), required && /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
|
|
45
|
+
}, children)), required && /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
|
|
40
46
|
colorTheme: "error",
|
|
41
47
|
shade: "04",
|
|
42
48
|
variant: _inputs.TITLE_VARIANTS[size],
|
|
@@ -62,6 +68,7 @@ UTFieldLabel.propTypes = {
|
|
|
62
68
|
className: _propTypes.string,
|
|
63
69
|
dataTestId: _propTypes.string,
|
|
64
70
|
highlighted: _propTypes.bool,
|
|
71
|
+
icon: _propTypes.string,
|
|
65
72
|
readOnly: _propTypes.bool,
|
|
66
73
|
required: _propTypes.bool,
|
|
67
74
|
size: _propTypes.string,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _propTypes = require("prop-types");
|
|
9
|
+
var _reactFlagpack = _interopRequireDefault(require("react-flagpack"));
|
|
10
|
+
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
const FlagComponent = _ref => {
|
|
13
|
+
let {
|
|
14
|
+
className,
|
|
15
|
+
name,
|
|
16
|
+
size
|
|
17
|
+
} = _ref;
|
|
18
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
19
|
+
className: "".concat(className, " ").concat(_stylesModule.default.flagContainer),
|
|
20
|
+
style: {
|
|
21
|
+
width: size,
|
|
22
|
+
height: size
|
|
23
|
+
}
|
|
24
|
+
}, /*#__PURE__*/_react.default.createElement(_reactFlagpack.default, {
|
|
25
|
+
code: name,
|
|
26
|
+
className: _stylesModule.default.flag
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
FlagComponent.propTypes = {
|
|
30
|
+
className: _propTypes.string,
|
|
31
|
+
name: _propTypes.string,
|
|
32
|
+
size: _propTypes.number
|
|
33
|
+
};
|
|
34
|
+
var _default = exports.default = FlagComponent;
|
|
@@ -6,11 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _propTypes = require("prop-types");
|
|
9
|
-
var TablerIcons = _interopRequireWildcard(require("@tabler/icons-react"));
|
|
10
9
|
var _WithTheme = _interopRequireDefault(require("../WithTheme"));
|
|
11
10
|
var _theme = require("./theme");
|
|
12
11
|
var _constants = require("./constants");
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
13
|
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); }
|
|
16
14
|
const UTIcon = _ref => {
|
|
@@ -48,7 +46,7 @@ const UTIcon = _ref => {
|
|
|
48
46
|
size,
|
|
49
47
|
variant
|
|
50
48
|
});
|
|
51
|
-
const IconComponent =
|
|
49
|
+
const IconComponent = (0, _theme.getComponent)(name);
|
|
52
50
|
if (!IconComponent) return null;
|
|
53
51
|
return /*#__PURE__*/_react.default.createElement(IconComponent, _extends({
|
|
54
52
|
className: classNames,
|
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.retrieveStyle = exports.retrieveColor = exports.getIconProps = exports.getClassNames = void 0;
|
|
6
|
+
exports.retrieveStyle = exports.retrieveColor = exports.getIconProps = exports.getComponent = exports.getClassNames = void 0;
|
|
7
|
+
var TablerIcons = _interopRequireWildcard(require("@tabler/icons-react"));
|
|
7
8
|
var _componentUtils = require("../../utils/componentUtils");
|
|
9
|
+
var _countries = _interopRequireDefault(require("../../constants/countries"));
|
|
10
|
+
var _Flag = _interopRequireDefault(require("./components/Flag"));
|
|
8
11
|
var _constants = require("./constants");
|
|
9
12
|
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
10
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
15
|
const retrieveColor = _ref => {
|
|
12
16
|
var _theme$Palette$action;
|
|
13
17
|
let {
|
|
@@ -63,7 +67,8 @@ const getIconProps = _ref2 => {
|
|
|
63
67
|
...(internalFill && {
|
|
64
68
|
fill: internalFill
|
|
65
69
|
}),
|
|
66
|
-
...(isEnergyIcon ? energyIconProps : defaultIconProps)
|
|
70
|
+
...(isEnergyIcon ? energyIconProps : defaultIconProps),
|
|
71
|
+
name
|
|
67
72
|
};
|
|
68
73
|
};
|
|
69
74
|
exports.getIconProps = getIconProps;
|
|
@@ -124,4 +129,14 @@ const retrieveStyle = _ref4 => {
|
|
|
124
129
|
}, {});
|
|
125
130
|
return variantStyles;
|
|
126
131
|
};
|
|
127
|
-
exports.retrieveStyle = retrieveStyle;
|
|
132
|
+
exports.retrieveStyle = retrieveStyle;
|
|
133
|
+
const getComponent = name => {
|
|
134
|
+
if (_countries.default.find(_ref5 => {
|
|
135
|
+
let {
|
|
136
|
+
code
|
|
137
|
+
} = _ref5;
|
|
138
|
+
return code === name;
|
|
139
|
+
})) return _Flag.default;
|
|
140
|
+
return _constants.ENERGY_ICONS[name] || TablerIcons[name];
|
|
141
|
+
};
|
|
142
|
+
exports.getComponent = getComponent;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
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.
|
|
5
|
+
`UTPhoneInput` is a configurable phone input component that allows users to input phone numbers, optionally including an area code or country 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. The component now supports both string and object value formats for enhanced flexibility.
|
|
6
6
|
|
|
7
7
|
## Props
|
|
8
8
|
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
| actions | object | | Actions to render within `UTFieldLabel`. |
|
|
12
12
|
| areaCodeDataTestId | string | | Identifier for the area code input field, useful for testing. |
|
|
13
13
|
| areaCodePlaceholder | string | | Placeholder for the area code input field. |
|
|
14
|
-
|
|
|
14
|
+
| prefix | string | | Country code prefix for the phone number (e.g., "+54" for Argentina). When provided, enables country code selection functionality. |
|
|
15
|
+
| prefixDataTestId | string | | Identifier for the country code select field, useful for testing. |
|
|
15
16
|
| disabled | bool | false | Disables both the area code and phone number input fields. |
|
|
16
17
|
| error | string | | Error message displayed below the input fields. |
|
|
17
18
|
| inputSize | string | | Size of the input field. One of: `small`, `large`. |
|
|
18
19
|
| helpText | string | | Help text displayed below the input fields. |
|
|
19
20
|
| maxLength | number | 10 | Maximum number of characters allowed in the phone number input (excluding the area code). |
|
|
20
|
-
| onChange | func | | Function called when either the area code or phone number value changes.
|
|
21
|
+
| onChange | func | | Function called when either the area code or phone number value changes. Returns string format (`areaCode-phoneNumber`) or object format (`{number, prefix}`) when `prefix` is provided. |
|
|
21
22
|
| phoneNumberDataTestId | string | | Identifier for the phone number input field, useful for testing. |
|
|
22
23
|
| placeholder | string | | Placeholder text displayed in the phone number input when it's empty. |
|
|
23
24
|
| readOnly | bool | false | Makes the area code and phone number input fields read-only. |
|
|
@@ -25,15 +26,32 @@
|
|
|
25
26
|
| RightIcon | elementType | | Icon displayed on the right side of both the area code and phone number input fields. |
|
|
26
27
|
| title | string | | Title displayed above the input fields. |
|
|
27
28
|
| titleVariant | string | 'large' | Variant of the title, can be `small` or `large`. |
|
|
28
|
-
| translations | shape({ areaCodeWithoutZeroError: string, invalidAreaCodeError: string }) | `{ areaCodeWithoutZeroError: '
|
|
29
|
+
| translations | shape({ areaCodeWithoutZeroError: string, invalidAreaCodeError: string, areaCodeMinLenghtError: string }) | `{ areaCodeMinLenghtError: 'El código de área debe contener al menos 2 dígitos.', areaCodeWithoutZeroError: 'El código de área debe comenzar sin 0.', invalidAreaCodeError: 'No pudimos reconocer el código de área ingresado. Intenta con uno diferente.' }` | Translation strings used for error messages related to area code validation. |
|
|
30
|
+
| validationDataTestId | string | | Identifier for the validation component, useful for testing. |
|
|
29
31
|
| validations | object | | Object containing validation rules to be applied to the input fields. |
|
|
30
|
-
| value | string
|
|
32
|
+
| value | string \| object | | Current value of the phone input. Can be a string in format `areaCode-phoneNumber` or an object `{number, prefix}` when `prefix` is provided. |
|
|
31
33
|
| withAreaCode | bool | true | If `true`, displays the area code input field. If `false`, only the phone number input is shown. |
|
|
34
|
+
| editablePrefix | bool | false | If `true`, allows users to edit the country code prefix. When `false`, the prefix is read-only. Only applies when `prefix` is provided. |
|
|
35
|
+
|
|
36
|
+
### Value Formats
|
|
37
|
+
|
|
38
|
+
The component supports two value formats depending on the configuration:
|
|
39
|
+
|
|
40
|
+
#### String Format (Default)
|
|
41
|
+
When `prefix` is not provided, the component uses string format:
|
|
42
|
+
- **Input**: `"11-82712232"` (area code + phone number)
|
|
43
|
+
- **Output**: `"11-82712232"` via `onChange`
|
|
44
|
+
|
|
45
|
+
#### Object Format (prefix provided)
|
|
46
|
+
When `prefix` is provided, the component uses object format:
|
|
47
|
+
- **Input**: `{number: "1182712232", prefix: "+54"}`
|
|
48
|
+
- **Output**: `{number: "1182712232", prefix: "+54"}` via `onChange`
|
|
32
49
|
|
|
33
50
|
### Translations
|
|
34
51
|
|
|
35
52
|
The `translations` prop allows you to customize the error messages displayed when the area code is invalid. It supports the following keys:
|
|
36
53
|
|
|
54
|
+
- **areaCodeMinLenghtError**: Error message displayed when the area code has less than 2 digits.
|
|
37
55
|
- **areaCodeWithoutZeroError**: Error message displayed when the area code starts with a `0`.
|
|
38
56
|
- **invalidAreaCodeError**: Error message displayed when the area code is invalid.
|
|
39
57
|
|
|
@@ -52,6 +70,20 @@ Errors related to the area code or phone number input can be displayed using the
|
|
|
52
70
|
|
|
53
71
|
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
72
|
|
|
73
|
+
### Country Code Selection
|
|
74
|
+
|
|
75
|
+
When `prefix` is provided, the component displays a country selector with:
|
|
76
|
+
- Country flags using the `react-flagpack` library
|
|
77
|
+
- Phone prefixes for each country
|
|
78
|
+
- Automatic country code detection based on the current value
|
|
79
|
+
- Support for 195 countries with 2 digit ISO code
|
|
80
|
+
- Editable prefix selection when `editablePrefix` is `true`
|
|
81
|
+
|
|
55
82
|
### Combining the Area Code and Phone Number
|
|
56
83
|
|
|
57
|
-
|
|
84
|
+
The `withAreaCode` prop should not be `true` when `prefix` is provided. When the `onChange` handler is called, it returns the value in the appropriate format:
|
|
85
|
+
|
|
86
|
+
- **String format**: `areaCode-phoneNumber` (e.g., "11-82712232")
|
|
87
|
+
- **Object format**: `{number: "1182712232", prefix: "+54"}` when `prefix` is provided
|
|
88
|
+
|
|
89
|
+
If the `withAreaCode` prop is set to `false`, only the phone number will be returned in the appropriate format.
|
|
@@ -13,22 +13,26 @@ var _UTValidation = _interopRequireWildcard(require("../../../UTValidation"));
|
|
|
13
13
|
var _buttonTypes = require("../../../../types/buttonTypes");
|
|
14
14
|
var _constants = require("../../../UTBaseInputField/constants");
|
|
15
15
|
var _utils = require("../../../UTValidation/utils");
|
|
16
|
+
var _UTSelect = _interopRequireDefault(require("../../../UTSelect"));
|
|
17
|
+
var _countries = _interopRequireDefault(require("../../../../constants/countries"));
|
|
16
18
|
var _constants2 = require("./constants");
|
|
17
19
|
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
18
20
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
21
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
20
22
|
const UTPhoneInput = _ref => {
|
|
23
|
+
var _countries$find;
|
|
21
24
|
let {
|
|
22
25
|
actions,
|
|
23
26
|
areaCodeDataTestId,
|
|
24
27
|
areaCodePlaceholder,
|
|
25
|
-
countryCode,
|
|
26
28
|
disabled,
|
|
27
29
|
error,
|
|
28
30
|
helpText,
|
|
29
31
|
inputSize,
|
|
30
32
|
maxLength = 10,
|
|
31
33
|
onChange,
|
|
34
|
+
prefix,
|
|
35
|
+
prefixDataTestId,
|
|
32
36
|
phoneNumberDataTestId,
|
|
33
37
|
placeholder,
|
|
34
38
|
readOnly,
|
|
@@ -43,13 +47,15 @@ const UTPhoneInput = _ref => {
|
|
|
43
47
|
validationDataTestId,
|
|
44
48
|
validations,
|
|
45
49
|
value,
|
|
46
|
-
withAreaCode = true
|
|
50
|
+
withAreaCode = true,
|
|
51
|
+
editablePrefix = false
|
|
47
52
|
} = _ref;
|
|
48
53
|
const [areaCodeState, setAreaCodeState] = (0, _react.useState)({
|
|
49
54
|
code: '',
|
|
50
55
|
error: ''
|
|
51
56
|
});
|
|
52
57
|
const [blurWithError, setBlurWithError] = (0, _react.useState)(false);
|
|
58
|
+
const [prefixState, setPrefixState] = (0, _react.useState)((value === null || value === void 0 ? void 0 : value.prefix) || prefix);
|
|
53
59
|
const [phoneNumber, setPhoneNumber] = (0, _react.useState)('');
|
|
54
60
|
const {
|
|
55
61
|
areaCodeWithoutZeroError,
|
|
@@ -57,15 +63,22 @@ const UTPhoneInput = _ref => {
|
|
|
57
63
|
areaCodeMinLenghtError
|
|
58
64
|
} = translations;
|
|
59
65
|
(0, _react.useEffect)(() => {
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
const {
|
|
67
|
+
number: valueNumber
|
|
68
|
+
} = typeof value === 'string' ? {
|
|
69
|
+
number: value
|
|
70
|
+
} : value;
|
|
71
|
+
if (prefix) {
|
|
72
|
+
if (valueNumber && valueNumber !== phoneNumber) setPhoneNumber(valueNumber);
|
|
73
|
+
} else if (valueNumber && withAreaCode) {
|
|
74
|
+
const [code, phone] = valueNumber.split('-');
|
|
62
75
|
setAreaCodeState(prevState => ({
|
|
63
76
|
...prevState,
|
|
64
77
|
code: code || ''
|
|
65
78
|
}));
|
|
66
79
|
setPhoneNumber(phone || '');
|
|
67
|
-
} else if (
|
|
68
|
-
setPhoneNumber(
|
|
80
|
+
} else if (valueNumber && !withAreaCode) {
|
|
81
|
+
setPhoneNumber(valueNumber);
|
|
69
82
|
}
|
|
70
83
|
}, [value, withAreaCode]);
|
|
71
84
|
const validateAreaCode = code => {
|
|
@@ -102,7 +115,12 @@ const UTPhoneInput = _ref => {
|
|
|
102
115
|
setPhoneNumber(phoneNumberValue);
|
|
103
116
|
}, []);
|
|
104
117
|
(0, _react.useEffect)(() => {
|
|
105
|
-
if (
|
|
118
|
+
if (prefix) {
|
|
119
|
+
if (phoneNumber && (phoneNumber !== (value === null || value === void 0 ? void 0 : value.number) || prefixState !== (value === null || value === void 0 ? void 0 : value.prefix))) onChange({
|
|
120
|
+
number: phoneNumber,
|
|
121
|
+
prefix: prefixState
|
|
122
|
+
});
|
|
123
|
+
} else if (areaCodeState.code !== '' || phoneNumber !== '') {
|
|
106
124
|
const newValue = withAreaCode ? "".concat(areaCodeState.code, "-").concat(phoneNumber) : phoneNumber;
|
|
107
125
|
if (newValue !== value) {
|
|
108
126
|
onChange(newValue);
|
|
@@ -110,7 +128,7 @@ const UTPhoneInput = _ref => {
|
|
|
110
128
|
} else {
|
|
111
129
|
onChange('');
|
|
112
130
|
}
|
|
113
|
-
}, [areaCodeState.code, phoneNumber, withAreaCode, onChange, value]);
|
|
131
|
+
}, [areaCodeState.code, phoneNumber, withAreaCode, onChange, value, prefixState, prefix]);
|
|
114
132
|
const validationData = validations || areaCodeState.error && (0, _utils.formatErrorToValidation)(areaCodeState.error) || error && (0, _utils.formatErrorToValidation)(error);
|
|
115
133
|
const hasError = (validationData === null || validationData === void 0 ? void 0 : validationData.length) > 0;
|
|
116
134
|
const getAreaCodeMaxLength = () => Math.min(maxLength - phoneNumber.length, 4);
|
|
@@ -124,7 +142,40 @@ const UTPhoneInput = _ref => {
|
|
|
124
142
|
size: titleVariant
|
|
125
143
|
}, title), /*#__PURE__*/_react.default.createElement("div", {
|
|
126
144
|
className: _stylesModule.default.inputsContainer
|
|
127
|
-
},
|
|
145
|
+
}, prefix && /*#__PURE__*/_react.default.createElement(_UTSelect.default, {
|
|
146
|
+
version: "V1",
|
|
147
|
+
classNames: {
|
|
148
|
+
container: _stylesModule.default.countryCodeContainer
|
|
149
|
+
},
|
|
150
|
+
dataTestId: prefixDataTestId,
|
|
151
|
+
disabled: disabled || !editablePrefix,
|
|
152
|
+
options: _countries.default.map(_ref2 => {
|
|
153
|
+
let {
|
|
154
|
+
code,
|
|
155
|
+
prefix: prefixValue
|
|
156
|
+
} = _ref2;
|
|
157
|
+
return {
|
|
158
|
+
name: "".concat(prefixValue, " (").concat(code, ")"),
|
|
159
|
+
value: prefixValue,
|
|
160
|
+
icon: code
|
|
161
|
+
};
|
|
162
|
+
}),
|
|
163
|
+
clearable: false,
|
|
164
|
+
value: prefixState,
|
|
165
|
+
onChange: setPrefixState,
|
|
166
|
+
icon: (_countries$find = _countries.default.find(_ref3 => {
|
|
167
|
+
let {
|
|
168
|
+
prefix: prefixValue
|
|
169
|
+
} = _ref3;
|
|
170
|
+
return prefixValue === prefixState;
|
|
171
|
+
})) === null || _countries$find === void 0 ? void 0 : _countries$find.code,
|
|
172
|
+
className: _stylesModule.default.countryCodeSelect,
|
|
173
|
+
autocompleteProps: {
|
|
174
|
+
classes: {
|
|
175
|
+
popper: _stylesModule.default.popper
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}), !prefix && withAreaCode && /*#__PURE__*/_react.default.createElement(_UTBaseInputField.default, {
|
|
128
179
|
alwaysShowPlaceholder: true,
|
|
129
180
|
classNames: {
|
|
130
181
|
container: _stylesModule.default.areaCodeContainer
|
|
@@ -149,18 +200,13 @@ const UTPhoneInput = _ref => {
|
|
|
149
200
|
}), /*#__PURE__*/_react.default.createElement(_UTBaseInputField.default, {
|
|
150
201
|
alwaysShowPlaceholder: true,
|
|
151
202
|
classNames: {
|
|
152
|
-
container: _stylesModule.default.phoneContainer
|
|
203
|
+
container: _stylesModule.default.phoneContainer,
|
|
204
|
+
root: _stylesModule.default.phoneContainerRoot
|
|
153
205
|
},
|
|
154
206
|
dataTestId: phoneNumberDataTestId,
|
|
155
207
|
disabled: disabled,
|
|
156
208
|
error: hasError && !areaCodeState.error,
|
|
157
209
|
inputSize: inputSize,
|
|
158
|
-
leftAdornments: countryCode && !withAreaCode ? [{
|
|
159
|
-
name: _constants.COMPONENT_KEYS.PREFIX,
|
|
160
|
-
props: {
|
|
161
|
-
text: countryCode
|
|
162
|
-
}
|
|
163
|
-
}] : [],
|
|
164
210
|
maxLength: getPhoneNumberMaxLength(),
|
|
165
211
|
onChange: handleChangePhoneNumber,
|
|
166
212
|
placeholder: placeholder,
|
|
@@ -184,11 +230,12 @@ UTPhoneInput.propTypes = {
|
|
|
184
230
|
actions: (0, _propTypes.arrayOf)(_buttonTypes.buttonTypes),
|
|
185
231
|
areaCodeDataTestId: _propTypes.string,
|
|
186
232
|
areaCodePlaceholder: _propTypes.string,
|
|
187
|
-
|
|
233
|
+
prefix: _propTypes.string,
|
|
188
234
|
disabled: _propTypes.bool,
|
|
189
235
|
error: _propTypes.string,
|
|
190
236
|
helpText: _propTypes.string,
|
|
191
237
|
inputSize: _propTypes.string,
|
|
238
|
+
prefixDataTestId: _propTypes.string,
|
|
192
239
|
maxLength: _propTypes.number,
|
|
193
240
|
onChange: _propTypes.func,
|
|
194
241
|
phoneNumberDataTestId: _propTypes.string,
|
|
@@ -204,6 +251,7 @@ UTPhoneInput.propTypes = {
|
|
|
204
251
|
validationDataTestId: _propTypes.string,
|
|
205
252
|
validations: _UTValidation.validationDataProptypes,
|
|
206
253
|
value: _propTypes.string,
|
|
207
|
-
withAreaCode: _propTypes.bool
|
|
254
|
+
withAreaCode: _propTypes.bool,
|
|
255
|
+
editablePrefix: _propTypes.bool
|
|
208
256
|
};
|
|
209
257
|
var _default = exports.default = UTPhoneInput;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
.inputsContainer {
|
|
8
8
|
display: flex;
|
|
9
|
-
align-items:
|
|
9
|
+
align-items: center;
|
|
10
10
|
flex-direction: row;
|
|
11
11
|
grid-gap: 8px;
|
|
12
12
|
}
|
|
@@ -20,4 +20,17 @@
|
|
|
20
20
|
.phoneContainer {
|
|
21
21
|
flex: 1 1 auto;
|
|
22
22
|
min-width: 120px;
|
|
23
|
+
height: 100%;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.countryCodeSelect {
|
|
27
|
+
width: 180px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.phoneContainerRoot {
|
|
31
|
+
height: 100%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.popper {
|
|
35
|
+
width: unset !important;
|
|
23
36
|
}
|
|
@@ -36,6 +36,7 @@ const UTSelect = _ref => {
|
|
|
36
36
|
errorDataTestId,
|
|
37
37
|
freeWidth = false,
|
|
38
38
|
helpText,
|
|
39
|
+
icon,
|
|
39
40
|
inputSize,
|
|
40
41
|
itemDataTestId,
|
|
41
42
|
listDataTestId,
|
|
@@ -54,7 +55,8 @@ const UTSelect = _ref => {
|
|
|
54
55
|
titleVariant = _inputs.TITLE_VARIANTS.large,
|
|
55
56
|
value = multiple ? [] : null,
|
|
56
57
|
variant = 'select',
|
|
57
|
-
withAutoReset = true
|
|
58
|
+
withAutoReset = true,
|
|
59
|
+
autocompleteProps = {}
|
|
58
60
|
} = _ref;
|
|
59
61
|
const optionsSortedByCategory = (0, _react.useMemo)(() => {
|
|
60
62
|
if (!options || options.length === 0) return [];
|
|
@@ -137,8 +139,9 @@ const UTSelect = _ref => {
|
|
|
137
139
|
error,
|
|
138
140
|
multiple,
|
|
139
141
|
value,
|
|
140
|
-
prefix
|
|
141
|
-
|
|
142
|
+
prefix,
|
|
143
|
+
icon
|
|
144
|
+
}), [multiple, value, prefix, icon]);
|
|
142
145
|
const rightAdornments = (0, _react.useMemo)(() => (0, _utils2.getRightAdornments)({
|
|
143
146
|
action,
|
|
144
147
|
clearable,
|
|
@@ -203,7 +206,7 @@ const UTSelect = _ref => {
|
|
|
203
206
|
options: optionsSortedByCategory,
|
|
204
207
|
PaperComponent: _UTPaper.default,
|
|
205
208
|
renderInput: InputComponentToRender
|
|
206
|
-
})), helpText && /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
|
|
209
|
+
}, autocompleteProps)), helpText && /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
|
|
207
210
|
colorTheme: "gray",
|
|
208
211
|
variant: "small"
|
|
209
212
|
}, helpText), validationData && /*#__PURE__*/_react.default.createElement(_UTValidation.default, {
|
|
@@ -228,6 +231,7 @@ UTSelect.propTypes = {
|
|
|
228
231
|
errorDataTestId: _propTypes.string,
|
|
229
232
|
freeWidth: _propTypes.bool,
|
|
230
233
|
helpText: _propTypes.string,
|
|
234
|
+
icon: _propTypes.string,
|
|
231
235
|
inputSize: _propTypes.string,
|
|
232
236
|
itemDataTestId: _propTypes.string,
|
|
233
237
|
listDataTestId: _propTypes.string,
|
|
@@ -249,6 +253,7 @@ UTSelect.propTypes = {
|
|
|
249
253
|
titleVariant: _propTypes.string,
|
|
250
254
|
value: (0, _propTypes.oneOfType)([_propTypes.string, (0, _propTypes.arrayOf)((0, _propTypes.oneOfType)([_propTypes.string, _propTypes.number]))]),
|
|
251
255
|
variant: _propTypes.string,
|
|
252
|
-
withAutoReset: _propTypes.bool
|
|
256
|
+
withAutoReset: _propTypes.bool,
|
|
257
|
+
autocompleteProps: _propTypes.object
|
|
253
258
|
};
|
|
254
259
|
var _default = exports.default = UTSelect;
|