@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
package/AutoForm.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const AutoFormDefaults = {
|
|
6
|
+
components: {
|
|
7
|
+
...components,
|
|
8
|
+
AutoForm,
|
|
9
|
+
AutoInput,
|
|
10
|
+
Form,
|
|
11
|
+
CancelButton,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
function AutoForm(props) {
|
|
15
|
+
if (!props.action && !props.onSubmit && !props.form) {
|
|
16
|
+
return props.children || null;
|
|
17
|
+
}
|
|
18
|
+
return /*#__PURE__*/ React.createElement(AutoFormBase, {
|
|
19
|
+
...props,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export default withWQ(AutoForm, {
|
|
23
|
+
defaults: AutoFormDefaults,
|
|
24
|
+
});
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
[![@wq/form][logo]][docs]
|
|
2
|
+
|
|
3
|
+
**@wq/form-web** provides web bindings for [@wq/form], via the [Material UI] library.
|
|
4
|
+
|
|
5
|
+
### [Documentation][docs]
|
|
6
|
+
|
|
7
|
+
[logo]: https://wq.io/images/@wq/form.svg
|
|
8
|
+
[docs]: https://form.wq.io/@wq/form-common
|
|
9
|
+
[@wq/form]: https://form.wq.io/
|
|
10
|
+
[Material UI]: https://mui.com/material-ui/
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
function Checkbox({ label, ...props }) {
|
|
8
|
+
return /*#__PURE__*/ React.createElement(
|
|
9
|
+
React.Fragment,
|
|
10
|
+
null,
|
|
11
|
+
/*#__PURE__*/ React.createElement(Field, {
|
|
12
|
+
component: CheckboxWithLabel,
|
|
13
|
+
Label: {
|
|
14
|
+
label,
|
|
15
|
+
},
|
|
16
|
+
...props,
|
|
17
|
+
type: "checkbox",
|
|
18
|
+
}),
|
|
19
|
+
/*#__PURE__*/ React.createElement(HelperText, {
|
|
20
|
+
name: props.name,
|
|
21
|
+
hint: props.hint,
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
Checkbox.propTypes = {
|
|
26
|
+
name: PropTypes.string,
|
|
27
|
+
label: PropTypes.string,
|
|
28
|
+
hint: PropTypes.string,
|
|
29
|
+
};
|
|
30
|
+
export default withWQ(Checkbox);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import Input from "./Input.js";
|
|
4
|
+
function DateTime({ InputLabelProps: overrides, ...rest }) {
|
|
5
|
+
const InputLabelProps = {
|
|
6
|
+
shrink: true,
|
|
7
|
+
...overrides,
|
|
8
|
+
};
|
|
9
|
+
return /*#__PURE__*/ React.createElement(Input, {
|
|
10
|
+
InputLabelProps: InputLabelProps,
|
|
11
|
+
...rest,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export default withWQ(DateTime);
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
const DeleteFormFallback = {
|
|
12
|
+
messages: {
|
|
13
|
+
CONFIRM_DELETE: "Are you sure you want to delete this record?",
|
|
14
|
+
},
|
|
15
|
+
components: {
|
|
16
|
+
Form,
|
|
17
|
+
SubmitButton,
|
|
18
|
+
...createFallbackComponents(["View", "HorizontalView"], "@wq/material"),
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
function DeleteForm({ action }) {
|
|
22
|
+
const { Form, SubmitButton, View, HorizontalView } = useComponents(),
|
|
23
|
+
message = useMessage("CONFIRM_DELETE");
|
|
24
|
+
function confirmSubmit() {
|
|
25
|
+
return window.confirm(message);
|
|
26
|
+
}
|
|
27
|
+
return /*#__PURE__*/ React.createElement(
|
|
28
|
+
Form,
|
|
29
|
+
{
|
|
30
|
+
action: action,
|
|
31
|
+
method: "DELETE",
|
|
32
|
+
backgroundSync: false,
|
|
33
|
+
onSubmit: confirmSubmit,
|
|
34
|
+
},
|
|
35
|
+
/*#__PURE__*/ React.createElement(
|
|
36
|
+
HorizontalView,
|
|
37
|
+
null,
|
|
38
|
+
/*#__PURE__*/ React.createElement(View, null),
|
|
39
|
+
/*#__PURE__*/ React.createElement(
|
|
40
|
+
SubmitButton,
|
|
41
|
+
{
|
|
42
|
+
icon: "delete",
|
|
43
|
+
variant: "text",
|
|
44
|
+
color: "secondary",
|
|
45
|
+
},
|
|
46
|
+
"Delete",
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
DeleteForm.propTypes = {
|
|
52
|
+
action: PropTypes.string,
|
|
53
|
+
};
|
|
54
|
+
export default withWQ(DeleteForm, {
|
|
55
|
+
fallback: DeleteFormFallback,
|
|
56
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
import { useComponents, withWQ, createFallbackComponent } from "@wq/react";
|
|
3
|
+
import MapboxDraw from "@mapbox/mapbox-gl-draw";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
const DrawFallback = {
|
|
6
|
+
components: {
|
|
7
|
+
useControl: createFallbackComponent(
|
|
8
|
+
"useControl",
|
|
9
|
+
"@wq/map-gl",
|
|
10
|
+
"MapProvider",
|
|
11
|
+
),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
function Draw({ type, required, data, setData }) {
|
|
15
|
+
const types = type === "all" ? ["point", "line_string", "polygon"] : [type],
|
|
16
|
+
controls = {},
|
|
17
|
+
ref = useRef();
|
|
18
|
+
types.forEach((type) => (controls[type] = true));
|
|
19
|
+
if (!required) {
|
|
20
|
+
controls.trash = true;
|
|
21
|
+
}
|
|
22
|
+
const { useControl } = useComponents();
|
|
23
|
+
const draw = useControl(
|
|
24
|
+
() => {
|
|
25
|
+
const { classes } = MapboxDraw.constants;
|
|
26
|
+
for (const [key, value] of Object.entries(classes)) {
|
|
27
|
+
if (value.startsWith("mapboxgl-")) {
|
|
28
|
+
classes[key] = value.replace("mapboxgl-", "maplibregl-");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return new MapboxDraw({
|
|
32
|
+
displayControlsDefault: false,
|
|
33
|
+
controls,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
({ map }) => {
|
|
37
|
+
map.on("draw.create", handleChange);
|
|
38
|
+
map.on("draw.delete", handleChange);
|
|
39
|
+
map.on("draw.update", handleChange);
|
|
40
|
+
map.on("draw.combine", handleChange);
|
|
41
|
+
map.on("draw.uncombine", handleChange);
|
|
42
|
+
},
|
|
43
|
+
({ map }) => {
|
|
44
|
+
map.off("draw.create", handleChange);
|
|
45
|
+
map.off("draw.delete", handleChange);
|
|
46
|
+
map.off("draw.update", handleChange);
|
|
47
|
+
map.off("draw.combine", handleChange);
|
|
48
|
+
map.off("draw.uncombine", handleChange);
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
position: "top-right",
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
ref.current = {
|
|
56
|
+
draw,
|
|
57
|
+
};
|
|
58
|
+
}, [draw]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (draw && data) {
|
|
61
|
+
draw.set(data);
|
|
62
|
+
}
|
|
63
|
+
}, [draw, data]);
|
|
64
|
+
function handleChange() {
|
|
65
|
+
const { draw } = ref.current;
|
|
66
|
+
setData(draw.getAll());
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
Draw.propTypes = {
|
|
71
|
+
type: PropTypes.string,
|
|
72
|
+
required: PropTypes.boolean,
|
|
73
|
+
data: PropTypes.object,
|
|
74
|
+
setData: PropTypes.func,
|
|
75
|
+
};
|
|
76
|
+
export default withWQ(Draw, {
|
|
77
|
+
fallback: DrawFallback,
|
|
78
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Card, Typography, CardContent } from "@mui/material";
|
|
3
|
+
import { withWQ } from "@wq/react";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
function Fieldset({ label, children }) {
|
|
6
|
+
return /*#__PURE__*/ React.createElement(
|
|
7
|
+
Card,
|
|
8
|
+
{
|
|
9
|
+
sx: {
|
|
10
|
+
mb: 2,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
/*#__PURE__*/ React.createElement(
|
|
14
|
+
CardContent,
|
|
15
|
+
null,
|
|
16
|
+
label &&
|
|
17
|
+
/*#__PURE__*/ React.createElement(
|
|
18
|
+
Typography,
|
|
19
|
+
{
|
|
20
|
+
color: "textSecondary",
|
|
21
|
+
},
|
|
22
|
+
label,
|
|
23
|
+
),
|
|
24
|
+
children,
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
Fieldset.propTypes = {
|
|
29
|
+
label: PropTypes.string,
|
|
30
|
+
children: PropTypes.node,
|
|
31
|
+
};
|
|
32
|
+
export default withWQ(Fieldset);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useComponents, withWQ, createFallbackComponents } from "@wq/react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
const FieldsetArrayFallback = {
|
|
5
|
+
components: createFallbackComponents(["View", "Button"], "@wq/material"),
|
|
6
|
+
};
|
|
7
|
+
function FieldsetArray({ label, children, addRow }) {
|
|
8
|
+
const { View, Button } = useComponents();
|
|
9
|
+
return /*#__PURE__*/ React.createElement(
|
|
10
|
+
View,
|
|
11
|
+
null,
|
|
12
|
+
children,
|
|
13
|
+
addRow &&
|
|
14
|
+
/*#__PURE__*/ React.createElement(
|
|
15
|
+
Button,
|
|
16
|
+
{
|
|
17
|
+
onClick: () => addRow(),
|
|
18
|
+
},
|
|
19
|
+
`Add ${label}`,
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
FieldsetArray.propTypes = {
|
|
24
|
+
label: PropTypes.string,
|
|
25
|
+
children: PropTypes.node,
|
|
26
|
+
addRow: PropTypes.func,
|
|
27
|
+
};
|
|
28
|
+
export default withWQ(FieldsetArray, {
|
|
29
|
+
fallback: FieldsetArrayFallback,
|
|
30
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { useMemo, useCallback, useRef } from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { useField } from "formik";
|
|
4
|
+
import { DropzoneArea } from "mui2-file-dropzone";
|
|
5
|
+
import { InputLabel } from "@mui/material";
|
|
6
|
+
import HelperText from "./HelperText.js";
|
|
7
|
+
import PropTypes from "prop-types";
|
|
8
|
+
function File({ name, accept, hint, label }) {
|
|
9
|
+
const [, { initialValue }, { setValue }] = useField(name),
|
|
10
|
+
loadedRef = useRef(null);
|
|
11
|
+
const initialFiles = useMemo(() => {
|
|
12
|
+
if (!initialValue || initialValue === "__clear__") {
|
|
13
|
+
return [];
|
|
14
|
+
} else if (initialValue.type && initialValue.body) {
|
|
15
|
+
return [initialValue.body];
|
|
16
|
+
} else if (typeof initialValue === "string") {
|
|
17
|
+
return [initialValue];
|
|
18
|
+
}
|
|
19
|
+
}, [initialValue]),
|
|
20
|
+
acceptedFiles = useMemo(
|
|
21
|
+
() => (accept ? accept.split(",") : null),
|
|
22
|
+
[accept],
|
|
23
|
+
),
|
|
24
|
+
setFile = useCallback(
|
|
25
|
+
(files) => {
|
|
26
|
+
if (!loadedRef.current) {
|
|
27
|
+
// initialFiles loaded
|
|
28
|
+
loadedRef.current = files && files.length ? files[0] : true;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (files && files.length) {
|
|
32
|
+
if (files[0] !== loadedRef.current) {
|
|
33
|
+
const { name, type } = files[0];
|
|
34
|
+
setValue({
|
|
35
|
+
name,
|
|
36
|
+
type,
|
|
37
|
+
body: files[0],
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
} else if (initialValue) {
|
|
41
|
+
setValue("__clear__");
|
|
42
|
+
} else {
|
|
43
|
+
setValue(null);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
[initialValue],
|
|
47
|
+
);
|
|
48
|
+
return /*#__PURE__*/ React.createElement(
|
|
49
|
+
React.Fragment,
|
|
50
|
+
null,
|
|
51
|
+
/*#__PURE__*/ React.createElement(
|
|
52
|
+
InputLabel,
|
|
53
|
+
{
|
|
54
|
+
shrink: true,
|
|
55
|
+
},
|
|
56
|
+
label,
|
|
57
|
+
),
|
|
58
|
+
/*#__PURE__*/ React.createElement(DropzoneArea, {
|
|
59
|
+
initialFiles: initialFiles,
|
|
60
|
+
acceptedFiles: acceptedFiles,
|
|
61
|
+
onChange: setFile,
|
|
62
|
+
filesLimit: 1,
|
|
63
|
+
maxFileSize: 100000000,
|
|
64
|
+
}),
|
|
65
|
+
/*#__PURE__*/ React.createElement(HelperText, {
|
|
66
|
+
name: name,
|
|
67
|
+
hint: hint,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
File.propTypes = {
|
|
72
|
+
name: PropTypes.string,
|
|
73
|
+
accept: PropTypes.string,
|
|
74
|
+
label: PropTypes.string,
|
|
75
|
+
hint: PropTypes.string,
|
|
76
|
+
};
|
|
77
|
+
export default withWQ(File);
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, { useMemo, useCallback, useRef } from "react";
|
|
2
|
+
import { useComponents, withWQ } from "@wq/react";
|
|
3
|
+
import { useField } from "formik";
|
|
4
|
+
import { DropzoneArea } from "mui2-file-dropzone";
|
|
5
|
+
import Fieldset from "./Fieldset.js";
|
|
6
|
+
import HelperText from "./HelperText.js";
|
|
7
|
+
import PropTypes from "prop-types";
|
|
8
|
+
const FileArrayFallback = {
|
|
9
|
+
components: {
|
|
10
|
+
Fieldset,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
function FileArray({ name, label, subform, hint, maxRows }) {
|
|
14
|
+
const [, { initialValue = [] }, { setValue }] = useField(name),
|
|
15
|
+
fileField = subform.find(
|
|
16
|
+
(field) => field.type === "file" || field.type === "image",
|
|
17
|
+
) || {
|
|
18
|
+
name: "file",
|
|
19
|
+
type: "file",
|
|
20
|
+
},
|
|
21
|
+
accept = fileField.type === "image" ? "image/*" : null,
|
|
22
|
+
loadedRef = useRef(null),
|
|
23
|
+
{ Fieldset } = useComponents();
|
|
24
|
+
const initialFiles = useMemo(() => {
|
|
25
|
+
if (!initialValue || initialValue.length === 0) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
return initialValue
|
|
29
|
+
.filter((row) => {
|
|
30
|
+
if (
|
|
31
|
+
!row[fileField.name] ||
|
|
32
|
+
row[fileField.name] === "__clear__"
|
|
33
|
+
) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
})
|
|
38
|
+
.map((row) => {
|
|
39
|
+
const value = row[fileField.name];
|
|
40
|
+
if (value.type && value.body) {
|
|
41
|
+
return value.body;
|
|
42
|
+
} else if (typeof value === "string") {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}, [initialValue]),
|
|
47
|
+
acceptedFiles = useMemo(
|
|
48
|
+
() => (accept ? accept.split(",") : null),
|
|
49
|
+
[accept],
|
|
50
|
+
),
|
|
51
|
+
setFiles = useCallback(
|
|
52
|
+
(files) => {
|
|
53
|
+
if (!loadedRef.current) {
|
|
54
|
+
// initialFiles loaded
|
|
55
|
+
let fileIndex = 0;
|
|
56
|
+
loadedRef.current = initialValue.map((row) => {
|
|
57
|
+
let file;
|
|
58
|
+
if (
|
|
59
|
+
row[fileField.name] &&
|
|
60
|
+
row[fileField.name] !== "__clear__"
|
|
61
|
+
) {
|
|
62
|
+
file = files[fileIndex];
|
|
63
|
+
fileIndex++;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
row,
|
|
67
|
+
file,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const nextValue = files.map((file, i) => {
|
|
73
|
+
const { row, file: initialFile } = loadedRef.current[i] || {
|
|
74
|
+
row: {},
|
|
75
|
+
file: null,
|
|
76
|
+
};
|
|
77
|
+
if (initialFile === file) {
|
|
78
|
+
return row;
|
|
79
|
+
} else {
|
|
80
|
+
return {
|
|
81
|
+
...row,
|
|
82
|
+
[fileField.name]: {
|
|
83
|
+
name: file.name,
|
|
84
|
+
type: file.type,
|
|
85
|
+
body: file,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
if (initialValue && nextValue.length < initialValue.length) {
|
|
91
|
+
initialValue.slice(nextValue.length).forEach((row) => {
|
|
92
|
+
nextValue.push({
|
|
93
|
+
...row,
|
|
94
|
+
[fileField.name]: "__clear__",
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
setValue(nextValue);
|
|
99
|
+
},
|
|
100
|
+
[initialValue],
|
|
101
|
+
);
|
|
102
|
+
return /*#__PURE__*/ React.createElement(
|
|
103
|
+
Fieldset,
|
|
104
|
+
{
|
|
105
|
+
label: label,
|
|
106
|
+
},
|
|
107
|
+
/*#__PURE__*/ React.createElement(DropzoneArea, {
|
|
108
|
+
initialFiles: initialFiles,
|
|
109
|
+
acceptedFiles: acceptedFiles,
|
|
110
|
+
onChange: setFiles,
|
|
111
|
+
filesLimit: maxRows,
|
|
112
|
+
}),
|
|
113
|
+
/*#__PURE__*/ React.createElement(HelperText, {
|
|
114
|
+
name: name,
|
|
115
|
+
hint: hint,
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
FileArray.Fieldset = function EmptyFieldset() {
|
|
120
|
+
return null;
|
|
121
|
+
};
|
|
122
|
+
FileArray.propTypes = {
|
|
123
|
+
name: PropTypes.string,
|
|
124
|
+
accept: PropTypes.string,
|
|
125
|
+
label: PropTypes.string,
|
|
126
|
+
subform: PropTypes.arrayOf(PropTypes.object),
|
|
127
|
+
hint: PropTypes.string,
|
|
128
|
+
maxRows: PropTypes.number,
|
|
129
|
+
};
|
|
130
|
+
export default withWQ(FileArray, {
|
|
131
|
+
fallback: FileArrayFallback,
|
|
132
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useComponents, withWQ, createFallbackComponent } from "@wq/react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
const FlatFieldsetFallback = {
|
|
5
|
+
components: {
|
|
6
|
+
Typography: createFallbackComponent("Typography", "@wq/material"),
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
function FlatFieldset({ label, children }) {
|
|
10
|
+
const { Typography } = useComponents();
|
|
11
|
+
return /*#__PURE__*/ React.createElement(
|
|
12
|
+
React.Fragment,
|
|
13
|
+
null,
|
|
14
|
+
/*#__PURE__*/ React.createElement(
|
|
15
|
+
Typography,
|
|
16
|
+
{
|
|
17
|
+
color: "textSecondary",
|
|
18
|
+
},
|
|
19
|
+
label,
|
|
20
|
+
),
|
|
21
|
+
children,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
FlatFieldset.propTypes = {
|
|
25
|
+
label: PropTypes.string,
|
|
26
|
+
children: PropTypes.node,
|
|
27
|
+
};
|
|
28
|
+
export default withWQ(FlatFieldset, {
|
|
29
|
+
fallback: FlatFieldsetFallback,
|
|
30
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { useField } from "formik";
|
|
4
|
+
import { FormHelperText } from "@mui/material";
|
|
5
|
+
function FormError(props) {
|
|
6
|
+
const [, { error }] = useField("__other__");
|
|
7
|
+
if (!error) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return /*#__PURE__*/ React.createElement(
|
|
11
|
+
FormHelperText,
|
|
12
|
+
{
|
|
13
|
+
error: true,
|
|
14
|
+
...props,
|
|
15
|
+
},
|
|
16
|
+
error,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
export default withWQ(FormError);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { Form } from "formik";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
function FormRoot({ children }) {
|
|
6
|
+
return /*#__PURE__*/ React.createElement(
|
|
7
|
+
"div",
|
|
8
|
+
{
|
|
9
|
+
style: {
|
|
10
|
+
flex: 1,
|
|
11
|
+
display: "flex",
|
|
12
|
+
justifyContent: "center",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
/*#__PURE__*/ React.createElement(
|
|
16
|
+
Form,
|
|
17
|
+
{
|
|
18
|
+
style: {
|
|
19
|
+
width: "100%",
|
|
20
|
+
maxWidth: "70em",
|
|
21
|
+
padding: "1em",
|
|
22
|
+
boxSizing: "border-box",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
children,
|
|
26
|
+
),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
FormRoot.propTypes = {
|
|
30
|
+
children: PropTypes.node,
|
|
31
|
+
};
|
|
32
|
+
export default withWQ(FormRoot);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
function GeoHelpIcon({ name, type }) {
|
|
5
|
+
const iconClass = getIconClass(name, type);
|
|
6
|
+
if (!iconClass) {
|
|
7
|
+
return `{${name}}`;
|
|
8
|
+
}
|
|
9
|
+
return /*#__PURE__*/ React.createElement("span", {
|
|
10
|
+
className: iconClass,
|
|
11
|
+
style: {
|
|
12
|
+
display: "inline-block",
|
|
13
|
+
width: 18,
|
|
14
|
+
height: 18,
|
|
15
|
+
verticalAlign: "middle",
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
GeoHelpIcon.propTypes = {
|
|
20
|
+
name: PropTypes.string,
|
|
21
|
+
type: PropTypes.string,
|
|
22
|
+
};
|
|
23
|
+
export default withWQ(GeoHelpIcon);
|
|
24
|
+
const SHAPES = ["point", "line", "polygon"],
|
|
25
|
+
ICONS = SHAPES.map((shape) => `${shape.toUpperCase()}_ICON`);
|
|
26
|
+
function getIconClass(iconName, drawType) {
|
|
27
|
+
let shape = null;
|
|
28
|
+
if (iconName === "TOOL_ICON") {
|
|
29
|
+
if (drawType === "line_string") {
|
|
30
|
+
shape = "line";
|
|
31
|
+
} else if (SHAPES.includes(drawType)) {
|
|
32
|
+
shape = drawType;
|
|
33
|
+
}
|
|
34
|
+
} else if (ICONS.includes(iconName)) {
|
|
35
|
+
shape = SHAPES[ICONS.indexOf(iconName)];
|
|
36
|
+
}
|
|
37
|
+
if (shape) {
|
|
38
|
+
return `mapbox-gl-draw_${shape}`;
|
|
39
|
+
} else {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { useFormikContext, getIn } from "formik";
|
|
4
|
+
import { FormHelperText } from "@mui/material";
|
|
5
|
+
import PropTypes from "prop-types";
|
|
6
|
+
function HelperText({ name, hint }) {
|
|
7
|
+
const { errors, touched } = useFormikContext(),
|
|
8
|
+
error = getIn(errors, name),
|
|
9
|
+
showError = !!error && !!getIn(touched, name);
|
|
10
|
+
if (showError) {
|
|
11
|
+
hint = error;
|
|
12
|
+
}
|
|
13
|
+
if (!hint) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return /*#__PURE__*/ React.createElement(
|
|
17
|
+
FormHelperText,
|
|
18
|
+
{
|
|
19
|
+
error: !!showError,
|
|
20
|
+
},
|
|
21
|
+
hint,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
HelperText.propTypes = {
|
|
25
|
+
name: PropTypes.string,
|
|
26
|
+
hint: PropTypes.string,
|
|
27
|
+
};
|
|
28
|
+
export default withWQ(HelperText);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import { Field } from "formik";
|
|
4
|
+
import HelperText from "./HelperText.js";
|
|
5
|
+
import PropTypes from "prop-types";
|
|
6
|
+
function Hidden(props) {
|
|
7
|
+
return /*#__PURE__*/ React.createElement(
|
|
8
|
+
React.Fragment,
|
|
9
|
+
null,
|
|
10
|
+
/*#__PURE__*/ React.createElement(Field, {
|
|
11
|
+
...props,
|
|
12
|
+
type: "hidden",
|
|
13
|
+
}),
|
|
14
|
+
/*#__PURE__*/ React.createElement(HelperText, {
|
|
15
|
+
name: props.name,
|
|
16
|
+
hint: props.hint,
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
Hidden.propTypes = {
|
|
21
|
+
name: PropTypes.string,
|
|
22
|
+
hint: PropTypes.string,
|
|
23
|
+
};
|
|
24
|
+
export default withWQ(Hidden);
|