@jasperoosthoek/react-toolbox 0.5.5 → 0.5.6

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 jasperoosthoek
3
+ Copyright (c) 2024 jasperoosthoek
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/change-log.md CHANGED
@@ -239,3 +239,7 @@
239
239
 
240
240
  ##### Version 0.5.5
241
241
  - Remove unnecessary packages from devDependencies
242
+
243
+ ##### Version 0.5.6
244
+ - Rename `CreateEditModal` & `CreateEditModalProvider` to `FormModal` & `FormModalProvider`
245
+ - Remove out of context error when clicking row to open `EditModal` on `DataTable`
@@ -0,0 +1,41 @@
1
+ import React, { ReactElement } from 'react';
2
+ import { FormComponentProps, FormSelectProps, FormOnChange, FormValue } from './FormFields';
3
+ export type FormField = {
4
+ initialValue?: any;
5
+ type?: 'string' | 'number';
6
+ required?: boolean;
7
+ formProps?: any;
8
+ component?: (props: FormComponentProps | FormSelectProps) => ReactElement;
9
+ onChange?: FormOnChange;
10
+ label?: ReactElement | string;
11
+ };
12
+ export type IncludeData<T> = {
13
+ [key in Exclude<string, keyof T>]: any;
14
+ };
15
+ export type InitialState<T> = Partial<{
16
+ [key in keyof T]: FormValue;
17
+ }>;
18
+ export type FormFields = {
19
+ [key: string]: FormField;
20
+ };
21
+ export type OnSave<T, K> = (state: ({
22
+ [key in keyof T]: FormValue;
23
+ }), callback: () => void) => void;
24
+ export type Validate = (state: any) => any;
25
+ export type ModalTitle = ReactElement | string;
26
+ export type Width = 25 | 50 | 75 | 100;
27
+ export type FormModalProps<T extends FormFields, K extends IncludeData<T>> = {
28
+ initialState: InitialState<T> | K;
29
+ includeData?: K;
30
+ formFields: T;
31
+ show?: boolean;
32
+ onSave: OnSave<T, K>;
33
+ onHide: () => void;
34
+ validate?: Validate;
35
+ modalTitle?: ModalTitle;
36
+ loading?: boolean;
37
+ dialogClassName?: string;
38
+ width?: Width;
39
+ };
40
+ export declare const FormModal: <T extends FormFields, K extends IncludeData<T>>({ initialState, formFields, includeData, show, onSave, onHide, validate, modalTitle, loading, dialogClassName, width, ...restProps }: FormModalProps<T, K>) => React.JSX.Element;
41
+ export declare const DisabledFormField: ({ value }: any) => React.JSX.Element;
@@ -0,0 +1,42 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { FormFields, IncludeData, InitialState, OnSave, Validate, ModalTitle, Width } from './FormModal';
3
+ import { FormValue } from './FormFields';
4
+ import { ButtonProps } from '../buttons/IconButtons';
5
+ export type ShowCreateModal = (show?: boolean) => void;
6
+ export type ShowEditModal<T, K> = (state: {
7
+ [key in keyof T]: FormValue;
8
+ } & K) => void;
9
+ export type ShowCreateModalButton = ButtonProps;
10
+ export declare const ShowCreateModalButton: ({ onClick, ...props }: ButtonProps) => React.JSX.Element;
11
+ export interface ShowEditModalButtonProps<T, K> extends ButtonProps {
12
+ state: {
13
+ [key in keyof T]: FormValue;
14
+ } & K;
15
+ }
16
+ export declare const ShowEditModalButton: ({ state, onClick, ...props }: ShowEditModalButtonProps<T, K>) => React.JSX.Element;
17
+ type FormModalContextType<T, K> = {
18
+ showCreateModal: ShowCreateModal;
19
+ showEditModal: ShowEditModal<T, K>;
20
+ hasProvider: boolean;
21
+ };
22
+ type T = any;
23
+ type K = any;
24
+ export declare const FormModalContext: React.Context<FormModalContextType<any, any>>;
25
+ export declare const useFormModal: () => FormModalContextType<any, any>;
26
+ export type FormModalProviderProps<T extends FormFields, K extends IncludeData<T>> = {
27
+ initialState: InitialState<T> | K;
28
+ includeData?: K;
29
+ formFields: T;
30
+ onSave?: OnSave<T, K>;
31
+ onCreate?: OnSave<T, K>;
32
+ onUpdate?: OnSave<T, K>;
33
+ validate?: Validate;
34
+ createModalTitle?: ModalTitle;
35
+ editModalTitle?: ModalTitle;
36
+ loading?: boolean;
37
+ dialogClassName?: string;
38
+ width?: Width;
39
+ children: ReactNode;
40
+ };
41
+ export declare const FormModalProvider: React.FC<FormModalProviderProps<T, K>>;
42
+ export {};
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@ export * from './components/buttons/ConfirmButton';
3
3
  export { default as ConfirmButton } from './components/buttons/ConfirmButton';
4
4
  export { default as DeleteConfirmButton } from './components/buttons/DeleteConfirmButton';
5
5
  export * from './components/buttons/DeleteConfirmButton';
6
- export * from './components/forms/CreateEditModal';
7
- export * from './components/forms/CreateEditModalProvider';
6
+ export * from './components/forms/FormModal';
7
+ export * from './components/forms/FormModalProvider';
8
8
  export * from './components/forms/FormFields';
9
9
  export * from './components/indicators/LoadingIndicator';
10
10
  export * from './components/indicators/CheckIndicator';