@insticc/genericform 2.1.0 β 2.1.1
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/build/FormFields/CustomMobilePhone.js +42 -91
- package/build/index.js +1 -3
- package/package.json +1 -1
|
@@ -15,45 +15,18 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
15
15
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
16
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
17
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
18
|
-
var COUNTRY_CODES = [{
|
|
19
|
-
label: "π΅πΉ +351",
|
|
20
|
-
value: "+351"
|
|
21
|
-
}, {
|
|
22
|
-
label: "πͺπΈ +34",
|
|
23
|
-
value: "+34"
|
|
24
|
-
}, {
|
|
25
|
-
label: "π¬π§ +44",
|
|
26
|
-
value: "+44"
|
|
27
|
-
}, {
|
|
28
|
-
label: "πΊπΈ +1",
|
|
29
|
-
value: "+1"
|
|
30
|
-
}, {
|
|
31
|
-
label: "π«π· +33",
|
|
32
|
-
value: "+33"
|
|
33
|
-
}, {
|
|
34
|
-
label: "π©πͺ +49",
|
|
35
|
-
value: "+49"
|
|
36
|
-
}
|
|
37
|
-
// ...
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Mobile phone input with country code selector.
|
|
42
|
-
* value format: "+351 916999999"
|
|
43
|
-
* onChange(value, name) β same signature as other custom inputs.
|
|
44
|
-
*/
|
|
45
18
|
var CustomMobilePhone = function CustomMobilePhone(_ref) {
|
|
46
19
|
var onChange = _ref.onChange,
|
|
47
20
|
name = _ref.name,
|
|
48
21
|
label = _ref.label,
|
|
49
22
|
_ref$value = _ref.value,
|
|
50
|
-
|
|
23
|
+
externalValue = _ref$value === void 0 ? "" : _ref$value,
|
|
51
24
|
_ref$disabled = _ref.disabled,
|
|
52
25
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
53
26
|
_ref$required = _ref.required,
|
|
54
27
|
required = _ref$required === void 0 ? false : _ref$required,
|
|
55
28
|
_ref$placeholder = _ref.placeholder,
|
|
56
|
-
placeholder = _ref$placeholder === void 0 ? "
|
|
29
|
+
placeholder = _ref$placeholder === void 0 ? "+351 912345678" : _ref$placeholder,
|
|
57
30
|
error = _ref.error,
|
|
58
31
|
_ref$tooltip = _ref.tooltip,
|
|
59
32
|
tooltip = _ref$tooltip === void 0 ? "" : _ref$tooltip,
|
|
@@ -70,33 +43,33 @@ var CustomMobilePhone = function CustomMobilePhone(_ref) {
|
|
|
70
43
|
_ref$inputStyle = _ref.inputStyle,
|
|
71
44
|
inputStyle = _ref$inputStyle === void 0 ? {} : _ref$inputStyle,
|
|
72
45
|
_ref$tooltipStyle = _ref.tooltipStyle,
|
|
73
|
-
tooltipStyle = _ref$tooltipStyle === void 0 ? {} : _ref$tooltipStyle
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
46
|
+
tooltipStyle = _ref$tooltipStyle === void 0 ? {} : _ref$tooltipStyle;
|
|
47
|
+
var _useState = (0, _react.useState)(externalValue),
|
|
48
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
49
|
+
localValue = _useState2[0],
|
|
50
|
+
setLocalValue = _useState2[1];
|
|
51
|
+
|
|
52
|
+
// Sync with external value
|
|
53
|
+
(0, _react.useEffect)(function () {
|
|
54
|
+
setLocalValue(externalValue);
|
|
55
|
+
}, [externalValue]);
|
|
56
|
+
var handleChange = (0, _react.useCallback)(function (e) {
|
|
57
|
+
var rawValue = e.target.value;
|
|
58
|
+
|
|
59
|
+
// Auto-add "+" if user starts typing digits without it
|
|
60
|
+
var newValue = rawValue;
|
|
61
|
+
if (rawValue && !rawValue.startsWith('+')) {
|
|
62
|
+
var digits = rawValue.replace(/\D/g, '');
|
|
63
|
+
newValue = "+".concat(digits);
|
|
64
|
+
} else {
|
|
65
|
+
// Keep existing + and clean other characters
|
|
66
|
+
newValue = rawValue.replace(/[^\d+]/g, '');
|
|
67
|
+
}
|
|
68
|
+
setLocalValue(newValue);
|
|
69
|
+
onChange === null || onChange === void 0 || onChange(name, newValue);
|
|
70
|
+
}, [onChange, name]);
|
|
97
71
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
98
72
|
className: "ufg-field-group",
|
|
99
|
-
id: "form-telDiv-".concat(name),
|
|
100
73
|
style: mainDivStyle,
|
|
101
74
|
children: [(0, _defaults.labelJsx)({
|
|
102
75
|
name: name,
|
|
@@ -106,37 +79,20 @@ var CustomMobilePhone = function CustomMobilePhone(_ref) {
|
|
|
106
79
|
spanStyle: spanStyle,
|
|
107
80
|
showHelp: showHelp,
|
|
108
81
|
helpText: helpText
|
|
109
|
-
}), /*#__PURE__*/(0, _jsxRuntime.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
children: countryCodes.map(function (c) {
|
|
124
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
|
|
125
|
-
value: c.value,
|
|
126
|
-
children: c.label
|
|
127
|
-
}, c.value);
|
|
128
|
-
})
|
|
129
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
130
|
-
id: "form-input-".concat(name),
|
|
131
|
-
type: "tel",
|
|
132
|
-
value: localNumber,
|
|
133
|
-
disabled: disabled,
|
|
134
|
-
required: required,
|
|
135
|
-
placeholder: placeholder,
|
|
136
|
-
onChange: handleNumberChange,
|
|
137
|
-
className: "ufg-input".concat(error ? " error" : ""),
|
|
138
|
-
style: inputStyle
|
|
139
|
-
})]
|
|
82
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
83
|
+
id: "form-input-".concat(name),
|
|
84
|
+
type: "tel",
|
|
85
|
+
value: localValue,
|
|
86
|
+
disabled: disabled,
|
|
87
|
+
required: required,
|
|
88
|
+
placeholder: placeholder,
|
|
89
|
+
onChange: handleChange,
|
|
90
|
+
className: "ufg-input".concat(error ? " error" : ""),
|
|
91
|
+
style: inputStyle,
|
|
92
|
+
inputMode: "numeric",
|
|
93
|
+
pattern: "[0-9+]*",
|
|
94
|
+
autoComplete: "tel",
|
|
95
|
+
title: "Phone number (auto-adds + prefix)"
|
|
140
96
|
}), (0, _defaults.errorJsx)(error), (0, _defaults.tooltipJsx)(tooltip, tooltipStyle)]
|
|
141
97
|
});
|
|
142
98
|
};
|
|
@@ -156,11 +112,6 @@ CustomMobilePhone.propTypes = {
|
|
|
156
112
|
labelStyle: _propTypes["default"].object,
|
|
157
113
|
spanStyle: _propTypes["default"].object,
|
|
158
114
|
inputStyle: _propTypes["default"].object,
|
|
159
|
-
tooltipStyle: _propTypes["default"].object
|
|
160
|
-
countryCodes: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
161
|
-
label: _propTypes["default"].string.isRequired,
|
|
162
|
-
value: _propTypes["default"].string.isRequired
|
|
163
|
-
})),
|
|
164
|
-
defaultCountryCode: _propTypes["default"].string
|
|
115
|
+
tooltipStyle: _propTypes["default"].object
|
|
165
116
|
};
|
|
166
117
|
var _default = exports["default"] = CustomMobilePhone;
|
package/build/index.js
CHANGED
|
@@ -615,9 +615,7 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
615
615
|
case 'tel':
|
|
616
616
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomMobilePhone["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
617
617
|
value: value,
|
|
618
|
-
onChange: fieldHandler
|
|
619
|
-
countryCodes: field.countryCodes,
|
|
620
|
-
defaultCountryCode: field.defaultCountryCode
|
|
618
|
+
onChange: fieldHandler(field)
|
|
621
619
|
}), field.name);
|
|
622
620
|
|
|
623
621
|
// Date
|
package/package.json
CHANGED