@wq/form-web 3.0.0-alpha.0
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/AutoForm.js +24 -0
- package/README.md +10 -0
- package/components/Checkbox.js +30 -0
- package/components/DateTime.js +14 -0
- package/components/DeleteForm.js +56 -0
- package/components/Draw.js +78 -0
- package/components/Fieldset.js +32 -0
- package/components/FieldsetArray.js +30 -0
- package/components/File.js +77 -0
- package/components/FileArray.js +132 -0
- package/components/FlatFieldset.js +30 -0
- package/components/FormError.js +19 -0
- package/components/FormRoot.js +32 -0
- package/components/GeoHelpIcon.js +42 -0
- package/components/HelperText.js +28 -0
- package/components/Hidden.js +24 -0
- package/components/IconSubmitButton.js +20 -0
- package/components/Image.js +10 -0
- package/components/Input.js +28 -0
- package/components/Radio.js +53 -0
- package/components/Select.js +191 -0
- package/components/SubmitButton.js +36 -0
- package/components/Toggle.js +52 -0
- package/components/index.js +50 -0
- package/index.js +3 -0
- package/package.json +47 -0
- package/src/AutoForm.js +17 -0
- package/src/components/Checkbox.js +28 -0
- package/src/components/DateTime.js +13 -0
- package/src/components/DeleteForm.js +52 -0
- package/src/components/Draw.js +82 -0
- package/src/components/Fieldset.js +24 -0
- package/src/components/FieldsetArray.js +27 -0
- package/src/components/File.js +73 -0
- package/src/components/FileArray.js +129 -0
- package/src/components/FlatFieldset.js +26 -0
- package/src/components/FormError.js +18 -0
- package/src/components/FormRoot.js +27 -0
- package/src/components/GeoHelpIcon.js +52 -0
- package/src/components/HelperText.js +28 -0
- package/src/components/Hidden.js +21 -0
- package/src/components/IconSubmitButton.js +18 -0
- package/src/components/Image.js +9 -0
- package/src/components/Input.js +30 -0
- package/src/components/Radio.js +38 -0
- package/src/components/Select.js +158 -0
- package/src/components/SubmitButton.js +38 -0
- package/src/components/Toggle.js +35 -0
- package/src/components/index.js +52 -0
- package/src/index.js +3 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useComponents, withWQ, createFallbackComponent } from "@wq/react";
|
|
3
|
+
import { useFormikContext } from "formik";
|
|
4
|
+
const IconSubmitButtonFallback = {
|
|
5
|
+
components: {
|
|
6
|
+
IconButton: createFallbackComponent("IconButton", "@wq/material"),
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
function IconSubmitButton(props) {
|
|
10
|
+
const { IconButton } = useComponents(),
|
|
11
|
+
{ isSubmitting } = useFormikContext();
|
|
12
|
+
return /*#__PURE__*/ React.createElement(IconButton, {
|
|
13
|
+
type: "submit",
|
|
14
|
+
disabled: isSubmitting,
|
|
15
|
+
...props,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export default withWQ(IconSubmitButton, {
|
|
19
|
+
fallback: IconSubmitButtonFallback,
|
|
20
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { Field } from "formik";
|
|
4
|
+
import { TextField } from "formik-mui";
|
|
5
|
+
import { useHtmlInput } from "@wq/form-common";
|
|
6
|
+
import PropTypes from "prop-types";
|
|
7
|
+
function Input({ hint, inputProps, ...rest }) {
|
|
8
|
+
const { name, type, maxLength } = useHtmlInput(rest);
|
|
9
|
+
return /*#__PURE__*/ React.createElement(Field, {
|
|
10
|
+
name: name,
|
|
11
|
+
fullWidth: true,
|
|
12
|
+
margin: "dense",
|
|
13
|
+
component: TextField,
|
|
14
|
+
helperText: hint,
|
|
15
|
+
inputProps: {
|
|
16
|
+
maxLength,
|
|
17
|
+
...inputProps,
|
|
18
|
+
},
|
|
19
|
+
...rest,
|
|
20
|
+
type: type,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
Input.propTypes = {
|
|
24
|
+
name: PropTypes.string,
|
|
25
|
+
hint: PropTypes.string,
|
|
26
|
+
inputProps: PropTypes.object,
|
|
27
|
+
};
|
|
28
|
+
export default withWQ(Input);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { Field } from "formik";
|
|
4
|
+
import { RadioGroup } from "formik-mui";
|
|
5
|
+
import {
|
|
6
|
+
FormControl,
|
|
7
|
+
FormLabel,
|
|
8
|
+
FormControlLabel,
|
|
9
|
+
Radio as MuiRadio,
|
|
10
|
+
} from "@mui/material";
|
|
11
|
+
import HelperText from "./HelperText.js";
|
|
12
|
+
import PropTypes from "prop-types";
|
|
13
|
+
function Radio({ choices, label, ...rest }) {
|
|
14
|
+
return /*#__PURE__*/ React.createElement(
|
|
15
|
+
FormControl,
|
|
16
|
+
{
|
|
17
|
+
component: "fieldset",
|
|
18
|
+
fullWidth: true,
|
|
19
|
+
margin: "dense",
|
|
20
|
+
},
|
|
21
|
+
/*#__PURE__*/ React.createElement(
|
|
22
|
+
FormLabel,
|
|
23
|
+
{
|
|
24
|
+
component: "legend",
|
|
25
|
+
},
|
|
26
|
+
label,
|
|
27
|
+
),
|
|
28
|
+
/*#__PURE__*/ React.createElement(
|
|
29
|
+
Field,
|
|
30
|
+
{
|
|
31
|
+
component: RadioGroup,
|
|
32
|
+
...rest,
|
|
33
|
+
},
|
|
34
|
+
choices.map(({ name, label }) =>
|
|
35
|
+
/*#__PURE__*/ React.createElement(FormControlLabel, {
|
|
36
|
+
key: name,
|
|
37
|
+
value: name,
|
|
38
|
+
label: label,
|
|
39
|
+
control: /*#__PURE__*/ React.createElement(MuiRadio, null),
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
/*#__PURE__*/ React.createElement(HelperText, {
|
|
44
|
+
name: rest.name,
|
|
45
|
+
hint: rest.hint,
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
Radio.propTypes = {
|
|
50
|
+
choices: PropTypes.arrayOf(PropTypes.object),
|
|
51
|
+
label: PropTypes.string,
|
|
52
|
+
};
|
|
53
|
+
export default withWQ(Radio);
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { Field, getIn } from "formik";
|
|
4
|
+
import { Select as FMuiSelect } from "formik-mui";
|
|
5
|
+
import { MenuItem, Checkbox, ListItemText, ListSubheader } from "@mui/material";
|
|
6
|
+
import PropTypes from "prop-types";
|
|
7
|
+
import { useFormikContext } from "formik";
|
|
8
|
+
function ContextCheckbox({ value, field }) {
|
|
9
|
+
const { values } = useFormikContext();
|
|
10
|
+
const checked = (getIn(values, field) || []).some((val) => val === value);
|
|
11
|
+
return /*#__PURE__*/ React.createElement(Checkbox, {
|
|
12
|
+
checked: checked,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
ContextCheckbox.propTypes = {
|
|
16
|
+
value: PropTypes.string,
|
|
17
|
+
field: PropTypes.string,
|
|
18
|
+
};
|
|
19
|
+
function Select({
|
|
20
|
+
choices,
|
|
21
|
+
label,
|
|
22
|
+
required,
|
|
23
|
+
native,
|
|
24
|
+
placeholder,
|
|
25
|
+
renderValue,
|
|
26
|
+
InputLabelProps,
|
|
27
|
+
...rest
|
|
28
|
+
}) {
|
|
29
|
+
const { name: fieldName, type, hint } = rest,
|
|
30
|
+
{ errors, touched } = useFormikContext(),
|
|
31
|
+
showError = !!getIn(errors, fieldName) && getIn(touched, fieldName),
|
|
32
|
+
multiple = type === "select";
|
|
33
|
+
if (multiple && !renderValue) {
|
|
34
|
+
renderValue = (sel) => sel.map(getLabel).join(", ");
|
|
35
|
+
}
|
|
36
|
+
if (placeholder && !renderValue) {
|
|
37
|
+
renderValue = (sel) => getLabel(sel) || sel || placeholder;
|
|
38
|
+
}
|
|
39
|
+
const getLabel = useMemo(() => {
|
|
40
|
+
const labels = {};
|
|
41
|
+
choices.forEach(({ name, label }) => {
|
|
42
|
+
labels[name] = label;
|
|
43
|
+
});
|
|
44
|
+
return (name) => labels[name];
|
|
45
|
+
}, [choices]);
|
|
46
|
+
const choiceGroups = useMemo(() => {
|
|
47
|
+
const choiceGroups = {};
|
|
48
|
+
choices.forEach((choice) => {
|
|
49
|
+
const group = choice.group || "";
|
|
50
|
+
if (!choiceGroups[group]) {
|
|
51
|
+
choiceGroups[group] = [];
|
|
52
|
+
}
|
|
53
|
+
choiceGroups[group].push(choice);
|
|
54
|
+
});
|
|
55
|
+
return choiceGroups;
|
|
56
|
+
}, [choices]);
|
|
57
|
+
const Option = useMemo(
|
|
58
|
+
() =>
|
|
59
|
+
native
|
|
60
|
+
? ({ value, children }) =>
|
|
61
|
+
/*#__PURE__*/ React.createElement(
|
|
62
|
+
"option",
|
|
63
|
+
{
|
|
64
|
+
value: value,
|
|
65
|
+
},
|
|
66
|
+
children,
|
|
67
|
+
)
|
|
68
|
+
: ({ children, ...rest }) =>
|
|
69
|
+
/*#__PURE__*/ React.createElement(
|
|
70
|
+
MenuItem,
|
|
71
|
+
{
|
|
72
|
+
...rest,
|
|
73
|
+
},
|
|
74
|
+
multiple &&
|
|
75
|
+
/*#__PURE__*/ React.createElement(
|
|
76
|
+
ContextCheckbox,
|
|
77
|
+
{
|
|
78
|
+
value: rest["data-value"],
|
|
79
|
+
field: fieldName,
|
|
80
|
+
},
|
|
81
|
+
),
|
|
82
|
+
/*#__PURE__*/ React.createElement(ListItemText, {
|
|
83
|
+
primary: children,
|
|
84
|
+
"data-value": rest["data-value"],
|
|
85
|
+
primaryTypographyProps: {
|
|
86
|
+
"data-value": rest["data-value"],
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
),
|
|
90
|
+
[native, multiple, fieldName],
|
|
91
|
+
);
|
|
92
|
+
const renderChoices = (choices) =>
|
|
93
|
+
choices.map(({ name, label }) =>
|
|
94
|
+
/*#__PURE__*/ React.createElement(
|
|
95
|
+
Option,
|
|
96
|
+
{
|
|
97
|
+
key: name,
|
|
98
|
+
value: name,
|
|
99
|
+
},
|
|
100
|
+
label,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
const renderGroups = native
|
|
104
|
+
? (choiceGroups) =>
|
|
105
|
+
Object.entries(choiceGroups).map(([group, choices]) =>
|
|
106
|
+
group
|
|
107
|
+
? /*#__PURE__*/ React.createElement(
|
|
108
|
+
"optgroup",
|
|
109
|
+
{
|
|
110
|
+
key: group,
|
|
111
|
+
label: group,
|
|
112
|
+
},
|
|
113
|
+
renderChoices(choices),
|
|
114
|
+
)
|
|
115
|
+
: /*#__PURE__*/ React.createElement(
|
|
116
|
+
React.Fragment,
|
|
117
|
+
null,
|
|
118
|
+
renderChoices(choices),
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
: (choiceGroups) => {
|
|
122
|
+
const flattened = [];
|
|
123
|
+
Object.entries(choiceGroups).forEach(([group, choices]) => {
|
|
124
|
+
if (group) {
|
|
125
|
+
flattened.push(
|
|
126
|
+
/*#__PURE__*/ React.createElement(
|
|
127
|
+
ListSubheader,
|
|
128
|
+
{
|
|
129
|
+
style: {
|
|
130
|
+
backgroundColor: "white",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
group,
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
flattened.push(...renderChoices(choices));
|
|
138
|
+
});
|
|
139
|
+
return flattened;
|
|
140
|
+
};
|
|
141
|
+
return /*#__PURE__*/ React.createElement(
|
|
142
|
+
Field,
|
|
143
|
+
{
|
|
144
|
+
component: FMuiSelect,
|
|
145
|
+
formControl: {
|
|
146
|
+
fullWidth: true,
|
|
147
|
+
margin: "dense",
|
|
148
|
+
},
|
|
149
|
+
inputLabel: {
|
|
150
|
+
required,
|
|
151
|
+
error: showError,
|
|
152
|
+
...InputLabelProps,
|
|
153
|
+
},
|
|
154
|
+
formHelperText: {
|
|
155
|
+
children: hint,
|
|
156
|
+
},
|
|
157
|
+
multiple: multiple,
|
|
158
|
+
required: required,
|
|
159
|
+
native: native,
|
|
160
|
+
label: label,
|
|
161
|
+
renderValue: renderValue,
|
|
162
|
+
displayEmpty: !!placeholder,
|
|
163
|
+
...(InputLabelProps && InputLabelProps.shrink
|
|
164
|
+
? {
|
|
165
|
+
notched: true,
|
|
166
|
+
}
|
|
167
|
+
: {}),
|
|
168
|
+
...rest,
|
|
169
|
+
},
|
|
170
|
+
!multiple &&
|
|
171
|
+
/*#__PURE__*/ React.createElement(
|
|
172
|
+
Option,
|
|
173
|
+
{
|
|
174
|
+
value: "",
|
|
175
|
+
disabled: !!required,
|
|
176
|
+
},
|
|
177
|
+
required ? "Select one..." : "(No Selection)",
|
|
178
|
+
),
|
|
179
|
+
renderGroups(choiceGroups),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
Select.propTypes = {
|
|
183
|
+
choices: PropTypes.arrayOf(PropTypes.object),
|
|
184
|
+
label: PropTypes.string,
|
|
185
|
+
placeholder: PropTypes.string,
|
|
186
|
+
required: PropTypes.bool,
|
|
187
|
+
native: PropTypes.bool,
|
|
188
|
+
renderValue: PropTypes.func,
|
|
189
|
+
InputLabelProps: PropTypes.object,
|
|
190
|
+
};
|
|
191
|
+
export default withWQ(Select);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
useMessage,
|
|
4
|
+
useComponents,
|
|
5
|
+
withWQ,
|
|
6
|
+
createFallbackComponent,
|
|
7
|
+
} from "@wq/react";
|
|
8
|
+
import { useFormikContext } from "formik";
|
|
9
|
+
const SubmitButtonFallback = {
|
|
10
|
+
messages: {
|
|
11
|
+
SUBMIT: "Submit",
|
|
12
|
+
},
|
|
13
|
+
components: {
|
|
14
|
+
Button: createFallbackComponent("Button", "@wq/material"),
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
function SubmitButton(props) {
|
|
18
|
+
const { Button } = useComponents(),
|
|
19
|
+
defaultLabel = useMessage("SUBMIT"),
|
|
20
|
+
label = props.children || defaultLabel,
|
|
21
|
+
{ isSubmitting } = useFormikContext();
|
|
22
|
+
return /*#__PURE__*/ React.createElement(
|
|
23
|
+
Button,
|
|
24
|
+
{
|
|
25
|
+
type: "submit",
|
|
26
|
+
color: "primary",
|
|
27
|
+
variant: "contained",
|
|
28
|
+
disabled: isSubmitting,
|
|
29
|
+
...props,
|
|
30
|
+
},
|
|
31
|
+
label,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
export default withWQ(SubmitButton, {
|
|
35
|
+
fallback: SubmitButtonFallback,
|
|
36
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { Field } from "formik";
|
|
4
|
+
import { ToggleButton, FormControl, FormLabel } from "@mui/material";
|
|
5
|
+
import { ToggleButtonGroup } from "formik-mui";
|
|
6
|
+
import HelperText from "./HelperText.js";
|
|
7
|
+
import PropTypes from "prop-types";
|
|
8
|
+
function Toggle({ choices, label, ...rest }) {
|
|
9
|
+
return /*#__PURE__*/ React.createElement(
|
|
10
|
+
FormControl,
|
|
11
|
+
{
|
|
12
|
+
component: "fieldset",
|
|
13
|
+
fullWidth: true,
|
|
14
|
+
margin: "dense",
|
|
15
|
+
},
|
|
16
|
+
/*#__PURE__*/ React.createElement(
|
|
17
|
+
FormLabel,
|
|
18
|
+
{
|
|
19
|
+
component: "legend",
|
|
20
|
+
},
|
|
21
|
+
label,
|
|
22
|
+
),
|
|
23
|
+
/*#__PURE__*/ React.createElement(
|
|
24
|
+
Field,
|
|
25
|
+
{
|
|
26
|
+
component: ToggleButtonGroup,
|
|
27
|
+
exclusive: true,
|
|
28
|
+
...rest,
|
|
29
|
+
type: "checkbox",
|
|
30
|
+
},
|
|
31
|
+
choices.map(({ name, label }) =>
|
|
32
|
+
/*#__PURE__*/ React.createElement(
|
|
33
|
+
ToggleButton,
|
|
34
|
+
{
|
|
35
|
+
key: name,
|
|
36
|
+
value: name,
|
|
37
|
+
},
|
|
38
|
+
label,
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
/*#__PURE__*/ React.createElement(HelperText, {
|
|
43
|
+
name: rest.name,
|
|
44
|
+
hint: rest.hint,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
Toggle.propTypes = {
|
|
49
|
+
choices: PropTypes.arrayOf(PropTypes.object),
|
|
50
|
+
label: PropTypes.string,
|
|
51
|
+
};
|
|
52
|
+
export default withWQ(Toggle);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import FormRoot from "./FormRoot.js";
|
|
2
|
+
import FormError from "./FormError.js";
|
|
3
|
+
import Input from "./Input.js";
|
|
4
|
+
import Checkbox from "./Checkbox.js";
|
|
5
|
+
import DateTime from "./DateTime.js";
|
|
6
|
+
import File from "./File.js";
|
|
7
|
+
import Image from "./Image.js";
|
|
8
|
+
import Select from "./Select.js";
|
|
9
|
+
import Radio from "./Radio.js";
|
|
10
|
+
import Toggle from "./Toggle.js";
|
|
11
|
+
import Hidden from "./Hidden.js";
|
|
12
|
+
import HelperText from "./HelperText.js";
|
|
13
|
+
import Fieldset from "./Fieldset.js";
|
|
14
|
+
import FlatFieldset from "./FlatFieldset.js";
|
|
15
|
+
import FieldsetArray from "./FieldsetArray.js";
|
|
16
|
+
import FileArray from "./FileArray.js";
|
|
17
|
+
import SubmitButton from "./SubmitButton.js";
|
|
18
|
+
import IconSubmitButton from "./IconSubmitButton.js";
|
|
19
|
+
import DeleteForm from "./DeleteForm.js";
|
|
20
|
+
import Draw from "./Draw.js";
|
|
21
|
+
import GeoHelpIcon from "./GeoHelpIcon.js";
|
|
22
|
+
const Date = DateTime;
|
|
23
|
+
const Time = DateTime;
|
|
24
|
+
const dateTime = DateTime;
|
|
25
|
+
export {
|
|
26
|
+
FormRoot,
|
|
27
|
+
FormError,
|
|
28
|
+
Input,
|
|
29
|
+
Checkbox,
|
|
30
|
+
DateTime,
|
|
31
|
+
Date,
|
|
32
|
+
Time,
|
|
33
|
+
dateTime,
|
|
34
|
+
File,
|
|
35
|
+
Image,
|
|
36
|
+
Select,
|
|
37
|
+
Radio,
|
|
38
|
+
Toggle,
|
|
39
|
+
Hidden,
|
|
40
|
+
HelperText,
|
|
41
|
+
Fieldset,
|
|
42
|
+
FlatFieldset,
|
|
43
|
+
FieldsetArray,
|
|
44
|
+
FileArray,
|
|
45
|
+
SubmitButton,
|
|
46
|
+
IconSubmitButton,
|
|
47
|
+
DeleteForm,
|
|
48
|
+
Draw,
|
|
49
|
+
GeoHelpIcon,
|
|
50
|
+
};
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wq/form-web",
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
|
+
"description": "Web bindings for @wq/form",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "cd ../../ && npm run jest packages/form-web",
|
|
9
|
+
"build": "npm run babel && npm run prettier",
|
|
10
|
+
"babel": "cd ../../ && npm run babel -- packages/form-web/src --out-dir packages/form-web/",
|
|
11
|
+
"prettier": "cd ../../ && npm run prettier -- --write packages/form-web/",
|
|
12
|
+
"lint": "cd ../../ && npm run eslint packages/form-web/{,src/,src/*/,src/*/*/}*.js"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/wq/form.git",
|
|
17
|
+
"directory": "packages/form-web"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"wq",
|
|
21
|
+
"react",
|
|
22
|
+
"material",
|
|
23
|
+
"material-ui"
|
|
24
|
+
],
|
|
25
|
+
"author": "S. Andrew Sheppard",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/wq/form/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://form.wq.io/@wq/form-web",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@wq/form-common": "^3.0.0-alpha.0",
|
|
33
|
+
"@wq/react": "^3.0.0-alpha.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@mapbox/mapbox-gl-draw": "*",
|
|
37
|
+
"@mui/material": "*",
|
|
38
|
+
"formik-mui": "*",
|
|
39
|
+
"mui2-file-dropzone": "*"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@mapbox/mapbox-gl-draw": "^1.5.1",
|
|
43
|
+
"@mui/material": "^6.5.0",
|
|
44
|
+
"formik-mui": "^5.0.0-alpha.1",
|
|
45
|
+
"mui2-file-dropzone": "^6.3.0"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/AutoForm.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { AutoFormBase, AutoInput, Form, CancelButton } from "@wq/form-common";
|
|
4
|
+
import * as components from "./components/index.js";
|
|
5
|
+
|
|
6
|
+
const AutoFormDefaults = {
|
|
7
|
+
components: { ...components, AutoForm, AutoInput, Form, CancelButton },
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function AutoForm(props) {
|
|
11
|
+
if (!props.action && !props.onSubmit && !props.form) {
|
|
12
|
+
return props.children || null;
|
|
13
|
+
}
|
|
14
|
+
return <AutoFormBase {...props} />;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default withWQ(AutoForm, { defaults: AutoFormDefaults });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { Field } from "formik";
|
|
4
|
+
import { CheckboxWithLabel } from "formik-mui";
|
|
5
|
+
import HelperText from "./HelperText.js";
|
|
6
|
+
import PropTypes from "prop-types";
|
|
7
|
+
|
|
8
|
+
function Checkbox({ label, ...props }) {
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
<Field
|
|
12
|
+
component={CheckboxWithLabel}
|
|
13
|
+
Label={{ label }}
|
|
14
|
+
{...props}
|
|
15
|
+
type="checkbox"
|
|
16
|
+
/>
|
|
17
|
+
<HelperText name={props.name} hint={props.hint} />
|
|
18
|
+
</>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Checkbox.propTypes = {
|
|
23
|
+
name: PropTypes.string,
|
|
24
|
+
label: PropTypes.string,
|
|
25
|
+
hint: PropTypes.string,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default withWQ(Checkbox);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import Input from "./Input.js";
|
|
4
|
+
|
|
5
|
+
function DateTime({ InputLabelProps: overrides, ...rest }) {
|
|
6
|
+
const InputLabelProps = {
|
|
7
|
+
shrink: true,
|
|
8
|
+
...overrides,
|
|
9
|
+
};
|
|
10
|
+
return <Input InputLabelProps={InputLabelProps} {...rest} />;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default withWQ(DateTime);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
useComponents,
|
|
4
|
+
useMessage,
|
|
5
|
+
withWQ,
|
|
6
|
+
createFallbackComponents,
|
|
7
|
+
} from "@wq/react";
|
|
8
|
+
import { Form } from "@wq/form-common";
|
|
9
|
+
import SubmitButton from "./SubmitButton.js";
|
|
10
|
+
import PropTypes from "prop-types";
|
|
11
|
+
|
|
12
|
+
const DeleteFormFallback = {
|
|
13
|
+
messages: {
|
|
14
|
+
CONFIRM_DELETE: "Are you sure you want to delete this record?",
|
|
15
|
+
},
|
|
16
|
+
components: {
|
|
17
|
+
Form,
|
|
18
|
+
SubmitButton,
|
|
19
|
+
...createFallbackComponents(["View", "HorizontalView"], "@wq/material"),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function DeleteForm({ action }) {
|
|
24
|
+
const { Form, SubmitButton, View, HorizontalView } = useComponents(),
|
|
25
|
+
message = useMessage("CONFIRM_DELETE");
|
|
26
|
+
|
|
27
|
+
function confirmSubmit() {
|
|
28
|
+
return window.confirm(message);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Form
|
|
33
|
+
action={action}
|
|
34
|
+
method="DELETE"
|
|
35
|
+
backgroundSync={false}
|
|
36
|
+
onSubmit={confirmSubmit}
|
|
37
|
+
>
|
|
38
|
+
<HorizontalView>
|
|
39
|
+
<View />
|
|
40
|
+
<SubmitButton icon="delete" variant="text" color="secondary">
|
|
41
|
+
Delete
|
|
42
|
+
</SubmitButton>
|
|
43
|
+
</HorizontalView>
|
|
44
|
+
</Form>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
DeleteForm.propTypes = {
|
|
49
|
+
action: PropTypes.string,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default withWQ(DeleteForm, { fallback: DeleteFormFallback });
|