Files
HiveGrid-Wireframes/hivegrid-cloud/apps/web/app/components/ui/uploaders/MediaItem.tsx
T

68 lines
3.0 KiB
TypeScript

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>
);
}