@bouko/react 2.1.8 → 2.1.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.
@@ -18,12 +18,8 @@ type Props<T> = FormSection<T> & {
18
18
  fields: FormBuilderField<T>;
19
19
  validator: ZodTypeAny;
20
20
  sound?: string;
21
- submit: {
22
- label?: string;
23
- icon?: React.ReactNode;
24
- action: (data: T) => void;
25
- cancel?: boolean;
26
- };
21
+ cancel?: boolean;
22
+ action: (data: T) => Promise<void | never>;
27
23
  };
28
24
  export declare function useSound(filename?: string): import("use-sound/dist/types").PlayFunction | undefined;
29
- export declare function FormBuilder<T>({ fields, validator, id, data, styles, update, setField, submit, sound, clear }: Props<T>): Promise<import("react/jsx-runtime").JSX.Element>;
25
+ export declare function FormBuilder<T>({ fields, validator, id, data, styles, update, setField, action, cancel, sound, clear }: Props<T>): Promise<import("react/jsx-runtime").JSX.Element>;
@@ -1,9 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useState } from "react";
4
3
  import { cn } from "@bouko/style";
5
4
  import CheckCircle from "../../assets/icons/check-circle.svg";
6
- import Spinner from "../../assets/icons/spinner.svg";
7
5
  import XCircle from "../../assets/icons/x-circle.svg";
8
6
  import { default as base } from "use-sound";
9
7
  export * from "./functions";
@@ -21,15 +19,12 @@ export function useSound(filename) {
21
19
  return;
22
20
  return base(filename)[0];
23
21
  }
24
- export async function FormBuilder({ fields, validator, id, data, styles, update, setField, submit, sound, clear }) {
22
+ export async function FormBuilder({ fields, validator, id, data, styles, update, setField, action, cancel = false, sound, clear }) {
25
23
  const fields2 = await loadJson("forms/" + id);
26
24
  const isValid = validator.safeParse(data).success;
27
- const [isLoading, setLoading] = useState(false);
28
25
  const play = useSound(sound);
29
26
  const handleSubmit = async () => {
30
- setLoading(true);
31
- await submit.action(data);
32
- setLoading(false);
27
+ await action(data);
33
28
  };
34
29
  return (_jsxs("div", { className: cn("flex flex-col w-full gap-4", styles?.container), children: [(fields2 ?? fields).map((row, i) => (_jsx(RowBox, { style: "w-full gap-5 overflow-hidden", children: row.map(({ element, id, rows, label, placeholder, disabled, options, required, note }) => {
35
30
  if (element === "input")
@@ -42,5 +37,5 @@ export async function FormBuilder({ fields, validator, id, data, styles, update,
42
37
  return (_jsx(MultipleChoice, { id: id, label: label, options: options || [], value: data[id], update: update, note: note, required: required }, id));
43
38
  else if (element === "attachment")
44
39
  return (_jsx(Attachment, { id: id, label: label, value: data[id], update: update, note: note, required: required }, id));
45
- }) }, i))), _jsxs(RowBox, { style: "items-center gap-2 mt-2 w-full", children: [_jsxs(Button, { style: cn("text-sm", styles?.submit), onClick: handleSubmit, disabled: !isValid, children: [_jsx(Spinner, { className: isLoading ? "animate-spin" : "hidden" }), _jsx("div", { className: isLoading ? "hidden" : "", children: submit.icon || _jsx(CheckCircle, {}) }), submit.label || "Submit"] }), submit.cancel !== false && (_jsxs(Button, { style: cn("text-sm text-error hover:text-error-light", styles?.cancel), variant: "ghost", onClick: clear, children: [_jsx(XCircle, {}), "Cancel"] }))] })] }));
40
+ }) }, i))), _jsxs(RowBox, { style: "items-center gap-2 mt-2 w-full", children: [_jsxs(Button, { style: cn("text-sm", styles?.submit), onClick: handleSubmit, disabled: !isValid, children: [_jsx("div", { children: _jsx(CheckCircle, {}) }), "Submit"] }), cancel !== false && (_jsxs(Button, { style: cn("text-sm text-error hover:text-error-light", styles?.cancel), variant: "ghost", onClick: clear, children: [_jsx(XCircle, {}), "Cancel"] }))] })] }));
46
41
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  "name": "@bouko/react",
4
4
 
5
- "version": "2.1.8",
5
+ "version": "2.1.9",
6
6
 
7
7
  "main": "./dist/index.js",
8
8