@commercetools-uikit/password-field 14.0.0 → 14.0.3

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
@@ -50,14 +50,14 @@ export default Example;
50
50
  | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
51
51
  | `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. |
52
52
  | `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;Unknown errors will be forwarded to `renderError` |
53
- | `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.&#xA;<br />&#xA;Signature: `(key, error) => React.node` |
53
+ | `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. |
54
54
  | `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
55
55
  | `touched` | `boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
56
56
  | `name` | `string` | | | Used as HTML name of the input component. property |
57
57
  | `value` | `string` | ✅ | | Value of the input component. |
58
- | `onChange` | `ChangeEventHandler` | | | Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.&#xA;<br />&#xA;Signature: `(event) => void` |
59
- | `onBlur` | `FocusEventHandler` | | | Called when input is blurred&#xA;<br />&#xA;Signature: `(event) => void` |
60
- | `onFocus` | `FocusEventHandler` | | | Called when input is focused&#xA;<br />&#xA;Signature: `(event) => void` |
58
+ | `onChange` | `ChangeEventHandler` | | | Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value. |
59
+ | `onBlur` | `FocusEventHandler` | | | Called when input is blurred |
60
+ | `onFocus` | `FocusEventHandler` | | | Called when input is focused |
61
61
  | `isAutofocussed` | `boolean` | | | Focus the input on initial render |
62
62
  | `isDisabled` | `boolean` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
63
63
  | `isReadOnly` | `boolean` | | | Indicates that the field is displaying read-only content |
@@ -66,7 +66,7 @@ export default Example;
66
66
  | `title` | `union`<br/>Possible values:<br/>`string , ReactNode` | ✅ | | Title of the label |
67
67
  | `hint` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`. |
68
68
  | `description` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Provides a description for the title. |
69
- | `onInfoButtonClick` | `Function`<br/>[See signature.](#signature-onInfoButtonClick) | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed.&#xA;<br />&#xA;Signature: `(event) => void` |
69
+ | `onInfoButtonClick` | `Function`<br/>[See signature.](#signature-onInfoButtonClick) | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed. |
70
70
  | `hintIcon` | `ReactElement` | | | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well. |
71
71
  | `badge` | `ReactNode` | | | Badge to be displayed beside the label.&#xA;<br />&#xA;Might be used to display additional information about the content of the field (E.g verified email) |
72
72
 
@@ -105,3 +105,21 @@ Known error keys are:
105
105
  ## Main Functions and use cases are:
106
106
 
107
107
  - Password field in login forms
108
+
109
+ ## Static methods
110
+
111
+ ### `PasswordField.toFieldErrors`
112
+
113
+ Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
114
+
115
+ ```ts
116
+ type FormValues = {
117
+ myField: string;
118
+ };
119
+
120
+ <PasswordField
121
+ // ...
122
+ name="my-field"
123
+ errors={PasswordField.toFieldErrors<FormValues>(formik.errors).myField}
124
+ />;
125
+ ```
@@ -91,7 +91,7 @@ var PasswordField = function PasswordField(props) {
91
91
  var hasError = props.touched && hasErrors(props.errors);
92
92
 
93
93
  if (!props.isReadOnly) {
94
- process.env.NODE_ENV !== "production" ? utils.warning(Boolean(props.onChange), 'PasswordField: `onChange` is required when is not read only.') : void 0;
94
+ process.env.NODE_ENV !== "production" ? utils.warning(Boolean(props.onChange), 'PasswordField: `onChange` is required when field is not read only.') : void 0;
95
95
  }
96
96
 
97
97
  if (props.hintIcon) {
@@ -175,10 +175,20 @@ PasswordField.propTypes = process.env.NODE_ENV !== "production" ? {
175
175
  } : {};
176
176
  PasswordField.displayName = 'PasswordField';
177
177
  PasswordField.defaultProps = defaultProps;
178
+ /**
179
+ * Use this function to convert the Formik `errors` object type to
180
+ * our custom field errors type.
181
+ * This is primarly useful when using TypeScript.
182
+ */
183
+
184
+ PasswordField.toFieldErrors = function toFieldErrors(errors) {
185
+ return errors;
186
+ };
187
+
178
188
  var PasswordField$1 = PasswordField;
179
189
 
180
190
  // NOTE: This string will be replaced on build time with the package version.
181
- var version = "14.0.0";
191
+ var version = "14.0.3";
182
192
 
183
193
  exports["default"] = PasswordField$1;
184
194
  exports.version = version;
@@ -147,10 +147,20 @@ var PasswordField = function PasswordField(props) {
147
147
  PasswordField.propTypes = {};
148
148
  PasswordField.displayName = 'PasswordField';
149
149
  PasswordField.defaultProps = defaultProps;
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
+
156
+ PasswordField.toFieldErrors = function toFieldErrors(errors) {
157
+ return errors;
158
+ };
159
+
150
160
  var PasswordField$1 = PasswordField;
151
161
 
152
162
  // NOTE: This string will be replaced on build time with the package version.
153
- var version = "14.0.0";
163
+ var version = "14.0.3";
154
164
 
155
165
  exports["default"] = PasswordField$1;
156
166
  exports.version = version;
@@ -66,7 +66,7 @@ var PasswordField = function PasswordField(props) {
66
66
  var hasError = props.touched && hasErrors(props.errors);
67
67
 
68
68
  if (!props.isReadOnly) {
69
- process.env.NODE_ENV !== "production" ? warning(Boolean(props.onChange), 'PasswordField: `onChange` is required when is not read only.') : void 0;
69
+ process.env.NODE_ENV !== "production" ? warning(Boolean(props.onChange), 'PasswordField: `onChange` is required when field is not read only.') : void 0;
70
70
  }
71
71
 
72
72
  if (props.hintIcon) {
@@ -150,9 +150,19 @@ PasswordField.propTypes = process.env.NODE_ENV !== "production" ? {
150
150
  } : {};
151
151
  PasswordField.displayName = 'PasswordField';
152
152
  PasswordField.defaultProps = defaultProps;
153
+ /**
154
+ * Use this function to convert the Formik `errors` object type to
155
+ * our custom field errors type.
156
+ * This is primarly useful when using TypeScript.
157
+ */
158
+
159
+ PasswordField.toFieldErrors = function toFieldErrors(errors) {
160
+ return errors;
161
+ };
162
+
153
163
  var PasswordField$1 = PasswordField;
154
164
 
155
165
  // NOTE: This string will be replaced on build time with the package version.
156
- var version = "14.0.0";
166
+ var version = "14.0.3";
157
167
 
158
168
  export { PasswordField$1 as default, version };
@@ -1,18 +1,21 @@
1
1
  import { type ReactElement, type ReactNode, type MouseEvent, type KeyboardEvent, type ChangeEventHandler, type FocusEventHandler } from 'react';
2
- declare type TPasswordFieldError = Record<string, boolean>;
2
+ declare type TFieldErrors = Record<string, boolean>;
3
+ declare type TCustomFormErrors<Values> = {
4
+ [K in keyof Values]?: TFieldErrors;
5
+ };
3
6
  declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
4
7
  declare type TPasswordField = {
5
8
  id?: string;
6
9
  horizontalConstraint?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
7
- errors?: TPasswordFieldError;
10
+ errors?: TFieldErrors;
8
11
  renderError?: TErrorRenderer;
9
12
  isRequired?: boolean;
10
13
  touched?: boolean;
11
14
  name?: string;
12
15
  value: string;
13
- onChange?: ChangeEventHandler;
14
- onBlur?: FocusEventHandler;
15
- onFocus?: FocusEventHandler;
16
+ onChange?: ChangeEventHandler<HTMLInputElement>;
17
+ onBlur?: FocusEventHandler<HTMLInputElement>;
18
+ onFocus?: FocusEventHandler<HTMLInputElement>;
16
19
  isAutofocussed?: boolean;
17
20
  isDisabled?: boolean;
18
21
  isReadOnly?: boolean;
@@ -29,5 +32,6 @@ declare const PasswordField: {
29
32
  (props: TPasswordField): import("@emotion/react/jsx-runtime").JSX.Element;
30
33
  displayName: string;
31
34
  defaultProps: Pick<TPasswordField, "horizontalConstraint">;
35
+ toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
32
36
  };
33
37
  export default PasswordField;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/password-field",
3
3
  "description": "A controlled text input component for passwords with validation states.",
4
- "version": "14.0.0",
4
+ "version": "14.0.3",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,17 +21,17 @@
21
21
  "dependencies": {
22
22
  "@babel/runtime": "^7.17.2",
23
23
  "@babel/runtime-corejs3": "^7.17.2",
24
- "@commercetools-uikit/constraints": "14.0.0",
24
+ "@commercetools-uikit/constraints": "14.0.1",
25
25
  "@commercetools-uikit/design-system": "14.0.0",
26
- "@commercetools-uikit/field-errors": "14.0.0",
27
- "@commercetools-uikit/field-label": "14.0.0",
28
- "@commercetools-uikit/flat-button": "14.0.0",
29
- "@commercetools-uikit/hooks": "14.0.0",
30
- "@commercetools-uikit/icons": "14.0.0",
31
- "@commercetools-uikit/password-input": "14.0.0",
32
- "@commercetools-uikit/spacings-inline": "14.0.0",
33
- "@commercetools-uikit/spacings-stack": "14.0.0",
34
- "@commercetools-uikit/utils": "14.0.0",
26
+ "@commercetools-uikit/field-errors": "14.0.1",
27
+ "@commercetools-uikit/field-label": "14.0.2",
28
+ "@commercetools-uikit/flat-button": "14.0.2",
29
+ "@commercetools-uikit/hooks": "14.0.3",
30
+ "@commercetools-uikit/icons": "14.0.1",
31
+ "@commercetools-uikit/password-input": "14.0.2",
32
+ "@commercetools-uikit/spacings-inline": "14.0.1",
33
+ "@commercetools-uikit/spacings-stack": "14.0.1",
34
+ "@commercetools-uikit/utils": "14.0.1",
35
35
  "@emotion/react": "^11.4.0",
36
36
  "@emotion/styled": "^11.3.0",
37
37
  "prop-types": "15.8.1"