@thecb/components 8.0.6-beta.8 → 8.0.6-beta.9

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/dist/index.d.ts CHANGED
@@ -61,21 +61,53 @@ interface CardProps {
61
61
  declare const Card: React.FC<Expand<CardProps> &
62
62
  React.HTMLAttributes<HTMLElement>>;
63
63
 
64
- interface ErrorMessage {
65
- [fieldName: string]: string;
66
- }
67
-
68
64
  interface Field {
69
- hasErrors?: boolean;
70
- dirty?: boolean;
71
- rawValue?: string;
65
+ hasErrors?: boolean;
66
+ dirty?: boolean;
67
+ rawValue?: string;
68
+ }
69
+
70
+ interface ReduxAction<T = string, P = {}> {
71
+ type: T;
72
+ payload?: P;
73
+ }
74
+
75
+ /**
76
+ * These types should be moved to and referenced from redux-freeform if it implements TypeScript
77
+ */
78
+
79
+ type ValidatorFn = (value: string) => boolean;
80
+
81
+ interface FieldActionPayload {
82
+ fieldName: string;
83
+ value?: string;
84
+ validator?: ValidatorFn;
72
85
  }
73
86
 
87
+ type SetAction = ReduxAction<"field/SET", FieldActionPayload>;
88
+ type AddValidatorAction = ReduxAction<
89
+ "field/ADD_VALIDATOR",
90
+ FieldActionPayload
91
+ >;
92
+ type RemoveValidatorAction = ReduxAction<
93
+ "field/REMOVE_VALIDATOR",
94
+ FieldActionPayload
95
+ >;
96
+ type ClearAction = ReduxAction<"field/CLEAR">;
97
+
74
98
  interface FieldActions {
75
- set?: (value: any) => void;
76
- addValidator?: (validator: any) => void;
77
- removeValidator?: (validator: any) => void;
78
- clear?: () => void;
99
+ set?: (fieldName: string) => (value: string) => SetAction;
100
+ addValidator?: (
101
+ fieldName: string
102
+ ) => (validator: ValidatorFn) => AddValidatorAction;
103
+ removeValidator?: (
104
+ fieldName: string
105
+ ) => (validator: ValidatorFn) => RemoveValidatorAction;
106
+ clear?: () => ClearAction;
107
+ }
108
+
109
+ interface ErrorMessage {
110
+ [fieldName: string]: string;
79
111
  }
80
112
 
81
113
  interface FormInputProps {
@@ -107,8 +139,8 @@ interface FormSelectProps {
107
139
  options?: Option[];
108
140
  fieldActions?: FieldActions;
109
141
  showErrors?: boolean;
110
- errorMessages?: ErrorMessage[]
111
- field?: Field
142
+ errorMessages?: ErrorMessage[];
143
+ field?: Field;
112
144
  }
113
145
 
114
146
  declare const FormSelect: React.FC<Expand<FormSelectProps> &
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "8.0.6-beta.8",
3
+ "version": "8.0.6-beta.9",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import Expand from "../../../util/expand";
3
- import { ErrorMessage, Field, FieldActions} from "../../../types/common";
3
+ import { ErrorMessage, Field, FieldActions } from "../../../types/common";
4
4
 
5
5
  interface Option {
6
6
  text?: string;
@@ -14,8 +14,8 @@ export interface FormSelectProps {
14
14
  options?: Option[];
15
15
  fieldActions?: FieldActions;
16
16
  showErrors?: boolean;
17
- errorMessages?: ErrorMessage[]
18
- field?: Field
17
+ errorMessages?: ErrorMessage[];
18
+ field?: Field;
19
19
  }
20
20
 
21
21
  export const FormSelect: React.FC<Expand<FormSelectProps> &
@@ -1,4 +1,3 @@
1
1
  export default interface ErrorMessage {
2
- [fieldName: string]: string;
3
- }
4
-
2
+ [fieldName: string]: string;
3
+ }
@@ -1,5 +1,5 @@
1
1
  export default interface Field {
2
- hasErrors?: boolean;
3
- dirty?: boolean;
4
- rawValue?: string;
5
- }
2
+ hasErrors?: boolean;
3
+ dirty?: boolean;
4
+ rawValue?: string;
5
+ }
@@ -1,6 +1,35 @@
1
+ import ReduxAction from "./ReduxAction";
2
+
3
+ /**
4
+ * These types should be moved to and referenced from redux-freeform if it implements TypeScript
5
+ */
6
+
7
+ type ValidatorFn = (value: string) => boolean;
8
+
9
+ interface FieldActionPayload {
10
+ fieldName: string;
11
+ value?: string;
12
+ validator?: ValidatorFn;
13
+ }
14
+
15
+ type SetAction = ReduxAction<"field/SET", FieldActionPayload>;
16
+ type AddValidatorAction = ReduxAction<
17
+ "field/ADD_VALIDATOR",
18
+ FieldActionPayload
19
+ >;
20
+ type RemoveValidatorAction = ReduxAction<
21
+ "field/REMOVE_VALIDATOR",
22
+ FieldActionPayload
23
+ >;
24
+ type ClearAction = ReduxAction<"field/CLEAR">;
25
+
1
26
  export default interface FieldActions {
2
- set?: (value: any) => void;
3
- addValidator?: (validator: any) => void;
4
- removeValidator?: (validator: any) => void;
5
- clear?: () => void;
27
+ set?: (fieldName: string) => (value: string) => SetAction;
28
+ addValidator?: (
29
+ fieldName: string
30
+ ) => (validator: ValidatorFn) => AddValidatorAction;
31
+ removeValidator?: (
32
+ fieldName: string
33
+ ) => (validator: ValidatorFn) => RemoveValidatorAction;
34
+ clear?: () => ClearAction;
6
35
  }
@@ -0,0 +1,4 @@
1
+ export default interface ReduxAction<T = string, P = {}> {
2
+ type: T;
3
+ payload?: P;
4
+ }
@@ -1,3 +1,4 @@
1
- export type { default as ErrorMessage } from "./ErrorMessage";
2
- export type { default as Field } from "./Field";
3
- export type { default as FieldActions } from "./FieldActions"
1
+ export { default as Field } from "./Field";
2
+ export { default as ReduxAction } from "./ReduxAction";
3
+ export { default as FieldActions } from "./FieldActions";
4
+ export { default as ErrorMessage } from "./ErrorMessage";