@bouko/react 2.1.4 → 2.1.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/components/badge.d.ts +5 -0
- package/dist/components/badge.js +4 -0
- package/dist/components/flex.d.ts +16 -0
- package/dist/components/flex.js +8 -0
- package/dist/components/form/index.d.ts +3 -2
- package/dist/components/form/index.js +4 -2
- package/dist/components/form/test-next.d.ts +1 -0
- package/dist/components/form/test-next.js +6 -0
- package/dist/components/form/types.d.ts +1 -1
- package/dist/components/heading/normal.d.ts +29 -0
- package/dist/components/heading/normal.js +22 -0
- package/dist/components/heading/page.d.ts +1 -0
- package/dist/components/heading/page.js +5 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +2 -1
- package/dist/components/layout/heading.d.ts +3 -1
- package/dist/components/layout/heading.js +2 -2
- package/dist/components/search/index.d.ts +6 -0
- package/dist/components/search/index.js +12 -0
- package/dist/core/functions.d.ts +5 -2
- package/dist/core/functions.js +1 -7
- package/dist/hooks/color.d.ts +7 -0
- package/dist/hooks/color.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export default function Badge({ style, children }) {
|
|
3
|
+
return (_jsx("span", { className: "w-min px-3 py-1 bg-accent/20 border border-accent-dark rounded-full text-xs text-accent-dark font-semibold", children: children }));
|
|
4
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
type Props = Position & {
|
|
3
|
+
style?: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
type Position = {
|
|
7
|
+
center?: boolean;
|
|
8
|
+
centerX?: boolean;
|
|
9
|
+
centerY?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function ColumnBox({ style, center, centerX, centerY, children }: Props): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare function RowBox({ style, children }: {
|
|
13
|
+
style?: string;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "@bouko/style";
|
|
3
|
+
export function ColumnBox({ style, center, centerX, centerY, children }) {
|
|
4
|
+
return (_jsx("div", { className: cn("flex flex-col", center && "items-center justify-center", centerX && "items-center", centerY && "justify-center", style), children: children }));
|
|
5
|
+
}
|
|
6
|
+
export function RowBox({ style, children }) {
|
|
7
|
+
return (_jsx("div", { className: cn("flex", style), children: children }));
|
|
8
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { ZodTypeAny } from "zod";
|
|
|
2
2
|
import type { Field, Option, FormSection } from "./types";
|
|
3
3
|
export * from "./functions";
|
|
4
4
|
export * from "./types";
|
|
5
|
-
type FormBuilderField<T> = (Omit<Field<T>, "value" | "update"> & {
|
|
5
|
+
type FormBuilderField<T = unknown> = (Omit<Field<T>, "value" | "update"> & {
|
|
6
6
|
element: string;
|
|
7
7
|
rows?: number;
|
|
8
8
|
placeholder?: string;
|
|
@@ -14,6 +14,7 @@ type Props<T> = FormSection<T> & {
|
|
|
14
14
|
submit?: string;
|
|
15
15
|
cancel?: string;
|
|
16
16
|
};
|
|
17
|
+
id?: string;
|
|
17
18
|
fields: FormBuilderField<T>;
|
|
18
19
|
validator: ZodTypeAny;
|
|
19
20
|
sound?: string;
|
|
@@ -25,4 +26,4 @@ type Props<T> = FormSection<T> & {
|
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
export declare function useSound(filename?: string): import("use-sound/dist/types").PlayFunction | undefined;
|
|
28
|
-
export declare function FormBuilder<T>({ fields, validator, data, styles, update, setField, submit, sound, clear }: Props<T>): import("react/jsx-runtime").JSX.Element
|
|
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>;
|
|
@@ -15,12 +15,14 @@ import TextArea from "../textarea";
|
|
|
15
15
|
import MultipleChoice from "../multiple-choice";
|
|
16
16
|
import { Button } from "../button";
|
|
17
17
|
import Attachment from "../attachment";
|
|
18
|
+
import { loadJson } from "./test-next";
|
|
18
19
|
export function useSound(filename) {
|
|
19
20
|
if (!filename)
|
|
20
21
|
return;
|
|
21
22
|
return base(filename)[0];
|
|
22
23
|
}
|
|
23
|
-
export function FormBuilder({ fields, validator, data, styles, update, setField, submit, sound, clear }) {
|
|
24
|
+
export async function FormBuilder({ fields, validator, id, data, styles, update, setField, submit, sound, clear }) {
|
|
25
|
+
const fields2 = await loadJson("forms/" + id);
|
|
24
26
|
const isValid = validator.safeParse(data).success;
|
|
25
27
|
const [isLoading, setLoading] = useState(false);
|
|
26
28
|
const play = useSound(sound);
|
|
@@ -29,7 +31,7 @@ export function FormBuilder({ fields, validator, data, styles, update, setField,
|
|
|
29
31
|
await submit.action(data);
|
|
30
32
|
setLoading(false);
|
|
31
33
|
};
|
|
32
|
-
return (_jsxs("div", { className: cn("flex flex-col w-full gap-4", styles?.container), children: [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 }) => {
|
|
34
|
+
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 }) => {
|
|
33
35
|
if (element === "input")
|
|
34
36
|
return (_jsx(Input, { id: id, styles: { container: "flex-1" }, label: label, placeholder: placeholder, value: data[id], update: x => setField(id, x), disabled: disabled, note: note, required: required }, id));
|
|
35
37
|
else if (element === "select")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadJson<T>(name: string): Promise<T>;
|
|
@@ -3,7 +3,7 @@ export type SetState<T> = Dispatch<SetStateAction<T>>;
|
|
|
3
3
|
export type FormSection<T> = {
|
|
4
4
|
data: T;
|
|
5
5
|
update: SetState<T>;
|
|
6
|
-
setField: (x:
|
|
6
|
+
setField: (x: string, value: unknown) => void;
|
|
7
7
|
clear: () => void;
|
|
8
8
|
};
|
|
9
9
|
export type Field<T, K = string> = {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
badge?: string;
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
subtitle?: ReactNode;
|
|
6
|
+
style?: Styles;
|
|
7
|
+
};
|
|
8
|
+
type Styles = {
|
|
9
|
+
container?: string;
|
|
10
|
+
badge?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
subtitle?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Text heading with badge, title, subtitle.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} badge - Little note above the title (optional).
|
|
18
|
+
* @param {ReactNode} title - Main title content.
|
|
19
|
+
* @param {ReactNode} subtitle - Subtitle content (optional).
|
|
20
|
+
* @param {Styles} style - Additional styles (optional).
|
|
21
|
+
**/
|
|
22
|
+
export default function Heading({ badge, title, subtitle, style }: Props): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export {};
|
|
24
|
+
/**
|
|
25
|
+
* Problems
|
|
26
|
+
*
|
|
27
|
+
* - Perfect `Badge`
|
|
28
|
+
* - Long `subtitle` style
|
|
29
|
+
**/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { mergeStyles } from "@bouko/style";
|
|
3
|
+
import { RowBox, ColumnBox } from "../layout/flex";
|
|
4
|
+
import { Badge } from "../text/badge";
|
|
5
|
+
/**
|
|
6
|
+
* Text heading with badge, title, subtitle.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} badge - Little note above the title (optional).
|
|
9
|
+
* @param {ReactNode} title - Main title content.
|
|
10
|
+
* @param {ReactNode} subtitle - Subtitle content (optional).
|
|
11
|
+
* @param {Styles} style - Additional styles (optional).
|
|
12
|
+
**/
|
|
13
|
+
export default function Heading({ badge, title, subtitle, style = {} }) {
|
|
14
|
+
const styles = mergeStyles(base, style);
|
|
15
|
+
return (_jsxs(ColumnBox, { style: styles.container, children: [_jsx(Badge, { style: styles.badge, children: badge }), _jsx(RowBox, { style: styles.title, children: title }), _jsx(RowBox, { style: styles.subtitle, children: subtitle })] }));
|
|
16
|
+
}
|
|
17
|
+
const base = {
|
|
18
|
+
container: "items-center",
|
|
19
|
+
badge: "mb-2",
|
|
20
|
+
title: "items-center gap-2 text-xl sm:text-2xl 2xl:text-3xl font-bold text-primary",
|
|
21
|
+
subtitle: "items-center gap-2 max-sm:text-sm 2xl:text-lg text-center text-primary-light dark:text-primary-dark"
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function PageHeading(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { default as Heading } from "./layout/heading";
|
|
2
1
|
export { default as Separator } from "./layout/separator";
|
|
3
2
|
export { default as FadeBox } from "./layout/fade";
|
|
3
|
+
export { default as Heading } from "./heading/normal";
|
|
4
|
+
export { default as PageHeading } from "./heading/page";
|
|
4
5
|
export * from "./layout/flex";
|
|
5
6
|
export { default as Badge } from "./text/badge";
|
|
6
7
|
export { default as Dropdown } from "./dropdown/normal";
|
package/dist/components/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { default as Heading } from "./layout/heading";
|
|
2
1
|
export { default as Separator } from "./layout/separator";
|
|
3
2
|
export { default as FadeBox } from "./layout/fade";
|
|
3
|
+
export { default as Heading } from "./heading/normal";
|
|
4
|
+
export { default as PageHeading } from "./heading/page";
|
|
4
5
|
export * from "./layout/flex";
|
|
5
6
|
export { default as Badge } from "./text/badge";
|
|
6
7
|
export { default as Dropdown } from "./dropdown/normal";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { mergeStyles } from "@bouko/style";
|
|
3
3
|
import { RowBox, ColumnBox } from "./flex";
|
|
4
|
-
import { Badge } from "../text/badge";
|
|
4
|
+
import { default as Badge } from "../text/badge";
|
|
5
5
|
/**
|
|
6
6
|
* Text heading with badge, title, subtitle.
|
|
7
7
|
*
|
|
@@ -18,5 +18,5 @@ const base = {
|
|
|
18
18
|
container: "items-center",
|
|
19
19
|
badge: "mb-2",
|
|
20
20
|
title: "items-center gap-2 text-xl sm:text-2xl 2xl:text-3xl font-bold text-primary",
|
|
21
|
-
subtitle: "items-center gap-2 max-sm:text-sm 2xl:text-lg text-
|
|
21
|
+
subtitle: "items-center gap-2 max-sm:text-sm 2xl:text-lg text-primary-light dark:text-primary-dark"
|
|
22
22
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { RowBox } from "../flex";
|
|
5
|
+
import { Button } from "../button";
|
|
6
|
+
export default function SearchBar({ placeholder, action }) {
|
|
7
|
+
const [query, search] = useState("");
|
|
8
|
+
return (_jsxs(RowBox, { style: styles.container, children: [_jsxs("div", { className: "relative grow", children: [_jsx("input", { className: "w-full outline-none lowercase text-lg placeholder-slate-500 tracking-wide", placeholder: placeholder, value: query, onChange: (e) => search(e.target.value), onKeyUp: (e) => e.key === "Enter" ? action(query) : null }), _jsx("div", { className: "absolute top-0 right-0 w-12 h-full bg-gradient-to-l from-slate-950" })] }), _jsx(Button, { size: "sm", style: "gap-[0.4rem] font-extrabold py-1 px-3 font-mono", onClick: () => action(query), children: "GO" })] }));
|
|
9
|
+
}
|
|
10
|
+
const styles = {
|
|
11
|
+
container: "items-center gap-6 w-xl pl-5 pr-4 py-3 bg-slate-950 border border-border rounded-md"
|
|
12
|
+
};
|
package/dist/core/functions.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export declare const getFilesData: (files: File[]) => Promise<
|
|
1
|
+
export declare const getFilesData: (files: File[]) => Promise<{
|
|
2
|
+
filename: string;
|
|
3
|
+
mimetype: string;
|
|
4
|
+
data?: string;
|
|
5
|
+
}[]>;
|
|
2
6
|
export declare const getFileData: (file: File) => Promise<{
|
|
3
7
|
filename: string;
|
|
4
8
|
mimetype: string;
|
|
@@ -6,5 +10,4 @@ export declare const getFileData: (file: File) => Promise<{
|
|
|
6
10
|
}>;
|
|
7
11
|
export declare const bufferToFile: (buffer: Buffer<ArrayBuffer>, name?: string) => Promise<File>;
|
|
8
12
|
export declare const getAudioDuration: (file: File) => Promise<number>;
|
|
9
|
-
export declare const getEnv: (key: string) => string;
|
|
10
13
|
export declare function getBase64(image: string): Promise<string>;
|
package/dist/core/functions.js
CHANGED
|
@@ -4,7 +4,7 @@ export const getFilesData = (files) => Promise.all(files.map((file) => {
|
|
|
4
4
|
const reader = new FileReader();
|
|
5
5
|
reader.onload = () => {
|
|
6
6
|
const base64 = reader.result?.toString().split(",")[1]; // Remove data prefix
|
|
7
|
-
resolve({
|
|
7
|
+
return resolve({
|
|
8
8
|
filename: file.name,
|
|
9
9
|
mimetype: file.type,
|
|
10
10
|
data: base64,
|
|
@@ -57,12 +57,6 @@ export const getAudioDuration = (file) => {
|
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
};
|
|
60
|
-
export const getEnv = (key) => {
|
|
61
|
-
const value = process.env[key];
|
|
62
|
-
if (!value)
|
|
63
|
-
throw new Error(`Missing required env: ${key}`);
|
|
64
|
-
return value;
|
|
65
|
-
};
|
|
66
60
|
export async function getBase64(image) {
|
|
67
61
|
if (image.startsWith("data:")) {
|
|
68
62
|
return image; // already a base64 data URL
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
export default function useColor({ variable, color, original }) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
document.documentElement.style.setProperty(`--${variable}`, color);
|
|
6
|
+
return () => document.documentElement.style.setProperty(`--${variable}`, original);
|
|
7
|
+
}, []);
|
|
8
|
+
}
|