envoc-form 4.0.1-1 → 4.0.1-10
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 +2 -2
- package/es/ConfirmBaseForm/ConfirmBaseForm.d.ts +3 -1
- package/es/ConfirmBaseForm/ConfirmBaseForm.js +3 -2
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +2 -1
- package/es/DatePicker/DatePickerGroup.d.ts +2 -1
- package/es/DatePicker/DatePickerGroup.js +22 -5
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/es/DatePicker/{DateOnlyDatePickerGroup.js → StringDateOnlyPickerGroup.js} +7 -6
- package/es/Field/Field.d.ts +3 -3
- package/es/Field/Field.js +9 -4
- package/es/FieldArray/FieldArray.js +10 -7
- package/es/File/FileGroup.js +5 -3
- package/es/File/FileList.js +2 -1
- package/es/Form/Form.d.ts +8 -3
- package/es/Form/Form.js +32 -3
- package/es/FormActions.js +5 -1
- package/es/FormDefaults.d.ts +3 -0
- package/es/FormDefaults.js +1 -0
- package/es/Group.d.ts +2 -1
- package/es/Group.js +8 -5
- package/es/Input/IconInputGroup.js +2 -1
- package/es/Input/InputGroup.d.ts +1 -1
- package/es/Input/InputGroup.js +3 -2
- package/es/Input/MoneyInputGroup.js +2 -1
- package/es/Input/NumberInputGroup.js +2 -1
- package/es/Input/StringInputGroup.js +2 -1
- package/es/Select/SelectGroup.d.ts +1 -1
- package/es/Select/SelectGroup.js +8 -3
- package/es/StandardFormActions.js +2 -1
- package/es/SubmitFormButton.js +4 -2
- package/es/TextArea/TextAreaGroup.js +3 -2
- package/es/__Tests__/FormTestBase.d.ts +3 -3
- package/es/index.d.ts +4 -2
- package/es/index.js +4 -1
- package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +3 -1
- package/lib/ConfirmBaseForm/ConfirmBaseForm.js +3 -2
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +2 -1
- package/lib/DatePicker/DatePickerGroup.d.ts +2 -1
- package/lib/DatePicker/DatePickerGroup.js +23 -4
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/lib/DatePicker/{DateOnlyDatePickerGroup.js → StringDateOnlyPickerGroup.js} +8 -7
- package/lib/Field/Field.d.ts +3 -3
- package/lib/Field/Field.js +9 -4
- package/lib/FieldArray/FieldArray.js +10 -7
- package/lib/File/FileGroup.js +5 -3
- package/lib/File/FileList.js +2 -1
- package/lib/Form/Form.d.ts +8 -3
- package/lib/Form/Form.js +32 -3
- package/lib/FormActions.js +5 -1
- package/lib/FormDefaults.d.ts +3 -0
- package/lib/FormDefaults.js +4 -0
- package/lib/Group.d.ts +2 -1
- package/lib/Group.js +8 -5
- package/lib/Input/IconInputGroup.js +2 -1
- package/lib/Input/InputGroup.d.ts +1 -1
- package/lib/Input/InputGroup.js +3 -2
- package/lib/Input/MoneyInputGroup.js +2 -1
- package/lib/Input/NumberInputGroup.js +2 -1
- package/lib/Input/StringInputGroup.js +2 -1
- package/lib/Select/SelectGroup.d.ts +1 -1
- package/lib/Select/SelectGroup.js +8 -3
- package/lib/StandardFormActions.js +2 -1
- package/lib/SubmitFormButton.js +4 -2
- package/lib/TextArea/TextAreaGroup.js +3 -2
- package/lib/__Tests__/FormTestBase.d.ts +3 -3
- package/lib/index.d.ts +4 -2
- package/lib/index.js +8 -3
- package/package.json +4 -2
- package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +15 -10
- package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +13 -3
- package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +3 -3
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +8 -1
- package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +2 -2
- package/src/DatePicker/DatePicker.test.tsx +3 -3
- package/src/DatePicker/DatePickerGroup.tsx +40 -7
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +23 -0
- package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +3 -2
- package/src/Field/Field.tsx +22 -7
- package/src/FieldArray/FieldArray.tsx +21 -9
- package/src/File/FileGroup.tsx +14 -2
- package/src/File/FileList.tsx +3 -1
- package/src/File/__snapshots__/FileGroup.test.tsx.snap +5 -3
- package/src/Form/Form.tsx +56 -4
- package/src/Form/__snapshots__/Form.test.tsx.snap +1 -0
- package/src/FormActions.tsx +8 -2
- package/src/FormDefaults.ts +1 -0
- package/src/Group.tsx +21 -6
- package/src/Input/IconInputGroup.tsx +5 -2
- package/src/Input/InputGroup.tsx +11 -2
- package/src/Input/MoneyInputGroup.tsx +5 -1
- package/src/Input/NumberInputGroup.tsx +5 -1
- package/src/Input/StringInputGroup.tsx +5 -1
- package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +4 -2
- package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +4 -2
- package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +4 -2
- package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +4 -2
- package/src/Select/SelectGroup.tsx +15 -3
- package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +3 -2
- package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +6 -4
- package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +6 -4
- package/src/StandardFormActions.tsx +4 -1
- package/src/SubmitFormButton.tsx +7 -1
- package/src/TextArea/TextAreaGroup.tsx +11 -2
- package/src/__Tests__/FormTestBase.tsx +3 -3
- package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +4 -2
- package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +3 -1
- package/src/index.ts +7 -6
- package/es/DatePicker/DateOnlyDatePickerGroup.d.ts +0 -10
- package/lib/DatePicker/DateOnlyDatePickerGroup.d.ts +0 -10
- package/src/DatePicker/DateOnlyDatePickerGroup.tsx +0 -24
package/es/SubmitFormButton.js
CHANGED
@@ -24,14 +24,16 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import React from 'react';
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import { useFormikContext } from 'formik';
|
27
|
+
import { FormDefaults } from './FormDefaults';
|
27
28
|
function SubmitFormButton(_a, ref) {
|
28
29
|
var allowPristineSubmit = _a.allowPristineSubmit, children = _a.children, disabled = _a.disabled, title = _a.title, className = _a.className, props = __rest(_a, ["allowPristineSubmit", "children", "disabled", "title", "className"]);
|
29
30
|
var _b = useFormikContext(), isSubmitting = _b.isSubmitting, dirty = _b.dirty;
|
30
31
|
var preventSubmit = (!dirty && !allowPristineSubmit) || isSubmitting;
|
31
|
-
|
32
|
+
var buttonName = typeof children === 'string' ? children : 'Submit';
|
33
|
+
return (_jsx("button", __assign({}, props, { ref: ref, type: "submit", disabled: preventSubmit || disabled, "aria-label": buttonName, title: title || isSubmitting
|
32
34
|
? 'Loading, please wait...'
|
33
35
|
: preventSubmit
|
34
36
|
? "You haven't made any changes"
|
35
|
-
: '', className: classNames('submit-form-button', className) }, { children: children || 'Submit' })));
|
37
|
+
: '', className: classNames(FormDefaults.cssClassPrefix + 'submit-form-button', className) }, { children: children || 'Submit' })));
|
36
38
|
}
|
37
39
|
export default React.forwardRef(SubmitFormButton);
|
@@ -24,10 +24,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
24
|
import React from 'react';
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import Group from '../Group';
|
27
|
+
import { FormDefaults } from '../FormDefaults';
|
27
28
|
/** generic controlled <textarea/> wrapped by a Group */
|
28
29
|
function TextAreaGroup(_a, ref) {
|
29
|
-
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "icon"]);
|
30
|
-
return (_jsxs(Group, __assign({ input: input, meta: meta, disabled: disabled, label: label, helpText: helpText, className: classNames(className, 'text-area-group') }, { children: [icon, _jsx("textarea", __assign({}, input, rest, { value: input.value, onChange: function (val) { return input.onChange(val.target.value); }, ref: ref, className: classNames(className, 'text-area-group') }))] })));
|
30
|
+
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "icon"]);
|
31
|
+
return (_jsxs(Group, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: classNames(className, FormDefaults.cssClassPrefix + 'text-area-group') }, { children: [icon, _jsx("textarea", __assign({}, input, rest, { value: input.value, onChange: function (val) { return input.onChange(val.target.value); }, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'text-area-group') }))] })));
|
31
32
|
}
|
32
33
|
var TextAreaGroupWithRef = React.forwardRef(TextAreaGroup);
|
33
34
|
export default TextAreaGroupWithRef;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import '@testing-library/jest-dom/extend-expect';
|
3
|
-
import {
|
3
|
+
import { FormBuilderProp } from '../../src';
|
4
4
|
interface FormTestBaseProps<TForm extends object> {
|
5
5
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
6
6
|
initialValues?: TForm;
|
@@ -13,8 +13,8 @@ interface PersonDto {
|
|
13
13
|
phoneNumber?: string;
|
14
14
|
yearlySalaryUSD?: number;
|
15
15
|
isCool?: boolean;
|
16
|
-
gradDate?:
|
17
|
-
favoriteDate?:
|
16
|
+
gradDate?: string;
|
17
|
+
favoriteDate?: string;
|
18
18
|
favoriteNumber?: number;
|
19
19
|
favoriteColor?: string;
|
20
20
|
favoriteColors?: string[];
|
package/es/index.d.ts
CHANGED
@@ -8,11 +8,12 @@ export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteF
|
|
8
8
|
export type { ConfirmDeleteFormProps } from './ConfirmDeleteForm/ConfirmDeleteForm';
|
9
9
|
export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
|
10
10
|
export type { DatePickerGroupProps as DatePickerGroupProps } from './DatePicker/DatePickerGroup';
|
11
|
+
export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
|
11
12
|
export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
|
12
|
-
export { default as DateOnlyDatePickerGroup } from './DatePicker/DateOnlyDatePickerGroup';
|
13
|
-
export type { DateOnly, DateOnlyDatePickerGroupProps, } from './DatePicker/DateOnlyDatePickerGroup';
|
14
13
|
export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
|
15
14
|
export type { StringDatePickerGroupProps } from './DatePicker/StringDatePickerGroup';
|
15
|
+
export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
|
16
|
+
export type { StringDateOnlyPickerGroupProps } from './DatePicker/StringDateOnlyPickerGroup';
|
16
17
|
export { default as Field } from './Field/Field';
|
17
18
|
export type { FieldProps } from './Field/Field';
|
18
19
|
export type { RenderComponent } from './Field/Field';
|
@@ -36,6 +37,7 @@ export { default as FormActions } from './FormActions';
|
|
36
37
|
export type { FormActionsProps as FormActionsProps } from './FormActions';
|
37
38
|
export { default as StandardFormActions } from './StandardFormActions';
|
38
39
|
export type { StandardFormActionsProps as StandardFormActionsProps } from './StandardFormActions';
|
40
|
+
export { FormDefaults } from './FormDefaults';
|
39
41
|
export { default as Group } from './Group';
|
40
42
|
export type { GroupProps as GroupProps } from './Group';
|
41
43
|
export { default as IconInputGroup } from './Input/IconInputGroup';
|
package/es/index.js
CHANGED
@@ -8,8 +8,9 @@ export { default as ConfirmBaseForm } from './ConfirmBaseForm/ConfirmBaseForm';
|
|
8
8
|
export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteForm';
|
9
9
|
// Date
|
10
10
|
export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
|
11
|
-
export {
|
11
|
+
export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
|
12
12
|
export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
|
13
|
+
export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
|
13
14
|
// Field
|
14
15
|
export { default as Field } from './Field/Field';
|
15
16
|
export { default as FieldErrorScrollTarget } from './Field/FieldErrorScrollTarget';
|
@@ -25,6 +26,8 @@ export { default as Form } from './Form/Form';
|
|
25
26
|
export { ServerErrorContext } from './Form/ServerErrorContext';
|
26
27
|
export { default as FormActions } from './FormActions';
|
27
28
|
export { default as StandardFormActions } from './StandardFormActions';
|
29
|
+
// FormDefaults
|
30
|
+
export { FormDefaults } from './FormDefaults';
|
28
31
|
// Input
|
29
32
|
export { default as Group } from './Group';
|
30
33
|
export { default as IconInputGroup } from './Input/IconInputGroup';
|
@@ -5,6 +5,8 @@ export interface ConfirmBaseFormProps {
|
|
5
5
|
request: useAxiosRequestProps;
|
6
6
|
style?: React.CSSProperties;
|
7
7
|
title?: string;
|
8
|
+
confirmButtonText?: string;
|
9
|
+
confirmButtonClass?: string;
|
8
10
|
children?: React.ReactNode;
|
9
11
|
}
|
10
|
-
export default function ConfirmBaseForm({ handleCancel, request, style, title, children, ...props }: ConfirmBaseFormProps): JSX.Element;
|
12
|
+
export default function ConfirmBaseForm({ handleCancel, request, style, title, confirmButtonText, confirmButtonClass, children, ...props }: ConfirmBaseFormProps): JSX.Element;
|
@@ -28,12 +28,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
29
29
|
var classnames_1 = __importDefault(require("classnames"));
|
30
30
|
var envoc_request_1 = require("envoc-request");
|
31
|
+
var FormDefaults_1 = require("../FormDefaults");
|
31
32
|
// TODO: ask about how we should use 'children'
|
32
33
|
function ConfirmBaseForm(_a) {
|
33
|
-
var handleCancel = _a.handleCancel, request = _a.request, style = _a.style, title = _a.title, children = _a.children, props = __rest(_a, ["handleCancel", "request", "style", "title", "children"]);
|
34
|
+
var handleCancel = _a.handleCancel, request = _a.request, style = _a.style, title = _a.title, confirmButtonText = _a.confirmButtonText, confirmButtonClass = _a.confirmButtonClass, children = _a.children, props = __rest(_a, ["handleCancel", "request", "style", "title", "confirmButtonText", "confirmButtonClass", "children"]);
|
34
35
|
var webRequest = (0, envoc_request_1.useAxiosRequest)(Object.assign({}, request, { autoExecute: false }));
|
35
36
|
var onCancel = handleCancel !== null && handleCancel !== void 0 ? handleCancel : goBack;
|
36
|
-
return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: __assign({ textAlign: 'center' }, style) }, props, { children: [(0, jsx_runtime_1.jsx)("h3", { children: title }), children, (0, jsx_runtime_1.jsx)("button", __assign({ className: (0, classnames_1.default)('confirm-base-form-
|
37
|
+
return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: __assign({ textAlign: 'center' }, style) }, props, { children: [(0, jsx_runtime_1.jsx)("h3", { children: title }), children, (0, jsx_runtime_1.jsx)("button", __assign({ className: (0, classnames_1.default)(confirmButtonClass !== null && confirmButtonClass !== void 0 ? confirmButtonClass : FormDefaults_1.FormDefaults.cssClassPrefix + 'confirm-base-form-confirm-button'), type: "button", onClick: webRequest.submitRequest }, { children: confirmButtonText !== null && confirmButtonText !== void 0 ? confirmButtonText : 'Confirm' })), (0, jsx_runtime_1.jsx)("button", __assign({ className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'confirm-base-form-cancel-button'), type: "button", onClick: onCancel }, { children: "Cancel" }))] })));
|
37
38
|
function goBack() {
|
38
39
|
window.history.back();
|
39
40
|
}
|
@@ -29,6 +29,7 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
29
|
var react_router_dom_1 = require("react-router-dom");
|
30
30
|
var react_toastify_1 = require("react-toastify");
|
31
31
|
var ConfirmBaseForm_1 = __importDefault(require("../ConfirmBaseForm/ConfirmBaseForm"));
|
32
|
+
var FormDefaults_1 = require("../FormDefaults");
|
32
33
|
function ConfirmDeleteForm(_a) {
|
33
34
|
var successUrl = _a.successUrl, form = _a.form, title = _a.title, handleComplete = _a.handleComplete, handleError = _a.handleError, children = _a.children, props = __rest(_a, ["successUrl", "form", "title", "handleComplete", "handleError", "children"]);
|
34
35
|
var navigate = (0, react_router_dom_1.useNavigate)();
|
@@ -47,7 +48,7 @@ function ConfirmDeleteForm(_a) {
|
|
47
48
|
onComplete: onComplete,
|
48
49
|
onError: onError,
|
49
50
|
};
|
50
|
-
return ((0, jsx_runtime_1.jsx)(ConfirmBaseForm_1.default, __assign({ request: request, handleCancel: goBack, title: title !== null && title !== void 0 ? title : 'Are you sure you want to delete this?' }, props, { children: children })));
|
51
|
+
return ((0, jsx_runtime_1.jsx)(ConfirmBaseForm_1.default, __assign({ request: request, handleCancel: goBack, title: title !== null && title !== void 0 ? title : 'Are you sure you want to delete this?', confirmButtonText: "Yes", confirmButtonClass: FormDefaults_1.FormDefaults.cssClassPrefix + 'confirm-delete-form-yes-button' }, props, { children: children })));
|
51
52
|
function goBack() {
|
52
53
|
if (successUrl) {
|
53
54
|
navigate(successUrl);
|
@@ -5,4 +5,5 @@ import { GroupProps } from '../Group';
|
|
5
5
|
export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
|
6
6
|
convert: (arg: Date) => T;
|
7
7
|
}
|
8
|
-
export default function DatePickerGroup<T>({ input, meta, label, helpText, className, disabled, convert, ...rest }: DatePickerGroupProps<T>): JSX.Element;
|
8
|
+
export default function DatePickerGroup<T>({ input, meta, label, helpText, className, required, disabled, convert, ...rest }: DatePickerGroupProps<T>): JSX.Element;
|
9
|
+
export declare function convertToTimeZoneInsensitiveISOString(date: Date): string;
|
@@ -25,16 +25,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
26
26
|
};
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
28
|
+
exports.convertToTimeZoneInsensitiveISOString = void 0;
|
28
29
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
29
30
|
var react_1 = require("react");
|
30
31
|
var entry_nostyle_1 = __importDefault(require("react-date-picker/dist/entry.nostyle"));
|
31
32
|
var classnames_1 = __importDefault(require("classnames"));
|
32
33
|
var parseISO_1 = __importDefault(require("date-fns/parseISO"));
|
34
|
+
var FormDefaults_1 = require("../FormDefaults");
|
33
35
|
var Group_1 = __importDefault(require("../Group"));
|
34
36
|
function DatePickerGroup(_a) {
|
35
|
-
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "convert"]);
|
37
|
+
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "convert"]);
|
36
38
|
var _b = (0, react_1.useState)(null), displayDate = _b[0], setDisplayDate = _b[1];
|
37
|
-
|
39
|
+
(0, react_1.useEffect)(function () {
|
40
|
+
if (input.value != null) {
|
41
|
+
setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
setDisplayDate(null);
|
45
|
+
}
|
46
|
+
}, [setDisplayDate, input.value]);
|
47
|
+
return ((0, jsx_runtime_1.jsx)(Group_1.default, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'date-picker'), required: required, disabled: disabled }, { children: (0, jsx_runtime_1.jsx)(entry_nostyle_1.default, __assign({}, rest, { className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'date-picker', className), value: displayDate, onChange: handleChange })) })));
|
38
48
|
function handleChange(e) {
|
39
49
|
var onChange = input.onChange;
|
40
50
|
if (onChange === null) {
|
@@ -51,16 +61,25 @@ function DatePickerGroup(_a) {
|
|
51
61
|
onChange(convert(parsedValue));
|
52
62
|
}
|
53
63
|
else if (e instanceof Date) {
|
54
|
-
var parsedValue = (0, parseISO_1.default)(e
|
64
|
+
var parsedValue = (0, parseISO_1.default)(convertToTimeZoneInsensitiveISOString(e).split('T')[0]);
|
55
65
|
setDisplayDate(parsedValue);
|
56
66
|
onChange(convert(parsedValue));
|
57
67
|
}
|
58
68
|
else {
|
59
69
|
// e is instanceof Date[]
|
60
|
-
var parsedValue = (0, parseISO_1.default)(e[0]
|
70
|
+
var parsedValue = (0, parseISO_1.default)(convertToTimeZoneInsensitiveISOString(e[0]).split('T')[0]);
|
61
71
|
setDisplayDate(parsedValue);
|
62
72
|
onChange(convert(parsedValue));
|
63
73
|
}
|
64
74
|
}
|
65
75
|
}
|
66
76
|
exports.default = DatePickerGroup;
|
77
|
+
function convertToTimeZoneInsensitiveISOString(date) {
|
78
|
+
var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
79
|
+
.format(date)
|
80
|
+
.padStart(4, '0');
|
81
|
+
var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(date);
|
82
|
+
var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
|
83
|
+
return "".concat(year, "-").concat(month, "-").concat(day, "T00:00:00.000Z");
|
84
|
+
}
|
85
|
+
exports.convertToTimeZoneInsensitiveISOString = convertToTimeZoneInsensitiveISOString;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
+
export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined> {
|
4
|
+
}
|
5
|
+
export default function StringDatePickerGroup(props: StringDateOnlyPickerGroupProps): JSX.Element;
|
@@ -16,14 +16,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
18
18
|
var DatePickerGroup_1 = __importDefault(require("./DatePickerGroup"));
|
19
|
-
function
|
19
|
+
function StringDatePickerGroup(props) {
|
20
20
|
return (0, jsx_runtime_1.jsx)(DatePickerGroup_1.default, __assign({}, props, { convert: convertToDateOnly }));
|
21
21
|
}
|
22
|
-
exports.default =
|
22
|
+
exports.default = StringDatePickerGroup;
|
23
23
|
function convertToDateOnly(arg) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
};
|
24
|
+
var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
25
|
+
.format(arg)
|
26
|
+
.padStart(4, '0');
|
27
|
+
var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(arg);
|
28
|
+
var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(arg);
|
29
|
+
return "".concat(year, "-").concat(month, "-").concat(day);
|
29
30
|
}
|
package/lib/Field/Field.d.ts
CHANGED
@@ -2,8 +2,8 @@ import { ComponentProps, ElementType, LegacyRef } from 'react';
|
|
2
2
|
import { InjectedFieldProps } from './InjectedFieldProps';
|
3
3
|
import { NormalizationFunction } from '../Normalization/NormalizationFunction';
|
4
4
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
5
|
-
export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue>> ? TRenderComponent : never;
|
6
|
-
export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue>> ? ComponentProps<TRenderComponent> : never;
|
5
|
+
export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined>> ? TRenderComponent : never;
|
6
|
+
export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined>> ? ComponentProps<TRenderComponent> : never;
|
7
7
|
/** A specific Field instance to be rendered by the given TRenderComponent or by whatever default is reasonable */
|
8
8
|
export declare type FieldProps<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType> = {
|
9
9
|
name: TProp;
|
@@ -17,6 +17,6 @@ export declare type FieldProps<TForm extends object, TProp extends keyof TForm,
|
|
17
17
|
* Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
|
18
18
|
* Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
|
19
19
|
*/
|
20
|
-
declare function Field<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType>({ name, Component, id,
|
20
|
+
declare function Field<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType>({ name, Component, id, disabled, validate, normalize, ...rest }: FieldProps<TForm, TProp, TRenderComponent>, ref: LegacyRef<any>): JSX.Element;
|
21
21
|
declare const _default: typeof Field;
|
22
22
|
export default _default;
|
package/lib/Field/Field.js
CHANGED
@@ -29,22 +29,27 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
29
|
var react_1 = __importDefault(require("react"));
|
30
30
|
var FieldNameContext_1 = require("./FieldNameContext");
|
31
31
|
var useStandardField_1 = __importDefault(require("./useStandardField"));
|
32
|
+
var validators_1 = require("../Validation/validators");
|
32
33
|
/**
|
33
34
|
* Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
|
34
35
|
* Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
|
35
36
|
*/
|
36
37
|
function Field(_a, ref) {
|
37
|
-
var name = _a.name, Component = _a.Component, id = _a.id,
|
38
|
+
var name = _a.name, Component = _a.Component, id = _a.id, disabled = _a.disabled, validate = _a.validate, normalize = _a.normalize, rest = __rest(_a, ["name", "Component", "id", "disabled", "validate", "normalize"]);
|
38
39
|
var _b = (0, useStandardField_1.default)({
|
39
40
|
name: String(name),
|
40
41
|
id: id,
|
41
|
-
normalize: normalize,
|
42
|
-
validate: validate,
|
43
42
|
disabled: disabled,
|
43
|
+
validate: validate,
|
44
|
+
normalize: normalize,
|
44
45
|
}), input = _b[0], meta = _b[1];
|
46
|
+
var isRequired = (rest === null || rest === void 0 ? void 0 : rest.required) !== undefined
|
47
|
+
? rest.required
|
48
|
+
: validate === validators_1.required ||
|
49
|
+
(Array.isArray(validate) && validate.includes(validators_1.required));
|
45
50
|
// a bit of a hack so JSX is happy with us
|
46
51
|
var Wrapped = Component;
|
47
|
-
return ((0, jsx_runtime_1.jsx)(FieldNameContext_1.FieldNameContext.Provider, __assign({ value: input.name }, { children: (0, jsx_runtime_1.jsx)(Wrapped, __assign({}, rest, { ref: ref, id: id, input: input, meta: meta })) })));
|
52
|
+
return ((0, jsx_runtime_1.jsx)(FieldNameContext_1.FieldNameContext.Provider, __assign({ value: input.name }, { children: (0, jsx_runtime_1.jsx)(Wrapped, __assign({}, rest, { ref: ref, id: input.id, input: input, meta: meta, required: isRequired, disabled: disabled })) })));
|
48
53
|
}
|
49
54
|
// hack to get forwarded refs to work
|
50
55
|
var FieldWithRef = react_1.default.forwardRef(Field);
|
@@ -39,26 +39,29 @@ var classnames_1 = __importDefault(require("classnames"));
|
|
39
39
|
var Field_1 = __importDefault(require("../Field/Field"));
|
40
40
|
var FieldNameContext_1 = require("../Field/FieldNameContext");
|
41
41
|
var useStandardField_1 = __importDefault(require("../Field/useStandardField"));
|
42
|
+
var FormDefaults_1 = require("../FormDefaults");
|
42
43
|
function FieldArray(_a) {
|
44
|
+
var _b;
|
43
45
|
var name = _a.name, label = _a.label, validate = _a.validate, disabled = _a.disabled, children = _a.children, rest = __rest(_a, ["name", "label", "validate", "disabled", "children"]);
|
44
|
-
var
|
46
|
+
var _c = (0, useStandardField_1.default)({
|
45
47
|
name: String(name),
|
46
48
|
validate: validate,
|
47
49
|
disabled: disabled,
|
48
|
-
}), input =
|
50
|
+
}), input = _c[0], meta = _c[1];
|
49
51
|
var values = !input.value
|
50
52
|
? []
|
51
53
|
: Array.isArray(input.value)
|
52
54
|
? input.value
|
53
55
|
: [];
|
54
|
-
return ((0, jsx_runtime_1.jsxs)("div", __assign({ className:
|
56
|
+
return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'field-array' }, { children: [(0, jsx_runtime_1.jsxs)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'field-array-header' }, { children: [(0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'field-array-title' }, { children: label })), (0, jsx_runtime_1.jsx)("button", __assign({ className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'add-array-item-button', (_b = {}, _b[FormDefaults_1.FormDefaults.cssClassPrefix + 'disabled'] = disabled, _b)), title: "Add Item", type: "button", onClick: addItem }, { children: "+" }))] })), (0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'field-array-body' }, { children: values.map(function (value, index) {
|
57
|
+
var _a, _b;
|
55
58
|
var itemName = "".concat(input.name, "[").concat(index, "]");
|
56
|
-
return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: (0, classnames_1.default)('field-array-item', {
|
57
|
-
removed
|
58
|
-
|
59
|
+
return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'field-array-item', (_a = {},
|
60
|
+
_a[FormDefaults_1.FormDefaults.cssClassPrefix + 'removed'] = value.isDeleted,
|
61
|
+
_a)), role: "listitem" }, { children: [(0, jsx_runtime_1.jsx)(FieldNameContext_1.FieldNameContext.Provider, __assign({ value: itemName }, { children: children({
|
59
62
|
Field: Field_1.default,
|
60
63
|
FieldArray: FieldArray,
|
61
|
-
}) })), (0, jsx_runtime_1.jsx)("button", __assign({ className: (0, classnames_1.default)('remove-array-item-button', { disabled
|
64
|
+
}) })), (0, jsx_runtime_1.jsx)("button", __assign({ className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'remove-array-item-button', (_b = {}, _b[FormDefaults_1.FormDefaults.cssClassPrefix + 'disabled'] = disabled, _b)), type: "button", title: "Remove Item", onClick: function () { return removeItem(value); } }, { children: "-" }))] }), (value && value['form-input-array-key']) ||
|
62
65
|
(value && value['id']) ||
|
63
66
|
itemName));
|
64
67
|
}) }))] })));
|
package/lib/File/FileGroup.js
CHANGED
@@ -30,9 +30,11 @@ var react_1 = __importDefault(require("react"));
|
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
31
31
|
var FileList_1 = __importDefault(require("./FileList"));
|
32
32
|
var Group_1 = __importDefault(require("../Group"));
|
33
|
+
var FormDefaults_1 = require("../FormDefaults");
|
33
34
|
function FileGroup(_a, ref) {
|
34
|
-
var
|
35
|
-
|
35
|
+
var _b;
|
36
|
+
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, multiple = _a.multiple, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "multiple"]);
|
37
|
+
return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: (0, classnames_1.default)(className, (_b = {}, _b[FormDefaults_1.FormDefaults.cssClassPrefix + 'multiple'] = multiple, _b), FormDefaults_1.FormDefaults.cssClassPrefix + 'file-group'), required: required, disabled: disabled }, { children: [(0, jsx_runtime_1.jsx)("input", __assign({}, input, rest, { multiple: multiple, onChange: function (e) {
|
36
38
|
var _a, _b;
|
37
39
|
if (!((_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b.length)) {
|
38
40
|
input.onChange(undefined);
|
@@ -49,7 +51,7 @@ function FileGroup(_a, ref) {
|
|
49
51
|
input.onChange(files);
|
50
52
|
}
|
51
53
|
}
|
52
|
-
}, value: undefined, ref: ref, type: "file", className: (0, classnames_1.default)(className, 'file-group') })), (0, jsx_runtime_1.jsx)(FileList_1.default, { files: input.value })] })));
|
54
|
+
}, value: undefined, ref: ref, type: "file", className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'file-group') })), (0, jsx_runtime_1.jsx)(FileList_1.default, { files: input.value })] })));
|
53
55
|
}
|
54
56
|
var FileGroupWithRef = react_1.default.forwardRef(FileGroup);
|
55
57
|
exports.default = FileGroupWithRef;
|
package/lib/File/FileList.js
CHANGED
@@ -12,9 +12,10 @@ var __assign = (this && this.__assign) || function () {
|
|
12
12
|
};
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
14
14
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
15
|
+
var FormDefaults_1 = require("../FormDefaults");
|
15
16
|
function FileList(_a) {
|
16
17
|
var files = _a.files, rejectedFiles = _a.rejectedFiles;
|
17
|
-
return ((0, jsx_runtime_1.jsx)("div", __assign({ className:
|
18
|
+
return ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'file-list' }, { children: !files ? null : Array.isArray(files) ? (files.map(function (x, i) { return (0, jsx_runtime_1.jsx)(File, { file: x }, i); })) : ((0, jsx_runtime_1.jsx)(File, { file: files })) })));
|
18
19
|
}
|
19
20
|
exports.default = FileList;
|
20
21
|
function File(_a) {
|
package/lib/Form/Form.d.ts
CHANGED
@@ -7,15 +7,20 @@ export declare type FormBuilderProp<TForm extends object> = {
|
|
7
7
|
Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
|
8
8
|
FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
|
9
9
|
};
|
10
|
-
export interface
|
10
|
+
export interface FullFormProps<TForm extends object> {
|
11
11
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
12
|
-
onSubmit: (formValues:
|
12
|
+
onSubmit: (formValues: TForm, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
13
|
+
onFormDataSubmit: (formValues: FormData, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
13
14
|
className?: string;
|
14
15
|
style?: CSSProperties;
|
15
16
|
ignoreLostChanges?: boolean;
|
16
17
|
initialValues?: TForm;
|
17
18
|
}
|
18
|
-
declare
|
19
|
+
declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
20
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
21
|
+
}[Keys];
|
22
|
+
export declare type FormProps<TForm extends object> = RequireAtLeastOne<FullFormProps<TForm>, 'onSubmit' | 'onFormDataSubmit'>;
|
23
|
+
declare function Form<TForm extends object>({ children, className, style, ignoreLostChanges, onSubmit, onFormDataSubmit, initialValues, ...props }: FormProps<TForm>): JSX.Element;
|
19
24
|
declare namespace Form {
|
20
25
|
var DisplayFormState: () => JSX.Element;
|
21
26
|
}
|
package/lib/Form/Form.js
CHANGED
@@ -27,16 +27,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
28
28
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
29
29
|
var react_1 = require("react");
|
30
|
+
var classnames_1 = __importDefault(require("classnames"));
|
30
31
|
var formik_1 = require("formik");
|
31
32
|
var FocusError_1 = __importDefault(require("./FocusError"));
|
32
33
|
var FormBasedPreventNavigation_1 = __importDefault(require("./FormBasedPreventNavigation"));
|
33
34
|
var ServerErrorContext_1 = require("./ServerErrorContext");
|
34
35
|
var Field_1 = __importDefault(require("../Field/Field"));
|
35
36
|
var FieldArray_1 = __importDefault(require("../FieldArray/FieldArray"));
|
37
|
+
var FormDefaults_1 = require("../FormDefaults");
|
36
38
|
var objectContainsNonSerializableProperty_1 = __importDefault(require("../utils/objectContainsNonSerializableProperty"));
|
37
39
|
var objectToFormData_1 = __importDefault(require("../utils/objectToFormData"));
|
38
40
|
function Form(_a) {
|
39
|
-
var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "initialValues"]);
|
41
|
+
var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, onFormDataSubmit = _a.onFormDataSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "onFormDataSubmit", "initialValues"]);
|
40
42
|
// formik resets all error on each blur (with our settings)
|
41
43
|
// this means that ALL errors from the server disappear when any one field is blurred
|
42
44
|
// So, we have to store server errors ourselves
|
@@ -56,13 +58,14 @@ function Form(_a) {
|
|
56
58
|
_a)));
|
57
59
|
},
|
58
60
|
}); }, [serverErrors]);
|
59
|
-
return ((0, jsx_runtime_1.jsx)(formik_1.Formik, __assign({ validateOnChange: false, validateOnBlur: true, validateOnMount: false, initialValues: initialValues || {}, onSubmit: handleSubmit }, props, { children: (0, jsx_runtime_1.jsx)(ServerErrorContext_1.ServerErrorContext.Provider, __assign({ value: serverErrorContextValue }, { children: (0, jsx_runtime_1.jsxs)(formik_1.Form, __assign({ className: className, style: style }, { children: [(0, jsx_runtime_1.jsx)(FocusError_1.default, { serverErrors: serverErrorContextValue }), (0, jsx_runtime_1.jsx)(FormBasedPreventNavigation_1.default, { ignoreLostChanges: ignoreLostChanges }), children({
|
61
|
+
return ((0, jsx_runtime_1.jsx)(formik_1.Formik, __assign({ validateOnChange: false, validateOnBlur: true, validateOnMount: false, initialValues: initialValues || {}, onSubmit: handleSubmit }, props, { children: (0, jsx_runtime_1.jsx)(ServerErrorContext_1.ServerErrorContext.Provider, __assign({ value: serverErrorContextValue }, { children: (0, jsx_runtime_1.jsxs)(formik_1.Form, __assign({ className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'form'), style: style }, { children: [(0, jsx_runtime_1.jsx)(FocusError_1.default, { serverErrors: serverErrorContextValue }), (0, jsx_runtime_1.jsx)(FormBasedPreventNavigation_1.default, { ignoreLostChanges: ignoreLostChanges }), children({
|
60
62
|
// hack for ref forwarding
|
61
63
|
Field: Field_1.default,
|
62
64
|
FieldArray: FieldArray_1.default,
|
63
65
|
})] })) })) })));
|
64
66
|
function handleSubmit(values, formikBag) {
|
65
67
|
var formData = undefined;
|
68
|
+
var submitFunc;
|
66
69
|
if ((0, objectContainsNonSerializableProperty_1.default)(values)) {
|
67
70
|
formData = (0, objectToFormData_1.default)(values, {
|
68
71
|
indices: true,
|
@@ -70,8 +73,34 @@ function Form(_a) {
|
|
70
73
|
allowEmptyArrays: true,
|
71
74
|
noFileListBrackets: true,
|
72
75
|
});
|
76
|
+
if (onFormDataSubmit === undefined) {
|
77
|
+
throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
|
78
|
+
}
|
79
|
+
submitFunc = function () {
|
80
|
+
return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
|
81
|
+
};
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
if (onSubmit === undefined) {
|
85
|
+
formData = (0, objectToFormData_1.default)(values, {
|
86
|
+
indices: true,
|
87
|
+
dotNotation: true,
|
88
|
+
allowEmptyArrays: true,
|
89
|
+
noFileListBrackets: true,
|
90
|
+
});
|
91
|
+
if (onFormDataSubmit === undefined) {
|
92
|
+
// This error should never occur, as this case is covered by RequireAtLeastOne type safety
|
93
|
+
throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
|
94
|
+
}
|
95
|
+
submitFunc = function () {
|
96
|
+
return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
|
97
|
+
};
|
98
|
+
}
|
99
|
+
else {
|
100
|
+
submitFunc = function () { return onSubmit(values, formikBag); };
|
101
|
+
}
|
73
102
|
}
|
74
|
-
return
|
103
|
+
return submitFunc()
|
75
104
|
.then(function (response) {
|
76
105
|
return response;
|
77
106
|
})
|
package/lib/FormActions.js
CHANGED
@@ -15,12 +15,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
18
|
+
var FormDefaults_1 = require("./FormDefaults");
|
18
19
|
var formik_1 = require("formik");
|
19
20
|
var SubmitFormButton_1 = __importDefault(require("./SubmitFormButton"));
|
20
21
|
function FormActions(_a) {
|
21
22
|
var allowPristineSubmit = _a.allowPristineSubmit, handleCancel = _a.handleCancel, disabled = _a.disabled;
|
22
23
|
var isSubmitting = (0, formik_1.useFormikContext)().isSubmitting;
|
23
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SubmitFormButton_1.default, { className:
|
24
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SubmitFormButton_1.default, { className: FormDefaults_1.FormDefaults.cssClassPrefix + 'form-actions', allowPristineSubmit: allowPristineSubmit, disabled: disabled }), (0, jsx_runtime_1.jsx)("button", __assign({ type: "button", className: FormDefaults_1.FormDefaults.cssClassPrefix +
|
25
|
+
'form-actions ' +
|
26
|
+
FormDefaults_1.FormDefaults.cssClassPrefix +
|
27
|
+
'cancel-form-button', disabled: isSubmitting || disabled, onClick: handleCancel || goBack }, { children: "Cancel" }))] }));
|
24
28
|
function goBack() {
|
25
29
|
window.history.back();
|
26
30
|
}
|
package/lib/Group.d.ts
CHANGED
@@ -8,6 +8,7 @@ export interface GroupProps extends InjectedFieldProps<any> {
|
|
8
8
|
/** simple helper text after the input*/
|
9
9
|
helpText?: string | React.ReactNode;
|
10
10
|
disabled?: boolean;
|
11
|
+
required?: boolean;
|
11
12
|
}
|
12
13
|
/** contains standard field bits like a label, helper text, error scroll target, validation message container, etc */
|
13
|
-
export default function Group({ className, children, label, helpText, meta, input, disabled, }: GroupProps): JSX.Element;
|
14
|
+
export default function Group({ className, children, label, helpText, meta, input, disabled, required, }: GroupProps): JSX.Element;
|
package/lib/Group.js
CHANGED
@@ -16,13 +16,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
18
18
|
var classnames_1 = __importDefault(require("classnames"));
|
19
|
+
var FormDefaults_1 = require("./FormDefaults");
|
19
20
|
var FieldErrorScrollTarget_1 = __importDefault(require("./Field/FieldErrorScrollTarget"));
|
20
21
|
/** contains standard field bits like a label, helper text, error scroll target, validation message container, etc */
|
21
22
|
function Group(_a) {
|
22
|
-
var
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
var _b;
|
24
|
+
var className = _a.className, children = _a.children, label = _a.label, helpText = _a.helpText, meta = _a.meta, input = _a.input, disabled = _a.disabled, required = _a.required;
|
25
|
+
return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'group', (_b = {},
|
26
|
+
_b[FormDefaults_1.FormDefaults.cssClassPrefix + 'invalid'] = meta.error,
|
27
|
+
_b[FormDefaults_1.FormDefaults.cssClassPrefix + 'disabled'] = disabled,
|
28
|
+
_b[FormDefaults_1.FormDefaults.cssClassPrefix + 'required'] = required,
|
29
|
+
_b)) }, { children: [(0, jsx_runtime_1.jsx)(FieldErrorScrollTarget_1.default, {}), meta.warning && ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'warning' }, { children: meta.warning }))), (0, jsx_runtime_1.jsx)("label", __assign({ htmlFor: input.id }, { children: label })), children, meta.error && ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'error' }, { children: meta.error }))), helpText && ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'help' }, { children: helpText })))] })));
|
27
30
|
}
|
28
31
|
exports.default = Group;
|
@@ -29,10 +29,11 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
29
|
var react_1 = __importDefault(require("react"));
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
31
31
|
var InputGroup_1 = __importDefault(require("./InputGroup"));
|
32
|
+
var FormDefaults_1 = require("../FormDefaults");
|
32
33
|
function IconInputGroup(_a, ref) {
|
33
34
|
var icon = _a.icon, className = _a.className, rest = __rest(_a, ["icon", "className"]);
|
34
35
|
var input = rest.input;
|
35
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(InputGroup_1.default, __assign({ icon: icon, ref: ref, className: (0, classnames_1.default)(className, 'icon-input-group'), value: input.value || '', onChange: function (e) {
|
36
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(InputGroup_1.default, __assign({ icon: icon, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'icon-input-group'), value: input.value || '', onChange: function (e) {
|
36
37
|
if (!e.target.value) {
|
37
38
|
input.onChange(undefined);
|
38
39
|
}
|
@@ -7,6 +7,6 @@ export interface InputGroupProps<TValue> extends InjectedFieldProps<TValue>, Omi
|
|
7
7
|
icon?: React.ReactNode;
|
8
8
|
}
|
9
9
|
/** generic controlled <input/> wrapped by a Group */
|
10
|
-
declare function InputGroup<TValue>({ input, meta, label, helpText, className, disabled, onChange, value, icon, ...rest }: InputGroupProps<TValue>, ref: LegacyRef<HTMLInputElement>): JSX.Element;
|
10
|
+
declare function InputGroup<TValue>({ input, meta, label, helpText, className, required, disabled, onChange, value, icon, ...rest }: InputGroupProps<TValue>, ref: LegacyRef<HTMLInputElement>): JSX.Element;
|
11
11
|
declare const InputGroupWithRef: typeof InputGroup;
|
12
12
|
export default InputGroupWithRef;
|
package/lib/Input/InputGroup.js
CHANGED
@@ -29,10 +29,11 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
29
|
var react_1 = __importDefault(require("react"));
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
31
31
|
var Group_1 = __importDefault(require("../Group"));
|
32
|
+
var FormDefaults_1 = require("../FormDefaults");
|
32
33
|
/** generic controlled <input/> wrapped by a Group */
|
33
34
|
function InputGroup(_a, ref) {
|
34
|
-
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, onChange = _a.onChange, value = _a.value, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "onChange", "value", "icon"]);
|
35
|
-
return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, disabled: disabled, label: label, helpText: helpText, className: (0, classnames_1.default)(className, 'input-group') }, { children: [icon, (0, jsx_runtime_1.jsx)("input", __assign({}, input, rest, { value: value, onChange: onChange, ref: ref, className: (0, classnames_1.default)(className, 'input-group') }))] })));
|
35
|
+
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, onChange = _a.onChange, value = _a.value, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "onChange", "value", "icon"]);
|
36
|
+
return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'input-group') }, { children: [icon, (0, jsx_runtime_1.jsx)("input", __assign({}, input, rest, { value: value, onChange: onChange, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'input-group') }))] })));
|
36
37
|
}
|
37
38
|
var InputGroupWithRef = react_1.default.forwardRef(InputGroup);
|
38
39
|
exports.default = InputGroupWithRef;
|