@raketa-builder/next-form 1.3.6 → 1.3.9

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/index.js CHANGED
@@ -1,333 +1,25 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
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
+ 'use strict';
2
+
3
+ var Form = require('./Form');
4
+ var Fields = require('./Fields');
5
+ var Submit = require('./Submit');
6
+ var Fieldset = require('./Fieldset');
7
+ var FormNavigation = require('./FormNavigation');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var Form__default = /*#__PURE__*/_interopDefault(Form);
12
+ var Submit__default = /*#__PURE__*/_interopDefault(Submit);
13
+ var Fieldset__default = /*#__PURE__*/_interopDefault(Fieldset);
14
+ var FormNavigation__default = /*#__PURE__*/_interopDefault(FormNavigation);
15
+
16
+ Form__default.default.Field = Fields.Field;
17
+ Form__default.default.CustomField = Fields.CustomField;
18
+ Form__default.default.CheckboxGroup = Fields.CheckboxGroup;
19
+ Form__default.default.Checkbox = Fields.Checkbox;
20
+ Form__default.default.Submit = Submit__default.default;
21
+ Form__default.default.Fieldset = Fieldset__default.default;
22
+ Form__default.default.FormNavigation = FormNavigation__default.default;
23
+ var index_default = Form__default.default;
24
+
25
+ module.exports = index_default;
package/package.json CHANGED
@@ -1,8 +1,22 @@
1
1
  {
2
2
  "name": "@raketa-builder/next-form",
3
- "version": "1.3.6",
3
+ "version": "1.3.9",
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
22
  "build": "tsup src/index.js --format cjs --loader \".js=jsx\"",
@@ -15,7 +29,7 @@
15
29
  "react-dom": "19.1.0"
16
30
  },
17
31
  "dependencies": {
18
- "@raketa-builder/ui": "1.3.6"
32
+ "@raketa-builder/ui": "1.3.9"
19
33
  },
20
34
  "devDependencies": {
21
35
  "@biomejs/biome": "1.9.4",
package/CHANGELOG.md DELETED
@@ -1,13 +0,0 @@
1
- # @raketa-builder/next-form
2
-
3
- ## 0.2.0
4
-
5
- ### Minor Changes
6
-
7
- - Update the form onSubmit callback signature
8
-
9
- ## 0.1.0
10
-
11
- ### Minor Changes
12
-
13
- - First publishing of @raketa-builder/next-form
package/biome.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["../../biome.json"]
3
- }
package/src/Context.js DELETED
@@ -1,3 +0,0 @@
1
- import React from "react";
2
-
3
- export default React.createContext({});
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
- &nbsp;
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
- &nbsp;
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;
@@ -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
- }
@@ -1,7 +0,0 @@
1
- const slugify = (string) =>
2
- string
3
- .toLowerCase()
4
- .replace(/[^a-z0-9]+/g, "-")
5
- .replace(/(^-|-$)/g, "");
6
-
7
- export default slugify;
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "tsconfig/react-library.json",
3
- "include": ["src"],
4
- "exclude": ["dist", "build", "node_modules"],
5
- }