@bouko/react 2.0.9 → 2.1.1

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.
@@ -3,6 +3,7 @@ export declare const useForm: <T>(init: T) => {
3
3
  data: T;
4
4
  update: import("react").Dispatch<import("react").SetStateAction<T>>;
5
5
  clear: () => void;
6
+ setField: <T_1>(name: string, value: T_1) => void;
6
7
  };
7
8
  export declare const setField: <T>(update: SetState<T>, id: string, value: unknown) => void;
8
9
  export declare const parseData: <T extends Record<string, unknown>>(data: T) => T;
@@ -8,7 +8,8 @@ export const useForm = (init) => {
8
8
  return {
9
9
  data,
10
10
  update: setData,
11
- clear: () => setData(initial)
11
+ clear: () => setData(initial),
12
+ setField: (name, value) => setField(setData, name, value)
12
13
  };
13
14
  };
14
15
  export const setField = (update, id, value) => update(prev => ({
@@ -16,6 +16,7 @@ type Props<T> = FormSection<T> & {
16
16
  };
17
17
  fields: FormBuilderField<T>;
18
18
  validator: ZodTypeAny;
19
+ sound?: string;
19
20
  submit: {
20
21
  label?: string;
21
22
  icon?: React.ReactNode;
@@ -23,4 +24,5 @@ type Props<T> = FormSection<T> & {
23
24
  cancel?: boolean;
24
25
  };
25
26
  };
26
- export declare function FormBuilder<T>({ fields, validator, data, styles, update, submit, clear }: Props<T>): import("react/jsx-runtime").JSX.Element;
27
+ export declare function useSound(filename?: string): import("use-sound/dist/types").PlayFunction | undefined;
28
+ export declare function FormBuilder<T>({ fields, validator, data, styles, update, submit, sound, clear }: Props<T>): import("react/jsx-runtime").JSX.Element;
@@ -5,6 +5,7 @@ import { cn } from "@bouko/style";
5
5
  import CheckCircle from "../../assets/icons/check-circle.svg";
6
6
  import Spinner from "../../assets/icons/spinner.svg";
7
7
  import XCircle from "../../assets/icons/x-circle.svg";
8
+ import { default as base } from "use-sound";
8
9
  export * from "./functions";
9
10
  export * from "./types";
10
11
  import { RowBox } from "../layout/flex";
@@ -14,9 +15,15 @@ import TextArea from "../textarea";
14
15
  import MultipleChoice from "../multiple-choice";
15
16
  import { Button } from "../button";
16
17
  import Attachment from "../attachment";
17
- export function FormBuilder({ fields, validator, data, styles, update, submit, clear }) {
18
+ export function useSound(filename) {
19
+ if (!filename)
20
+ return;
21
+ return base(filename)[0];
22
+ }
23
+ export function FormBuilder({ fields, validator, data, styles, update, submit, sound, clear }) {
18
24
  const isValid = validator.safeParse(data).success;
19
25
  const [isLoading, setLoading] = useState(false);
26
+ const play = useSound(sound);
20
27
  const handleSubmit = async () => {
21
28
  setLoading(true);
22
29
  await submit.action(data);
@@ -24,8 +24,5 @@ export {};
24
24
  /**
25
25
  * Problems
26
26
  *
27
- * - Perfect `mergeStyles`
28
- * - Perfect `RowBox`
29
- * - Perfect `ColumnBox`
30
27
  * - Perfect `Badge`
31
28
  **/
@@ -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 { default as Badge } from "../text/badge";
4
+ import { Badge } from "../text/badge";
5
5
  /**
6
6
  * Text heading with badge, title, subtitle.
7
7
  *
@@ -1,8 +1,12 @@
1
- type Color = "accent" | "orange" | "dark";
2
- type Props = {
3
- style?: string;
4
- color?: Color;
5
- children?: string;
1
+ import { Component } from "../../core/types";
2
+ type Props = Component & {
3
+ variant?: "accent" | "background";
4
+ color?: string;
6
5
  };
7
- export default function Badge({ style, color, children }: Props): import("react/jsx-runtime").JSX.Element;
8
- export {};
6
+ export declare const Badge: ({ style, variant, color, children }: Props) => import("react/jsx-runtime").JSX.Element | undefined;
7
+ export default Badge;
8
+ /**
9
+ * Problems:
10
+ *
11
+ * - Ugly code
12
+ **/
@@ -1,18 +1,24 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cn, tv } from "@bouko/style";
3
- export default function Badge({ style, color, children }) {
4
- if (!children)
5
- return _jsx(_Fragment, {});
6
- return (_jsx("span", { className: cn(styles({ color }), style), children: children }));
7
- }
3
+ export const Badge = ({ style, variant, color, children }) => {
4
+ if (children)
5
+ return (_jsx("span", { className: cn(styles({ variant }), style), style: overrideStyle(color), children: children }));
6
+ };
7
+ const overrideStyle = (color) => {
8
+ if (color)
9
+ return {
10
+ background: color + "50",
11
+ borderColor: color
12
+ };
13
+ };
8
14
  const styles = tv({
9
- base: "w-min px-3 py-1 border rounded-full text-xs font-semibold",
10
- defaultVariants: { color: "accent" },
15
+ base: "w-min px-3 py-1 border rounded-full text-xs font-semibold text-primary",
16
+ defaultVariants: { variant: "accent" },
11
17
  variants: {
12
- color: {
13
- accent: "bg-accent/20 border-accent-dark text-accent-dark",
14
- orange: "bg-orange-400/20 border-orange-500 text-orange-500",
15
- dark: "bg-slate-600/20 border-slate-700 text-slate-700"
18
+ variant: {
19
+ accent: "bg-accent-light/50 border-accent-light",
20
+ background: "bg-background-lighter/50 border-background-lighter"
16
21
  }
17
22
  }
18
23
  });
24
+ export default Badge;
@@ -1,4 +1,9 @@
1
- export declare const getFileData: (files: File[]) => Promise<unknown[]>;
1
+ export declare const getFilesData: (files: File[]) => Promise<unknown[]>;
2
+ export declare const getFileData: (file: File) => Promise<{
3
+ filename: string;
4
+ mimetype: string;
5
+ data?: string;
6
+ }>;
2
7
  export declare const bufferToFile: (buffer: Buffer<ArrayBuffer>, name?: string) => Promise<File>;
3
8
  export declare const getAudioDuration: (file: File) => Promise<number>;
4
9
  export declare const getEnv: (key: string) => string;
@@ -1,5 +1,5 @@
1
1
  import { fileTypeFromBuffer } from "file-type";
2
- export const getFileData = (files) => Promise.all(files.map((file) => {
2
+ export const getFilesData = (files) => Promise.all(files.map((file) => {
3
3
  return new Promise((resolve, reject) => {
4
4
  const reader = new FileReader();
5
5
  reader.onload = () => {
@@ -14,6 +14,19 @@ export const getFileData = (files) => Promise.all(files.map((file) => {
14
14
  reader.readAsDataURL(file);
15
15
  });
16
16
  }));
17
+ export const getFileData = (file) => new Promise((resolve, reject) => {
18
+ const reader = new FileReader();
19
+ reader.onload = () => {
20
+ const base64 = reader.result?.toString().split(",")[1]; // Remove data prefix
21
+ return resolve({
22
+ filename: file.name,
23
+ mimetype: file.type,
24
+ data: base64,
25
+ });
26
+ };
27
+ reader.onerror = reject;
28
+ reader.readAsDataURL(file);
29
+ });
17
30
  async function detectFileExtension(buffer) {
18
31
  const type = await fileTypeFromBuffer(buffer);
19
32
  if (!type)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "2.0.9",
4
+ "version": "2.1.1",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",
@@ -20,6 +20,7 @@
20
20
  },
21
21
 
22
22
  "dependencies": {
23
+ "@bouko/audio": "^0.1.0",
23
24
  "@bouko/style": "^0.1.6",
24
25
  "clsx": "^2.1.1",
25
26
  "file-type": "^21.0.0",