@raketa-builder/next-form 1.3.8 → 1.3.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/dist/Context.js +6 -0
- package/dist/Fields.js +114 -0
- package/dist/Fieldset.js +56 -0
- package/dist/Form.js +53 -0
- package/dist/FormNavigation.js +26 -0
- package/dist/Submit.js +13 -0
- package/dist/chunk-ORMEWXMH.js +33 -0
- package/dist/index.js +17 -333
- package/dist/utils/slugify.js +6 -0
- package/package.json +18 -4
- package/CHANGELOG.md +0 -13
- package/biome.json +0 -3
- package/src/Context.js +0 -3
- package/src/Fields.js +0 -142
- package/src/Fieldset.js +0 -50
- package/src/Form.js +0 -56
- package/src/FormNavigation.js +0 -27
- package/src/Submit.js +0 -15
- package/src/index.js +0 -15
- package/src/styles.css +0 -76
- package/src/utils/slugify.js +0 -7
- package/tsconfig.json +0 -5
package/dist/Context.js
ADDED
package/dist/Fields.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { __objRest, __spreadValues, __spreadProps } from './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Hint, FormGroup, Label, cn, Stack, Textarea, Select, Input } from '@raketa-builder/ui';
|
|
5
|
+
import Context from './Context';
|
|
6
|
+
|
|
7
|
+
const HiddenInput = ({ value, name }) => {
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
return /* @__PURE__ */ jsx(Input, { type: "hidden", defaultValue: value, name });
|
|
10
|
+
} else {
|
|
11
|
+
return /* @__PURE__ */ jsx(Input, { type: "hidden", defaultValue: JSON.stringify(value), name });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const CustomField = ({ component, name }) => {
|
|
15
|
+
const { defaultValues, errors } = React.useContext(Context);
|
|
16
|
+
const [value, setValue] = React.useState(defaultValues[name]);
|
|
17
|
+
const Component = component;
|
|
18
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
19
|
+
/* @__PURE__ */ jsx(Component, { onChange: (newValue) => setValue(newValue), value }),
|
|
20
|
+
/* @__PURE__ */ jsx(HiddenInput, { name, value }),
|
|
21
|
+
errors[name] && /* @__PURE__ */ jsx(Hint, { type: "error", children: errors[name] })
|
|
22
|
+
] });
|
|
23
|
+
};
|
|
24
|
+
const CheckboxGroup = ({ name, label, hint = "", entities }) => {
|
|
25
|
+
const { defaultValues, errors } = React.useContext(Context);
|
|
26
|
+
let defaultChecked = [];
|
|
27
|
+
if (defaultValues[name]) {
|
|
28
|
+
defaultChecked = Array.isArray(defaultValues[name]) ? defaultValues[name] : [defaultValues[name]];
|
|
29
|
+
}
|
|
30
|
+
return /* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
31
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: name, children: label }),
|
|
32
|
+
entities.map((entity, idx) => /* @__PURE__ */ jsx(
|
|
33
|
+
"label",
|
|
34
|
+
{
|
|
35
|
+
className: cn("r-reset", "r-next-form-checkbox-label"),
|
|
36
|
+
children: /* @__PURE__ */ jsxs("div", { children: [
|
|
37
|
+
/* @__PURE__ */ jsx(
|
|
38
|
+
"input",
|
|
39
|
+
{
|
|
40
|
+
type: "checkbox",
|
|
41
|
+
name,
|
|
42
|
+
value: `${entity.value}`,
|
|
43
|
+
defaultChecked: !!defaultChecked.find((dv) => dv === entity.value)
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
"\xA0",
|
|
47
|
+
entity.label
|
|
48
|
+
] })
|
|
49
|
+
},
|
|
50
|
+
`${entity.value}-${idx}`
|
|
51
|
+
)),
|
|
52
|
+
hint && /* @__PURE__ */ jsx(Hint, { children: hint }),
|
|
53
|
+
errors[name] && /* @__PURE__ */ jsx(Hint, { type: "error", children: errors[name] })
|
|
54
|
+
] });
|
|
55
|
+
};
|
|
56
|
+
const Checkbox = (_a) => {
|
|
57
|
+
var _b = _a, { name, label, hint = "" } = _b, rest = __objRest(_b, ["name", "label", "hint"]);
|
|
58
|
+
const { defaultValues, errors } = React.useContext(Context);
|
|
59
|
+
return /* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
60
|
+
/* @__PURE__ */ jsx(Label, { children: /* @__PURE__ */ jsxs(Stack, { className: "r-stack-align-center", children: [
|
|
61
|
+
/* @__PURE__ */ jsx(
|
|
62
|
+
"input",
|
|
63
|
+
__spreadValues({
|
|
64
|
+
type: "checkbox",
|
|
65
|
+
name,
|
|
66
|
+
defaultChecked: defaultValues[name]
|
|
67
|
+
}, rest)
|
|
68
|
+
),
|
|
69
|
+
"\xA0",
|
|
70
|
+
label
|
|
71
|
+
] }) }),
|
|
72
|
+
hint && /* @__PURE__ */ jsx(Hint, { children: hint }),
|
|
73
|
+
errors[name] && /* @__PURE__ */ jsx(Hint, { type: "error", children: errors[name] })
|
|
74
|
+
] });
|
|
75
|
+
};
|
|
76
|
+
const Field = (_c) => {
|
|
77
|
+
var _d = _c, {
|
|
78
|
+
as = "input",
|
|
79
|
+
hint = "",
|
|
80
|
+
name,
|
|
81
|
+
label,
|
|
82
|
+
children
|
|
83
|
+
} = _d, props = __objRest(_d, [
|
|
84
|
+
"as",
|
|
85
|
+
"hint",
|
|
86
|
+
"name",
|
|
87
|
+
"label",
|
|
88
|
+
"children"
|
|
89
|
+
]);
|
|
90
|
+
const { defaultValues, errors } = React.useContext(Context);
|
|
91
|
+
const types = {
|
|
92
|
+
input: Input,
|
|
93
|
+
select: Select,
|
|
94
|
+
textarea: Textarea
|
|
95
|
+
};
|
|
96
|
+
const Component = types[as] || Input;
|
|
97
|
+
return /* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
98
|
+
label && /* @__PURE__ */ jsx(Label, { htmlFor: name, children: label }),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
Component,
|
|
101
|
+
__spreadProps(__spreadValues({
|
|
102
|
+
id: name,
|
|
103
|
+
name,
|
|
104
|
+
defaultValue: defaultValues[name]
|
|
105
|
+
}, props), {
|
|
106
|
+
children
|
|
107
|
+
})
|
|
108
|
+
),
|
|
109
|
+
hint && /* @__PURE__ */ jsx(Hint, { children: hint }),
|
|
110
|
+
errors[name] && /* @__PURE__ */ jsx(Hint, { type: "error", children: errors[name] })
|
|
111
|
+
] });
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { Checkbox, CheckboxGroup, CustomField, Field };
|
package/dist/Fieldset.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { __objRest, __spreadValues } from './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import { cn } from '@raketa-builder/ui';
|
|
5
|
+
import slugify from './utils/slugify';
|
|
6
|
+
|
|
7
|
+
const Wrapper = (_a) => {
|
|
8
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
9
|
+
return /* @__PURE__ */ jsx(
|
|
10
|
+
"div",
|
|
11
|
+
__spreadValues({
|
|
12
|
+
className: cn("r-reset", "r-next-form-fieldset-wrapper", className)
|
|
13
|
+
}, rest)
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
const LegendWrapper = (_c) => {
|
|
17
|
+
var _d = _c, { className } = _d, rest = __objRest(_d, ["className"]);
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
"div",
|
|
20
|
+
__spreadValues({
|
|
21
|
+
className: cn("r-reset", "r-next-form-legend-wrapper", className)
|
|
22
|
+
}, rest)
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
const Legend = (_e) => {
|
|
26
|
+
var _f = _e, { className } = _f, rest = __objRest(_f, ["className"]);
|
|
27
|
+
return /* @__PURE__ */ jsx("div", __spreadValues({ className: cn("r-reset", "r-next-form-legend", className) }, rest));
|
|
28
|
+
};
|
|
29
|
+
const Description = (_g) => {
|
|
30
|
+
var _h = _g, { className } = _h, rest = __objRest(_h, ["className"]);
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
"div",
|
|
33
|
+
__spreadValues({
|
|
34
|
+
className: cn("r-reset", "r-next-form-description", className)
|
|
35
|
+
}, rest)
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
const FieldWrapper = (_i) => {
|
|
39
|
+
var _j = _i, { className } = _j, rest = __objRest(_j, ["className"]);
|
|
40
|
+
return /* @__PURE__ */ jsx(
|
|
41
|
+
"div",
|
|
42
|
+
__spreadValues({
|
|
43
|
+
className: cn("r-reset", "r-next-form-field-wrapper", className)
|
|
44
|
+
}, rest)
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
const Fieldset = ({ label, description, children }) => /* @__PURE__ */ jsxs(Wrapper, { id: slugify(label), children: [
|
|
48
|
+
/* @__PURE__ */ jsxs(LegendWrapper, { children: [
|
|
49
|
+
/* @__PURE__ */ jsx(Legend, { children: label }),
|
|
50
|
+
description && /* @__PURE__ */ jsx(Description, { dangerouslySetInnerHTML: { __html: description } })
|
|
51
|
+
] }),
|
|
52
|
+
/* @__PURE__ */ jsx(FieldWrapper, { children })
|
|
53
|
+
] });
|
|
54
|
+
var Fieldset_default = Fieldset;
|
|
55
|
+
|
|
56
|
+
export { Fieldset_default as default };
|
package/dist/Form.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { __objRest, __spreadProps, __spreadValues } from './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import Context from './Context';
|
|
5
|
+
|
|
6
|
+
const Form = (_a) => {
|
|
7
|
+
var _b = _a, { children, defaultValues = {}, onSubmit } = _b, rest = __objRest(_b, ["children", "defaultValues", "onSubmit"]);
|
|
8
|
+
const [state, setState] = React.useState({ submitting: false, errors: {} });
|
|
9
|
+
const setErrors = (errors) => {
|
|
10
|
+
let newErrors = {};
|
|
11
|
+
errors.map((error) => newErrors[error.key] = error.message);
|
|
12
|
+
if (state.submitting) {
|
|
13
|
+
setState({
|
|
14
|
+
submitting: false,
|
|
15
|
+
errors: newErrors
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
setState({
|
|
19
|
+
submitting: state.submitting,
|
|
20
|
+
errors: newErrors
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
"form",
|
|
26
|
+
__spreadProps(__spreadValues({
|
|
27
|
+
onSubmit: (e) => {
|
|
28
|
+
if (!onSubmit) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
const formData = new FormData(e.target);
|
|
33
|
+
setState(__spreadProps(__spreadValues({}, state), { submitting: true }));
|
|
34
|
+
onSubmit(formData, setErrors, e.target);
|
|
35
|
+
}
|
|
36
|
+
}, rest), {
|
|
37
|
+
children: /* @__PURE__ */ jsx(
|
|
38
|
+
Context.Provider,
|
|
39
|
+
{
|
|
40
|
+
value: {
|
|
41
|
+
defaultValues,
|
|
42
|
+
errors: state.errors,
|
|
43
|
+
submitting: state.submitting
|
|
44
|
+
},
|
|
45
|
+
children
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
var Form_default = Form;
|
|
52
|
+
|
|
53
|
+
export { Form_default as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { __objRest, __spreadValues } from './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import { cn } from '@raketa-builder/ui';
|
|
5
|
+
import slugify from './utils/slugify';
|
|
6
|
+
|
|
7
|
+
const Wrapper = (_a) => {
|
|
8
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
9
|
+
return /* @__PURE__ */ jsx(
|
|
10
|
+
"div",
|
|
11
|
+
__spreadValues({
|
|
12
|
+
className: cn("r-reset", "r-next-form-nav-wrapper", className)
|
|
13
|
+
}, rest)
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
const Link = (_c) => {
|
|
17
|
+
var _d = _c, { className } = _d, rest = __objRest(_d, ["className"]);
|
|
18
|
+
return /* @__PURE__ */ jsx("a", __spreadValues({ className: cn("r-reset", "r-next-form-nav-link", className) }, rest));
|
|
19
|
+
};
|
|
20
|
+
const FormNavigation = ({ sections, children }) => /* @__PURE__ */ jsxs(Wrapper, { children: [
|
|
21
|
+
sections.map((section, idx) => /* @__PURE__ */ jsx(Link, { href: `#${slugify(section)}`, children: section }, `${section}-${idx}`)),
|
|
22
|
+
children
|
|
23
|
+
] });
|
|
24
|
+
var FormNavigation_default = FormNavigation;
|
|
25
|
+
|
|
26
|
+
export { FormNavigation_default as default };
|
package/dist/Submit.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Button } from '@raketa-builder/ui';
|
|
5
|
+
import Context from './Context';
|
|
6
|
+
|
|
7
|
+
const Submit = ({ children }) => {
|
|
8
|
+
const { submitting } = React.useContext(Context);
|
|
9
|
+
return /* @__PURE__ */ jsx(Button, { disabled: submitting, type: "submit", variant: "primary", children });
|
|
10
|
+
};
|
|
11
|
+
var Submit_default = Submit;
|
|
12
|
+
|
|
13
|
+
export { Submit_default as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { __objRest, __spreadProps, __spreadValues };
|
package/dist/index.js
CHANGED
|
@@ -1,333 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
|
|
59
|
-
// src/index.js
|
|
60
|
-
var index_exports = {};
|
|
61
|
-
__export(index_exports, {
|
|
62
|
-
default: () => index_default
|
|
63
|
-
});
|
|
64
|
-
module.exports = __toCommonJS(index_exports);
|
|
65
|
-
|
|
66
|
-
// src/Form.js
|
|
67
|
-
var import_react2 = __toESM(require("react"));
|
|
68
|
-
|
|
69
|
-
// src/Context.js
|
|
70
|
-
var import_react = __toESM(require("react"));
|
|
71
|
-
var Context_default = import_react.default.createContext({});
|
|
72
|
-
|
|
73
|
-
// src/Form.js
|
|
74
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
75
|
-
var Form = (_a) => {
|
|
76
|
-
var _b = _a, { children, defaultValues = {}, onSubmit } = _b, rest = __objRest(_b, ["children", "defaultValues", "onSubmit"]);
|
|
77
|
-
const [state, setState] = import_react2.default.useState({ submitting: false, errors: {} });
|
|
78
|
-
const setErrors = (errors) => {
|
|
79
|
-
let newErrors = {};
|
|
80
|
-
errors.map((error) => newErrors[error.key] = error.message);
|
|
81
|
-
if (state.submitting) {
|
|
82
|
-
setState({
|
|
83
|
-
submitting: false,
|
|
84
|
-
errors: newErrors
|
|
85
|
-
});
|
|
86
|
-
} else {
|
|
87
|
-
setState({
|
|
88
|
-
submitting: state.submitting,
|
|
89
|
-
errors: newErrors
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
94
|
-
"form",
|
|
95
|
-
__spreadProps(__spreadValues({
|
|
96
|
-
onSubmit: (e) => {
|
|
97
|
-
if (!onSubmit) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
e.preventDefault();
|
|
101
|
-
const formData = new FormData(e.target);
|
|
102
|
-
setState(__spreadProps(__spreadValues({}, state), { submitting: true }));
|
|
103
|
-
onSubmit(formData, setErrors, e.target);
|
|
104
|
-
}
|
|
105
|
-
}, rest), {
|
|
106
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
107
|
-
Context_default.Provider,
|
|
108
|
-
{
|
|
109
|
-
value: {
|
|
110
|
-
defaultValues,
|
|
111
|
-
errors: state.errors,
|
|
112
|
-
submitting: state.submitting
|
|
113
|
-
},
|
|
114
|
-
children
|
|
115
|
-
}
|
|
116
|
-
)
|
|
117
|
-
})
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
var Form_default = Form;
|
|
121
|
-
|
|
122
|
-
// src/Fields.js
|
|
123
|
-
var import_react3 = __toESM(require("react"));
|
|
124
|
-
var import_ui = require("@raketa-builder/ui");
|
|
125
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
126
|
-
var HiddenInput = ({ value, name }) => {
|
|
127
|
-
if (typeof value === "string") {
|
|
128
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Input, { type: "hidden", defaultValue: value, name });
|
|
129
|
-
} else {
|
|
130
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Input, { type: "hidden", defaultValue: JSON.stringify(value), name });
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var CustomField = ({ component, name }) => {
|
|
134
|
-
const { defaultValues, errors } = import_react3.default.useContext(Context_default);
|
|
135
|
-
const [value, setValue] = import_react3.default.useState(defaultValues[name]);
|
|
136
|
-
const Component = component;
|
|
137
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react3.default.Fragment, { children: [
|
|
138
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { onChange: (newValue) => setValue(newValue), value }),
|
|
139
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(HiddenInput, { name, value }),
|
|
140
|
-
errors[name] && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Hint, { type: "error", children: errors[name] })
|
|
141
|
-
] });
|
|
142
|
-
};
|
|
143
|
-
var CheckboxGroup = ({ name, label, hint = "", entities }) => {
|
|
144
|
-
const { defaultValues, errors } = import_react3.default.useContext(Context_default);
|
|
145
|
-
let defaultChecked = [];
|
|
146
|
-
if (defaultValues[name]) {
|
|
147
|
-
defaultChecked = Array.isArray(defaultValues[name]) ? defaultValues[name] : [defaultValues[name]];
|
|
148
|
-
}
|
|
149
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui.FormGroup, { children: [
|
|
150
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Label, { htmlFor: name, children: label }),
|
|
151
|
-
entities.map((entity, idx) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
152
|
-
"label",
|
|
153
|
-
{
|
|
154
|
-
className: (0, import_ui.cn)("r-reset", "r-next-form-checkbox-label"),
|
|
155
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
156
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
157
|
-
"input",
|
|
158
|
-
{
|
|
159
|
-
type: "checkbox",
|
|
160
|
-
name,
|
|
161
|
-
value: `${entity.value}`,
|
|
162
|
-
defaultChecked: !!defaultChecked.find((dv) => dv === entity.value)
|
|
163
|
-
}
|
|
164
|
-
),
|
|
165
|
-
"\xA0",
|
|
166
|
-
entity.label
|
|
167
|
-
] })
|
|
168
|
-
},
|
|
169
|
-
`${entity.value}-${idx}`
|
|
170
|
-
)),
|
|
171
|
-
hint && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Hint, { children: hint }),
|
|
172
|
-
errors[name] && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Hint, { type: "error", children: errors[name] })
|
|
173
|
-
] });
|
|
174
|
-
};
|
|
175
|
-
var Checkbox = (_a) => {
|
|
176
|
-
var _b = _a, { name, label, hint = "" } = _b, rest = __objRest(_b, ["name", "label", "hint"]);
|
|
177
|
-
const { defaultValues, errors } = import_react3.default.useContext(Context_default);
|
|
178
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui.FormGroup, { children: [
|
|
179
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Label, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui.Stack, { className: "r-stack-align-center", children: [
|
|
180
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
181
|
-
"input",
|
|
182
|
-
__spreadValues({
|
|
183
|
-
type: "checkbox",
|
|
184
|
-
name,
|
|
185
|
-
defaultChecked: defaultValues[name]
|
|
186
|
-
}, rest)
|
|
187
|
-
),
|
|
188
|
-
"\xA0",
|
|
189
|
-
label
|
|
190
|
-
] }) }),
|
|
191
|
-
hint && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Hint, { children: hint }),
|
|
192
|
-
errors[name] && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Hint, { type: "error", children: errors[name] })
|
|
193
|
-
] });
|
|
194
|
-
};
|
|
195
|
-
var Field = (_a) => {
|
|
196
|
-
var _b = _a, {
|
|
197
|
-
as = "input",
|
|
198
|
-
hint = "",
|
|
199
|
-
name,
|
|
200
|
-
label,
|
|
201
|
-
children
|
|
202
|
-
} = _b, props = __objRest(_b, [
|
|
203
|
-
"as",
|
|
204
|
-
"hint",
|
|
205
|
-
"name",
|
|
206
|
-
"label",
|
|
207
|
-
"children"
|
|
208
|
-
]);
|
|
209
|
-
const { defaultValues, errors } = import_react3.default.useContext(Context_default);
|
|
210
|
-
const types = {
|
|
211
|
-
input: import_ui.Input,
|
|
212
|
-
select: import_ui.Select,
|
|
213
|
-
textarea: import_ui.Textarea
|
|
214
|
-
};
|
|
215
|
-
const Component = types[as] || import_ui.Input;
|
|
216
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui.FormGroup, { children: [
|
|
217
|
-
label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Label, { htmlFor: name, children: label }),
|
|
218
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
219
|
-
Component,
|
|
220
|
-
__spreadProps(__spreadValues({
|
|
221
|
-
id: name,
|
|
222
|
-
name,
|
|
223
|
-
defaultValue: defaultValues[name]
|
|
224
|
-
}, props), {
|
|
225
|
-
children
|
|
226
|
-
})
|
|
227
|
-
),
|
|
228
|
-
hint && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Hint, { children: hint }),
|
|
229
|
-
errors[name] && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Hint, { type: "error", children: errors[name] })
|
|
230
|
-
] });
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
// src/Submit.js
|
|
234
|
-
var import_react4 = __toESM(require("react"));
|
|
235
|
-
var import_ui2 = require("@raketa-builder/ui");
|
|
236
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
237
|
-
var Submit = ({ children }) => {
|
|
238
|
-
const { submitting } = import_react4.default.useContext(Context_default);
|
|
239
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui2.Button, { disabled: submitting, type: "submit", variant: "primary", children });
|
|
240
|
-
};
|
|
241
|
-
var Submit_default = Submit;
|
|
242
|
-
|
|
243
|
-
// src/Fieldset.js
|
|
244
|
-
var import_react5 = __toESM(require("react"));
|
|
245
|
-
var import_ui3 = require("@raketa-builder/ui");
|
|
246
|
-
|
|
247
|
-
// src/utils/slugify.js
|
|
248
|
-
var slugify = (string) => string.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
249
|
-
var slugify_default = slugify;
|
|
250
|
-
|
|
251
|
-
// src/Fieldset.js
|
|
252
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
253
|
-
var Wrapper = (_a) => {
|
|
254
|
-
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
255
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
256
|
-
"div",
|
|
257
|
-
__spreadValues({
|
|
258
|
-
className: (0, import_ui3.cn)("r-reset", "r-next-form-fieldset-wrapper", className)
|
|
259
|
-
}, rest)
|
|
260
|
-
);
|
|
261
|
-
};
|
|
262
|
-
var LegendWrapper = (_a) => {
|
|
263
|
-
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
264
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
265
|
-
"div",
|
|
266
|
-
__spreadValues({
|
|
267
|
-
className: (0, import_ui3.cn)("r-reset", "r-next-form-legend-wrapper", className)
|
|
268
|
-
}, rest)
|
|
269
|
-
);
|
|
270
|
-
};
|
|
271
|
-
var Legend = (_a) => {
|
|
272
|
-
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
273
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", __spreadValues({ className: (0, import_ui3.cn)("r-reset", "r-next-form-legend", className) }, rest));
|
|
274
|
-
};
|
|
275
|
-
var Description = (_a) => {
|
|
276
|
-
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
277
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
278
|
-
"div",
|
|
279
|
-
__spreadValues({
|
|
280
|
-
className: (0, import_ui3.cn)("r-reset", "r-next-form-description", className)
|
|
281
|
-
}, rest)
|
|
282
|
-
);
|
|
283
|
-
};
|
|
284
|
-
var FieldWrapper = (_a) => {
|
|
285
|
-
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
286
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
287
|
-
"div",
|
|
288
|
-
__spreadValues({
|
|
289
|
-
className: (0, import_ui3.cn)("r-reset", "r-next-form-field-wrapper", className)
|
|
290
|
-
}, rest)
|
|
291
|
-
);
|
|
292
|
-
};
|
|
293
|
-
var Fieldset = ({ label, description, children }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Wrapper, { id: slugify_default(label), children: [
|
|
294
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(LegendWrapper, { children: [
|
|
295
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Legend, { children: label }),
|
|
296
|
-
description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Description, { dangerouslySetInnerHTML: { __html: description } })
|
|
297
|
-
] }),
|
|
298
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldWrapper, { children })
|
|
299
|
-
] });
|
|
300
|
-
var Fieldset_default = Fieldset;
|
|
301
|
-
|
|
302
|
-
// src/FormNavigation.js
|
|
303
|
-
var import_react6 = __toESM(require("react"));
|
|
304
|
-
var import_ui4 = require("@raketa-builder/ui");
|
|
305
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
306
|
-
var Wrapper2 = (_a) => {
|
|
307
|
-
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
308
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
309
|
-
"div",
|
|
310
|
-
__spreadValues({
|
|
311
|
-
className: (0, import_ui4.cn)("r-reset", "r-next-form-nav-wrapper", className)
|
|
312
|
-
}, rest)
|
|
313
|
-
);
|
|
314
|
-
};
|
|
315
|
-
var Link = (_a) => {
|
|
316
|
-
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
317
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", __spreadValues({ className: (0, import_ui4.cn)("r-reset", "r-next-form-nav-link", className) }, rest));
|
|
318
|
-
};
|
|
319
|
-
var FormNavigation = ({ sections, children }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Wrapper2, { children: [
|
|
320
|
-
sections.map((section, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Link, { href: `#${slugify_default(section)}`, children: section }, `${section}-${idx}`)),
|
|
321
|
-
children
|
|
322
|
-
] });
|
|
323
|
-
var FormNavigation_default = FormNavigation;
|
|
324
|
-
|
|
325
|
-
// src/index.js
|
|
326
|
-
Form_default.Field = Field;
|
|
327
|
-
Form_default.CustomField = CustomField;
|
|
328
|
-
Form_default.CheckboxGroup = CheckboxGroup;
|
|
329
|
-
Form_default.Checkbox = Checkbox;
|
|
330
|
-
Form_default.Submit = Submit_default;
|
|
331
|
-
Form_default.Fieldset = Fieldset_default;
|
|
332
|
-
Form_default.FormNavigation = FormNavigation_default;
|
|
333
|
-
var index_default = Form_default;
|
|
1
|
+
import './chunk-ORMEWXMH.js';
|
|
2
|
+
import Form from './Form';
|
|
3
|
+
import { Field, CustomField, CheckboxGroup, Checkbox } from './Fields';
|
|
4
|
+
import Submit from './Submit';
|
|
5
|
+
import Fieldset from './Fieldset';
|
|
6
|
+
import FormNavigation from './FormNavigation';
|
|
7
|
+
|
|
8
|
+
Form.Field = Field;
|
|
9
|
+
Form.CustomField = CustomField;
|
|
10
|
+
Form.CheckboxGroup = CheckboxGroup;
|
|
11
|
+
Form.Checkbox = Checkbox;
|
|
12
|
+
Form.Submit = Submit;
|
|
13
|
+
Form.Fieldset = Fieldset;
|
|
14
|
+
Form.FormNavigation = FormNavigation;
|
|
15
|
+
var index_default = Form;
|
|
16
|
+
|
|
17
|
+
export { index_default as default };
|
package/package.json
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raketa-builder/next-form",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.10",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
5
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./*": {
|
|
14
|
+
"import": "./dist/*.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
6
20
|
"license": "MIT",
|
|
7
21
|
"scripts": {
|
|
8
|
-
"build": "tsup
|
|
9
|
-
"dev": "tsup
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
10
24
|
"format": "prettier --write .",
|
|
11
25
|
"lint": "biome lint --max-diagnostics=5000 ."
|
|
12
26
|
},
|
|
@@ -15,7 +29,7 @@
|
|
|
15
29
|
"react-dom": "19.1.0"
|
|
16
30
|
},
|
|
17
31
|
"dependencies": {
|
|
18
|
-
"@raketa-builder/ui": "1.3.
|
|
32
|
+
"@raketa-builder/ui": "1.3.10"
|
|
19
33
|
},
|
|
20
34
|
"devDependencies": {
|
|
21
35
|
"@biomejs/biome": "1.9.4",
|
package/CHANGELOG.md
DELETED
package/biome.json
DELETED
package/src/Context.js
DELETED
package/src/Fields.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
FormGroup,
|
|
4
|
-
Label,
|
|
5
|
-
Input,
|
|
6
|
-
Textarea,
|
|
7
|
-
Select,
|
|
8
|
-
Hint,
|
|
9
|
-
Stack,
|
|
10
|
-
cn,
|
|
11
|
-
} from "@raketa-builder/ui";
|
|
12
|
-
import Context from "./Context";
|
|
13
|
-
|
|
14
|
-
const HiddenInput = ({ value, name }) => {
|
|
15
|
-
if (typeof value === "string") {
|
|
16
|
-
return <Input type="hidden" defaultValue={value} name={name} />;
|
|
17
|
-
} else {
|
|
18
|
-
return (
|
|
19
|
-
<Input type="hidden" defaultValue={JSON.stringify(value)} name={name} />
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const CustomField = ({ component, name }) => {
|
|
25
|
-
const { defaultValues, errors } = React.useContext(Context);
|
|
26
|
-
const [value, setValue] = React.useState(defaultValues[name]);
|
|
27
|
-
const Component = component;
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<React.Fragment>
|
|
31
|
-
<Component onChange={(newValue) => setValue(newValue)} value={value} />
|
|
32
|
-
|
|
33
|
-
<HiddenInput name={name} value={value} />
|
|
34
|
-
|
|
35
|
-
{errors[name] && <Hint type="error">{errors[name]}</Hint>}
|
|
36
|
-
</React.Fragment>
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const CheckboxGroup = ({ name, label, hint = "", entities }) => {
|
|
41
|
-
const { defaultValues, errors } = React.useContext(Context);
|
|
42
|
-
|
|
43
|
-
let defaultChecked = [];
|
|
44
|
-
|
|
45
|
-
if (defaultValues[name]) {
|
|
46
|
-
defaultChecked = Array.isArray(defaultValues[name])
|
|
47
|
-
? defaultValues[name]
|
|
48
|
-
: [defaultValues[name]];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<FormGroup>
|
|
53
|
-
<Label htmlFor={name}>{label}</Label>
|
|
54
|
-
|
|
55
|
-
{entities.map((entity, idx) => (
|
|
56
|
-
<label
|
|
57
|
-
key={`${entity.value}-${idx}`}
|
|
58
|
-
className={cn("r-reset", "r-next-form-checkbox-label")}
|
|
59
|
-
>
|
|
60
|
-
<div>
|
|
61
|
-
<input
|
|
62
|
-
type="checkbox"
|
|
63
|
-
name={name}
|
|
64
|
-
value={`${entity.value}`}
|
|
65
|
-
defaultChecked={
|
|
66
|
-
!!defaultChecked.find((dv) => dv === entity.value)
|
|
67
|
-
}
|
|
68
|
-
/>
|
|
69
|
-
|
|
70
|
-
{entity.label}
|
|
71
|
-
</div>
|
|
72
|
-
</label>
|
|
73
|
-
))}
|
|
74
|
-
|
|
75
|
-
{hint && <Hint>{hint}</Hint>}
|
|
76
|
-
{errors[name] && <Hint type="error">{errors[name]}</Hint>}
|
|
77
|
-
</FormGroup>
|
|
78
|
-
);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const Checkbox = ({ name, label, hint = "", ...rest }) => {
|
|
82
|
-
const { defaultValues, errors } = React.useContext(Context);
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<FormGroup>
|
|
86
|
-
<Label>
|
|
87
|
-
<Stack className="r-stack-align-center">
|
|
88
|
-
<input
|
|
89
|
-
type="checkbox"
|
|
90
|
-
name={name}
|
|
91
|
-
defaultChecked={defaultValues[name]}
|
|
92
|
-
{...rest}
|
|
93
|
-
/>
|
|
94
|
-
|
|
95
|
-
{label}
|
|
96
|
-
</Stack>
|
|
97
|
-
</Label>
|
|
98
|
-
|
|
99
|
-
{hint && <Hint>{hint}</Hint>}
|
|
100
|
-
{errors[name] && <Hint type="error">{errors[name]}</Hint>}
|
|
101
|
-
</FormGroup>
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const Field = ({
|
|
106
|
-
as = "input",
|
|
107
|
-
hint = "",
|
|
108
|
-
name,
|
|
109
|
-
label,
|
|
110
|
-
children,
|
|
111
|
-
...props
|
|
112
|
-
}) => {
|
|
113
|
-
const { defaultValues, errors } = React.useContext(Context);
|
|
114
|
-
|
|
115
|
-
const types = {
|
|
116
|
-
input: Input,
|
|
117
|
-
select: Select,
|
|
118
|
-
textarea: Textarea,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const Component = types[as] || Input;
|
|
122
|
-
|
|
123
|
-
return (
|
|
124
|
-
<FormGroup>
|
|
125
|
-
{label && <Label htmlFor={name}>{label}</Label>}
|
|
126
|
-
|
|
127
|
-
<Component
|
|
128
|
-
id={name}
|
|
129
|
-
name={name}
|
|
130
|
-
defaultValue={defaultValues[name]}
|
|
131
|
-
{...props}
|
|
132
|
-
>
|
|
133
|
-
{children}
|
|
134
|
-
</Component>
|
|
135
|
-
|
|
136
|
-
{hint && <Hint>{hint}</Hint>}
|
|
137
|
-
{errors[name] && <Hint type="error">{errors[name]}</Hint>}
|
|
138
|
-
</FormGroup>
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export { Field, CustomField, Checkbox, CheckboxGroup };
|
package/src/Fieldset.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { cn } from "@raketa-builder/ui";
|
|
3
|
-
import slugify from "./utils/slugify";
|
|
4
|
-
|
|
5
|
-
const Wrapper = ({ className, ...rest }) => (
|
|
6
|
-
<div
|
|
7
|
-
className={cn("r-reset", "r-next-form-fieldset-wrapper", className)}
|
|
8
|
-
{...rest}
|
|
9
|
-
/>
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
const LegendWrapper = ({ className, ...rest }) => (
|
|
13
|
-
<div
|
|
14
|
-
className={cn("r-reset", "r-next-form-legend-wrapper", className)}
|
|
15
|
-
{...rest}
|
|
16
|
-
/>
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const Legend = ({ className, ...rest }) => (
|
|
20
|
-
<div className={cn("r-reset", "r-next-form-legend", className)} {...rest} />
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
const Description = ({ className, ...rest }) => (
|
|
24
|
-
<div
|
|
25
|
-
className={cn("r-reset", "r-next-form-description", className)}
|
|
26
|
-
{...rest}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const FieldWrapper = ({ className, ...rest }) => (
|
|
31
|
-
<div
|
|
32
|
-
className={cn("r-reset", "r-next-form-field-wrapper", className)}
|
|
33
|
-
{...rest}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const Fieldset = ({ label, description, children }) => (
|
|
38
|
-
<Wrapper id={slugify(label)}>
|
|
39
|
-
<LegendWrapper>
|
|
40
|
-
<Legend>{label}</Legend>
|
|
41
|
-
{description && (
|
|
42
|
-
<Description dangerouslySetInnerHTML={{ __html: description }} />
|
|
43
|
-
)}
|
|
44
|
-
</LegendWrapper>
|
|
45
|
-
|
|
46
|
-
<FieldWrapper>{children}</FieldWrapper>
|
|
47
|
-
</Wrapper>
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
export default Fieldset;
|
package/src/Form.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import Context from "./Context";
|
|
3
|
-
|
|
4
|
-
const Form = ({ children, defaultValues = {}, onSubmit, ...rest }) => {
|
|
5
|
-
const [state, setState] = React.useState({ submitting: false, errors: {} });
|
|
6
|
-
|
|
7
|
-
const setErrors = (errors) => {
|
|
8
|
-
let newErrors = {};
|
|
9
|
-
|
|
10
|
-
errors.map((error) => (newErrors[error.key] = error.message));
|
|
11
|
-
|
|
12
|
-
if (state.submitting) {
|
|
13
|
-
setState({
|
|
14
|
-
submitting: false,
|
|
15
|
-
errors: newErrors,
|
|
16
|
-
});
|
|
17
|
-
} else {
|
|
18
|
-
setState({
|
|
19
|
-
submitting: state.submitting,
|
|
20
|
-
errors: newErrors,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<form
|
|
27
|
-
onSubmit={(e) => {
|
|
28
|
-
// Note: When custom submit event is missing just act as regular form.
|
|
29
|
-
if (!onSubmit) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
e.preventDefault();
|
|
34
|
-
|
|
35
|
-
const formData = new FormData(e.target);
|
|
36
|
-
|
|
37
|
-
setState({ ...state, submitting: true });
|
|
38
|
-
|
|
39
|
-
onSubmit(formData, setErrors, e.target);
|
|
40
|
-
}}
|
|
41
|
-
{...rest}
|
|
42
|
-
>
|
|
43
|
-
<Context.Provider
|
|
44
|
-
value={{
|
|
45
|
-
defaultValues,
|
|
46
|
-
errors: state.errors,
|
|
47
|
-
submitting: state.submitting,
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
50
|
-
{children}
|
|
51
|
-
</Context.Provider>
|
|
52
|
-
</form>
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default Form;
|
package/src/FormNavigation.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { cn } from "@raketa-builder/ui";
|
|
3
|
-
import slugify from "./utils/slugify";
|
|
4
|
-
|
|
5
|
-
const Wrapper = ({ className, ...rest }) => (
|
|
6
|
-
<div
|
|
7
|
-
className={cn("r-reset", "r-next-form-nav-wrapper", className)}
|
|
8
|
-
{...rest}
|
|
9
|
-
/>
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
const Link = ({ className, ...rest }) => (
|
|
13
|
-
<a className={cn("r-reset", "r-next-form-nav-link", className)} {...rest} />
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const FormNavigation = ({ sections, children }) => (
|
|
17
|
-
<Wrapper>
|
|
18
|
-
{sections.map((section, idx) => (
|
|
19
|
-
<Link key={`${section}-${idx}`} href={`#${slugify(section)}`}>
|
|
20
|
-
{section}
|
|
21
|
-
</Link>
|
|
22
|
-
))}
|
|
23
|
-
{children}
|
|
24
|
-
</Wrapper>
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
export default FormNavigation;
|
package/src/Submit.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Button } from "@raketa-builder/ui";
|
|
3
|
-
import Context from "./Context";
|
|
4
|
-
|
|
5
|
-
const Submit = ({ children }) => {
|
|
6
|
-
const { submitting } = React.useContext(Context);
|
|
7
|
-
|
|
8
|
-
return (
|
|
9
|
-
<Button disabled={submitting} type="submit" variant="primary">
|
|
10
|
-
{children}
|
|
11
|
-
</Button>
|
|
12
|
-
);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default Submit;
|
package/src/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import Form from "./Form";
|
|
2
|
-
import { Field, CustomField, Checkbox, CheckboxGroup } from "./Fields";
|
|
3
|
-
import Submit from "./Submit";
|
|
4
|
-
import Fieldset from "./Fieldset";
|
|
5
|
-
import FormNavigation from "./FormNavigation";
|
|
6
|
-
|
|
7
|
-
Form.Field = Field;
|
|
8
|
-
Form.CustomField = CustomField;
|
|
9
|
-
Form.CheckboxGroup = CheckboxGroup;
|
|
10
|
-
Form.Checkbox = Checkbox;
|
|
11
|
-
Form.Submit = Submit;
|
|
12
|
-
Form.Fieldset = Fieldset;
|
|
13
|
-
Form.FormNavigation = FormNavigation;
|
|
14
|
-
|
|
15
|
-
export default Form;
|
package/src/styles.css
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
@layer raketa-builder {
|
|
2
|
-
.r-fieldset-wrapper {
|
|
3
|
-
margin: 0;
|
|
4
|
-
margin-bottom: 2em;
|
|
5
|
-
padding: 0;
|
|
6
|
-
border: 0;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.r-next-form-legend {
|
|
10
|
-
margin-bottom: 1em;
|
|
11
|
-
font-weight: 700;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.r-next-form-description {
|
|
15
|
-
opacity: 0.5;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.r-next-form-field-wrapper {
|
|
19
|
-
width: 100%;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.r-next-form-nav-wrapper {
|
|
23
|
-
display: flex;
|
|
24
|
-
gap: 1em;
|
|
25
|
-
flex-direction: column;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.r-next-form-nav-link {
|
|
29
|
-
color: var(--r-primary);
|
|
30
|
-
font-weight: 500;
|
|
31
|
-
text-decoration: none;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.r-next-form-nav-link:hover {
|
|
35
|
-
text-decoration: underline;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.r-next-form-checkbox-label {
|
|
39
|
-
display: block;
|
|
40
|
-
margin-bottom: 0.5rem;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.r-next-form-checkbox-label:last-of-type {
|
|
44
|
-
margin-bottom: 0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@media (min-width: 1184px) {
|
|
48
|
-
.r-next-form-fieldset-wrapper {
|
|
49
|
-
display: flex;
|
|
50
|
-
gap: 1em;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.r-next-form-legend-wrapper {
|
|
54
|
-
width: 250px;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.r-next-form-nav-wrapper {
|
|
58
|
-
position: sticky;
|
|
59
|
-
top: 80px;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@media (max-width: 1183px) {
|
|
64
|
-
.r-next-form-fieldset-wrapper {
|
|
65
|
-
width: 100%;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.r-next-form-legend-wrapper {
|
|
69
|
-
width: 100%;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.r-next-form-nav-wrapper {
|
|
73
|
-
margin-bottom: 2em;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/utils/slugify.js
DELETED