mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
Add Media.Dropzone and Media.Preview as isolated elements
Introduce `Media.*` to modularize and customize file upload handling. Refactor media-related components to improve usability, add max item limits, overwrite support, and event callbacks.
This commit is contained in:
78
app/src/ui/routes/test/tests/dropzone-element-test.tsx
Normal file
78
app/src/ui/routes/test/tests/dropzone-element-test.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import { type DropzoneRenderProps, Media } from "ui/elements";
|
||||
import { Scrollable } from "ui/layouts/AppShell/AppShell";
|
||||
|
||||
export default function DropzoneElementTest() {
|
||||
return (
|
||||
<Scrollable>
|
||||
<div className="flex flex-col w-full h-full p-4 gap-4">
|
||||
<div>
|
||||
<b>Dropzone User Avatar 1 (fully customized)</b>
|
||||
<Media.Dropzone
|
||||
entity={{ name: "users", id: 1, field: "avatar" }}
|
||||
maxItems={1}
|
||||
overwrite
|
||||
>
|
||||
{(props) => <CustomUserAvatarDropzone {...props} />}
|
||||
</Media.Dropzone>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<b>Dropzone User Avatar 1 (overwrite)</b>
|
||||
<Media.Dropzone
|
||||
entity={{ name: "users", id: 1, field: "avatar" }}
|
||||
maxItems={1}
|
||||
overwrite
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<b>Dropzone User Avatar 1</b>
|
||||
<Media.Dropzone entity={{ name: "users", id: 1, field: "avatar" }} maxItems={1} />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<b>Dropzone Container blank w/ query</b>
|
||||
<Media.Dropzone query={{ limit: 2 }} />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<b>Dropzone Container blank</b>
|
||||
<Media.Dropzone />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<b>Dropzone Post 12</b>
|
||||
<Media.Dropzone entity={{ name: "posts", id: 12, field: "images" }} />
|
||||
</div>
|
||||
</div>
|
||||
</Scrollable>
|
||||
);
|
||||
}
|
||||
|
||||
function CustomUserAvatarDropzone({
|
||||
wrapperRef,
|
||||
inputProps,
|
||||
state: { files, isOver, isOverAccepted, showPlaceholder },
|
||||
actions: { openFileInput }
|
||||
}: DropzoneRenderProps) {
|
||||
const file = files[0];
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={wrapperRef}
|
||||
className="size-32 rounded-full border border-gray-200 flex justify-center items-center leading-none overflow-hidden"
|
||||
>
|
||||
<div className="hidden">
|
||||
<input {...inputProps} />
|
||||
</div>
|
||||
{showPlaceholder && <>{isOver && isOverAccepted ? "let it drop" : "drop here"}</>}
|
||||
{file && (
|
||||
<Media.Preview
|
||||
file={file}
|
||||
className="object-cover w-full h-full"
|
||||
onClick={openFileInput}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user