@ttoss/forms 0.5.4 → 0.5.6
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/esm/index.js +85 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +114 -0
- package/package.json +3 -3
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
3
|
+
|
|
4
|
+
// tsup.inject.js
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
|
|
7
|
+
// src/Form.tsx
|
|
8
|
+
import * as React2 from "react";
|
|
9
|
+
import { Box } from "@ttoss/ui";
|
|
10
|
+
import { FormProvider } from "react-hook-form";
|
|
11
|
+
var Form = ({
|
|
12
|
+
children,
|
|
13
|
+
onSubmit,
|
|
14
|
+
sx,
|
|
15
|
+
...formMethods
|
|
16
|
+
}) => {
|
|
17
|
+
return /* @__PURE__ */ React2.createElement(FormProvider, {
|
|
18
|
+
...formMethods
|
|
19
|
+
}, /* @__PURE__ */ React2.createElement(Box, {
|
|
20
|
+
as: "form",
|
|
21
|
+
variant: "forms.form",
|
|
22
|
+
onSubmit: formMethods.handleSubmit((data) => onSubmit(data)),
|
|
23
|
+
sx
|
|
24
|
+
}, children));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/FormFieldInput.tsx
|
|
28
|
+
import { Box as Box2, Input, Label } from "@ttoss/ui";
|
|
29
|
+
|
|
30
|
+
// src/ErrorMessage.tsx
|
|
31
|
+
import { useFormContext } from "react-hook-form";
|
|
32
|
+
import { ErrorMessage as HookFormErrorMessage } from "@hookform/error-message";
|
|
33
|
+
import { Text } from "@ttoss/ui";
|
|
34
|
+
var ErrorMessage = ({
|
|
35
|
+
name
|
|
36
|
+
}) => {
|
|
37
|
+
const {
|
|
38
|
+
formState: { errors }
|
|
39
|
+
} = useFormContext();
|
|
40
|
+
return /* @__PURE__ */ React.createElement(HookFormErrorMessage, {
|
|
41
|
+
errors,
|
|
42
|
+
name,
|
|
43
|
+
as: /* @__PURE__ */ React.createElement(Text, {
|
|
44
|
+
variant: "text.error",
|
|
45
|
+
role: "alert"
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/FormFieldInput.tsx
|
|
51
|
+
import { useController } from "react-hook-form";
|
|
52
|
+
var FormFieldInput = ({
|
|
53
|
+
label,
|
|
54
|
+
name
|
|
55
|
+
}) => {
|
|
56
|
+
const {
|
|
57
|
+
field: { onChange, onBlur, value, ref }
|
|
58
|
+
} = useController({
|
|
59
|
+
name,
|
|
60
|
+
defaultValue: ""
|
|
61
|
+
});
|
|
62
|
+
const id = `form-field-input-${name}`;
|
|
63
|
+
return /* @__PURE__ */ React.createElement(Box2, null, label && /* @__PURE__ */ React.createElement(Label, {
|
|
64
|
+
htmlFor: id
|
|
65
|
+
}, label), /* @__PURE__ */ React.createElement(Input, {
|
|
66
|
+
ref,
|
|
67
|
+
onChange,
|
|
68
|
+
onBlur,
|
|
69
|
+
value,
|
|
70
|
+
name,
|
|
71
|
+
id
|
|
72
|
+
}), /* @__PURE__ */ React.createElement(ErrorMessage, {
|
|
73
|
+
name
|
|
74
|
+
}));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/FormField.tsx
|
|
78
|
+
var FormField = () => {
|
|
79
|
+
return null;
|
|
80
|
+
};
|
|
81
|
+
FormField.Input = FormFieldInput;
|
|
82
|
+
export {
|
|
83
|
+
Form,
|
|
84
|
+
FormField
|
|
85
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FieldValues } from 'react-hook-form';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { BoxProps } from '@ttoss/ui';
|
|
5
|
+
|
|
6
|
+
declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
onSubmit: (data: TFieldValues) => Promise<void> | void;
|
|
9
|
+
sx?: BoxProps['sx'];
|
|
10
|
+
} & {
|
|
11
|
+
children: React.ReactNode | React.ReactNode[];
|
|
12
|
+
} & react_hook_form.UseFormReturn<TFieldValues, any>) => JSX.Element;
|
|
13
|
+
|
|
14
|
+
declare const FormField: {
|
|
15
|
+
(): null;
|
|
16
|
+
Input: <TFieldValues extends react_hook_form.FieldValues = react_hook_form.FieldValues>({ label, name, }: {
|
|
17
|
+
label?: string | undefined;
|
|
18
|
+
name: react_hook_form.Path<TFieldValues>;
|
|
19
|
+
}) => JSX.Element;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { Form, FormField };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
|
|
24
|
+
// src/index.ts
|
|
25
|
+
var src_exports = {};
|
|
26
|
+
__export(src_exports, {
|
|
27
|
+
Form: () => Form,
|
|
28
|
+
FormField: () => FormField
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(src_exports);
|
|
31
|
+
|
|
32
|
+
// tsup.inject.js
|
|
33
|
+
var React = __toESM(require("react"));
|
|
34
|
+
|
|
35
|
+
// src/Form.tsx
|
|
36
|
+
var React2 = __toESM(require("react"));
|
|
37
|
+
var import_ui = require("@ttoss/ui");
|
|
38
|
+
var import_react_hook_form = require("react-hook-form");
|
|
39
|
+
var Form = ({
|
|
40
|
+
children,
|
|
41
|
+
onSubmit,
|
|
42
|
+
sx,
|
|
43
|
+
...formMethods
|
|
44
|
+
}) => {
|
|
45
|
+
return /* @__PURE__ */ React2.createElement(import_react_hook_form.FormProvider, {
|
|
46
|
+
...formMethods
|
|
47
|
+
}, /* @__PURE__ */ React2.createElement(import_ui.Box, {
|
|
48
|
+
as: "form",
|
|
49
|
+
variant: "forms.form",
|
|
50
|
+
onSubmit: formMethods.handleSubmit((data) => onSubmit(data)),
|
|
51
|
+
sx
|
|
52
|
+
}, children));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/FormFieldInput.tsx
|
|
56
|
+
var import_ui3 = require("@ttoss/ui");
|
|
57
|
+
|
|
58
|
+
// src/ErrorMessage.tsx
|
|
59
|
+
var import_react_hook_form2 = require("react-hook-form");
|
|
60
|
+
var import_error_message = require("@hookform/error-message");
|
|
61
|
+
var import_ui2 = require("@ttoss/ui");
|
|
62
|
+
var ErrorMessage = ({
|
|
63
|
+
name
|
|
64
|
+
}) => {
|
|
65
|
+
const {
|
|
66
|
+
formState: { errors }
|
|
67
|
+
} = (0, import_react_hook_form2.useFormContext)();
|
|
68
|
+
return /* @__PURE__ */ React.createElement(import_error_message.ErrorMessage, {
|
|
69
|
+
errors,
|
|
70
|
+
name,
|
|
71
|
+
as: /* @__PURE__ */ React.createElement(import_ui2.Text, {
|
|
72
|
+
variant: "text.error",
|
|
73
|
+
role: "alert"
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/FormFieldInput.tsx
|
|
79
|
+
var import_react_hook_form3 = require("react-hook-form");
|
|
80
|
+
var FormFieldInput = ({
|
|
81
|
+
label,
|
|
82
|
+
name
|
|
83
|
+
}) => {
|
|
84
|
+
const {
|
|
85
|
+
field: { onChange, onBlur, value, ref }
|
|
86
|
+
} = (0, import_react_hook_form3.useController)({
|
|
87
|
+
name,
|
|
88
|
+
defaultValue: ""
|
|
89
|
+
});
|
|
90
|
+
const id = `form-field-input-${name}`;
|
|
91
|
+
return /* @__PURE__ */ React.createElement(import_ui3.Box, null, label && /* @__PURE__ */ React.createElement(import_ui3.Label, {
|
|
92
|
+
htmlFor: id
|
|
93
|
+
}, label), /* @__PURE__ */ React.createElement(import_ui3.Input, {
|
|
94
|
+
ref,
|
|
95
|
+
onChange,
|
|
96
|
+
onBlur,
|
|
97
|
+
value,
|
|
98
|
+
name,
|
|
99
|
+
id
|
|
100
|
+
}), /* @__PURE__ */ React.createElement(ErrorMessage, {
|
|
101
|
+
name
|
|
102
|
+
}));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/FormField.tsx
|
|
106
|
+
var FormField = () => {
|
|
107
|
+
return null;
|
|
108
|
+
};
|
|
109
|
+
FormField.Input = FormFieldInput;
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
Form,
|
|
113
|
+
FormField
|
|
114
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@hookform/resolvers": "^2.9.8",
|
|
30
30
|
"@ttoss/config": "^1.18.3",
|
|
31
31
|
"@ttoss/test-utils": "^1.16.10",
|
|
32
|
-
"@ttoss/ui": "^1.
|
|
32
|
+
"@ttoss/ui": "^1.21.1",
|
|
33
33
|
"@types/jest": "^29.0.3",
|
|
34
34
|
"jest": "^29.0.3",
|
|
35
35
|
"react": "^18.2.0",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "3879642eff43efd073abf52595ed0efe7196946a"
|
|
46
46
|
}
|