@commercetools-uikit/localized-text-field 13.0.2 → 14.0.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/README.md +19 -1
- package/dist/commercetools-uikit-localized-text-field.cjs.dev.js +20 -4
- package/dist/commercetools-uikit-localized-text-field.cjs.prod.js +19 -3
- package/dist/commercetools-uikit-localized-text-field.esm.js +20 -4
- package/dist/declarations/src/localized-text-field.d.ts +5 -1
- package/package.json +12 -13
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ export default Example;
|
|
|
53
53
|
| ------------------------------- | -------------------------------------------------------------------------------------------- | :------: | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
54
54
|
| `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
|
|
55
55
|
| `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
|
|
56
|
-
| `errors` | `
|
|
56
|
+
| `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.
<br />
Unknown errors will be forwarded to `renderError` |
|
|
57
57
|
| `renderError` | `Function`<br/>[See signature.](#signature-renderError) | | | Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error. |
|
|
58
58
|
| `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
|
|
59
59
|
| `touched` | `boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
|
|
@@ -107,3 +107,21 @@ When the `key` is known, and when the value is truthy, and when `renderError` re
|
|
|
107
107
|
Known error keys are:
|
|
108
108
|
|
|
109
109
|
- `missing`: tells the user that this field is required
|
|
110
|
+
|
|
111
|
+
## Static methods
|
|
112
|
+
|
|
113
|
+
### `LocalizedTextField.toFieldErrors`
|
|
114
|
+
|
|
115
|
+
Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
type FormValues = {
|
|
119
|
+
myField: string;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
<LocalizedTextField
|
|
123
|
+
// ...
|
|
124
|
+
name="my-field"
|
|
125
|
+
errors={LocalizedTextField.toFieldErrors<FormValues>(formik.errors).myField}
|
|
126
|
+
/>;
|
|
127
|
+
```
|
|
@@ -59,6 +59,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
59
59
|
|
|
60
60
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
61
61
|
var sequentialId = utils.createSequentialId('localized-text-field-');
|
|
62
|
+
var sequentialErrorsId = utils.createSequentialId('localized-text-field-error-')();
|
|
62
63
|
|
|
63
64
|
var hasErrors = function hasErrors(errors) {
|
|
64
65
|
var _context;
|
|
@@ -117,7 +118,7 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
117
118
|
badge: this.props.badge,
|
|
118
119
|
hasRequiredIndicator: this.props.isRequired,
|
|
119
120
|
htmlFor: this.state.id
|
|
120
|
-
}), jsxRuntime.jsx(LocalizedTextInput__default["default"], _objectSpread({
|
|
121
|
+
}), jsxRuntime.jsx(LocalizedTextInput__default["default"], _objectSpread(_objectSpread({
|
|
121
122
|
autoComplete: this.props.autoComplete,
|
|
122
123
|
id: this.state.id,
|
|
123
124
|
name: this.props.name,
|
|
@@ -135,7 +136,11 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
135
136
|
hasError: hasError,
|
|
136
137
|
placeholder: this.props.placeholder,
|
|
137
138
|
horizontalConstraint: "scale"
|
|
138
|
-
}, utils.filterDataAttributes(this.props))
|
|
139
|
+
}, utils.filterDataAttributes(this.props)), {}, {
|
|
140
|
+
"aria-invalid": hasError,
|
|
141
|
+
"aria-errormessage": sequentialErrorsId
|
|
142
|
+
})), jsxRuntime.jsx(FieldErrors__default["default"], {
|
|
143
|
+
id: sequentialErrorsId,
|
|
139
144
|
errors: this.props.errors,
|
|
140
145
|
isVisible: hasError,
|
|
141
146
|
renderError: this.props.renderError
|
|
@@ -143,6 +148,17 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
143
148
|
})
|
|
144
149
|
});
|
|
145
150
|
}
|
|
151
|
+
}], [{
|
|
152
|
+
key: "toFieldErrors",
|
|
153
|
+
value:
|
|
154
|
+
/**
|
|
155
|
+
* Use this function to convert the Formik `errors` object type to
|
|
156
|
+
* our custom field errors type.
|
|
157
|
+
* This is primarly useful when using TypeScript.
|
|
158
|
+
*/
|
|
159
|
+
function toFieldErrors(errors) {
|
|
160
|
+
return errors;
|
|
161
|
+
}
|
|
146
162
|
}]);
|
|
147
163
|
|
|
148
164
|
return LocalizedTextField;
|
|
@@ -162,7 +178,7 @@ LocalizedTextField.getDerivedStateFromProps = function (props, state) {
|
|
|
162
178
|
LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
163
179
|
id: _pt__default["default"].string,
|
|
164
180
|
horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
165
|
-
errors: _pt__default["default"].
|
|
181
|
+
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
166
182
|
renderError: _pt__default["default"].func,
|
|
167
183
|
isRequired: _pt__default["default"].bool,
|
|
168
184
|
touched: _pt__default["default"].bool,
|
|
@@ -189,7 +205,7 @@ LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
189
205
|
var LocalizedTextField$1 = LocalizedTextField;
|
|
190
206
|
|
|
191
207
|
// NOTE: This string will be replaced on build time with the package version.
|
|
192
|
-
var version = "
|
|
208
|
+
var version = "14.0.1";
|
|
193
209
|
|
|
194
210
|
exports["default"] = LocalizedTextField$1;
|
|
195
211
|
exports.version = version;
|
|
@@ -58,6 +58,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
58
58
|
|
|
59
59
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
60
60
|
var sequentialId = utils.createSequentialId('localized-text-field-');
|
|
61
|
+
var sequentialErrorsId = utils.createSequentialId('localized-text-field-error-')();
|
|
61
62
|
|
|
62
63
|
var hasErrors = function hasErrors(errors) {
|
|
63
64
|
var _context;
|
|
@@ -112,7 +113,7 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
112
113
|
badge: this.props.badge,
|
|
113
114
|
hasRequiredIndicator: this.props.isRequired,
|
|
114
115
|
htmlFor: this.state.id
|
|
115
|
-
}), jsxRuntime.jsx(LocalizedTextInput__default["default"], _objectSpread({
|
|
116
|
+
}), jsxRuntime.jsx(LocalizedTextInput__default["default"], _objectSpread(_objectSpread({
|
|
116
117
|
autoComplete: this.props.autoComplete,
|
|
117
118
|
id: this.state.id,
|
|
118
119
|
name: this.props.name,
|
|
@@ -130,7 +131,11 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
130
131
|
hasError: hasError,
|
|
131
132
|
placeholder: this.props.placeholder,
|
|
132
133
|
horizontalConstraint: "scale"
|
|
133
|
-
}, utils.filterDataAttributes(this.props))
|
|
134
|
+
}, utils.filterDataAttributes(this.props)), {}, {
|
|
135
|
+
"aria-invalid": hasError,
|
|
136
|
+
"aria-errormessage": sequentialErrorsId
|
|
137
|
+
})), jsxRuntime.jsx(FieldErrors__default["default"], {
|
|
138
|
+
id: sequentialErrorsId,
|
|
134
139
|
errors: this.props.errors,
|
|
135
140
|
isVisible: hasError,
|
|
136
141
|
renderError: this.props.renderError
|
|
@@ -138,6 +143,17 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
138
143
|
})
|
|
139
144
|
});
|
|
140
145
|
}
|
|
146
|
+
}], [{
|
|
147
|
+
key: "toFieldErrors",
|
|
148
|
+
value:
|
|
149
|
+
/**
|
|
150
|
+
* Use this function to convert the Formik `errors` object type to
|
|
151
|
+
* our custom field errors type.
|
|
152
|
+
* This is primarly useful when using TypeScript.
|
|
153
|
+
*/
|
|
154
|
+
function toFieldErrors(errors) {
|
|
155
|
+
return errors;
|
|
156
|
+
}
|
|
141
157
|
}]);
|
|
142
158
|
|
|
143
159
|
return LocalizedTextField;
|
|
@@ -158,7 +174,7 @@ LocalizedTextField.propTypes = {};
|
|
|
158
174
|
var LocalizedTextField$1 = LocalizedTextField;
|
|
159
175
|
|
|
160
176
|
// NOTE: This string will be replaced on build time with the package version.
|
|
161
|
-
var version = "
|
|
177
|
+
var version = "14.0.1";
|
|
162
178
|
|
|
163
179
|
exports["default"] = LocalizedTextField$1;
|
|
164
180
|
exports.version = version;
|
|
@@ -34,6 +34,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
34
34
|
|
|
35
35
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
36
36
|
var sequentialId = createSequentialId('localized-text-field-');
|
|
37
|
+
var sequentialErrorsId = createSequentialId('localized-text-field-error-')();
|
|
37
38
|
|
|
38
39
|
var hasErrors = function hasErrors(errors) {
|
|
39
40
|
var _context;
|
|
@@ -92,7 +93,7 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
92
93
|
badge: this.props.badge,
|
|
93
94
|
hasRequiredIndicator: this.props.isRequired,
|
|
94
95
|
htmlFor: this.state.id
|
|
95
|
-
}), jsx(LocalizedTextInput, _objectSpread({
|
|
96
|
+
}), jsx(LocalizedTextInput, _objectSpread(_objectSpread({
|
|
96
97
|
autoComplete: this.props.autoComplete,
|
|
97
98
|
id: this.state.id,
|
|
98
99
|
name: this.props.name,
|
|
@@ -110,7 +111,11 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
110
111
|
hasError: hasError,
|
|
111
112
|
placeholder: this.props.placeholder,
|
|
112
113
|
horizontalConstraint: "scale"
|
|
113
|
-
}, filterDataAttributes(this.props))
|
|
114
|
+
}, filterDataAttributes(this.props)), {}, {
|
|
115
|
+
"aria-invalid": hasError,
|
|
116
|
+
"aria-errormessage": sequentialErrorsId
|
|
117
|
+
})), jsx(FieldErrors, {
|
|
118
|
+
id: sequentialErrorsId,
|
|
114
119
|
errors: this.props.errors,
|
|
115
120
|
isVisible: hasError,
|
|
116
121
|
renderError: this.props.renderError
|
|
@@ -118,6 +123,17 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
118
123
|
})
|
|
119
124
|
});
|
|
120
125
|
}
|
|
126
|
+
}], [{
|
|
127
|
+
key: "toFieldErrors",
|
|
128
|
+
value:
|
|
129
|
+
/**
|
|
130
|
+
* Use this function to convert the Formik `errors` object type to
|
|
131
|
+
* our custom field errors type.
|
|
132
|
+
* This is primarly useful when using TypeScript.
|
|
133
|
+
*/
|
|
134
|
+
function toFieldErrors(errors) {
|
|
135
|
+
return errors;
|
|
136
|
+
}
|
|
121
137
|
}]);
|
|
122
138
|
|
|
123
139
|
return LocalizedTextField;
|
|
@@ -137,7 +153,7 @@ LocalizedTextField.getDerivedStateFromProps = function (props, state) {
|
|
|
137
153
|
LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
138
154
|
id: _pt.string,
|
|
139
155
|
horizontalConstraint: _pt.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
140
|
-
errors: _pt.
|
|
156
|
+
errors: _pt.objectOf(_pt.bool),
|
|
141
157
|
renderError: _pt.func,
|
|
142
158
|
isRequired: _pt.bool,
|
|
143
159
|
touched: _pt.bool,
|
|
@@ -164,6 +180,6 @@ LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
164
180
|
var LocalizedTextField$1 = LocalizedTextField;
|
|
165
181
|
|
|
166
182
|
// NOTE: This string will be replaced on build time with the package version.
|
|
167
|
-
var version = "
|
|
183
|
+
var version = "14.0.1";
|
|
168
184
|
|
|
169
185
|
export { LocalizedTextField$1 as default, version };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Component, type ChangeEventHandler, type FocusEventHandler, type KeyboardEvent, type MouseEvent, type ReactElement, type ReactNode } from 'react';
|
|
2
|
-
import { type TFieldErrors } from '@commercetools-uikit/field-errors';
|
|
3
2
|
declare type TEvent = MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>;
|
|
4
3
|
declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
|
|
4
|
+
declare type TFieldErrors = Record<string, boolean>;
|
|
5
|
+
declare type TCustomFormErrors<Values> = {
|
|
6
|
+
[K in keyof Values]?: TFieldErrors;
|
|
7
|
+
};
|
|
5
8
|
declare type TLocalizedTextFieldProps = {
|
|
6
9
|
id?: string;
|
|
7
10
|
horizontalConstraint?: 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
@@ -40,6 +43,7 @@ declare class LocalizedTextField extends Component<TLocalizedTextFieldProps, TLo
|
|
|
40
43
|
static getDerivedStateFromProps: (props: TLocalizedTextFieldProps, state: TLocalizedTextFieldSTate) => {
|
|
41
44
|
id: string;
|
|
42
45
|
};
|
|
46
|
+
static toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
|
|
43
47
|
render(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
44
48
|
}
|
|
45
49
|
export default LocalizedTextField;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/localized-text-field",
|
|
3
3
|
"description": "A controlled text input component for localized single-line strings with validation states.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "14.0.1",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"directory": "packages/components/fields/localized-text-field"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://uikit.commercetools.com",
|
|
12
|
-
"keywords": ["javascript", "design
|
|
12
|
+
"keywords": ["javascript", "typescript", "design-system", "react", "uikit"],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
@@ -19,20 +19,19 @@
|
|
|
19
19
|
"module": "dist/commercetools-uikit-localized-text-field.esm.js",
|
|
20
20
|
"files": ["dist"],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@babel/runtime": "7.17.2",
|
|
23
|
-
"@babel/runtime-corejs3": "7.17.2",
|
|
24
|
-
"@commercetools-uikit/constraints": "
|
|
25
|
-
"@commercetools-uikit/design-system": "
|
|
26
|
-
"@commercetools-uikit/field-errors": "
|
|
27
|
-
"@commercetools-uikit/field-label": "
|
|
28
|
-
"@commercetools-uikit/localized-text-input": "
|
|
29
|
-
"@commercetools-uikit/spacings": "
|
|
30
|
-
"@commercetools-uikit/utils": "
|
|
22
|
+
"@babel/runtime": "^7.17.2",
|
|
23
|
+
"@babel/runtime-corejs3": "^7.17.2",
|
|
24
|
+
"@commercetools-uikit/constraints": "14.0.1",
|
|
25
|
+
"@commercetools-uikit/design-system": "14.0.0",
|
|
26
|
+
"@commercetools-uikit/field-errors": "14.0.1",
|
|
27
|
+
"@commercetools-uikit/field-label": "14.0.1",
|
|
28
|
+
"@commercetools-uikit/localized-text-input": "14.0.1",
|
|
29
|
+
"@commercetools-uikit/spacings": "14.0.1",
|
|
30
|
+
"@commercetools-uikit/utils": "14.0.1",
|
|
31
31
|
"@emotion/react": "^11.4.0",
|
|
32
32
|
"@emotion/styled": "^11.3.0",
|
|
33
|
-
"common-tags": "1.8.2",
|
|
34
33
|
"prop-types": "15.8.1",
|
|
35
|
-
"react-
|
|
34
|
+
"react-intl": "^5.24.6"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
37
|
"react": "17.0.2"
|