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/README.md
CHANGED
@@ -10,8 +10,8 @@ Base form package for envoc projects.
|
|
10
10
|
Important naming conventions for our sanity while creating envoc-form types:
|
11
11
|
|
12
12
|
- TForm = The type of the some form. e.g. LoginDto
|
13
|
-
- TProp = The key / symbol of a
|
14
|
-
- TValue = The value of an
|
13
|
+
- TProp = The key / symbol of a individual property of some form. e.g. TProp would be literally "Username" for the prop of the same name for a LoginDto
|
14
|
+
- TValue = The value of an individual property of some form. e.g. a "Username" property would probably have a TValue of string
|
15
15
|
- Field = the abstract thing that deals with some specific TProp. Might represent several composed elements (e.g. label, input, helperText, etc) or may just be a direct component
|
16
16
|
- TRenderComponent = The type of any 'Component' passed to a Field, e.g. 'StandardTextInputGroup' passed to Component means TRenderComponent is typeof(StandardTextInputGroup)
|
17
17
|
- TComponentProps = For any 'Component' passed to a Field as a prop, this represents that Component's props
|
@@ -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;
|
@@ -23,12 +23,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
23
23
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
24
|
import classNames from 'classnames';
|
25
25
|
import { useAxiosRequest } from 'envoc-request';
|
26
|
+
import { FormDefaults } from '../FormDefaults';
|
26
27
|
// TODO: ask about how we should use 'children'
|
27
28
|
export default function ConfirmBaseForm(_a) {
|
28
|
-
var handleCancel = _a.handleCancel, request = _a.request, style = _a.style, title = _a.title, children = _a.children, props = __rest(_a, ["handleCancel", "request", "style", "title", "children"]);
|
29
|
+
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"]);
|
29
30
|
var webRequest = useAxiosRequest(Object.assign({}, request, { autoExecute: false }));
|
30
31
|
var onCancel = handleCancel !== null && handleCancel !== void 0 ? handleCancel : goBack;
|
31
|
-
return (_jsxs("div", __assign({ style: __assign({ textAlign: 'center' }, style) }, props, { children: [_jsx("h3", { children: title }), children, _jsx("button", __assign({ className: classNames('confirm-base-form-
|
32
|
+
return (_jsxs("div", __assign({ style: __assign({ textAlign: 'center' }, style) }, props, { children: [_jsx("h3", { children: title }), children, _jsx("button", __assign({ className: classNames(confirmButtonClass !== null && confirmButtonClass !== void 0 ? confirmButtonClass : FormDefaults.cssClassPrefix + 'confirm-base-form-confirm-button'), type: "button", onClick: webRequest.submitRequest }, { children: confirmButtonText !== null && confirmButtonText !== void 0 ? confirmButtonText : 'Confirm' })), _jsx("button", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'confirm-base-form-cancel-button'), type: "button", onClick: onCancel }, { children: "Cancel" }))] })));
|
32
33
|
function goBack() {
|
33
34
|
window.history.back();
|
34
35
|
}
|
@@ -24,6 +24,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import { useNavigate, useParams } from 'react-router-dom';
|
25
25
|
import { toast } from 'react-toastify';
|
26
26
|
import ConfirmBaseForm from '../ConfirmBaseForm/ConfirmBaseForm';
|
27
|
+
import { FormDefaults } from '../FormDefaults';
|
27
28
|
export default function ConfirmDeleteForm(_a) {
|
28
29
|
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"]);
|
29
30
|
var navigate = useNavigate();
|
@@ -42,7 +43,7 @@ export default function ConfirmDeleteForm(_a) {
|
|
42
43
|
onComplete: onComplete,
|
43
44
|
onError: onError,
|
44
45
|
};
|
45
|
-
return (_jsx(ConfirmBaseForm, __assign({ request: request, handleCancel: goBack, title: title !== null && title !== void 0 ? title : 'Are you sure you want to delete this?' }, props, { children: children })));
|
46
|
+
return (_jsx(ConfirmBaseForm, __assign({ request: request, handleCancel: goBack, title: title !== null && title !== void 0 ? title : 'Are you sure you want to delete this?', confirmButtonText: "Yes", confirmButtonClass: FormDefaults.cssClassPrefix + 'confirm-delete-form-yes-button' }, props, { children: children })));
|
46
47
|
function goBack() {
|
47
48
|
if (successUrl) {
|
48
49
|
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;
|
@@ -21,15 +21,24 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
21
21
|
return t;
|
22
22
|
};
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
-
import { useState } from 'react';
|
24
|
+
import { useEffect, useState } from 'react';
|
25
25
|
import DatePicker from 'react-date-picker/dist/entry.nostyle';
|
26
26
|
import classnames from 'classnames';
|
27
27
|
import parseISO from 'date-fns/parseISO';
|
28
|
+
import { FormDefaults } from '../FormDefaults';
|
28
29
|
import Group from '../Group';
|
29
30
|
export default function DatePickerGroup(_a) {
|
30
|
-
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"]);
|
31
|
+
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"]);
|
31
32
|
var _b = useState(null), displayDate = _b[0], setDisplayDate = _b[1];
|
32
|
-
|
33
|
+
useEffect(function () {
|
34
|
+
if (input.value != null) {
|
35
|
+
setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
setDisplayDate(null);
|
39
|
+
}
|
40
|
+
}, [setDisplayDate, input.value]);
|
41
|
+
return (_jsx(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classnames(className, FormDefaults.cssClassPrefix + 'date-picker'), required: required, disabled: disabled }, { children: _jsx(DatePicker, __assign({}, rest, { className: classnames(FormDefaults.cssClassPrefix + 'date-picker', className), value: displayDate, onChange: handleChange })) })));
|
33
42
|
function handleChange(e) {
|
34
43
|
var onChange = input.onChange;
|
35
44
|
if (onChange === null) {
|
@@ -46,15 +55,23 @@ export default function DatePickerGroup(_a) {
|
|
46
55
|
onChange(convert(parsedValue));
|
47
56
|
}
|
48
57
|
else if (e instanceof Date) {
|
49
|
-
var parsedValue = parseISO(e
|
58
|
+
var parsedValue = parseISO(convertToTimeZoneInsensitiveISOString(e).split('T')[0]);
|
50
59
|
setDisplayDate(parsedValue);
|
51
60
|
onChange(convert(parsedValue));
|
52
61
|
}
|
53
62
|
else {
|
54
63
|
// e is instanceof Date[]
|
55
|
-
var parsedValue = parseISO(e[0]
|
64
|
+
var parsedValue = parseISO(convertToTimeZoneInsensitiveISOString(e[0]).split('T')[0]);
|
56
65
|
setDisplayDate(parsedValue);
|
57
66
|
onChange(convert(parsedValue));
|
58
67
|
}
|
59
68
|
}
|
60
69
|
}
|
70
|
+
export function convertToTimeZoneInsensitiveISOString(date) {
|
71
|
+
var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
72
|
+
.format(date)
|
73
|
+
.padStart(4, '0');
|
74
|
+
var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(date);
|
75
|
+
var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
|
76
|
+
return "".concat(year, "-").concat(month, "-").concat(day, "T00:00:00.000Z");
|
77
|
+
}
|
@@ -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;
|
@@ -11,13 +11,14 @@ var __assign = (this && this.__assign) || function () {
|
|
11
11
|
};
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
13
|
import DatePickerGroup from './DatePickerGroup';
|
14
|
-
export default function
|
14
|
+
export default function StringDatePickerGroup(props) {
|
15
15
|
return _jsx(DatePickerGroup, __assign({}, props, { convert: convertToDateOnly }));
|
16
16
|
}
|
17
17
|
function convertToDateOnly(arg) {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
};
|
18
|
+
var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
19
|
+
.format(arg)
|
20
|
+
.padStart(4, '0');
|
21
|
+
var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(arg);
|
22
|
+
var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(arg);
|
23
|
+
return "".concat(year, "-").concat(month, "-").concat(day);
|
23
24
|
}
|
package/es/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/es/Field/Field.js
CHANGED
@@ -24,22 +24,27 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import React from 'react';
|
25
25
|
import { FieldNameContext } from './FieldNameContext';
|
26
26
|
import useStandardFormInput from './useStandardField';
|
27
|
+
import { required as requiredValidator } from '../Validation/validators';
|
27
28
|
/**
|
28
29
|
* Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
|
29
30
|
* Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
|
30
31
|
*/
|
31
32
|
function Field(_a, ref) {
|
32
|
-
var name = _a.name, Component = _a.Component, id = _a.id,
|
33
|
+
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"]);
|
33
34
|
var _b = useStandardFormInput({
|
34
35
|
name: String(name),
|
35
36
|
id: id,
|
36
|
-
normalize: normalize,
|
37
|
-
validate: validate,
|
38
37
|
disabled: disabled,
|
38
|
+
validate: validate,
|
39
|
+
normalize: normalize,
|
39
40
|
}), input = _b[0], meta = _b[1];
|
41
|
+
var isRequired = (rest === null || rest === void 0 ? void 0 : rest.required) !== undefined
|
42
|
+
? rest.required
|
43
|
+
: validate === requiredValidator ||
|
44
|
+
(Array.isArray(validate) && validate.includes(requiredValidator));
|
40
45
|
// a bit of a hack so JSX is happy with us
|
41
46
|
var Wrapped = Component;
|
42
|
-
return (_jsx(FieldNameContext.Provider, __assign({ value: input.name }, { children: _jsx(Wrapped, __assign({}, rest, { ref: ref, id: id, input: input, meta: meta })) })));
|
47
|
+
return (_jsx(FieldNameContext.Provider, __assign({ value: input.name }, { children: _jsx(Wrapped, __assign({}, rest, { ref: ref, id: input.id, input: input, meta: meta, required: isRequired, disabled: disabled })) })));
|
43
48
|
}
|
44
49
|
// hack to get forwarded refs to work
|
45
50
|
var FieldWithRef = React.forwardRef(Field);
|
@@ -34,26 +34,29 @@ import classNames from 'classnames';
|
|
34
34
|
import Field from '../Field/Field';
|
35
35
|
import { FieldNameContext } from '../Field/FieldNameContext';
|
36
36
|
import useStandardFormInput from '../Field/useStandardField';
|
37
|
+
import { FormDefaults } from '../FormDefaults';
|
37
38
|
export default function FieldArray(_a) {
|
39
|
+
var _b;
|
38
40
|
var name = _a.name, label = _a.label, validate = _a.validate, disabled = _a.disabled, children = _a.children, rest = __rest(_a, ["name", "label", "validate", "disabled", "children"]);
|
39
|
-
var
|
41
|
+
var _c = useStandardFormInput({
|
40
42
|
name: String(name),
|
41
43
|
validate: validate,
|
42
44
|
disabled: disabled,
|
43
|
-
}), input =
|
45
|
+
}), input = _c[0], meta = _c[1];
|
44
46
|
var values = !input.value
|
45
47
|
? []
|
46
48
|
: Array.isArray(input.value)
|
47
49
|
? input.value
|
48
50
|
: [];
|
49
|
-
return (_jsxs("div", __assign({ className:
|
51
|
+
return (_jsxs("div", __assign({ className: FormDefaults.cssClassPrefix + 'field-array' }, { children: [_jsxs("div", __assign({ className: FormDefaults.cssClassPrefix + 'field-array-header' }, { children: [_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'field-array-title' }, { children: label })), _jsx("button", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'add-array-item-button', (_b = {}, _b[FormDefaults.cssClassPrefix + 'disabled'] = disabled, _b)), title: "Add Item", type: "button", onClick: addItem }, { children: "+" }))] })), _jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'field-array-body' }, { children: values.map(function (value, index) {
|
52
|
+
var _a, _b;
|
50
53
|
var itemName = "".concat(input.name, "[").concat(index, "]");
|
51
|
-
return (_jsxs("div", __assign({ className: classNames('field-array-item', {
|
52
|
-
removed
|
53
|
-
|
54
|
+
return (_jsxs("div", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'field-array-item', (_a = {},
|
55
|
+
_a[FormDefaults.cssClassPrefix + 'removed'] = value.isDeleted,
|
56
|
+
_a)), role: "listitem" }, { children: [_jsx(FieldNameContext.Provider, __assign({ value: itemName }, { children: children({
|
54
57
|
Field: Field,
|
55
58
|
FieldArray: FieldArray,
|
56
|
-
}) })), _jsx("button", __assign({ className: classNames('remove-array-item-button', { disabled
|
59
|
+
}) })), _jsx("button", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'remove-array-item-button', (_b = {}, _b[FormDefaults.cssClassPrefix + 'disabled'] = disabled, _b)), type: "button", title: "Remove Item", onClick: function () { return removeItem(value); } }, { children: "-" }))] }), (value && value['form-input-array-key']) ||
|
57
60
|
(value && value['id']) ||
|
58
61
|
itemName));
|
59
62
|
}) }))] })));
|
package/es/File/FileGroup.js
CHANGED
@@ -25,9 +25,11 @@ import React from 'react';
|
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import FileList from './FileList';
|
27
27
|
import Group from '../Group';
|
28
|
+
import { FormDefaults } from '../FormDefaults';
|
28
29
|
function FileGroup(_a, ref) {
|
29
|
-
var
|
30
|
-
|
30
|
+
var _b;
|
31
|
+
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"]);
|
32
|
+
return (_jsxs(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classNames(className, (_b = {}, _b[FormDefaults.cssClassPrefix + 'multiple'] = multiple, _b), FormDefaults.cssClassPrefix + 'file-group'), required: required, disabled: disabled }, { children: [_jsx("input", __assign({}, input, rest, { multiple: multiple, onChange: function (e) {
|
31
33
|
var _a, _b;
|
32
34
|
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)) {
|
33
35
|
input.onChange(undefined);
|
@@ -44,7 +46,7 @@ function FileGroup(_a, ref) {
|
|
44
46
|
input.onChange(files);
|
45
47
|
}
|
46
48
|
}
|
47
|
-
}, value: undefined, ref: ref, type: "file", className: classNames(className, 'file-group') })), _jsx(FileList, { files: input.value })] })));
|
49
|
+
}, value: undefined, ref: ref, type: "file", className: classNames(className, FormDefaults.cssClassPrefix + 'file-group') })), _jsx(FileList, { files: input.value })] })));
|
48
50
|
}
|
49
51
|
var FileGroupWithRef = React.forwardRef(FileGroup);
|
50
52
|
export default FileGroupWithRef;
|
package/es/File/FileList.js
CHANGED
@@ -10,9 +10,10 @@ var __assign = (this && this.__assign) || function () {
|
|
10
10
|
return __assign.apply(this, arguments);
|
11
11
|
};
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
|
+
import { FormDefaults } from '../FormDefaults';
|
13
14
|
export default function FileList(_a) {
|
14
15
|
var files = _a.files, rejectedFiles = _a.rejectedFiles;
|
15
|
-
return (_jsx("div", __assign({ className:
|
16
|
+
return (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'file-list' }, { children: !files ? null : Array.isArray(files) ? (files.map(function (x, i) { return _jsx(File, { file: x }, i); })) : (_jsx(File, { file: files })) })));
|
16
17
|
}
|
17
18
|
function File(_a) {
|
18
19
|
var file = _a.file;
|
package/es/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/es/Form/Form.js
CHANGED
@@ -22,16 +22,18 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
22
22
|
};
|
23
23
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
24
|
import { useContext, useMemo, useState, } from 'react';
|
25
|
+
import classNames from 'classnames';
|
25
26
|
import { Form as FormikFormWrapper, Formik, useFormikContext, } from 'formik';
|
26
27
|
import FocusError from './FocusError';
|
27
28
|
import FormBasedPreventNavigation from './FormBasedPreventNavigation';
|
28
29
|
import { ServerErrorContext, } from './ServerErrorContext';
|
29
30
|
import Field from '../Field/Field';
|
30
31
|
import FieldArray from '../FieldArray/FieldArray';
|
32
|
+
import { FormDefaults } from '../FormDefaults';
|
31
33
|
import objectContainsNonSerializableProperty from '../utils/objectContainsNonSerializableProperty';
|
32
34
|
import objectToFormData from '../utils/objectToFormData';
|
33
35
|
export default function Form(_a) {
|
34
|
-
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"]);
|
36
|
+
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"]);
|
35
37
|
// formik resets all error on each blur (with our settings)
|
36
38
|
// this means that ALL errors from the server disappear when any one field is blurred
|
37
39
|
// So, we have to store server errors ourselves
|
@@ -51,13 +53,14 @@ export default function Form(_a) {
|
|
51
53
|
_a)));
|
52
54
|
},
|
53
55
|
}); }, [serverErrors]);
|
54
|
-
return (_jsx(Formik, __assign({ validateOnChange: false, validateOnBlur: true, validateOnMount: false, initialValues: initialValues || {}, onSubmit: handleSubmit }, props, { children: _jsx(ServerErrorContext.Provider, __assign({ value: serverErrorContextValue }, { children: _jsxs(FormikFormWrapper, __assign({ className: className, style: style }, { children: [_jsx(FocusError, { serverErrors: serverErrorContextValue }), _jsx(FormBasedPreventNavigation, { ignoreLostChanges: ignoreLostChanges }), children({
|
56
|
+
return (_jsx(Formik, __assign({ validateOnChange: false, validateOnBlur: true, validateOnMount: false, initialValues: initialValues || {}, onSubmit: handleSubmit }, props, { children: _jsx(ServerErrorContext.Provider, __assign({ value: serverErrorContextValue }, { children: _jsxs(FormikFormWrapper, __assign({ className: classNames(className, FormDefaults.cssClassPrefix + 'form'), style: style }, { children: [_jsx(FocusError, { serverErrors: serverErrorContextValue }), _jsx(FormBasedPreventNavigation, { ignoreLostChanges: ignoreLostChanges }), children({
|
55
57
|
// hack for ref forwarding
|
56
58
|
Field: Field,
|
57
59
|
FieldArray: FieldArray,
|
58
60
|
})] })) })) })));
|
59
61
|
function handleSubmit(values, formikBag) {
|
60
62
|
var formData = undefined;
|
63
|
+
var submitFunc;
|
61
64
|
if (objectContainsNonSerializableProperty(values)) {
|
62
65
|
formData = objectToFormData(values, {
|
63
66
|
indices: true,
|
@@ -65,8 +68,34 @@ export default function Form(_a) {
|
|
65
68
|
allowEmptyArrays: true,
|
66
69
|
noFileListBrackets: true,
|
67
70
|
});
|
71
|
+
if (onFormDataSubmit === undefined) {
|
72
|
+
throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
|
73
|
+
}
|
74
|
+
submitFunc = function () {
|
75
|
+
return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
|
76
|
+
};
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
if (onSubmit === undefined) {
|
80
|
+
formData = objectToFormData(values, {
|
81
|
+
indices: true,
|
82
|
+
dotNotation: true,
|
83
|
+
allowEmptyArrays: true,
|
84
|
+
noFileListBrackets: true,
|
85
|
+
});
|
86
|
+
if (onFormDataSubmit === undefined) {
|
87
|
+
// This error should never occur, as this case is covered by RequireAtLeastOne type safety
|
88
|
+
throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
|
89
|
+
}
|
90
|
+
submitFunc = function () {
|
91
|
+
return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
|
92
|
+
};
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
submitFunc = function () { return onSubmit(values, formikBag); };
|
96
|
+
}
|
68
97
|
}
|
69
|
-
return
|
98
|
+
return submitFunc()
|
70
99
|
.then(function (response) {
|
71
100
|
return response;
|
72
101
|
})
|
package/es/FormActions.js
CHANGED
@@ -10,12 +10,16 @@ var __assign = (this && this.__assign) || function () {
|
|
10
10
|
return __assign.apply(this, arguments);
|
11
11
|
};
|
12
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
+
import { FormDefaults } from './FormDefaults';
|
13
14
|
import { useFormikContext } from 'formik';
|
14
15
|
import SubmitFormButton from './SubmitFormButton';
|
15
16
|
export default function FormActions(_a) {
|
16
17
|
var allowPristineSubmit = _a.allowPristineSubmit, handleCancel = _a.handleCancel, disabled = _a.disabled;
|
17
18
|
var isSubmitting = useFormikContext().isSubmitting;
|
18
|
-
return (_jsxs(_Fragment, { children: [_jsx(SubmitFormButton, { className:
|
19
|
+
return (_jsxs(_Fragment, { children: [_jsx(SubmitFormButton, { className: FormDefaults.cssClassPrefix + 'form-actions', allowPristineSubmit: allowPristineSubmit, disabled: disabled }), _jsx("button", __assign({ type: "button", className: FormDefaults.cssClassPrefix +
|
20
|
+
'form-actions ' +
|
21
|
+
FormDefaults.cssClassPrefix +
|
22
|
+
'cancel-form-button', disabled: isSubmitting || disabled, onClick: handleCancel || goBack }, { children: "Cancel" }))] }));
|
19
23
|
function goBack() {
|
20
24
|
window.history.back();
|
21
25
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export var FormDefaults = { cssClassPrefix: 'envoc-form-' };
|
package/es/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/es/Group.js
CHANGED
@@ -11,12 +11,15 @@ var __assign = (this && this.__assign) || function () {
|
|
11
11
|
};
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13
13
|
import classNames from 'classnames';
|
14
|
+
import { FormDefaults } from './FormDefaults';
|
14
15
|
import FieldErrorScrollTarget from './Field/FieldErrorScrollTarget';
|
15
16
|
/** contains standard field bits like a label, helper text, error scroll target, validation message container, etc */
|
16
17
|
export default function Group(_a) {
|
17
|
-
var
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
var _b;
|
19
|
+
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;
|
20
|
+
return (_jsxs("div", __assign({ className: classNames(className, FormDefaults.cssClassPrefix + 'group', (_b = {},
|
21
|
+
_b[FormDefaults.cssClassPrefix + 'invalid'] = meta.error,
|
22
|
+
_b[FormDefaults.cssClassPrefix + 'disabled'] = disabled,
|
23
|
+
_b[FormDefaults.cssClassPrefix + 'required'] = required,
|
24
|
+
_b)) }, { children: [_jsx(FieldErrorScrollTarget, {}), meta.warning && (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'warning' }, { children: meta.warning }))), _jsx("label", __assign({ htmlFor: input.id }, { children: label })), children, meta.error && (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'error' }, { children: meta.error }))), helpText && (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'help' }, { children: helpText })))] })));
|
22
25
|
}
|
@@ -24,10 +24,11 @@ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
24
|
import React from 'react';
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import InputGroupWithRef from './InputGroup';
|
27
|
+
import { FormDefaults } from '../FormDefaults';
|
27
28
|
function IconInputGroup(_a, ref) {
|
28
29
|
var icon = _a.icon, className = _a.className, rest = __rest(_a, ["icon", "className"]);
|
29
30
|
var input = rest.input;
|
30
|
-
return (_jsx(_Fragment, { children: _jsx(InputGroupWithRef, __assign({ icon: icon, ref: ref, className: classNames(className, 'icon-input-group'), value: input.value || '', onChange: function (e) {
|
31
|
+
return (_jsx(_Fragment, { children: _jsx(InputGroupWithRef, __assign({ icon: icon, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'icon-input-group'), value: input.value || '', onChange: function (e) {
|
31
32
|
if (!e.target.value) {
|
32
33
|
input.onChange(undefined);
|
33
34
|
}
|
package/es/Input/InputGroup.d.ts
CHANGED
@@ -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/es/Input/InputGroup.js
CHANGED
@@ -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 <input/> wrapped by a Group */
|
28
29
|
function InputGroup(_a, ref) {
|
29
|
-
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"]);
|
30
|
-
return (_jsxs(Group, __assign({ input: input, meta: meta, disabled: disabled, label: label, helpText: helpText, className: classNames(className, 'input-group') }, { children: [icon, _jsx("input", __assign({}, input, rest, { value: value, onChange: onChange, ref: ref, className: classNames(className, 'input-group') }))] })));
|
30
|
+
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"]);
|
31
|
+
return (_jsxs(Group, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: classNames(className, FormDefaults.cssClassPrefix + 'input-group') }, { children: [icon, _jsx("input", __assign({}, input, rest, { value: value, onChange: onChange, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'input-group') }))] })));
|
31
32
|
}
|
32
33
|
var InputGroupWithRef = React.forwardRef(InputGroup);
|
33
34
|
export default InputGroupWithRef;
|
@@ -24,11 +24,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import React from 'react';
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import InputGroup from './InputGroup';
|
27
|
+
import { FormDefaults } from '../FormDefaults';
|
27
28
|
function MoneyInputGroup(_a, ref) {
|
28
29
|
var parseFunc = _a.parseFunc, className = _a.className, rest = __rest(_a, ["parseFunc", "className"]);
|
29
30
|
var effectiveParse = parseFunc !== null && parseFunc !== void 0 ? parseFunc : parseFloat;
|
30
31
|
var input = rest.input;
|
31
|
-
return (_jsx(InputGroup, __assign({ ref: ref, step: 0.01, min: 0 }, rest, { type: "number", className: classNames(className, 'money-group'), value: input.value || '', onChange: function (e) {
|
32
|
+
return (_jsx(InputGroup, __assign({ ref: ref, step: 0.01, min: 0 }, rest, { type: "number", className: classNames(className, FormDefaults.cssClassPrefix + 'money-group'), value: input.value || '', onChange: function (e) {
|
32
33
|
if (!e.target.value) {
|
33
34
|
input.onChange(undefined);
|
34
35
|
}
|
@@ -24,11 +24,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import React from 'react';
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import InputGroup from './InputGroup';
|
27
|
+
import { FormDefaults } from '../FormDefaults';
|
27
28
|
function NumberInputGroup(_a, ref) {
|
28
29
|
var parseFunc = _a.parseFunc, className = _a.className, rest = __rest(_a, ["parseFunc", "className"]);
|
29
30
|
var effectiveParse = parseFunc !== null && parseFunc !== void 0 ? parseFunc : parseFloat;
|
30
31
|
var input = rest.input;
|
31
|
-
return (_jsx(InputGroup, __assign({ ref: ref }, rest, { type: "number", className: classNames(className, 'number-group'), value: input.value || '', onChange: function (e) {
|
32
|
+
return (_jsx(InputGroup, __assign({ ref: ref }, rest, { type: "number", className: classNames(className, FormDefaults.cssClassPrefix + 'number-group'), value: input.value || '', onChange: function (e) {
|
32
33
|
if (!e.target.value) {
|
33
34
|
input.onChange(undefined);
|
34
35
|
}
|
@@ -24,10 +24,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import React from 'react';
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import InputGroup from './InputGroup';
|
27
|
+
import { FormDefaults } from '../FormDefaults';
|
27
28
|
function StringInputGroup(_a, ref) {
|
28
29
|
var className = _a.className, rest = __rest(_a, ["className"]);
|
29
30
|
var input = rest.input;
|
30
|
-
return (_jsx(InputGroup, __assign({ ref: ref }, rest, { className: classNames(className, 'string-group'), value: input.value || '', onChange: function (e) {
|
31
|
+
return (_jsx(InputGroup, __assign({ ref: ref }, rest, { className: classNames(className, FormDefaults.cssClassPrefix + 'string-group'), value: input.value || '', onChange: function (e) {
|
31
32
|
if (!e.target.value) {
|
32
33
|
input.onChange(undefined);
|
33
34
|
}
|
@@ -18,5 +18,5 @@ export interface SelectGroupProps<TValue> extends InjectedFieldProps<TValue | un
|
|
18
18
|
multiple: TValue extends Array<any> ? true : false;
|
19
19
|
placeholder?: string;
|
20
20
|
}
|
21
|
-
export default function SelectGroup<TValue>({ input, meta, className, options, multiple, placeholder, ...rest }: SelectGroupProps<TValue>): JSX.Element;
|
21
|
+
export default function SelectGroup<TValue>({ input, meta, className, required, disabled, options, multiple, placeholder, ...rest }: SelectGroupProps<TValue>): JSX.Element;
|
22
22
|
export {};
|
package/es/Select/SelectGroup.js
CHANGED
@@ -24,9 +24,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import { default as ReactSelect } from 'react-select';
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import Group from '../Group';
|
27
|
+
import { FormDefaults } from '../FormDefaults';
|
27
28
|
// TODO: we could also name this "ReactSelectGroup" or similar but the types are strongly defined now so kept the names consistent
|
28
29
|
export default function SelectGroup(_a) {
|
29
|
-
var
|
30
|
+
var _b;
|
31
|
+
var input = _a.input, meta = _a.meta, className = _a.className, required = _a.required, disabled = _a.disabled, options = _a.options, multiple = _a.multiple, placeholder = _a.placeholder, rest = __rest(_a, ["input", "meta", "className", "required", "disabled", "options", "multiple", "placeholder"]);
|
30
32
|
var effectiveOptions = !options
|
31
33
|
? []
|
32
34
|
: Array.isArray(options)
|
@@ -40,14 +42,17 @@ export default function SelectGroup(_a) {
|
|
40
42
|
? options.resp
|
41
43
|
: [];
|
42
44
|
var isLoading = (options && 'loading' in options && options.loading) || false;
|
43
|
-
return (_jsx(Group, __assign({}, rest, { input: input, meta: meta,
|
45
|
+
return (_jsx(Group, __assign({}, rest, { input: input, meta: meta, required: required, disabled: disabled, className: classNames(className, (_b = {},
|
46
|
+
_b[FormDefaults.cssClassPrefix + 'multiple'] = multiple,
|
47
|
+
_b[FormDefaults.cssClassPrefix + 'loading'] = isLoading,
|
48
|
+
_b), FormDefaults.cssClassPrefix + 'select-group') }, { children: _jsx(ReactSelect, { inputId: input.id, isMulti: multiple, isDisabled: disabled, options: effectiveOptions, onBlur: input.onBlur, value: getValue(), onChange: function (e) {
|
44
49
|
if (multiple === true) {
|
45
50
|
input.onChange(e === null || e === void 0 ? void 0 : e.map(function (x) { return x.value; }));
|
46
51
|
}
|
47
52
|
else {
|
48
53
|
input.onChange(e === null || e === void 0 ? void 0 : e.value);
|
49
54
|
}
|
50
|
-
}, getOptionLabel: function (option) { var _a; return (_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : ''; }, className: classNames(className, 'select-group'), classNamePrefix: "react-select", menuPortalTarget: document.body, menuPlacement: "auto", placeholder: placeholder }) })));
|
55
|
+
}, getOptionLabel: function (option) { var _a; return (_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : ''; }, className: classNames(className, FormDefaults.cssClassPrefix + 'select-group'), classNamePrefix: "react-select", menuPortalTarget: document.body, menuPlacement: "auto", placeholder: placeholder }) })));
|
51
56
|
function getValue() {
|
52
57
|
if (multiple) {
|
53
58
|
return effectiveOptions.filter(function (o) {
|
@@ -13,10 +13,11 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
13
13
|
import classNames from 'classnames';
|
14
14
|
import { useFormikContext } from 'formik';
|
15
15
|
import SubmitFormButton from './SubmitFormButton';
|
16
|
+
import { FormDefaults } from './FormDefaults';
|
16
17
|
export default function StandardFormActions(_a) {
|
17
18
|
var allowPristineSubmit = _a.allowPristineSubmit, handleCancel = _a.handleCancel;
|
18
19
|
var isSubmitting = useFormikContext().isSubmitting;
|
19
|
-
return (_jsxs(_Fragment, { children: [_jsx(SubmitFormButton, { allowPristineSubmit: allowPristineSubmit }), "\u00A0", _jsx("button", __assign({ className: classNames('standard-form-actions-cancel-button'), type: "button", disabled: isSubmitting, onClick: handleCancel || goBack }, { children: "Cancel" }))] }));
|
20
|
+
return (_jsxs(_Fragment, { children: [_jsx(SubmitFormButton, { allowPristineSubmit: allowPristineSubmit }), "\u00A0", _jsx("button", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'standard-form-actions-cancel-button'), type: "button", disabled: isSubmitting, onClick: handleCancel || goBack }, { children: "Cancel" }))] }));
|
20
21
|
function goBack() {
|
21
22
|
window.history.back();
|
22
23
|
}
|