From 1453a545ab1d12732ca631791c17f65b3b256561 Mon Sep 17 00:00:00 2001 From: Rizky Date: Sun, 1 Dec 2024 09:47:18 +0000 Subject: [PATCH] fix lib --- comps/form/field/type/TypeUploadSingle.tsx | 66 ++++++++++++++++------ comps/ui/toast.tsx | 12 +++- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/comps/form/field/type/TypeUploadSingle.tsx b/comps/form/field/type/TypeUploadSingle.tsx index 14eec2c..51d373c 100755 --- a/comps/form/field/type/TypeUploadSingle.tsx +++ b/comps/form/field/type/TypeUploadSingle.tsx @@ -237,24 +237,56 @@ export const FieldUploadSingle: FC<{ {!disabled ? ( <> -
{ - if (!disabled) { - e.preventDefault(); - e.stopPropagation(); - if (confirm("Clear this file ?")) { - input.fase = "start"; - fm.data[field.name] = null; - fm.render(); + {field.required !== true ? ( +
{ + if (!disabled) { + e.preventDefault(); + e.stopPropagation(); + if (confirm("Clear this file ?")) { + input.fase = "start"; + fm.data[field.name] = null; + fm.render(); + } } - } - }} - className={cx( - "c-flex c-flex-row c-items-center c-border c-px-2 c-rounded c-cursor-pointer hover:c-bg-red-100" - )} - > - -
+ }} + className={cx( + "c-flex c-flex-row c-items-center c-border c-px-2 c-rounded c-cursor-pointer hover:c-bg-red-100" + )} + > + +
+ ) : ( + <> +
{ + console.log(input.ref); + if (input.ref) { + input.ref.click(); + } + }} + className="c-items-center c-flex c-text-base c-px-1 c-outline-none c-rounded c-cursor-pointer " + > +
+ +
+
+ Replace +
+
+ (input.ref = ref)} + type="file" + multiple={false} + // accept={field.prop.upload?.accept} + accept={"file/**"} + onChange={on_upload} + className={cx( + "c-absolute c-w-full c-h-full c-cursor-pointer c-top-0 c-left-0 c-opacity-0" + )} + /> + + )} ) : ( <> diff --git a/comps/ui/toast.tsx b/comps/ui/toast.tsx index a0543bb..8ab3e36 100755 --- a/comps/ui/toast.tsx +++ b/comps/ui/toast.tsx @@ -17,7 +17,7 @@ export const toast = { sonner.dismiss(t.id); } } - sonner.dismiss() + sonner.dismiss(); } else { clearTimeout(timer.timeout); timer.timeout = null; @@ -31,6 +31,7 @@ export const toast = { timer.timeout = setTimeout(() => { toast.toasting.push( sonner.loading(el, { + dismissible: true, ...props, onDismiss: (t) => { toast.toasting = toast.toasting.filter((e) => e !== t.id); @@ -42,12 +43,18 @@ export const toast = { }, success: ( el: ReactElement, - props?: { dismissible?: boolean; className?: string; duration?: number } + props?: { + dismissible?: boolean; + className?: string; + duration?: number; + onClick?: () => void; + } ) => { clearTimeout(timer.timeout); timer.timeout = setTimeout(() => { toast.toasting.push( sonner.success(el, { + dismissible: true, ...props, onDismiss: (t) => { toast.toasting = toast.toasting.filter((e) => e !== t.id); @@ -65,6 +72,7 @@ export const toast = { timer.timeout = setTimeout(() => { toast.toasting.push( sonner.error(el, { + dismissible: true, ...props, onDismiss: (t) => { toast.toasting = toast.toasting.filter((e) => e !== t.id);