@droppii-org/chat-sdk
Version:
Droppii React Chat SDK
29 lines (28 loc) • 1.39 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { shortenFileName } from "../footer/FilePreview";
import { documentIcon } from "../../../assets/svg";
const FileMessageItem = (props) => {
var _a;
const { message } = props;
const handleDownload = () => {
var _a, _b;
const url = ((_a = message.fileElem) === null || _a === void 0 ? void 0 : _a.sourceUrl) || "";
const fileName = ((_b = message.fileElem) === null || _b === void 0 ? void 0 : _b.fileName) || "";
if (!url) {
console.warn("Không có link file để tải");
return;
}
const link = document.createElement("a");
link.href = url;
if (fileName) {
link.setAttribute("download", fileName);
}
link.setAttribute("target", "_blank");
link.setAttribute("rel", "noopener noreferrer");
document.body.appendChild(link);
link.click();
link.remove();
};
return (_jsxs("div", { className: "relative flex flex-row items-center gap-2 align-center bg-gray-100 rounded-md p-1 pr-2 cursor-pointer", onClick: handleDownload, children: [documentIcon, _jsx("span", { className: "text-xs text-gray-500", children: shortenFileName(((_a = message.fileElem) === null || _a === void 0 ? void 0 : _a.fileName) || "") })] }));
};
export default FileMessageItem;