@bouko/react 2.3.3 → 2.3.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.
@@ -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>
@@ -1,2 +1,2 @@
1
- import { type Field } from "./form";
1
+ import { type Field } from "./form/types";
2
2
  export default function Attachment<T>({ id, style, label, value, update, required, note }: Field<T, File[]>): import("react/jsx-runtime").JSX.Element;
@@ -1,12 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useRef } from "react";
3
3
  import PaperClip from "../assets/icons/paperclip.svg";
4
- import { setField } from "./form";
4
+ import { setField } from "./form/functions";
5
5
  import { cn } from "@bouko/style";
6
6
  export default function Attachment({ id, style, label, value, update, required = true, note }) {
7
7
  const ref = useRef(null);
8
8
  const handleFileChange = (e) => {
9
- if (e.target.files)
9
+ if (e.target.files && id)
10
10
  setField(update, id, [e.target.files[0]]);
11
11
  };
12
12
  return (_jsxs("div", { className: cn(styles.container, style), children: [label && _jsxs("span", { className: styles.label, children: [label, " ", !required ? _jsx("span", { className: "italic text-slate-400", children: "(optional)" }) : ""] }), _jsxs("div", { onClick: () => ref.current?.click(), className: "flex flex-col justify-center items-center py-3 gap-1 w-full cursor-pointer duration-200 hover:bg-slate-200/40 rounded border-2 border-slate-300 border-dashed", children: [!value || value.length === 0 && (_jsxs(_Fragment, { children: [_jsxs("span", { className: "flex gap-2 items-center font-semibold text-sm", children: [_jsx(PaperClip, {}), "Drag and drop files, paste screenshots, or"] }), _jsx("span", { className: "text-xs text-slate-500", children: "browse" }), _jsx("input", { type: "file", className: "hidden", onChange: handleFileChange, ref: ref })] })), value && value.length > 0 && value.map((x, i) => (_jsx("span", { className: "text-xs text-slate-500", children: x.name }, i)))] }), note && _jsx("span", { className: styles.note, children: note })] }));
@@ -0,0 +1,5 @@
1
+ import type { ReactNode } from "react";
2
+ export default function Badge({ style, children }: {
3
+ style?: string;
4
+ children: ReactNode;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -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
+ }
@@ -0,0 +1,16 @@
1
+ import { Field, Option } from "./types";
2
+ export type FormBuilderField<T = unknown> = (Omit<Field<T>, "value" | "update"> & {
3
+ id: string;
4
+ element: string;
5
+ rows?: number;
6
+ placeholder?: string;
7
+ options?: Option[];
8
+ })[][];
9
+ type Props<T> = {
10
+ id?: string;
11
+ fields: FormBuilderField<T>;
12
+ data: T;
13
+ setField: (x: string, y: unknown) => void;
14
+ };
15
+ export default function Fields<T>({ fields, data, setField }: Props<T>): Promise<import("react/jsx-runtime").JSX.Element[]>;
16
+ export {};
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { RowBox } from "../layout/flex";
3
+ import Input from "../input";
4
+ import Select from "../select";
5
+ import TextArea from "../textarea";
6
+ import MultipleChoice from "../multiple-choice";
7
+ import Attachment from "../attachment";
8
+ export default async function Fields({ fields, data, setField }) {
9
+ return 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 }) => {
10
+ if (element === "input")
11
+ 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));
12
+ else if (element === "select")
13
+ return (_jsx(Select, { id: id, label: label, placeholder: placeholder, options: options || [], value: data[id], update: x => setField(id, x), note: note, required: required }, id));
14
+ else if (element === "textarea")
15
+ return (_jsx(TextArea, { id: id, label: label, placeholder: placeholder, rows: rows, value: data[id], update: x => setField(id, x), note: note, required: required }, id));
16
+ else if (element === "multiple-choice")
17
+ return (_jsx(MultipleChoice, { id: id, label: label, options: options || [], value: data[id], update: x => setField(id, x), note: note, required: required }, id));
18
+ else if (element === "attachment")
19
+ return (_jsx(Attachment, { id: id, label: label, value: data[id], update: x => setField(id, x), note: note, required: required }, id));
20
+ }) }, i)));
21
+ }
@@ -3,8 +3,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useState } from "react";
4
4
  import { Button } from "../button";
5
5
  import { RowBox } from "../layout/flex";
6
- import CheckCircle from "./assets/check-circle.svg";
7
- import Spinner from "./assets/spinner.svg";
6
+ import CheckCircle from "../../assets/icons/check-circle.svg";
7
+ import Spinner from "../../assets/icons/spinner.svg";
8
8
  export default function FormFooter({ data, validator, submit, clear }) {
9
9
  const isValid = validator.safeParse(data).success;
10
10
  const [isLoading, setLoading] = useState(false);
@@ -0,0 +1,3 @@
1
+ import { FormBuilderField } from "./fields";
2
+ export declare function loadJson<T>(name: string): Promise<T>;
3
+ export declare function loadForm<T>(name?: string): Promise<FormBuilderField<T>>;
@@ -0,0 +1,11 @@
1
+ "use server";
2
+ import { promises as fs } from "fs";
3
+ export async function loadJson(name) {
4
+ const file = await fs.readFile(process.cwd() + "/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
+ return loadJson(`forms/${name}`);
11
+ }
@@ -0,0 +1 @@
1
+ export declare function loadJson<T>(name: string): Promise<T>;
@@ -0,0 +1,6 @@
1
+ "use server";
2
+ import { promises as fs } from "fs";
3
+ export async function loadJson(name) {
4
+ const file = await fs.readFile(process.cwd() + "/assets/" + name + ".json", "utf-8");
5
+ return JSON.parse(file);
6
+ }
@@ -35,3 +35,4 @@ export type OptionField<T> = Field<T> & {
35
35
  export type Form<T> = {
36
36
  data: T;
37
37
  };
38
+ export type FormSubmit<T> = (data: T, clear?: () => void) => Promise<void>;
@@ -24,6 +24,8 @@ export {};
24
24
  /**
25
25
  * Problems
26
26
  *
27
+ * - Perfect `mergeStyles`
28
+ * - Perfect `RowBox`
29
+ * - Perfect `ColumnBox`
27
30
  * - Perfect `Badge`
28
- * - Long `subtitle` style
29
31
  **/
@@ -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-center text-primary-light dark:text-primary-dark"
21
+ subtitle: "items-center gap-2 max-sm:text-sm 2xl:text-lg text-primary-light dark:text-primary-dark"
22
22
  };
@@ -1,2 +1,2 @@
1
- import { type OptionField } from "./form";
1
+ import { type OptionField } from "./form/types";
2
2
  export default function MultipleChoice<T>({ id, label, options, style, value, update, required }: OptionField<T>): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import Field from "./field";
3
- import { setField } from "./form";
3
+ import { setField } from "./form/functions";
4
4
  import { cn } from "@bouko/style";
5
5
  export default function MultipleChoice({ id, label, options, style, value, update, required = true }) {
6
- return (_jsx(Field, { style: style, label: label, required: required, children: _jsx("div", { className: styles.options, children: options.map((x, i) => (_jsxs("div", { className: styles.item, children: [_jsx(Dot, { ...x, active: x.id === value, select: () => setField(update, id, x.id) }), x.label] }, i))) }) }));
6
+ return (_jsx(Field, { style: style, label: label, required: required, children: _jsx("div", { className: styles.options, children: options.map((x, i) => (_jsxs("div", { className: styles.item, children: [_jsx(Dot, { ...x, active: x.id === value, select: () => id ? setField(update, id, x.id) : null }), x.label] }, i))) }) }));
7
7
  }
8
8
  const Dot = ({ active, select }) => (_jsx("div", { className: cn(styles.dot, active && "bg-accent border-accent-dark"), onClick: select }));
9
9
  const styles = {
@@ -0,0 +1,6 @@
1
+ type Props = {
2
+ placeholder?: string;
3
+ action: (query: string) => void;
4
+ };
5
+ export default function SearchBar({ placeholder, action }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -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
+ };
@@ -1,4 +1,4 @@
1
- import { type OptionField } from "./form";
1
+ import { type OptionField } from "./form/types";
2
2
  type Props<T> = OptionField<T> & {
3
3
  placeholder?: string;
4
4
  };
@@ -3,13 +3,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useState } from "react";
4
4
  import { AnimatePresence, motion } from "framer-motion";
5
5
  import Chevron from "../assets/icons/chevron.svg";
6
- import { setField } from "./form";
6
+ import { setField } from "./form/functions";
7
7
  import { cn } from "@bouko/style";
8
8
  export default function Select({ id, style, label, required = true, value, options, update, note }) {
9
9
  const [isOpen, setOpen] = useState(false);
10
10
  const active = options.find(x => x.id === value);
11
11
  const select = (x) => {
12
- setField(update, id, x);
12
+ if (id)
13
+ setField(update, id, x);
13
14
  setOpen(false);
14
15
  };
15
16
  return (_jsxs("div", { className: cn(styles.container, style), children: [_jsxs("div", { className: styles.subcontainer, children: [label && _jsxs("span", { className: styles.label, children: [label, " ", !required ? _jsx("span", { className: "italic text-slate-400", children: "(optional)" }) : ""] }), _jsxs("div", { className: cn(styles.trigger, !active?.label && "capitalize"), onClick: () => setOpen(x => !x), children: [active ? active.label ?? active.id : "None", _jsx(Chevron, { className: cn("text-xs text-slate-400 duration-200", isOpen && "rotate-180") })] }), note && !isOpen && _jsx("span", { className: styles.note, children: note })] }), _jsx(AnimatePresence, { children: isOpen && (_jsx(motion.div, { className: styles.dropdown, initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, children: options.map(({ id, label }) => (_jsx("span", { className: cn("w-full p-2 border-l-3 border-transparent hover:text-blue-600 duration-200 cursor-pointer", active?.id === id && "border-blue-600 bg-blue-500/10", !label && "capitalize"), onClick: () => select(id), children: label ?? id }, id))) }, "dropdown")) })] }));
@@ -1,4 +1,4 @@
1
- import { type Field as FieldProps } from "./form";
1
+ import { type Field as FieldProps } from "./form/types";
2
2
  type Props<T> = FieldProps<T> & {
3
3
  rows?: number;
4
4
  placeholder?: string;
@@ -0,0 +1,7 @@
1
+ type Props = {
2
+ variable: string;
3
+ color: string;
4
+ original: string;
5
+ };
6
+ export default function useColor({ variable, color, original }: Props): void;
7
+ export {};
@@ -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
+ }
package/package.json CHANGED
@@ -1,36 +1,66 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "2.3.3",
4
+
5
+ "version": "2.3.5",
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.7",
42
+
25
43
  "clsx": "^2.1.1",
44
+
26
45
  "file-type": "^21.0.0",
46
+
27
47
  "framer-motion": "^12.23.6",
48
+
28
49
  "ms": "^2.1.3",
50
+
29
51
  "tailwind-merge": "^3.3.1",
52
+
30
53
  "tailwind-variants": "^1.0.0",
54
+
31
55
  "zod": "^4.0.13"
56
+
32
57
  },
33
58
 
34
- "devDependencies": {}
59
+ "devDependencies": {
60
+
61
+ "dependency-cruiser": "^17.0.1"
62
+
63
+ }
64
+
65
+ }
35
66
 
36
- }