react-dialogger 1.1.19 → 1.1.21
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/components/Dependencies/Body.d.ts +8 -0
- package/components/Dependencies/Body.js +40 -0
- package/components/Dependencies/DialogBody.d.ts +8 -0
- package/components/Dependencies/DialogBody.js +40 -0
- package/components/DialogBase.d.ts +1 -0
- package/components/DialogBase.js +74 -10
- package/package.json +1 -1
- package/types/FormikProps.d.ts +302 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
import { TDialogCallbackNodeFn } from "../../types/DialogTypes";
|
2
|
+
import * as React from "react";
|
3
|
+
import { IDialogDef } from "react-dialogger/types";
|
4
|
+
declare const Body: ({ body, apiRef }: {
|
5
|
+
body: TDialogCallbackNodeFn;
|
6
|
+
apiRef?: IDialogDef;
|
7
|
+
}) => React.JSX.Element;
|
8
|
+
export default Body;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
var React = __importStar(require("react"));
|
27
|
+
var Body = function (_a) {
|
28
|
+
var body = _a.body, apiRef = _a.apiRef;
|
29
|
+
if (body instanceof Function) {
|
30
|
+
return React.createElement("div", { ref: apiRef._dialogBodyRef, className: 'dialog-body', style: { height: '100%' } },
|
31
|
+
apiRef.Placeholder(apiRef._holder),
|
32
|
+
body(apiRef));
|
33
|
+
}
|
34
|
+
return React.createElement("div", { style: { height: '100%', padding: 10 } }, apiRef._holder ?
|
35
|
+
apiRef.Placeholder(apiRef._holder)
|
36
|
+
:
|
37
|
+
//@ts-ignore
|
38
|
+
body);
|
39
|
+
};
|
40
|
+
exports.default = Body;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { TDialogCallbackNodeFn } from "../../types/DialogTypes";
|
2
|
+
import * as React from "react";
|
3
|
+
import DialogBase from "../DialogBase";
|
4
|
+
declare const DialogBody: ({ body, apiRef }: {
|
5
|
+
body: TDialogCallbackNodeFn;
|
6
|
+
apiRef?: DialogBase;
|
7
|
+
}) => React.JSX.Element;
|
8
|
+
export default DialogBody;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
var React = __importStar(require("react"));
|
27
|
+
var DialogBody = function (_a) {
|
28
|
+
var body = _a.body, apiRef = _a.apiRef;
|
29
|
+
if (body instanceof Function) {
|
30
|
+
return React.createElement("div", { ref: apiRef.dialogBodyRef, className: 'dialog-body', style: { height: '100%' } },
|
31
|
+
apiRef.Placeholder(apiRef.holder),
|
32
|
+
body(apiRef));
|
33
|
+
}
|
34
|
+
return React.createElement("div", { style: { height: '100%', padding: 10 } }, apiRef.holder ?
|
35
|
+
apiRef.Placeholder(apiRef.holder)
|
36
|
+
:
|
37
|
+
//@ts-ignore
|
38
|
+
body);
|
39
|
+
};
|
40
|
+
exports.default = DialogBody;
|
@@ -41,6 +41,7 @@ declare class DialogBase extends Component<BaseDialogProps, BaseDialogState> {
|
|
41
41
|
protected _shInterval: number;
|
42
42
|
protected _onClose: TDialogCallbackVoidFn;
|
43
43
|
private _inProcess;
|
44
|
+
private _footeRef;
|
44
45
|
/**
|
45
46
|
* @deprecated
|
46
47
|
* @see dialogOptions.snackbar.anchorOrigin */
|
package/components/DialogBase.js
CHANGED
@@ -95,6 +95,7 @@ var DialogBase = /** @class */ (function (_super) {
|
|
95
95
|
_this._dialogTranslate = { lastX: 0, lastY: 0 };
|
96
96
|
_this._shInterval = 300;
|
97
97
|
_this._inProcess = { inProcess: false };
|
98
|
+
_this._footeRef = React.createRef();
|
98
99
|
// Initialize a ref for each action dynamically
|
99
100
|
_this.initializeActionRef = function (key) {
|
100
101
|
if (!_this._actionRefs.hasOwnProperty(key)) {
|
@@ -170,7 +171,7 @@ var DialogBase = /** @class */ (function (_super) {
|
|
170
171
|
return _this;
|
171
172
|
};
|
172
173
|
_this.setInProcess = function (process, message, holder) {
|
173
|
-
var _a, _b;
|
174
|
+
var _a, _b, _c;
|
174
175
|
_this._inProcess = __assign({ inProcess: process }, message ? { message: message } : {});
|
175
176
|
// this.setState( prevState => ({
|
176
177
|
// ...prevState, inProcess: { inProcess: process, ...message ? {message} : {} }
|
@@ -212,7 +213,9 @@ var DialogBase = /** @class */ (function (_super) {
|
|
212
213
|
if (!process) {
|
213
214
|
_this.snackbar.close("kInProcess");
|
214
215
|
}
|
215
|
-
|
216
|
+
// @ts-ignore
|
217
|
+
(_c = _this._footeRef.current) === null || _c === void 0 ? void 0 : _c.setProcessing(process);
|
218
|
+
// this.forceUpdate();
|
216
219
|
return _this;
|
217
220
|
};
|
218
221
|
_this.isInProcess = function () {
|
@@ -401,9 +404,63 @@ var DialogBase = /** @class */ (function (_super) {
|
|
401
404
|
//@ts-ignore
|
402
405
|
body);
|
403
406
|
};
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
+
// private Footer = (actions?: DialogAction[]) => {
|
408
|
+
//
|
409
|
+
// const CustomFooter = this._dialogOptions.slot?.footer;
|
410
|
+
//
|
411
|
+
//
|
412
|
+
// const staticProps: BaseDialogSlotProps = {
|
413
|
+
// dialogValues: this.state.values,
|
414
|
+
// dialogOptions: this._dialogOptions,
|
415
|
+
// // apiRef: { current: this as IDialogRef } as RefObject<IDialogRef|IDialogCloseRef>
|
416
|
+
// // apiRef: { current: this as IDialogRef }
|
417
|
+
// dialog: this as IDialogDef
|
418
|
+
// };
|
419
|
+
//
|
420
|
+
// let footerProps = {};
|
421
|
+
//
|
422
|
+
// if( this._dialogOptions.slotProps.footer ){
|
423
|
+
// footerProps = this._dialogOptions.slotProps.footer({
|
424
|
+
// dialogValues: this.state.values,
|
425
|
+
// dialogOptions: this._dialogOptions,
|
426
|
+
// inProcess: this.isInProcess()
|
427
|
+
// })
|
428
|
+
// }
|
429
|
+
//
|
430
|
+
//
|
431
|
+
// console.log('FooterSlot_props_Y', footerProps, staticProps, 'V6 ya hazirlik -2');
|
432
|
+
//
|
433
|
+
// return <div className={'dialog-footer'} style={this._dialogOptions.base?.footer?.style}>
|
434
|
+
// <div>
|
435
|
+
// <WithHeaderFooterContext {...staticProps} dialog={this}>
|
436
|
+
// {
|
437
|
+
// this._dialogOptions.slot.footer ?
|
438
|
+
// /*<CustomFooter inProcess={this._inProcess} dialogValues={this.state.values} dialogOptions={this._dialogOptions} />*/
|
439
|
+
// <CustomFooter {...staticProps} {...footerProps} />
|
440
|
+
// :
|
441
|
+
// <DialogProcessing />
|
442
|
+
// /*<CircularProgress size={20} inProcess={this._inProcess} color={this._dialogOptions.progress.color}/>*/
|
443
|
+
// }
|
444
|
+
// </WithHeaderFooterContext>
|
445
|
+
//
|
446
|
+
//
|
447
|
+
// </div>
|
448
|
+
// { this.Actions(actions)}
|
449
|
+
// </div>
|
450
|
+
//
|
451
|
+
// };
|
452
|
+
_this.Footer = React.forwardRef(function (_a, ref) {
|
453
|
+
var _b, _c, _d;
|
454
|
+
var actions = _a.actions;
|
455
|
+
var CustomFooter = (_b = _this._dialogOptions.slot) === null || _b === void 0 ? void 0 : _b.footer;
|
456
|
+
// Imperative handle
|
457
|
+
var _e = React.useState(false), inProcess = _e[0], setInProcess = _e[1];
|
458
|
+
var setProcessing = function (inProcess) {
|
459
|
+
setInProcess(inProcess);
|
460
|
+
};
|
461
|
+
React.useImperativeHandle(ref, function () { return ({
|
462
|
+
setProcessing: setProcessing
|
463
|
+
}); });
|
407
464
|
var staticProps = {
|
408
465
|
dialogValues: _this.state.values,
|
409
466
|
dialogOptions: _this._dialogOptions,
|
@@ -419,8 +476,8 @@ var DialogBase = /** @class */ (function (_super) {
|
|
419
476
|
inProcess: _this.isInProcess()
|
420
477
|
});
|
421
478
|
}
|
422
|
-
console.log('FooterSlot_props_Y', footerProps, staticProps, 'V6 ya hazirlik');
|
423
|
-
return React.createElement("div", { className: 'dialog-footer', style: (
|
479
|
+
console.log('FooterSlot_props_Y', footerProps, staticProps, 'V6 ya hazirlik -2');
|
480
|
+
return React.createElement("div", { className: 'dialog-footer', style: (_d = (_c = _this._dialogOptions.base) === null || _c === void 0 ? void 0 : _c.footer) === null || _d === void 0 ? void 0 : _d.style },
|
424
481
|
React.createElement("div", null,
|
425
482
|
React.createElement(WithHeaderFooterContext, __assign({}, staticProps, { dialog: _this }), _this._dialogOptions.slot.footer ?
|
426
483
|
/*<CustomFooter inProcess={this._inProcess} dialogValues={this.state.values} dialogOptions={this._dialogOptions} />*/
|
@@ -430,7 +487,7 @@ var DialogBase = /** @class */ (function (_super) {
|
|
430
487
|
/*<CircularProgress size={20} inProcess={this._inProcess} color={this._dialogOptions.progress.color}/>*/
|
431
488
|
)),
|
432
489
|
_this.Actions(actions));
|
433
|
-
};
|
490
|
+
});
|
434
491
|
_this.Actions = function (actions) {
|
435
492
|
return React.createElement("div", { style: { position: 'relative', display: 'flex', flexDirection: 'row', columnGap: 10, alignItems: 'center' } }, actions.map(function (action, index) {
|
436
493
|
// const ref = this.slotActionsRef[index];
|
@@ -493,7 +550,7 @@ var DialogBase = /** @class */ (function (_super) {
|
|
493
550
|
React.createElement(WithSnackbar, { snackbarRef: _this._snackbarRef, maxSnack: _this._dialogOptions.snackbar.maxSnack },
|
494
551
|
(_this._header || _this._dialogOptions.slot.header) && _this.Header(header),
|
495
552
|
_this.Body(body),
|
496
|
-
_this.Footer
|
553
|
+
React.createElement(_this.Footer, { ref: _this._footeRef, actions: actions })),
|
497
554
|
(_this._dialogOptions.base.resizeable) &&
|
498
555
|
React.createElement(React.Fragment, null,
|
499
556
|
React.createElement("div", { className: "resizable-handle", onMouseDown: (_c = _this._Resizeable) === null || _c === void 0 ? void 0 : _c.resizeHandleMouseDown },
|
@@ -882,7 +939,14 @@ var DialogBase = /** @class */ (function (_super) {
|
|
882
939
|
this._dom = document.createElement('div');
|
883
940
|
this._dom.setAttribute('role', 'presentation');
|
884
941
|
this._dom.classList.add('appinsource-dialog-root');
|
885
|
-
|
942
|
+
// Find root element
|
943
|
+
var rootElement = document.getElementById('root');
|
944
|
+
if (rootElement) {
|
945
|
+
rootElement.appendChild(this._dom);
|
946
|
+
}
|
947
|
+
else {
|
948
|
+
document.body.appendChild(this._dom);
|
949
|
+
}
|
886
950
|
var root = (0, client_1.createRoot)(this._dom);
|
887
951
|
var props = {
|
888
952
|
ref: this._innerRef,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-dialogger",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.21",
|
4
4
|
"description": "This package is a continuation of the react-araci package. Due to an error, react-araci was removed, and it has been decided to continue under the new package name react-dialogger",
|
5
5
|
"main": "index.js",
|
6
6
|
"author": "Sueleyman Topaloglu",
|
@@ -0,0 +1,302 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import {JSX} from "react";
|
3
|
+
|
4
|
+
export interface FieldProps<V = any, FormValues = any> {
|
5
|
+
field: FieldInputProps<V>;
|
6
|
+
form: FormikProps<FormValues>;
|
7
|
+
meta: FieldMetaProps<V>;
|
8
|
+
}
|
9
|
+
interface FieldConfig<V = any> {
|
10
|
+
/**
|
11
|
+
* Field component to render. Can either be a string like 'select' or a component.
|
12
|
+
*/
|
13
|
+
component?: string | React.ComponentType<FieldProps<V>> | React.ComponentType | React.ForwardRefExoticComponent<any>;
|
14
|
+
/**
|
15
|
+
* Component to render. Can either be a string e.g. 'select', 'input', or 'textarea', or a component.
|
16
|
+
*/
|
17
|
+
as?: React.ComponentType<FieldProps<V>['field']> | string | React.ComponentType | React.ForwardRefExoticComponent<any>;
|
18
|
+
/**
|
19
|
+
* Render prop (works like React router's <Route render={props =>} />)
|
20
|
+
* @deprecated
|
21
|
+
*/
|
22
|
+
render?: (props: FieldProps<V>) => React.ReactNode;
|
23
|
+
/**
|
24
|
+
* Children render function <Field name>{props => ...}</Field>)
|
25
|
+
*/
|
26
|
+
children?: ((props: FieldProps<V>) => React.ReactNode) | React.ReactNode;
|
27
|
+
/**
|
28
|
+
* Validate a single field value independently
|
29
|
+
*/
|
30
|
+
validate?: FieldValidator;
|
31
|
+
/**
|
32
|
+
* Used for 'select' and related input types.
|
33
|
+
*/
|
34
|
+
multiple?: boolean;
|
35
|
+
/**
|
36
|
+
* Field name
|
37
|
+
*/
|
38
|
+
name: string;
|
39
|
+
/** HTML input type */
|
40
|
+
type?: string;
|
41
|
+
/** Field value */
|
42
|
+
value?: any;
|
43
|
+
/** Inner ref */
|
44
|
+
innerRef?: (instance: any) => void;
|
45
|
+
}
|
46
|
+
export type FieldAttributes<T> = {
|
47
|
+
className?: string;
|
48
|
+
} & GenericFieldHTMLAttributes & FieldConfig<T> & T & {
|
49
|
+
name: string;
|
50
|
+
};
|
51
|
+
export type FieldHookConfig<T> = GenericFieldHTMLAttributes & FieldConfig<T>;
|
52
|
+
export declare function useField<Val = any>(propsOrFieldName: string | FieldHookConfig<Val>): [FieldInputProps<Val>, FieldMetaProps<Val>, FieldHelperProps<Val>];
|
53
|
+
export declare function Field({ validate, name, render, children, as: is, // `as` is reserved in typescript lol
|
54
|
+
component, className, ...props }: FieldAttributes<any>): any;
|
55
|
+
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Values of fields in the form
|
59
|
+
*/
|
60
|
+
interface FormikValues {
|
61
|
+
[field: string]: any;
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
* An object containing error messages whose keys correspond to FormikValues.
|
65
|
+
* Should always be an object of strings, but any is allowed to support i18n libraries.
|
66
|
+
*/
|
67
|
+
type FormikErrors<Values> = {
|
68
|
+
[K in keyof Values]?: Values[K] extends any[] ? Values[K][number] extends object ? FormikErrors<Values[K][number]>[] | string | string[] : string | string[] : Values[K] extends object ? FormikErrors<Values[K]> : string;
|
69
|
+
};
|
70
|
+
/**
|
71
|
+
* An object containing touched state of the form whose keys correspond to FormikValues.
|
72
|
+
*/
|
73
|
+
type FormikTouched<Values> = {
|
74
|
+
[K in keyof Values]?: Values[K] extends any[] ? Values[K][number] extends object ? FormikTouched<Values[K][number]>[] : boolean : Values[K] extends object ? FormikTouched<Values[K]> : boolean;
|
75
|
+
};
|
76
|
+
/**
|
77
|
+
* Formik state tree
|
78
|
+
*/
|
79
|
+
interface FormikState<Values> {
|
80
|
+
/** Form values */
|
81
|
+
values: Values;
|
82
|
+
/** map of field names to specific error for that field */
|
83
|
+
errors: FormikErrors<Values>;
|
84
|
+
/** map of field names to whether the field has been touched */
|
85
|
+
touched: FormikTouched<Values>;
|
86
|
+
/** whether the form is currently submitting */
|
87
|
+
isSubmitting: boolean;
|
88
|
+
/** whether the form is currently validating (prior to submission) */
|
89
|
+
isValidating: boolean;
|
90
|
+
/** Top level status state, in case you need it */
|
91
|
+
status?: any;
|
92
|
+
/** Number of times user tried to submit the form */
|
93
|
+
submitCount: number;
|
94
|
+
}
|
95
|
+
/**
|
96
|
+
* Formik computed properties. These are read-only.
|
97
|
+
*/
|
98
|
+
interface FormikComputedProps<Values> {
|
99
|
+
/** True if any input has been touched. False otherwise. */
|
100
|
+
readonly dirty: boolean;
|
101
|
+
/** True if state.errors is empty */
|
102
|
+
readonly isValid: boolean;
|
103
|
+
/** The initial values of the form */
|
104
|
+
readonly initialValues: Values;
|
105
|
+
/** The initial errors of the form */
|
106
|
+
readonly initialErrors: FormikErrors<Values>;
|
107
|
+
/** The initial visited fields of the form */
|
108
|
+
readonly initialTouched: FormikTouched<Values>;
|
109
|
+
/** The initial status of the form */
|
110
|
+
readonly initialStatus?: any;
|
111
|
+
}
|
112
|
+
/**
|
113
|
+
* Formik state helpers
|
114
|
+
*/
|
115
|
+
interface FormikHelpers<Values> {
|
116
|
+
/** Manually set top level status. */
|
117
|
+
setStatus: (status?: any) => void;
|
118
|
+
/** Manually set errors object */
|
119
|
+
setErrors: (errors: FormikErrors<Values>) => void;
|
120
|
+
/** Manually set isSubmitting */
|
121
|
+
setSubmitting: (isSubmitting: boolean) => void;
|
122
|
+
/** Manually set touched object */
|
123
|
+
setTouched: (touched: FormikTouched<Values>, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
|
124
|
+
/** Manually set values object */
|
125
|
+
setValues: (values: React.SetStateAction<Values>, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
|
126
|
+
/** Set value of form field directly */
|
127
|
+
setFieldValue: (field: string, value: any, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
|
128
|
+
/** Set error message of a form field directly */
|
129
|
+
setFieldError: (field: string, message: string | undefined) => void;
|
130
|
+
/** Set whether field has been touched directly */
|
131
|
+
setFieldTouched: (field: string, isTouched?: boolean, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
|
132
|
+
/** Validate form values */
|
133
|
+
validateForm: (values?: any) => Promise<FormikErrors<Values>>|void;
|
134
|
+
/** Validate field value */
|
135
|
+
validateField: (field: string) => Promise<void> | Promise<string | undefined>;
|
136
|
+
/** Reset form */
|
137
|
+
resetForm: (nextState?: Partial<FormikState<Values>>) => void;
|
138
|
+
/** Submit the form imperatively */
|
139
|
+
submitForm: () => void; // Promise<void>;
|
140
|
+
/** Set Formik state, careful! */
|
141
|
+
setFormikState: (f: FormikState<Values> | ((prevState: FormikState<Values>) => FormikState<Values>), cb?: () => void) => void;
|
142
|
+
}
|
143
|
+
/**
|
144
|
+
* Formik form event handlers
|
145
|
+
*/
|
146
|
+
interface FormikHandlers {
|
147
|
+
/** Form submit handler */
|
148
|
+
handleSubmit: (e?: React.FormEvent<HTMLFormElement>) => void;
|
149
|
+
/** Reset form event handler */
|
150
|
+
handleReset: (e?: React.SyntheticEvent<any>) => void;
|
151
|
+
handleBlur: {
|
152
|
+
/** Classic React blur handler, keyed by input name */
|
153
|
+
(e: React.FocusEvent<any>): void;
|
154
|
+
/** Preact-like linkState. Will return a handleBlur function. */
|
155
|
+
<T = string | any>(fieldOrEvent: T): T extends string ? (e: any) => void : void;
|
156
|
+
};
|
157
|
+
handleChange: {
|
158
|
+
/** Classic React change handler, keyed by input name */
|
159
|
+
(e: React.ChangeEvent<any>): void;
|
160
|
+
/** Preact-like linkState. Will return a handleChange function. */
|
161
|
+
<T = string | React.ChangeEvent<any>>(field: T): T extends React.ChangeEvent<any> ? void : (e: string | React.ChangeEvent<any>) => void;
|
162
|
+
};
|
163
|
+
getFieldProps: <Value = any>(props: string | FieldConfig<Value>) => FieldInputProps<Value>;
|
164
|
+
getFieldMeta: <Value>(name: string) => FieldMetaProps<Value>;
|
165
|
+
getFieldHelpers: <Value = any>(name: string) => FieldHelperProps<Value>;
|
166
|
+
}
|
167
|
+
/**
|
168
|
+
* Base formik configuration/props shared between the HoC and Component.
|
169
|
+
*/
|
170
|
+
interface FormikSharedConfig<Props = {}> {
|
171
|
+
/** Tells Formik to validate the form on each input's onChange event */
|
172
|
+
validateOnChange?: boolean;
|
173
|
+
/** Tells Formik to validate the form on each input's onBlur event */
|
174
|
+
validateOnBlur?: boolean;
|
175
|
+
/** Tells Formik to validate upon mount */
|
176
|
+
validateOnMount?: boolean;
|
177
|
+
/** Tell Formik if initial form values are valid or not on first render */
|
178
|
+
isInitialValid?: boolean | ((props: Props) => boolean);
|
179
|
+
/** Should Formik reset the form when new initialValues change */
|
180
|
+
enableReinitialize?: boolean;
|
181
|
+
}
|
182
|
+
/**
|
183
|
+
* <Formik /> props
|
184
|
+
*/
|
185
|
+
interface FormikConfig<Values> extends FormikSharedConfig {
|
186
|
+
/**
|
187
|
+
* Form component to render
|
188
|
+
*/
|
189
|
+
component?: React.ComponentType<FormikProps<Values>>;
|
190
|
+
/**
|
191
|
+
* Render prop (works like React router's <Route render={props =>} />)
|
192
|
+
* @deprecated
|
193
|
+
*/
|
194
|
+
render?: (props: FormikProps<Values>) => React.ReactNode;
|
195
|
+
/**
|
196
|
+
* React children or child render callback
|
197
|
+
*/
|
198
|
+
children?: ((props: FormikProps<Values>) => React.ReactNode) | React.ReactNode;
|
199
|
+
/**
|
200
|
+
* Initial values of the form
|
201
|
+
*/
|
202
|
+
initialValues: Values;
|
203
|
+
/**
|
204
|
+
* Initial status
|
205
|
+
*/
|
206
|
+
initialStatus?: any;
|
207
|
+
/** Initial object map of field names to specific error for that field */
|
208
|
+
initialErrors?: FormikErrors<Values>;
|
209
|
+
/** Initial object map of field names to whether the field has been touched */
|
210
|
+
initialTouched?: FormikTouched<Values>;
|
211
|
+
/**
|
212
|
+
* Reset handler
|
213
|
+
*/
|
214
|
+
onReset?: (values: Values, formikHelpers: FormikHelpers<Values>) => void;
|
215
|
+
/**
|
216
|
+
* Submission handler
|
217
|
+
*/
|
218
|
+
onSubmit: (values: Values, formikHelpers: FormikHelpers<Values>) => void | Promise<any>;
|
219
|
+
/**
|
220
|
+
* A Yup Schema or a function that returns a Yup schema
|
221
|
+
*/
|
222
|
+
validationSchema?: any | (() => any);
|
223
|
+
/**
|
224
|
+
* Validation function. Must return an error object or promise that
|
225
|
+
* throws an error object where that object keys map to corresponding value.
|
226
|
+
*/
|
227
|
+
validate?: (values: Values) => void | object | Promise<FormikErrors<Values>>;
|
228
|
+
/** Inner ref */
|
229
|
+
innerRef?: React.Ref<FormikProps<Values>>;
|
230
|
+
|
231
|
+
}
|
232
|
+
/**
|
233
|
+
* State, handlers, and helpers made available to form component or render prop
|
234
|
+
* of <Formik/>.
|
235
|
+
*/
|
236
|
+
export type FormikProps<Values> = FormikSharedConfig & FormikState<Values> & FormikHelpers<Values> & FormikHandlers & FormikComputedProps<Values> & FormikRegistration
|
237
|
+
/** Internal Formik registration methods that get passed down as props */
|
238
|
+
interface FormikRegistration {
|
239
|
+
registerField: (name: string, fns: {
|
240
|
+
validate?: FieldValidator;
|
241
|
+
}) => void;
|
242
|
+
unregisterField: (name: string) => void;
|
243
|
+
}
|
244
|
+
/**
|
245
|
+
* State, handlers, and helpers made available to Formik's primitive components through context.
|
246
|
+
*/
|
247
|
+
type FormikContextType<Values> = FormikProps<Values> & Pick<FormikConfig<Values>, 'validate' | 'validationSchema'>;
|
248
|
+
interface SharedRenderProps<T> {
|
249
|
+
/**
|
250
|
+
* Field component to render. Can either be a string like 'select' or a component.
|
251
|
+
*/
|
252
|
+
component?: keyof JSX.IntrinsicElements | React.ComponentType<T | void>;
|
253
|
+
/**
|
254
|
+
* Render prop (works like React router's <Route render={props =>} />)
|
255
|
+
*/
|
256
|
+
render?: (props: T) => React.ReactNode;
|
257
|
+
/**
|
258
|
+
* Children render function <Field name>{props => ...}</Field>)
|
259
|
+
*/
|
260
|
+
children?: (props: T) => React.ReactNode;
|
261
|
+
}
|
262
|
+
type GenericFieldHTMLAttributes = JSX.IntrinsicElements['input'] | JSX.IntrinsicElements['select'] | JSX.IntrinsicElements['textarea'];
|
263
|
+
/** Field metadata */
|
264
|
+
interface FieldMetaProps<Value> {
|
265
|
+
/** Value of the field */
|
266
|
+
value: Value;
|
267
|
+
/** Error message of the field */
|
268
|
+
error?: string;
|
269
|
+
/** Has the field been visited? */
|
270
|
+
touched: boolean;
|
271
|
+
/** Initial value of the field */
|
272
|
+
initialValue?: Value;
|
273
|
+
/** Initial touched state of the field */
|
274
|
+
initialTouched: boolean;
|
275
|
+
/** Initial error message of the field */
|
276
|
+
initialError?: string;
|
277
|
+
}
|
278
|
+
/** Imperative handles to change a field's value, error and touched */
|
279
|
+
interface FieldHelperProps<Value> {
|
280
|
+
/** Set the field's value */
|
281
|
+
setValue: (value: Value, shouldValidate?: boolean) => Promise<void | FormikErrors<Value>>;
|
282
|
+
/** Set the field's touched value */
|
283
|
+
setTouched: (value: boolean, shouldValidate?: boolean) => Promise<void | FormikErrors<Value>>;
|
284
|
+
/** Set the field's error value */
|
285
|
+
setError: (value: string | undefined) => void;
|
286
|
+
}
|
287
|
+
/** Field input value, name, and event handlers */
|
288
|
+
interface FieldInputProps<Value> {
|
289
|
+
/** Value of the field */
|
290
|
+
value: Value;
|
291
|
+
/** Name of the field */
|
292
|
+
name: string;
|
293
|
+
/** Multiple select? */
|
294
|
+
multiple?: boolean;
|
295
|
+
/** Is the field checked? */
|
296
|
+
checked?: boolean;
|
297
|
+
/** Change event handler */
|
298
|
+
onChange: FormikHandlers['handleChange'];
|
299
|
+
/** Blur event handler */
|
300
|
+
onBlur: FormikHandlers['handleBlur'];
|
301
|
+
}
|
302
|
+
type FieldValidator = (value: any) => string | void | Promise<string | void>;
|