@bouko/react 3.1.1 → 3.1.2
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import type { Component } from "../../core/types";
|
|
3
3
|
export type ButtonProps = Component & {
|
|
4
|
-
variant?: "
|
|
4
|
+
variant?: "primary" | "outline" | "ghost" | "surface" | "error";
|
|
5
5
|
size?: "xs" | "sm" | "md" | "lg";
|
|
6
6
|
icon?: ReactNode;
|
|
7
7
|
action?: () => void;
|
|
@@ -13,29 +13,27 @@ export function Button({ size, variant, style, icon, action, disabled, children
|
|
|
13
13
|
catch { }
|
|
14
14
|
setLoading(false);
|
|
15
15
|
};
|
|
16
|
-
return (_jsxs("button", { className: cn(styles({ variant, size }), style), onClick: submit, disabled: disabled || isLoading, children: [icon && isLoading
|
|
16
|
+
return (_jsxs("button", { className: cn(styles({ variant, size }), variant === "ghost" && "p-0", style), onClick: submit, disabled: disabled || isLoading, children: [icon && isLoading
|
|
17
17
|
? _jsx(Spinner, { className: "animate-spin" })
|
|
18
|
-
: icon, children
|
|
18
|
+
: icon, children] }));
|
|
19
19
|
}
|
|
20
20
|
const styles = tv({
|
|
21
|
-
base: "
|
|
22
|
-
defaultVariants: {
|
|
21
|
+
base: "flex justify-center items-center gap-2 bg-accent border border-accent-darker rounded font-semibold text-background-light duration-200 cursor-pointer disabled:cursor-not-allowed hover:brightness-110",
|
|
22
|
+
defaultVariants: { size: "md" },
|
|
23
23
|
variants: {
|
|
24
24
|
variant: {
|
|
25
|
-
accent: "bg-accent border-accent-darker text-background-light",
|
|
26
25
|
primary: "bg-primary border-primary-dark",
|
|
27
26
|
outline: "bg-transparent border-accent hover:border-accent-dark text-primary",
|
|
28
|
-
ghost: "bg-transparent border-transparent text-
|
|
29
|
-
|
|
30
|
-
error: "bg-error border-error-dark"
|
|
31
|
-
future: "rounded-lg text-primary border-transparent backdrop-blur-sm test-button"
|
|
27
|
+
ghost: "bg-transparent border-transparent text-accent hover:brightness-110",
|
|
28
|
+
surface: "bg-surface-dark border-border-dark dark:border-border-light text-primary-dark",
|
|
29
|
+
error: "bg-error border-error-dark"
|
|
32
30
|
},
|
|
33
31
|
size: {
|
|
34
|
-
xs: "gap-1 px-2 py-1 text-xs",
|
|
32
|
+
xs: "gap-1 px-2 py-1 text-xs font-medium",
|
|
35
33
|
circle: "px-2 py-2 text-xs rounded-full",
|
|
36
34
|
sm: "px-3 py-2 text-xs sm:text-sm",
|
|
37
|
-
md: "px-4 py-2
|
|
38
|
-
lg: "px-5 py-
|
|
35
|
+
md: "px-4 py-2",
|
|
36
|
+
lg: "px-5 py-3 text-lg"
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
});
|
package/dist/components/input.js
CHANGED
|
@@ -32,7 +32,7 @@ export default function Input({ id, type = "text", variant, style, value, update
|
|
|
32
32
|
else if (update)
|
|
33
33
|
update(value);
|
|
34
34
|
};
|
|
35
|
-
return (_jsx(Field, { ...props, children: _jsx("input", { type: type, className: cn(styles({ variant }), style), placeholder: placeholder
|
|
35
|
+
return (_jsx(Field, { ...props, children: _jsx("input", { type: type, className: cn(styles({ variant }), style), placeholder: placeholder || `Enter ${id}`, value: value, onChange: ({ target: { value } }) => handleUpdate(value), onKeyUp: ({ key }) => key === "Enter" && value ? onEnter?.(value) : null, disabled: disabled }) }));
|
|
36
36
|
}
|
|
37
37
|
const styles = tv({
|
|
38
38
|
base: "px-3 py-2 duration-200 rounded text-xs sm:text-sm placeholder:text-primary-darker text-primary disabled:brightness-90 disabled:cursor-not-allowed",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from "react";
|
|
2
1
|
type Props<T> = {
|
|
3
2
|
id?: string;
|
|
4
3
|
style?: string;
|
|
5
4
|
placeholder?: string;
|
|
6
5
|
value?: string;
|
|
7
6
|
update?: (x: string) => void;
|
|
8
|
-
updateForm?:
|
|
7
|
+
updateForm?: (id: string, x: string) => void;
|
|
9
8
|
disabled?: boolean;
|
|
9
|
+
controls?: boolean;
|
|
10
10
|
};
|
|
11
|
-
export declare function ImageUploader<T>({ id, style, placeholder, value, update, updateForm, disabled }: Props<T>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare function ImageUploader<T>({ id, style, placeholder, value, update, updateForm, disabled, controls }: Props<T>): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
export default ImageUploader;
|
|
@@ -3,7 +3,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useState, useRef, useEffect } from "react";
|
|
4
4
|
import { cn } from "@bouko/style";
|
|
5
5
|
import Camera from "../../assets/icons/camera.svg";
|
|
6
|
-
|
|
6
|
+
import Upload from "../../assets/icons/upload.svg";
|
|
7
|
+
import Trash from "../../assets/icons/trash.svg";
|
|
8
|
+
import { ColumnBox, RowBox } from "../layout/flex";
|
|
9
|
+
import { Button } from "../button/normal";
|
|
10
|
+
export function ImageUploader({ id, style, placeholder, value, update, updateForm, disabled = false, controls = false }) {
|
|
7
11
|
const [preview, setPreview] = useState();
|
|
8
12
|
useEffect(() => {
|
|
9
13
|
if (value)
|
|
@@ -19,14 +23,14 @@ export function ImageUploader({ id, style, placeholder, value, update, updateFor
|
|
|
19
23
|
return;
|
|
20
24
|
const base64 = await fileToBase64(file);
|
|
21
25
|
if (id && updateForm)
|
|
22
|
-
updateForm(
|
|
26
|
+
updateForm(id, base64);
|
|
23
27
|
else
|
|
24
28
|
update?.(base64);
|
|
25
29
|
};
|
|
26
|
-
return (_jsxs("div", { className:
|
|
30
|
+
return (_jsxs(ColumnBox, { style: cn("gap-4", style), children: [_jsxs("div", { className: styles.container, onClick: !controls ? uploadFile : undefined, children: [_jsx("input", { type: "file", className: "hidden", onChange: handleFileChange, ref: ref }), _jsx("img", { className: "absolute top-0 left-0 w-full h-full", src: preview || placeholder, alt: "Image Uploader" }), !controls && _jsx("div", { className: "flex justify-center items-center w-full h-full z-10 opacity-0 hover:opacity-50 bg-background-light/80 duration-200 cursor-pointer", children: _jsx(Camera, { className: "text-xl text-primary-light" }) })] }), controls && _jsxs(RowBox, { style: "gap-1", children: [_jsxs(Button, { size: "xs", variant: "surface", action: uploadFile, children: [_jsx(Upload, {}), "Upload"] }), _jsxs(Button, { size: "xs", variant: "ghost", style: "!px-2 text-error", children: [_jsx(Trash, {}), "Clear"] })] })] }));
|
|
27
31
|
}
|
|
28
32
|
const styles = {
|
|
29
|
-
container: "relative shrink-0 border border-border rounded-md overflow-hidden",
|
|
33
|
+
container: "relative shrink-0 w-full aspect-square border border-border rounded-md overflow-hidden",
|
|
30
34
|
};
|
|
31
35
|
function fileToBase64(file) {
|
|
32
36
|
return new Promise((resolve, reject) => {
|