formeact 0.0.4 → 0.0.5

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.
@@ -36,7 +36,7 @@ export function Footer({ style, data, icon = _jsx(CheckCircle, {}), button = "Su
36
36
  toast.error(err.message);
37
37
  }
38
38
  };
39
- return (_jsxs(RowBox, { style: styles.container, children: [_jsx(Button, { style: cn(styles.submit, style), size: "sm", icon: icon, action: submitForm, disabled: !isValid, children: button }), clear && cancel && (_jsx(Button, { style: styles.cancel, size: "sm", variant: "secondary", icon: _jsx(XCircle, {}), action: clear, children: "Cancel" }))] }));
39
+ return (_jsxs(RowBox, { style: styles.container, children: [_jsx(Button, { style: cn(styles.submit, style), size: "sm", icon: icon, action: submitForm, disabled: !isValid, children: button }), clear && cancel && (_jsx(Button, { style: styles.cancel, size: "sm", variant: "surface", icon: _jsx(XCircle, {}), action: clear, children: "Cancel" }))] }));
40
40
  }
41
41
  const styles = {
42
42
  container: "items-center gap-2 mt-2 w-full",
@@ -0,0 +1,10 @@
1
+ import { FormFieldProps } from "../../core/types";
2
+ type Props<T> = {
3
+ direction?: "vertical" | "horizontal";
4
+ style?: string;
5
+ fields: FormFieldProps[][];
6
+ data: T;
7
+ update: (id: keyof T, x: string) => void;
8
+ };
9
+ export declare const FormFields: <T extends Record<string, string>>({ direction, style, fields, data, update }: Props<T>) => import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ColumnBox, RowBox, Input, ImageUploader } from "@bouko/react";
3
+ import { cn } from "@bouko/style";
4
+ export const FormFields = ({ direction = "vertical", style, fields, data, update }) => {
5
+ if (direction === "vertical")
6
+ return (_jsx(ColumnBox, { style: cn("gap-5", style), children: fields.map((row, i) => (_jsx(RowBox, { style: "w-full gap-5 items-center", children: row.map(({ element, id, label, style }) => {
7
+ if (element === "input")
8
+ return (_jsx(Input, { style: style, label: label, value: data[id], update: x => update(id, x) }, id));
9
+ if (element === "image")
10
+ return (_jsx(ImageUploader, { style: style, value: data[id], update: x => update(id, x), controls: true }, id));
11
+ }) }, i))) }));
12
+ else
13
+ return (_jsx(RowBox, { style: cn("gap-5 items-center overflow-hidden", style), children: fields.map((col, i) => (_jsx(ColumnBox, { style: cn("gap-5 overflow-hidden", i === fields.length - 1 && "grow"), children: col.map(({ element, id, label, style }) => {
14
+ if (element === "input")
15
+ return (_jsx(Input, { style: cn("w-full", style), label: label, value: data[id], update: x => update(id, x) }, id));
16
+ if (element === "image")
17
+ return (_jsx(ImageUploader, { style: style, value: data[id], update: x => update(id, x), controls: true }, id));
18
+ }) }, i))) }));
19
+ };
@@ -1,2 +1,3 @@
1
1
  export * from "./builder";
2
+ export * from "./fields";
2
3
  export { default as Input } from "./elements/input";
@@ -1,2 +1,3 @@
1
1
  export * from "./builder";
2
+ export * from "./fields";
2
3
  export { default as Input } from "./elements/input";
@@ -6,6 +6,12 @@ export type FormSection<T = string> = {
6
6
  setField: (x: string, value: T) => void;
7
7
  clear: () => void;
8
8
  };
9
+ export type FormFieldProps = {
10
+ id: string;
11
+ element: "input" | "image";
12
+ style?: string;
13
+ label?: string;
14
+ };
9
15
  export type FormBuilderField<T = unknown> = (Omit<Field<string>, "value" | "update"> & {
10
16
  id: string;
11
17
  element: string;
@@ -43,7 +49,3 @@ export type FormControls<T, K extends keyof T> = {
43
49
  update: (id: K, x: T[K]) => void;
44
50
  clear: () => void;
45
51
  };
46
- export type AuthCredentials = {
47
- email: string;
48
- password: string;
49
- };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "formeact",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
 
23
23
  "dependencies": {
24
24
  "@bouko/notify": "^0.1.8",
25
- "@bouko/react": "^2.6.6",
25
+ "@bouko/react": "^3.1.2",
26
26
  "@bouko/style": "^0.1.7",
27
27
  "@bouko/ts": "^0.2.0",
28
28
  "use-deep-compare": "^1.3.0"
@@ -1,3 +0,0 @@
1
- import { FormBuilderField } from "../../core/types";
2
- export declare function loadJson<T>(name: string): Promise<T>;
3
- export declare function loadForm<T>(name?: string): Promise<FormBuilderField<T>>;
@@ -1,16 +0,0 @@
1
- "use server";
2
- import { promises as fs } from "fs";
3
- export async function loadJson(name) {
4
- const file = await fs.readFile(process.cwd() + "/src/assets/" + name + ".json", "utf-8");
5
- return JSON.parse(file);
6
- }
7
- export async function loadForm(name) {
8
- if (!name)
9
- throw new Error("Form not found");
10
- try {
11
- return loadJson(`forms/${name}`);
12
- }
13
- catch {
14
- throw new Error(`Couldn't load form ${name}`);
15
- }
16
- }