Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import clsx from "clsx";
|
||||
import { MediaDto } from "~/application/dtos/entities/MediaDto";
|
||||
import ButtonTertiary from "../buttons/ButtonTertiary";
|
||||
import DownloadIcon from "../icons/DownloadIcon";
|
||||
import EyeIcon from "../icons/EyeIcon";
|
||||
import PaperClipIcon from "../icons/PaperClipIcon";
|
||||
import TrashIcon from "../icons/TrashIcon";
|
||||
import CheckIcon from "../icons/CheckIcon";
|
||||
import { t as i18nT } from "i18next";
|
||||
|
||||
interface Props {
|
||||
item: MediaDto;
|
||||
onChangeTitle: (e: string) => void;
|
||||
onDelete: () => void;
|
||||
onDownload: () => void;
|
||||
onPreview?: () => void;
|
||||
readOnly?: boolean;
|
||||
}
|
||||
export default function MediaItem({ item, onDelete, onDownload, onPreview, readOnly }: Props) {
|
||||
return (
|
||||
// Subframe FileUpload "uploaded" row: solid border-default, neutral-primary fill, rounded-md, px-3 py-1.
|
||||
<div className={clsx("border-border-default bg-surface-neutral-primary w-full rounded-md border border-solid px-3 text-xs", readOnly ? "" : "")}>
|
||||
{readOnly ? (
|
||||
<div className="flex items-center justify-between py-2 pr-4 text-sm">
|
||||
<div className="flex w-0 flex-1 items-center">
|
||||
<PaperClipIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
|
||||
<span className="ml-2 w-0 flex-1 truncate">{item.name}</span>
|
||||
</div>
|
||||
<div className="ml-4 shrink-0 space-x-2">
|
||||
<div className="flex items-center space-x-3">
|
||||
{onPreview && (
|
||||
<ButtonTertiary
|
||||
type="button"
|
||||
onClick={onPreview}
|
||||
aria-label={i18nT("components.media.actions.preview", { name: item.name })}
|
||||
className=" text-muted-foreground hover:text-muted-foreground border-0 font-medium shadow-none"
|
||||
>
|
||||
<EyeIcon className="text-muted-foreground h-4 w-4" />
|
||||
</ButtonTertiary>
|
||||
)}
|
||||
<ButtonTertiary
|
||||
type="button"
|
||||
onClick={onDownload}
|
||||
aria-label={i18nT("components.media.actions.download", { name: item.name })}
|
||||
className=" text-muted-foreground hover:text-muted-foreground border-0 font-medium shadow-none"
|
||||
>
|
||||
<DownloadIcon className="text-muted-foreground h-4 w-4" />
|
||||
</ButtonTertiary>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex select-none items-center justify-between space-x-2 py-1">
|
||||
<div className="flex grow items-center space-x-2 truncate py-1">
|
||||
<CheckIcon className={clsx("h-6 w-6 shrink-0 text-teal-600")} />
|
||||
<div className="truncate text-sm font-medium">{item.title}</div>
|
||||
</div>
|
||||
<div className="shrink-0">
|
||||
<ButtonTertiary disabled={readOnly} onClick={() => onDelete()} aria-label={i18nT("components.media.actions.delete", { name: item.name })} className="group p-2">
|
||||
<TrashIcon className={clsx("h-4 w-4", readOnly ? "opacity-80" : "group-hover:text-foreground")} />
|
||||
</ButtonTertiary>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { FileBase64 } from "~/application/dtos/shared/FileBase64";
|
||||
import UploadDocuments from "./UploadDocument";
|
||||
import { t as i18nT } from "i18next";
|
||||
|
||||
export default function PreviewUploadersDocument() {
|
||||
function droppedDocuments(fileBase64: FileBase64[], files: any[]) {
|
||||
alert(
|
||||
i18nT("components.uploaders.preview.droppedDocuments", {
|
||||
count: files.length,
|
||||
previews: files.map((f) => f.base64.substr(0, 30) + "...").join(", "),
|
||||
})
|
||||
);
|
||||
}
|
||||
function droppedDocument(base64: string, file: File) {
|
||||
alert(i18nT("components.uploaders.preview.droppedDocument", { preview: `${base64.substr(0, 30)}...`, name: file.name, size: file.size }));
|
||||
}
|
||||
return (
|
||||
<div id="uploaders" className="space-y-1">
|
||||
<div className="border-border bg-background border border-dashed p-6">
|
||||
<div className="w-full space-y-2">
|
||||
<UploadDocuments multiple={true} onDroppedFiles={droppedDocuments} onDropped={droppedDocument} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
import clsx from "clsx";
|
||||
import { ReactNode, useEffect, useState } from "react";
|
||||
import { FileBase64 } from "~/application/dtos/shared/FileBase64";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface Props {
|
||||
name?: string;
|
||||
title?: string;
|
||||
accept?: string;
|
||||
multiple?: boolean;
|
||||
description?: string;
|
||||
icon?: ReactNode;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
uploadText?: string;
|
||||
autoFocus?: boolean;
|
||||
onDropped?: (base64: string, file: File) => void;
|
||||
onDroppedFiles?: (fileBase64: FileBase64[], files: any[]) => void;
|
||||
}
|
||||
|
||||
export default function UploadDocuments({
|
||||
name = "uploadmyfile",
|
||||
className,
|
||||
title = "",
|
||||
accept,
|
||||
multiple,
|
||||
description,
|
||||
icon = "",
|
||||
disabled,
|
||||
onDropped,
|
||||
onDroppedFiles,
|
||||
uploadText,
|
||||
autoFocus,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const [loading] = useState(false);
|
||||
const [customClasses, setCustomClasses] = useState("");
|
||||
|
||||
function dragOver(e: any) {
|
||||
e.preventDefault();
|
||||
if (!loading) {
|
||||
setIsDragging(true);
|
||||
}
|
||||
}
|
||||
function dragLeave() {
|
||||
setIsDragging(false);
|
||||
}
|
||||
// async function compressFile(imageFile: File): Promise<File> {
|
||||
// const options = {
|
||||
// maxSizeMB: 0.5,
|
||||
// maxWidthOrHeight: 1920 / 2,
|
||||
// useWebWorker: true,
|
||||
// };
|
||||
// try {
|
||||
// return await imageCompression(imageFile, options);
|
||||
// } catch (error) {
|
||||
// return await Promise.reject(error);
|
||||
// }
|
||||
// }
|
||||
// async function compressFileNotImage(imageFile: File): Promise<File> {
|
||||
// return Promise.resolve(imageFile);
|
||||
// }
|
||||
async function drop(e: any) {
|
||||
try {
|
||||
e.preventDefault();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
const files: File[] = await Promise.all(
|
||||
[...e.dataTransfer.files].map(async (element: File) => {
|
||||
return element;
|
||||
// if (element.type.includes("image")) {
|
||||
// return await compressFile(element);
|
||||
// } else {
|
||||
// return await compressFileNotImage(element);
|
||||
// }
|
||||
})
|
||||
);
|
||||
const filesArray: FileBase64[] = [];
|
||||
|
||||
await Promise.all(
|
||||
files.map(async (file) => {
|
||||
const base64 = await getBase64(file);
|
||||
filesArray.push({
|
||||
base64,
|
||||
file,
|
||||
});
|
||||
if (onDropped) {
|
||||
onDropped(base64, file);
|
||||
}
|
||||
})
|
||||
);
|
||||
if (onDroppedFiles) {
|
||||
onDroppedFiles(filesArray, files);
|
||||
}
|
||||
setIsDragging(false);
|
||||
}
|
||||
function requestUploadFile() {
|
||||
const src = document.querySelector("#" + name);
|
||||
drop({ dataTransfer: src });
|
||||
}
|
||||
function getBase64(file: File): Promise<string> {
|
||||
const reader = new FileReader();
|
||||
return new Promise((resolve) => {
|
||||
reader.onload = (ev) => {
|
||||
resolve(ev?.target?.result?.toString() ?? "");
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// Subframe FileUpload "hover"/dragging state: 2px dashed information border + subtle information fill.
|
||||
setCustomClasses(
|
||||
isDragging && !loading && !disabled
|
||||
? "border-2 border-dashed border-border-information-solid bg-surface-feedback-subtle-information"
|
||||
: ""
|
||||
);
|
||||
}, [isDragging, loading, disabled]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
// Subframe FileUpload dropzone (default state): rounded-lg, single dashed border-strong,
|
||||
// neutral-primary fill, px-6 py-8 padding, centered content.
|
||||
"drop flex items-center justify-center overflow-hidden rounded-lg border border-dashed border-border-strong bg-surface-neutral-primary px-6 py-8 text-center",
|
||||
customClasses,
|
||||
className
|
||||
)}
|
||||
onDragOver={dragOver}
|
||||
onDragLeave={dragLeave}
|
||||
onDrop={drop}
|
||||
>
|
||||
{(() => {
|
||||
if (loading) {
|
||||
return <div className="mx-auto text-base font-medium">{t("shared.loading")}...</div>;
|
||||
} else {
|
||||
return (
|
||||
// Subframe FileUpload content: vertically centered column with gap-5 between
|
||||
// icon/label cluster and the description hint.
|
||||
<div className="flex flex-col items-center justify-center gap-5">
|
||||
<div className="text-primary mx-auto text-sm font-bold">{title}</div>
|
||||
<div className="manual">
|
||||
<div className="flex flex-col items-center justify-center gap-3 text-center">
|
||||
{/* Subframe upload icon color token */}
|
||||
<span className="text-icon-neutral-secondary">{icon}</span>
|
||||
<div className="text-text-neutral-secondary flex flex-col text-sm">
|
||||
<label
|
||||
htmlFor={name}
|
||||
className={clsx(
|
||||
" text-foreground focus-within:ring-ring relative cursor-pointer rounded-md font-medium focus-within:outline-hidden focus-within:ring-2 focus-within:ring-offset-2",
|
||||
!disabled && ""
|
||||
)}
|
||||
>
|
||||
<p className={clsx("text-sm font-semibold underline", !disabled ? "cursor-pointer" : "cursor-not-allowed")}>
|
||||
{uploadText ?? <span>{t("app.shared.buttons.uploadDocument")}</span>}
|
||||
</p>
|
||||
<input
|
||||
className="uploadmyfile"
|
||||
disabled={disabled}
|
||||
type="file"
|
||||
id={name}
|
||||
accept={accept}
|
||||
multiple={multiple}
|
||||
onChange={requestUploadFile}
|
||||
autoFocus={autoFocus}
|
||||
/>
|
||||
</label>
|
||||
{/* <p className="pl-1 lowercase">
|
||||
{t("shared.or")} {t("shared.dragAndDrop")}
|
||||
</p> */}
|
||||
</div>
|
||||
<p className="text-text-neutral-tertiary text-xs">
|
||||
{description ?? (
|
||||
<span className="lowercase">
|
||||
{t("shared.or")} {t("shared.dragAndDrop")}
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import SlideOver from "../slideOvers/SlideOver";
|
||||
import { useState } from "react";
|
||||
import UploadDocument from "./UploadDocument";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
initialImage?: string;
|
||||
onLoaded: (image: string, file: File) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export default function UploadImage({ title = "", initialImage, onLoaded, onClose }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const [image, setImage] = useState(initialImage);
|
||||
|
||||
function onChange(base64: string, file: File) {
|
||||
setImage(base64);
|
||||
onLoaded(base64, file);
|
||||
onClose();
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SlideOver
|
||||
onClose={onClose}
|
||||
title={title}
|
||||
content={
|
||||
<div className="space-y-2">
|
||||
<UploadDocument accept="image/png, image/jpg, image/jpeg" description={title} onDropped={onChange} />
|
||||
{image && (
|
||||
// Subframe-style preview hull: rounded-lg, solid border-default, neutral-primary fill.
|
||||
<div className="border-border-default bg-surface-neutral-primary overflow-hidden rounded-lg border border-solid">
|
||||
<img className="h-auto w-full" alt={t("shared.uploadedImageAlt")} src={image} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
></SlideOver>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user