@commercetools-uikit/text-field 14.0.0 → 14.0.6
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
CHANGED
|
@@ -46,13 +46,13 @@ export default Example;
|
|
|
46
46
|
| `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
|
|
47
47
|
| `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
|
|
48
48
|
| `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.
<br/>
Unknown errors will be forwarded to renderError. |
|
|
49
|
-
| `renderError` | `Function`<br/>[See signature.](#signature-renderError) | | | This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error
|
|
49
|
+
| `renderError` | `Function`<br/>[See signature.](#signature-renderError) | | | This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error. |
|
|
50
50
|
| `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
|
|
51
51
|
| `touched` | `boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
|
|
52
52
|
| `autoComplete` | `string` | | | Used as HTML autocomplete property |
|
|
53
53
|
| `name` | `string` | | | Used as HTML name of the input component. property |
|
|
54
54
|
| `value` | `string` | ✅ | | Value of the input component. |
|
|
55
|
-
| `onChange` | `ChangeEventHandler` | | | Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value
|
|
55
|
+
| `onChange` | `ChangeEventHandler` | | | Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value. |
|
|
56
56
|
| `onBlur` | `FocusEventHandler` | | | Called when input is blurred |
|
|
57
57
|
| `onFocus` | `FocusEventHandler` | | | Called when input is focused |
|
|
58
58
|
| `isAutofocussed` | `boolean` | | | Focus the input on initial render |
|
|
@@ -99,3 +99,21 @@ Known error keys are:
|
|
|
99
99
|
## Main Functions and use cases are:
|
|
100
100
|
|
|
101
101
|
- Input field for single-line strings
|
|
102
|
+
|
|
103
|
+
## Static methods
|
|
104
|
+
|
|
105
|
+
### `TextField.toFieldErrors`
|
|
106
|
+
|
|
107
|
+
Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
type FormValues = {
|
|
111
|
+
myField: string;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
<TextField
|
|
115
|
+
// ...
|
|
116
|
+
name="my-field"
|
|
117
|
+
errors={TextField.toFieldErrors<FormValues>(formik.errors).myField}
|
|
118
|
+
/>;
|
|
119
|
+
```
|
|
@@ -96,7 +96,7 @@ var TextField = /*#__PURE__*/function (_Component) {
|
|
|
96
96
|
key: "render",
|
|
97
97
|
value: function render() {
|
|
98
98
|
if (!this.props.isReadOnly) {
|
|
99
|
-
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'TextField: `onChange` is required when is not read only.') : void 0;
|
|
99
|
+
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'TextField: `onChange` is required when field is not read only.') : void 0;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
if (this.props.hintIcon) {
|
|
@@ -144,6 +144,17 @@ var TextField = /*#__PURE__*/function (_Component) {
|
|
|
144
144
|
})
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
+
}], [{
|
|
148
|
+
key: "toFieldErrors",
|
|
149
|
+
value:
|
|
150
|
+
/**
|
|
151
|
+
* Use this function to convert the Formik `errors` object type to
|
|
152
|
+
* our custom field errors type.
|
|
153
|
+
* This is primarly useful when using TypeScript.
|
|
154
|
+
*/
|
|
155
|
+
function toFieldErrors(errors) {
|
|
156
|
+
return errors;
|
|
157
|
+
}
|
|
147
158
|
}]);
|
|
148
159
|
|
|
149
160
|
return TextField;
|
|
@@ -187,7 +198,7 @@ TextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
187
198
|
var TextField$1 = TextField;
|
|
188
199
|
|
|
189
200
|
// NOTE: This string will be replaced on build time with the package version.
|
|
190
|
-
var version = "14.0.
|
|
201
|
+
var version = "14.0.6";
|
|
191
202
|
|
|
192
203
|
exports["default"] = TextField$1;
|
|
193
204
|
exports.version = version;
|
|
@@ -139,6 +139,17 @@ var TextField = /*#__PURE__*/function (_Component) {
|
|
|
139
139
|
})
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
+
}], [{
|
|
143
|
+
key: "toFieldErrors",
|
|
144
|
+
value:
|
|
145
|
+
/**
|
|
146
|
+
* Use this function to convert the Formik `errors` object type to
|
|
147
|
+
* our custom field errors type.
|
|
148
|
+
* This is primarly useful when using TypeScript.
|
|
149
|
+
*/
|
|
150
|
+
function toFieldErrors(errors) {
|
|
151
|
+
return errors;
|
|
152
|
+
}
|
|
142
153
|
}]);
|
|
143
154
|
|
|
144
155
|
return TextField;
|
|
@@ -159,7 +170,7 @@ TextField.propTypes = {};
|
|
|
159
170
|
var TextField$1 = TextField;
|
|
160
171
|
|
|
161
172
|
// NOTE: This string will be replaced on build time with the package version.
|
|
162
|
-
var version = "14.0.
|
|
173
|
+
var version = "14.0.6";
|
|
163
174
|
|
|
164
175
|
exports["default"] = TextField$1;
|
|
165
176
|
exports.version = version;
|
|
@@ -71,7 +71,7 @@ var TextField = /*#__PURE__*/function (_Component) {
|
|
|
71
71
|
key: "render",
|
|
72
72
|
value: function render() {
|
|
73
73
|
if (!this.props.isReadOnly) {
|
|
74
|
-
process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'TextField: `onChange` is required when is not read only.') : void 0;
|
|
74
|
+
process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'TextField: `onChange` is required when field is not read only.') : void 0;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
if (this.props.hintIcon) {
|
|
@@ -119,6 +119,17 @@ var TextField = /*#__PURE__*/function (_Component) {
|
|
|
119
119
|
})
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
+
}], [{
|
|
123
|
+
key: "toFieldErrors",
|
|
124
|
+
value:
|
|
125
|
+
/**
|
|
126
|
+
* Use this function to convert the Formik `errors` object type to
|
|
127
|
+
* our custom field errors type.
|
|
128
|
+
* This is primarly useful when using TypeScript.
|
|
129
|
+
*/
|
|
130
|
+
function toFieldErrors(errors) {
|
|
131
|
+
return errors;
|
|
132
|
+
}
|
|
122
133
|
}]);
|
|
123
134
|
|
|
124
135
|
return TextField;
|
|
@@ -162,6 +173,6 @@ TextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
162
173
|
var TextField$1 = TextField;
|
|
163
174
|
|
|
164
175
|
// NOTE: This string will be replaced on build time with the package version.
|
|
165
|
-
var version = "14.0.
|
|
176
|
+
var version = "14.0.6";
|
|
166
177
|
|
|
167
178
|
export { TextField$1 as default, version };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Component, type ChangeEventHandler, type FocusEventHandler, type ReactElement, type ReactNode } from 'react';
|
|
2
2
|
declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
|
|
3
3
|
declare type TFieldErrors = Record<string, boolean>;
|
|
4
|
+
declare type TCustomFormErrors<Values> = {
|
|
5
|
+
[K in keyof Values]?: TFieldErrors;
|
|
6
|
+
};
|
|
4
7
|
declare type TTextFieldProps = {
|
|
5
8
|
id?: string;
|
|
6
9
|
horizontalConstraint?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
@@ -11,9 +14,9 @@ declare type TTextFieldProps = {
|
|
|
11
14
|
autoComplete?: string;
|
|
12
15
|
name?: string;
|
|
13
16
|
value: string;
|
|
14
|
-
onChange?: ChangeEventHandler
|
|
15
|
-
onBlur?: FocusEventHandler
|
|
16
|
-
onFocus?: FocusEventHandler
|
|
17
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
18
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
19
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
17
20
|
isAutofocussed?: boolean;
|
|
18
21
|
isDisabled?: boolean;
|
|
19
22
|
isReadOnly?: boolean;
|
|
@@ -35,6 +38,7 @@ declare class TextField extends Component<TTextFieldProps, TTextFieldState> {
|
|
|
35
38
|
static getDerivedStateFromProps: (props: TTextFieldProps, state: TTextFieldState) => {
|
|
36
39
|
id: string;
|
|
37
40
|
};
|
|
41
|
+
static toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
|
|
38
42
|
render(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
39
43
|
}
|
|
40
44
|
export default TextField;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/text-field",
|
|
3
3
|
"description": "A controlled text input component for single-line strings with validation states.",
|
|
4
|
-
"version": "14.0.
|
|
4
|
+
"version": "14.0.6",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/runtime": "^7.17.2",
|
|
23
23
|
"@babel/runtime-corejs3": "^7.17.2",
|
|
24
|
-
"@commercetools-uikit/constraints": "14.0.
|
|
24
|
+
"@commercetools-uikit/constraints": "14.0.1",
|
|
25
25
|
"@commercetools-uikit/design-system": "14.0.0",
|
|
26
|
-
"@commercetools-uikit/field-errors": "14.0.
|
|
27
|
-
"@commercetools-uikit/field-label": "14.0.
|
|
28
|
-
"@commercetools-uikit/spacings-stack": "14.0.
|
|
29
|
-
"@commercetools-uikit/text-input": "14.0.
|
|
30
|
-
"@commercetools-uikit/utils": "14.0.
|
|
26
|
+
"@commercetools-uikit/field-errors": "14.0.1",
|
|
27
|
+
"@commercetools-uikit/field-label": "14.0.6",
|
|
28
|
+
"@commercetools-uikit/spacings-stack": "14.0.6",
|
|
29
|
+
"@commercetools-uikit/text-input": "14.0.6",
|
|
30
|
+
"@commercetools-uikit/utils": "14.0.1",
|
|
31
31
|
"@emotion/react": "^11.4.0",
|
|
32
32
|
"@emotion/styled": "^11.3.0",
|
|
33
33
|
"prop-types": "15.8.1",
|