envoc-form 4.0.1-0 → 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 +9 -0
- package/es/DatePicker/DatePickerGroup.js +77 -0
- package/es/DatePicker/DatePickerHelper.d.ts +3 -0
- package/es/DatePicker/DatePickerHelper.js +1 -0
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/es/DatePicker/StringDateOnlyPickerGroup.js +24 -0
- package/es/DatePicker/StringDatePickerGroup.d.ts +5 -0
- package/es/DatePicker/StringDatePickerGroup.js +19 -0
- package/es/Field/Field.d.ts +3 -3
- package/es/Field/Field.js +9 -4
- package/es/Field/StandAloneInput.d.ts +9 -0
- package/es/Field/StandAloneInput.js +49 -0
- 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 +3 -2
- 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.d.ts +1 -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.d.ts +8 -0
- package/es/TextArea/TextAreaGroup.js +34 -0
- package/es/Validation/validators.d.ts +1 -1
- package/es/Validation/validators.js +1 -1
- package/es/__Tests__/FormTestBase.d.ts +3 -3
- package/es/index.d.ts +21 -5
- package/es/index.js +10 -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 +9 -0
- package/lib/DatePicker/DatePickerGroup.js +85 -0
- package/lib/DatePicker/DatePickerHelper.d.ts +3 -0
- package/lib/DatePicker/DatePickerHelper.js +2 -0
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/lib/DatePicker/StringDateOnlyPickerGroup.js +30 -0
- package/lib/DatePicker/StringDatePickerGroup.d.ts +5 -0
- package/lib/DatePicker/StringDatePickerGroup.js +25 -0
- package/lib/Field/Field.d.ts +3 -3
- package/lib/Field/Field.js +9 -4
- package/lib/Field/StandAloneInput.d.ts +9 -0
- package/lib/Field/StandAloneInput.js +75 -0
- 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 +3 -2
- 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.d.ts +1 -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.d.ts +8 -0
- package/lib/TextArea/TextAreaGroup.js +39 -0
- package/lib/Validation/validators.d.ts +1 -1
- package/lib/Validation/validators.js +1 -1
- package/lib/__Tests__/FormTestBase.d.ts +3 -3
- package/lib/index.d.ts +21 -5
- package/lib/index.js +19 -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/{DatePickerInput/DatePickerInput.test.tsx → DatePicker/DatePicker.test.tsx} +3 -3
- package/src/DatePicker/DatePickerGroup.tsx +108 -0
- package/src/DatePicker/DatePickerHelper.ts +4 -0
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +23 -0
- package/src/DatePicker/StringDatePickerGroup.tsx +14 -0
- package/src/{DatePickerInput/__snapshots__/DatePickerInput.test.tsx.snap → DatePicker/__snapshots__/DatePicker.test.tsx.snap} +3 -2
- package/src/Field/Field.tsx +28 -10
- package/src/Field/StandAloneInput.tsx +51 -0
- 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 +22 -7
- 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 +14 -2
- 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 +64 -0
- package/src/Validation/validators.ts +2 -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 +41 -5
- package/es/DatePickerInput/DatePickerInput.d.ts +0 -14
- package/es/DatePickerInput/DatePickerInput.js +0 -63
- package/lib/DatePickerInput/DatePickerInput.d.ts +0 -14
- package/lib/DatePickerInput/DatePickerInput.js +0 -69
- package/src/DatePickerInput/DatePickerInput.tsx +0 -85
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);
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { DatePickerProps } from 'react-date-picker/dist/entry.nostyle';
|
3
|
+
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
4
|
+
import { GroupProps } from '../Group';
|
5
|
+
export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
|
6
|
+
convert: (arg: Date) => T;
|
7
|
+
}
|
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;
|
@@ -0,0 +1,77 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
+
import { useEffect, useState } from 'react';
|
25
|
+
import DatePicker from 'react-date-picker/dist/entry.nostyle';
|
26
|
+
import classnames from 'classnames';
|
27
|
+
import parseISO from 'date-fns/parseISO';
|
28
|
+
import { FormDefaults } from '../FormDefaults';
|
29
|
+
import Group from '../Group';
|
30
|
+
export default function DatePickerGroup(_a) {
|
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"]);
|
32
|
+
var _b = useState(null), displayDate = _b[0], setDisplayDate = _b[1];
|
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 })) })));
|
42
|
+
function handleChange(e) {
|
43
|
+
var onChange = input.onChange;
|
44
|
+
if (onChange === null) {
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
if (!e) {
|
48
|
+
onChange(undefined);
|
49
|
+
setDisplayDate(null);
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
else if (typeof e === 'string') {
|
53
|
+
var parsedValue = parseISO(e.toString().split('T')[0]);
|
54
|
+
setDisplayDate(parsedValue);
|
55
|
+
onChange(convert(parsedValue));
|
56
|
+
}
|
57
|
+
else if (e instanceof Date) {
|
58
|
+
var parsedValue = parseISO(convertToTimeZoneInsensitiveISOString(e).split('T')[0]);
|
59
|
+
setDisplayDate(parsedValue);
|
60
|
+
onChange(convert(parsedValue));
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
// e is instanceof Date[]
|
64
|
+
var parsedValue = parseISO(convertToTimeZoneInsensitiveISOString(e[0]).split('T')[0]);
|
65
|
+
setDisplayDate(parsedValue);
|
66
|
+
onChange(convert(parsedValue));
|
67
|
+
}
|
68
|
+
}
|
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 @@
|
|
1
|
+
export {};
|
@@ -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;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
13
|
+
import DatePickerGroup from './DatePickerGroup';
|
14
|
+
export default function StringDatePickerGroup(props) {
|
15
|
+
return _jsx(DatePickerGroup, __assign({}, props, { convert: convertToDateOnly }));
|
16
|
+
}
|
17
|
+
function convertToDateOnly(arg) {
|
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);
|
24
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
+
export interface StringDatePickerGroupProps extends DatePickerHelper<string | undefined> {
|
4
|
+
}
|
5
|
+
export default function StringDatePickerGroup(props: StringDatePickerGroupProps): JSX.Element;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
13
|
+
import DatePickerGroup from './DatePickerGroup';
|
14
|
+
export default function StringDatePickerGroup(props) {
|
15
|
+
return _jsx(DatePickerGroup, __assign({}, props, { convert: convertToDateOnly }));
|
16
|
+
}
|
17
|
+
function convertToDateOnly(arg) {
|
18
|
+
return arg.toISOString();
|
19
|
+
}
|
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
|
-
declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue>> ? TRenderComponent : never;
|
6
|
-
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);
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { ElementType } from 'react';
|
2
|
+
import { RenderComponent, RenderComponentProps } from './Field';
|
3
|
+
import { InjectedFieldProps } from './InjectedFieldProps';
|
4
|
+
export declare type StandAloneInputProps<TValue, TRenderComponent extends ElementType> = {
|
5
|
+
Component: RenderComponent<TValue, TRenderComponent>;
|
6
|
+
value: TValue;
|
7
|
+
onChange: (arg: TValue) => void;
|
8
|
+
} & Omit<RenderComponentProps<TValue, TRenderComponent>, keyof InjectedFieldProps<TValue> | 'value' | 'onChange' | 'normalize' | 'validate'>;
|
9
|
+
export default function StandAloneInput<TValue, TComponent extends ElementType>(props: StandAloneInputProps<TValue, TComponent>): JSX.Element;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
+
import { useRef } from 'react';
|
25
|
+
import * as uuid from 'uuid';
|
26
|
+
export default function StandAloneInput(props) {
|
27
|
+
var Component = props.Component, value = props.value, onChange = props.onChange, disabled = props.disabled, rest = __rest(props, ["Component", "value", "onChange", "disabled"]);
|
28
|
+
var handleChange = function (arg) {
|
29
|
+
if (!disabled) {
|
30
|
+
onChange(arg);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
var Wrapped = Component;
|
34
|
+
var idRef = useRef(uuid.v4());
|
35
|
+
var input = {
|
36
|
+
id: idRef.current,
|
37
|
+
name: idRef.current,
|
38
|
+
value: value,
|
39
|
+
onChange: handleChange,
|
40
|
+
onBlur: function () { },
|
41
|
+
};
|
42
|
+
var meta = {
|
43
|
+
warning: undefined,
|
44
|
+
value: value,
|
45
|
+
touched: false,
|
46
|
+
initialTouched: false,
|
47
|
+
};
|
48
|
+
return _jsx(Wrapped, __assign({}, rest, { disabled: disabled, input: input, meta: meta }));
|
49
|
+
}
|
@@ -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
@@ -6,8 +6,9 @@ export interface GroupProps extends InjectedFieldProps<any> {
|
|
6
6
|
/** simple text label before the input */
|
7
7
|
label?: string;
|
8
8
|
/** simple helper text after the input*/
|
9
|
-
helpText?: string;
|
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;
|