tenjin-ui-kit 0.3.50 → 0.3.52
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/components/input/index.js +48 -19
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ var _styles = require("@mui/material/styles");
|
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
14
14
|
var _text = _interopRequireDefault(require("../text"));
|
|
15
|
-
var _excluded = ["label", "id", "fullWidth", "disableAutocomplete", "startIcon", "endIcon", "size", "error", "errorMessage", "isRequired", "isDisabled", "isPastDateDisabled", "readOnly", "helperText", "autoFocus", "onBlurDelay", "restrictSpecialChars"];
|
|
15
|
+
var _excluded = ["label", "id", "fullWidth", "disableAutocomplete", "startIcon", "endIcon", "size", "error", "errorMessage", "isRequired", "isDisabled", "isPastDateDisabled", "readOnly", "helperText", "autoFocus", "onBlurDelay", "restrictSpecialChars", "input", "meta"];
|
|
16
16
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
17
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -31,6 +31,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
31
31
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
32
32
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
33
33
|
var Input = function Input(_ref) {
|
|
34
|
+
var _input$value;
|
|
34
35
|
var label = _ref.label,
|
|
35
36
|
id = _ref.id,
|
|
36
37
|
fullWidth = _ref.fullWidth,
|
|
@@ -49,9 +50,12 @@ var Input = function Input(_ref) {
|
|
|
49
50
|
onBlurDelay = _ref.onBlurDelay,
|
|
50
51
|
_ref$restrictSpecialC = _ref.restrictSpecialChars,
|
|
51
52
|
restrictSpecialChars = _ref$restrictSpecialC === void 0 ? false : _ref$restrictSpecialC,
|
|
53
|
+
input = _ref.input,
|
|
54
|
+
meta = _ref.meta,
|
|
52
55
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
53
56
|
var theme = (0, _styles.useTheme)();
|
|
54
57
|
var minDate = new Date().toISOString().split("T")[0];
|
|
58
|
+
var isUsingRFF = !!input && typeof input.onChange === "function";
|
|
55
59
|
var _useState = (0, _react.useState)(rest.value || ""),
|
|
56
60
|
_useState2 = _slicedToArray(_useState, 2),
|
|
57
61
|
localValue = _useState2[0],
|
|
@@ -64,24 +68,47 @@ var Input = function Input(_ref) {
|
|
|
64
68
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
65
69
|
localErrorMessage = _useState6[0],
|
|
66
70
|
setLocalErrorMessage = _useState6[1];
|
|
67
|
-
|
|
71
|
+
(0, _react.useEffect)(function () {
|
|
72
|
+
if (!isUsingRFF && rest.value !== undefined) {
|
|
73
|
+
setLocalValue(rest.value);
|
|
74
|
+
}
|
|
75
|
+
}, [rest.value, isUsingRFF]);
|
|
76
|
+
var showError = function showError(message) {
|
|
77
|
+
setLocalError(true);
|
|
78
|
+
setLocalErrorMessage(message);
|
|
79
|
+
};
|
|
80
|
+
var clearError = function clearError() {
|
|
81
|
+
setLocalError(false);
|
|
82
|
+
setLocalErrorMessage("");
|
|
83
|
+
};
|
|
68
84
|
var handleChange = function handleChange(e) {
|
|
69
85
|
var value = e.target.value;
|
|
70
86
|
if (restrictSpecialChars) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
var filteredValue = value.replace(/[^a-zA-Z0-9.,@_\-() ]/g, "");
|
|
88
|
+
if (filteredValue !== value) {
|
|
89
|
+
showError("Only letters, numbers, and . , _ - @ ( ) are allowed.");
|
|
90
|
+
value = filteredValue;
|
|
75
91
|
} else {
|
|
76
|
-
|
|
77
|
-
setLocalErrorMessage("");
|
|
92
|
+
clearError();
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
setLocalValue(value);
|
|
81
|
-
if (
|
|
96
|
+
if (isUsingRFF) {
|
|
97
|
+
input.onChange(_objectSpread(_objectSpread({}, e), {}, {
|
|
98
|
+
target: _objectSpread(_objectSpread({}, e.target), {}, {
|
|
99
|
+
value: value
|
|
100
|
+
})
|
|
101
|
+
}));
|
|
102
|
+
} else if (typeof rest.onChange === "function") {
|
|
103
|
+
rest.onChange(_objectSpread(_objectSpread({}, e), {}, {
|
|
104
|
+
target: _objectSpread(_objectSpread({}, e.target), {}, {
|
|
105
|
+
value: value
|
|
106
|
+
})
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
82
109
|
};
|
|
83
|
-
var
|
|
84
|
-
var
|
|
110
|
+
var value = isUsingRFF ? (_input$value = input.value) !== null && _input$value !== void 0 ? _input$value : "" : localValue;
|
|
111
|
+
var effectiveError = localError || isUsingRFF && (meta === null || meta === void 0 ? void 0 : meta.touched) && (meta.error || errorMessage) || errorMessage || error;
|
|
85
112
|
return /*#__PURE__*/_react.default.createElement(_FormControl.default, {
|
|
86
113
|
variant: "standard",
|
|
87
114
|
fullWidth: fullWidth
|
|
@@ -98,9 +125,9 @@ var Input = function Input(_ref) {
|
|
|
98
125
|
}
|
|
99
126
|
}, " * ") : "")), /*#__PURE__*/_react.default.createElement(_material.OutlinedInput, _extends({
|
|
100
127
|
id: id,
|
|
101
|
-
value:
|
|
128
|
+
value: value,
|
|
102
129
|
required: isRequired,
|
|
103
|
-
autoComplete: disableAutocomplete ? "
|
|
130
|
+
autoComplete: disableAutocomplete ? "off" : "on",
|
|
104
131
|
sx: {
|
|
105
132
|
"& input": {
|
|
106
133
|
backgroundColor: isDisabled && "#DDDDDD",
|
|
@@ -117,13 +144,13 @@ var Input = function Input(_ref) {
|
|
|
117
144
|
startAdornment: startIcon,
|
|
118
145
|
endAdornment: endIcon,
|
|
119
146
|
disabled: isDisabled,
|
|
120
|
-
error: effectiveError,
|
|
147
|
+
error: !!effectiveError,
|
|
121
148
|
onChange: handleChange,
|
|
122
149
|
onBlur: function onBlur(e) {
|
|
123
150
|
setTimeout(function () {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
151
|
+
var _input$onBlur;
|
|
152
|
+
if (isUsingRFF) (_input$onBlur = input.onBlur) === null || _input$onBlur === void 0 ? void 0 : _input$onBlur.call(input, e);
|
|
153
|
+
if (typeof rest.onBlur === "function") rest.onBlur(e);
|
|
127
154
|
}, onBlurDelay || 100);
|
|
128
155
|
},
|
|
129
156
|
autoFocus: !!autoFocus ? rest.value ? rest.value : true : false,
|
|
@@ -137,7 +164,7 @@ var Input = function Input(_ref) {
|
|
|
137
164
|
color: "red"
|
|
138
165
|
},
|
|
139
166
|
id: "component-error-text"
|
|
140
|
-
},
|
|
167
|
+
}, localErrorMessage || helperText));
|
|
141
168
|
};
|
|
142
169
|
Input.propTypes = {
|
|
143
170
|
label: _propTypes.default.string,
|
|
@@ -152,7 +179,9 @@ Input.propTypes = {
|
|
|
152
179
|
readOnly: _propTypes.default.bool,
|
|
153
180
|
// Added readOnly prop type
|
|
154
181
|
autoFocus: _propTypes.default.bool,
|
|
155
|
-
restrictSpecialChars: _propTypes.default.bool
|
|
182
|
+
restrictSpecialChars: _propTypes.default.bool,
|
|
183
|
+
input: _propTypes.default.object,
|
|
184
|
+
meta: _propTypes.default.object
|
|
156
185
|
};
|
|
157
186
|
var _default = Input;
|
|
158
187
|
exports.default = _default;
|