@commercetools-uikit/localized-text-field 13.0.4 → 14.0.2

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
@@ -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` | `TFieldErrors` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;Unknown errors will be forwarded to `renderError` |
56
+ | `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;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. |
@@ -89,7 +89,9 @@ export default Example;
89
89
  ### Signature `onInfoButtonClick`
90
90
 
91
91
  ```ts
92
- (event: TEvent) => void
92
+ (
93
+ event: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>
94
+ ) => void
93
95
  ```
94
96
 
95
97
  ## `data-*` props
@@ -107,3 +109,21 @@ When the `key` is known, and when the value is truthy, and when `renderError` re
107
109
  Known error keys are:
108
110
 
109
111
  - `missing`: tells the user that this field is required
112
+
113
+ ## Static methods
114
+
115
+ ### `LocalizedTextField.toFieldErrors`
116
+
117
+ Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
118
+
119
+ ```ts
120
+ type FormValues = {
121
+ myField: string;
122
+ };
123
+
124
+ <LocalizedTextField
125
+ // ...
126
+ name="my-field"
127
+ errors={LocalizedTextField.toFieldErrors<FormValues>(formik.errors).myField}
128
+ />;
129
+ ```
@@ -148,6 +148,17 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
148
148
  })
149
149
  });
150
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
+ }
151
162
  }]);
152
163
 
153
164
  return LocalizedTextField;
@@ -167,7 +178,7 @@ LocalizedTextField.getDerivedStateFromProps = function (props, state) {
167
178
  LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
168
179
  id: _pt__default["default"].string,
169
180
  horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
170
- errors: _pt__default["default"].any,
181
+ errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
171
182
  renderError: _pt__default["default"].func,
172
183
  isRequired: _pt__default["default"].bool,
173
184
  touched: _pt__default["default"].bool,
@@ -194,7 +205,7 @@ LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
194
205
  var LocalizedTextField$1 = LocalizedTextField;
195
206
 
196
207
  // NOTE: This string will be replaced on build time with the package version.
197
- var version = "13.0.4";
208
+ var version = "14.0.2";
198
209
 
199
210
  exports["default"] = LocalizedTextField$1;
200
211
  exports.version = version;
@@ -143,6 +143,17 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
143
143
  })
144
144
  });
145
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
+ }
146
157
  }]);
147
158
 
148
159
  return LocalizedTextField;
@@ -163,7 +174,7 @@ LocalizedTextField.propTypes = {};
163
174
  var LocalizedTextField$1 = LocalizedTextField;
164
175
 
165
176
  // NOTE: This string will be replaced on build time with the package version.
166
- var version = "13.0.4";
177
+ var version = "14.0.2";
167
178
 
168
179
  exports["default"] = LocalizedTextField$1;
169
180
  exports.version = version;
@@ -123,6 +123,17 @@ var LocalizedTextField = /*#__PURE__*/function (_Component) {
123
123
  })
124
124
  });
125
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
+ }
126
137
  }]);
127
138
 
128
139
  return LocalizedTextField;
@@ -142,7 +153,7 @@ LocalizedTextField.getDerivedStateFromProps = function (props, state) {
142
153
  LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
143
154
  id: _pt.string,
144
155
  horizontalConstraint: _pt.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
145
- errors: _pt.any,
156
+ errors: _pt.objectOf(_pt.bool),
146
157
  renderError: _pt.func,
147
158
  isRequired: _pt.bool,
148
159
  touched: _pt.bool,
@@ -169,6 +180,6 @@ LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
169
180
  var LocalizedTextField$1 = LocalizedTextField;
170
181
 
171
182
  // NOTE: This string will be replaced on build time with the package version.
172
- var version = "13.0.4";
183
+ var version = "14.0.2";
173
184
 
174
185
  export { LocalizedTextField$1 as default, version };
@@ -1,7 +1,12 @@
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
- declare type TEvent = MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>;
4
2
  declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
3
+ declare type TFieldErrors = Record<string, boolean>;
4
+ declare type TCustomFormErrors<Values> = {
5
+ [K in keyof Values]?: TFieldErrors;
6
+ };
7
+ interface HTMLLocalizedInputElement extends HTMLInputElement {
8
+ language: string;
9
+ }
5
10
  declare type TLocalizedTextFieldProps = {
6
11
  id?: string;
7
12
  horizontalConstraint?: 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
@@ -12,10 +17,10 @@ declare type TLocalizedTextFieldProps = {
12
17
  autoComplete?: string;
13
18
  name?: string;
14
19
  value: Record<string, string>;
15
- onChange?: ChangeEventHandler;
20
+ onChange?: ChangeEventHandler<HTMLLocalizedInputElement>;
16
21
  selectedLanguage: string;
17
- onBlur?: FocusEventHandler;
18
- onFocus?: FocusEventHandler;
22
+ onBlur?: FocusEventHandler<HTMLInputElement>;
23
+ onFocus?: FocusEventHandler<HTMLInputElement>;
19
24
  hideLanguageExpansionControls?: boolean;
20
25
  defaultExpandLanguages?: boolean;
21
26
  isAutofocussed?: boolean;
@@ -26,7 +31,7 @@ declare type TLocalizedTextFieldProps = {
26
31
  title: ReactNode;
27
32
  hint?: ReactNode;
28
33
  description?: ReactNode;
29
- onInfoButtonClick?: (event: TEvent) => void;
34
+ onInfoButtonClick?: (event: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>) => void;
30
35
  hintIcon?: ReactElement;
31
36
  badge?: ReactNode;
32
37
  };
@@ -40,6 +45,7 @@ declare class LocalizedTextField extends Component<TLocalizedTextFieldProps, TLo
40
45
  static getDerivedStateFromProps: (props: TLocalizedTextFieldProps, state: TLocalizedTextFieldSTate) => {
41
46
  id: string;
42
47
  };
48
+ static toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
43
49
  render(): import("@emotion/react/jsx-runtime").JSX.Element;
44
50
  }
45
51
  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": "13.0.4",
4
+ "version": "14.0.2",
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 system", "react", "uikit"],
12
+ "keywords": ["javascript", "typescript", "design-system", "react", "uikit"],
13
13
  "license": "MIT",
14
14
  "publishConfig": {
15
15
  "access": "public"
@@ -19,15 +19,15 @@
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": "13.0.2",
25
- "@commercetools-uikit/design-system": "13.0.0",
26
- "@commercetools-uikit/field-errors": "13.0.4",
27
- "@commercetools-uikit/field-label": "13.0.4",
28
- "@commercetools-uikit/localized-text-input": "13.0.4",
29
- "@commercetools-uikit/spacings": "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.2",
28
+ "@commercetools-uikit/localized-text-input": "14.0.2",
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
33
  "prop-types": "15.8.1",