@bouko/react 2.7.5 → 2.7.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.
|
@@ -11,6 +11,7 @@ type FieldProps<T> = {
|
|
|
11
11
|
};
|
|
12
12
|
type Variant = "normal" | "ghost";
|
|
13
13
|
type Props = Omit<FieldProps<string>, "id"> & {
|
|
14
|
+
type?: "text" | "number" | "email" | "password";
|
|
14
15
|
variant?: Variant;
|
|
15
16
|
style?: string;
|
|
16
17
|
placeholder?: string;
|
|
@@ -33,5 +34,5 @@ type Props = Omit<FieldProps<string>, "id"> & {
|
|
|
33
34
|
* @param {string} placeholder - Placeholder text for the input. (optional)
|
|
34
35
|
* @param {Function} onEnter - Callback when `Enter` key is pressed. (optional)
|
|
35
36
|
**/
|
|
36
|
-
export default function Input({ variant, style, value, update, onEnter, disabled, placeholder, ...props }: Props): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export default function Input({ type, variant, style, value, update, onEnter, disabled, placeholder, ...props }: Props): import("react/jsx-runtime").JSX.Element;
|
|
37
38
|
export {};
|
package/dist/components/input.js
CHANGED
|
@@ -25,8 +25,8 @@ const fieldStyles = {
|
|
|
25
25
|
* @param {string} placeholder - Placeholder text for the input. (optional)
|
|
26
26
|
* @param {Function} onEnter - Callback when `Enter` key is pressed. (optional)
|
|
27
27
|
**/
|
|
28
|
-
export default function Input({ variant, style, value, update, onEnter, disabled, placeholder, ...props }) {
|
|
29
|
-
return (_jsx(Field, { ...props, children: _jsx("input", { className: cn(styles({ variant }), style), placeholder: placeholder, value: value, onChange: ({ target: { value } }) => update?.(value), onKeyUp: ({ key }) => key === "Enter" && value ? onEnter?.(value) : null, disabled: disabled }) }));
|
|
28
|
+
export default function Input({ type = "text", variant, style, value, update, onEnter, disabled, placeholder, ...props }) {
|
|
29
|
+
return (_jsx(Field, { ...props, children: _jsx("input", { type: type, className: cn(styles({ variant }), style), placeholder: placeholder, value: value, onChange: ({ target: { value } }) => update?.(value), onKeyUp: ({ key }) => key === "Enter" && value ? onEnter?.(value) : null, disabled: disabled }) }));
|
|
30
30
|
}
|
|
31
31
|
const styles = tv({
|
|
32
32
|
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",
|
|
@@ -6,27 +6,34 @@ import Camera from "../../assets/icons/camera.svg";
|
|
|
6
6
|
export function ImageUploader({ id, style, placeholder, value, update, updateForm, disabled = false }) {
|
|
7
7
|
const [preview, setPreview] = useState();
|
|
8
8
|
useEffect(() => {
|
|
9
|
-
if (value)
|
|
10
|
-
|
|
11
|
-
setPreview(imageUrl);
|
|
12
|
-
}
|
|
9
|
+
if (value)
|
|
10
|
+
setPreview(value);
|
|
13
11
|
}, [value]);
|
|
14
12
|
const ref = useRef(null);
|
|
15
13
|
const uploadFile = () => ref.current?.click();
|
|
16
14
|
if (!update)
|
|
17
15
|
disabled = true;
|
|
18
|
-
const handleFileChange = (e) => {
|
|
16
|
+
const handleFileChange = async (e) => {
|
|
19
17
|
const file = e.target.files?.[0];
|
|
20
18
|
if (!file)
|
|
21
19
|
return;
|
|
20
|
+
const base64 = await fileToBase64(file);
|
|
22
21
|
if (id && updateForm)
|
|
23
|
-
updateForm(x => ({ ...x, [id]:
|
|
22
|
+
updateForm(x => ({ ...x, [id]: base64 }));
|
|
24
23
|
else
|
|
25
|
-
update?.(
|
|
24
|
+
update?.(base64);
|
|
26
25
|
};
|
|
27
26
|
return (_jsxs("div", { className: cn(styles.container, style), onClick: uploadFile, 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" }), _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" }) })] }));
|
|
28
27
|
}
|
|
29
28
|
const styles = {
|
|
30
29
|
container: "relative shrink-0 border border-border rounded-md overflow-hidden",
|
|
31
30
|
};
|
|
31
|
+
function fileToBase64(file) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const reader = new FileReader();
|
|
34
|
+
reader.onload = () => resolve(reader.result); // data:image/...;base64,...
|
|
35
|
+
reader.onerror = reject;
|
|
36
|
+
reader.readAsDataURL(file);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
32
39
|
export default ImageUploader;
|