@commercetools-uikit/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 CHANGED
@@ -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
+ ```
@@ -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('text-field-');
62
+ var sequentialErrorsId = utils.createSequentialId('text-field-error-')();
62
63
 
63
64
  var hasErrors = function hasErrors(errors) {
64
65
  var _context;
@@ -116,7 +117,7 @@ var TextField = /*#__PURE__*/function (_Component) {
116
117
  badge: this.props.badge,
117
118
  hasRequiredIndicator: this.props.isRequired,
118
119
  htmlFor: this.state.id
119
- }), jsxRuntime.jsx(TextInput__default["default"], _objectSpread({
120
+ }), jsxRuntime.jsx(TextInput__default["default"], _objectSpread(_objectSpread({
120
121
  id: this.state.id,
121
122
  name: this.props.name,
122
123
  autoComplete: this.props.autoComplete,
@@ -130,7 +131,12 @@ var TextField = /*#__PURE__*/function (_Component) {
130
131
  hasError: hasError,
131
132
  placeholder: this.props.placeholder,
132
133
  horizontalConstraint: "scale"
133
- }, utils.filterDataAttributes(this.props))), jsxRuntime.jsx(FieldErrors__default["default"], {
134
+ }, utils.filterDataAttributes(this.props)), {}, {
135
+ /* ARIA */
136
+ "aria-invalid": hasError,
137
+ "aria-errormessage": sequentialErrorsId
138
+ })), jsxRuntime.jsx(FieldErrors__default["default"], {
139
+ id: sequentialErrorsId,
134
140
  errors: this.props.errors,
135
141
  isVisible: hasError,
136
142
  renderError: this.props.renderError
@@ -138,6 +144,17 @@ var TextField = /*#__PURE__*/function (_Component) {
138
144
  })
139
145
  });
140
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
+ }
141
158
  }]);
142
159
 
143
160
  return TextField;
@@ -181,7 +198,7 @@ TextField.propTypes = process.env.NODE_ENV !== "production" ? {
181
198
  var TextField$1 = TextField;
182
199
 
183
200
  // NOTE: This string will be replaced on build time with the package version.
184
- var version = "13.0.2";
201
+ var version = "14.0.1";
185
202
 
186
203
  exports["default"] = TextField$1;
187
204
  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('text-field-');
61
+ var sequentialErrorsId = utils.createSequentialId('text-field-error-')();
61
62
 
62
63
  var hasErrors = function hasErrors(errors) {
63
64
  var _context;
@@ -111,7 +112,7 @@ var TextField = /*#__PURE__*/function (_Component) {
111
112
  badge: this.props.badge,
112
113
  hasRequiredIndicator: this.props.isRequired,
113
114
  htmlFor: this.state.id
114
- }), jsxRuntime.jsx(TextInput__default["default"], _objectSpread({
115
+ }), jsxRuntime.jsx(TextInput__default["default"], _objectSpread(_objectSpread({
115
116
  id: this.state.id,
116
117
  name: this.props.name,
117
118
  autoComplete: this.props.autoComplete,
@@ -125,7 +126,12 @@ var TextField = /*#__PURE__*/function (_Component) {
125
126
  hasError: hasError,
126
127
  placeholder: this.props.placeholder,
127
128
  horizontalConstraint: "scale"
128
- }, utils.filterDataAttributes(this.props))), jsxRuntime.jsx(FieldErrors__default["default"], {
129
+ }, utils.filterDataAttributes(this.props)), {}, {
130
+ /* ARIA */
131
+ "aria-invalid": hasError,
132
+ "aria-errormessage": sequentialErrorsId
133
+ })), jsxRuntime.jsx(FieldErrors__default["default"], {
134
+ id: sequentialErrorsId,
129
135
  errors: this.props.errors,
130
136
  isVisible: hasError,
131
137
  renderError: this.props.renderError
@@ -133,6 +139,17 @@ var TextField = /*#__PURE__*/function (_Component) {
133
139
  })
134
140
  });
135
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
+ }
136
153
  }]);
137
154
 
138
155
  return TextField;
@@ -153,7 +170,7 @@ TextField.propTypes = {};
153
170
  var TextField$1 = TextField;
154
171
 
155
172
  // NOTE: This string will be replaced on build time with the package version.
156
- var version = "13.0.2";
173
+ var version = "14.0.1";
157
174
 
158
175
  exports["default"] = TextField$1;
159
176
  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('text-field-');
37
+ var sequentialErrorsId = createSequentialId('text-field-error-')();
37
38
 
38
39
  var hasErrors = function hasErrors(errors) {
39
40
  var _context;
@@ -91,7 +92,7 @@ var TextField = /*#__PURE__*/function (_Component) {
91
92
  badge: this.props.badge,
92
93
  hasRequiredIndicator: this.props.isRequired,
93
94
  htmlFor: this.state.id
94
- }), jsx(TextInput, _objectSpread({
95
+ }), jsx(TextInput, _objectSpread(_objectSpread({
95
96
  id: this.state.id,
96
97
  name: this.props.name,
97
98
  autoComplete: this.props.autoComplete,
@@ -105,7 +106,12 @@ var TextField = /*#__PURE__*/function (_Component) {
105
106
  hasError: hasError,
106
107
  placeholder: this.props.placeholder,
107
108
  horizontalConstraint: "scale"
108
- }, filterDataAttributes(this.props))), jsx(FieldErrors, {
109
+ }, filterDataAttributes(this.props)), {}, {
110
+ /* ARIA */
111
+ "aria-invalid": hasError,
112
+ "aria-errormessage": sequentialErrorsId
113
+ })), jsx(FieldErrors, {
114
+ id: sequentialErrorsId,
109
115
  errors: this.props.errors,
110
116
  isVisible: hasError,
111
117
  renderError: this.props.renderError
@@ -113,6 +119,17 @@ var TextField = /*#__PURE__*/function (_Component) {
113
119
  })
114
120
  });
115
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
+ }
116
133
  }]);
117
134
 
118
135
  return TextField;
@@ -156,6 +173,6 @@ TextField.propTypes = process.env.NODE_ENV !== "production" ? {
156
173
  var TextField$1 = TextField;
157
174
 
158
175
  // NOTE: This string will be replaced on build time with the package version.
159
- var version = "13.0.2";
176
+ var version = "14.0.1";
160
177
 
161
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';
@@ -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": "13.0.2",
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/text-field"
10
10
  },
11
11
  "homepage": "https://uikit.commercetools.com",
12
- "keywords": ["javascript", "design system", "react", "uikit"],
12
+ "keywords": ["javascript", "typescript", "design-system", "react", "uikit"],
13
13
  "license": "MIT",
14
14
  "publishConfig": {
15
15
  "access": "public"
@@ -19,19 +19,19 @@
19
19
  "module": "dist/commercetools-uikit-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": "13.0.2",
25
- "@commercetools-uikit/design-system": "13.0.0",
26
- "@commercetools-uikit/field-errors": "13.0.2",
27
- "@commercetools-uikit/field-label": "13.0.2",
28
- "@commercetools-uikit/spacings-stack": "13.0.2",
29
- "@commercetools-uikit/text-input": "13.0.2",
30
- "@commercetools-uikit/utils": "13.0.2",
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/spacings-stack": "14.0.1",
29
+ "@commercetools-uikit/text-input": "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
33
  "prop-types": "15.8.1",
34
- "react-required-if": "1.0.3"
34
+ "react-intl": "^5.24.6"
35
35
  },
36
36
  "devDependencies": {
37
37
  "react": "17.0.2"