@jasperoosthoek/react-toolbox 0.9.0 → 0.9.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/change-log.md
CHANGED
|
@@ -327,4 +327,10 @@
|
|
|
327
327
|
- Support both declarative (modal) and flexible (custom layout) form patterns
|
|
328
328
|
- Backwards compatible - existing FormModalProvider usage continues to work
|
|
329
329
|
- Renamed `FormTextArea` to `FormTextarea`
|
|
330
|
-
- Many more tests with about 72% coverage
|
|
330
|
+
- Many more tests with about 72% coverage
|
|
331
|
+
|
|
332
|
+
##### Version 0.9.1
|
|
333
|
+
- Revert change that made type inference impossible in `FormModalProvider`
|
|
334
|
+
|
|
335
|
+
##### Version 0.9.2
|
|
336
|
+
- Make types in `FormModalProvider` more flexible
|
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { FormFields, InitialState,
|
|
2
|
+
import { FormFields, InitialState, Validate } from './FormProvider';
|
|
3
3
|
import { ModalTitle, Width } from './FormModal';
|
|
4
|
+
import { FormValue } from './FormFields';
|
|
4
5
|
import { ButtonProps } from '../buttons/IconButtons';
|
|
6
|
+
export type IncludeData<T extends FormFields> = {
|
|
7
|
+
[key in Exclude<string, keyof T>]: any;
|
|
8
|
+
};
|
|
5
9
|
export type ShowCreateModal = (show?: boolean) => void;
|
|
6
|
-
export type ShowEditModal<T
|
|
7
|
-
|
|
10
|
+
export type ShowEditModal<T, K> = (state: ({
|
|
11
|
+
[key in keyof T]: FormValue;
|
|
12
|
+
} & K) | null) => void;
|
|
13
|
+
type FormModalContextType<T, K> = {
|
|
8
14
|
showCreateModal: ShowCreateModal;
|
|
9
|
-
showEditModal: ShowEditModal<T>;
|
|
15
|
+
showEditModal: ShowEditModal<T, K>;
|
|
10
16
|
hasProvider: boolean;
|
|
11
17
|
};
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
type T = any;
|
|
19
|
+
type K = any;
|
|
20
|
+
export declare const FormModalContext: React.Context<FormModalContextType<any, any>>;
|
|
21
|
+
export declare const useFormModal: () => FormModalContextType<any, any>;
|
|
14
22
|
export type FormCreateModalButton = ButtonProps;
|
|
15
23
|
export declare const FormCreateModalButton: ({ onClick, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
export interface FormEditModalButtonProps<T
|
|
17
|
-
state:
|
|
24
|
+
export interface FormEditModalButtonProps<T, K> extends ButtonProps {
|
|
25
|
+
state: {
|
|
26
|
+
[key in keyof T]: FormValue;
|
|
27
|
+
} & K;
|
|
18
28
|
}
|
|
19
|
-
export declare const FormEditModalButton:
|
|
20
|
-
export type FormModalProviderProps<T extends FormFields
|
|
29
|
+
export declare const FormEditModalButton: ({ state, onClick, ...props }: FormEditModalButtonProps<T, K>) => import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
export type FormModalProviderProps<T extends FormFields, K extends IncludeData<T>> = {
|
|
21
31
|
formFields: T;
|
|
22
|
-
initialState
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
initialState: InitialState<T> | K;
|
|
33
|
+
includeData?: K;
|
|
34
|
+
onSave?: (state: {
|
|
35
|
+
[key in keyof T]: FormValue;
|
|
36
|
+
} & K, callback?: () => void) => void;
|
|
37
|
+
onCreate?: (state: {
|
|
38
|
+
[key in keyof T]: FormValue;
|
|
39
|
+
} & K, callback?: () => void) => void;
|
|
40
|
+
onUpdate?: (state: {
|
|
41
|
+
[key in keyof T]: FormValue;
|
|
42
|
+
} & K, callback?: () => void) => void;
|
|
26
43
|
validate?: Validate;
|
|
27
44
|
createModalTitle?: ModalTitle;
|
|
28
45
|
editModalTitle?: ModalTitle;
|
|
@@ -31,5 +48,5 @@ export type FormModalProviderProps<T extends FormFields> = {
|
|
|
31
48
|
width?: Width;
|
|
32
49
|
children: ReactNode;
|
|
33
50
|
};
|
|
34
|
-
export declare const FormModalProvider: <
|
|
51
|
+
export declare const FormModalProvider: React.FC<FormModalProviderProps<T, K>>;
|
|
35
52
|
export {};
|