@bouko/react 2.1.7 → 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.
- package/dist/assets/icons/angles-right.svg +6 -0
- package/dist/assets/icons/check copy.svg +6 -0
- package/dist/assets/icons/check-circle copy.svg +6 -0
- package/dist/assets/icons/chevron copy.svg +6 -0
- package/dist/assets/icons/paperclip copy.svg +6 -0
- package/dist/assets/icons/spinner copy.svg +6 -0
- package/dist/assets/icons/x-circle copy.svg +6 -0
- package/dist/components/form/index.d.ts +3 -7
- package/dist/components/form/index.js +3 -8
- package/dist/hooks/clock/interval.d.ts +1 -1
- package/dist/hooks/clock/interval.js +3 -3
- package/package.json +29 -4
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="1em" height="1em">
|
|
2
|
+
<path
|
|
3
|
+
d="M470.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 256 265.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160zm-352 160l160-160c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L210.7 256 73.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z"
|
|
4
|
+
fill="currentColor"
|
|
5
|
+
/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" width="1em" height="1em">
|
|
2
|
+
<path
|
|
3
|
+
d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"
|
|
4
|
+
fill="currentColor"
|
|
5
|
+
/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="1em" height="1em">
|
|
2
|
+
<path
|
|
3
|
+
d="M256 48a208 208 0 1 1 0 416 208 208 0 1 1 0-416zm0 464A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM369 209c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-111 111-47-47c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l64 64c9.4 9.4 24.6 9.4 33.9 0L369 209z"
|
|
4
|
+
fill="currentColor"
|
|
5
|
+
/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="1em" height="1em">
|
|
2
|
+
<path
|
|
3
|
+
d="M233.4 406.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 338.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"
|
|
4
|
+
fill="currentColor"
|
|
5
|
+
/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" width="1em" height="1em">
|
|
2
|
+
<path
|
|
3
|
+
d="M364.2 83.8c-24.4-24.4-64-24.4-88.4 0l-184 184c-42.1 42.1-42.1 110.3 0 152.4s110.3 42.1 152.4 0l152-152c10.9-10.9 28.7-10.9 39.6 0s10.9 28.7 0 39.6l-152 152c-64 64-167.6 64-231.6 0s-64-167.6 0-231.6l184-184c46.3-46.3 121.3-46.3 167.6 0s46.3 121.3 0 167.6l-176 176c-28.6 28.6-75 28.6-103.6 0s-28.6-75 0-103.6l144-144c10.9-10.9 28.7-10.9 39.6 0s10.9 28.7 0 39.6l-144 144c-6.7 6.7-6.7 17.7 0 24.4s17.7 6.7 24.4 0l176-176c24.4-24.4 24.4-64 0-88.4z"
|
|
4
|
+
fill="currentColor"
|
|
5
|
+
/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="1em" height="1em">
|
|
2
|
+
<path
|
|
3
|
+
d="M304 48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zm0 416a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM48 304a48 48 0 1 0 0-96 48 48 0 1 0 0 96zm464-48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM142.9 437A48 48 0 1 0 75 369.1 48 48 0 1 0 142.9 437zm0-294.2A48 48 0 1 0 75 75a48 48 0 1 0 67.9 67.9zM369.1 437A48 48 0 1 0 437 369.1 48 48 0 1 0 369.1 437z"
|
|
4
|
+
fill="currentColor"
|
|
5
|
+
/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="1em" height="1em">
|
|
2
|
+
<path
|
|
3
|
+
d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z"
|
|
4
|
+
fill="currentColor"
|
|
5
|
+
/>
|
|
6
|
+
</svg>
|
|
@@ -18,12 +18,8 @@ type Props<T> = FormSection<T> & {
|
|
|
18
18
|
fields: FormBuilderField<T>;
|
|
19
19
|
validator: ZodTypeAny;
|
|
20
20
|
sound?: string;
|
|
21
|
-
|
|
22
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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(
|
|
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
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function useInterval(action: () => boolean | void
|
|
1
|
+
export default function useInterval(action: () => Promise<boolean | void>, delay: number): void;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
3
|
export default function useInterval(action, delay) {
|
|
4
|
-
const ref = useRef(() => false);
|
|
4
|
+
const ref = useRef(async () => false);
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
ref.current = action;
|
|
7
7
|
}, [action]);
|
|
8
8
|
useEffect(() => {
|
|
9
|
-
const tick = () => {
|
|
10
|
-
const stop = ref.current();
|
|
9
|
+
const tick = async () => {
|
|
10
|
+
const stop = await ref.current();
|
|
11
11
|
if (stop && id)
|
|
12
12
|
clearInterval(id);
|
|
13
13
|
};
|
package/package.json
CHANGED
|
@@ -1,35 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "@bouko/react",
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
"version": "2.1.9",
|
|
6
|
+
|
|
5
7
|
"main": "./dist/index.js",
|
|
8
|
+
|
|
6
9
|
"types": "./dist/index.d.ts",
|
|
10
|
+
|
|
7
11
|
"license": "MIT",
|
|
12
|
+
|
|
8
13
|
"files": [
|
|
14
|
+
|
|
9
15
|
"dist"
|
|
16
|
+
|
|
10
17
|
],
|
|
18
|
+
|
|
11
19
|
"publishConfig": {
|
|
20
|
+
|
|
12
21
|
"access": "public"
|
|
22
|
+
|
|
13
23
|
},
|
|
24
|
+
|
|
14
25
|
"author": "",
|
|
26
|
+
|
|
15
27
|
"description": "",
|
|
28
|
+
|
|
16
29
|
"engines": {},
|
|
17
30
|
|
|
18
31
|
"scripts": {
|
|
32
|
+
|
|
19
33
|
"build": "tsc"
|
|
34
|
+
|
|
20
35
|
},
|
|
21
36
|
|
|
22
37
|
"dependencies": {
|
|
38
|
+
|
|
23
39
|
"@bouko/audio": "^0.1.0",
|
|
40
|
+
|
|
24
41
|
"@bouko/style": "^0.1.6",
|
|
42
|
+
|
|
25
43
|
"clsx": "^2.1.1",
|
|
44
|
+
|
|
26
45
|
"file-type": "^21.0.0",
|
|
46
|
+
|
|
27
47
|
"framer-motion": "^12.23.6",
|
|
48
|
+
|
|
49
|
+
"ms": "^2.1.3",
|
|
50
|
+
|
|
28
51
|
"tailwind-merge": "^3.3.1",
|
|
52
|
+
|
|
29
53
|
"tailwind-variants": "^1.0.0",
|
|
54
|
+
|
|
30
55
|
"zod": "^4.0.13"
|
|
31
|
-
},
|
|
32
56
|
|
|
33
|
-
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
34
60
|
|
|
35
|
-
}
|