@workday/canvas-kit-docs
Version:
Documentation components of Canvas Kit components
46 lines (45 loc) • 2.25 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Card } from '@workday/canvas-kit-react/card';
import { ExternalHyperlink, SecondaryButton } from '@workday/canvas-kit-react/button';
import { downloadIcon, fileIcon } from '@workday/canvas-system-icons-web';
import { SystemIcon } from '@workday/canvas-kit-react';
import { createStencil } from '@workday/canvas-kit-styling';
import { system } from '@workday/canvas-tokens-web';
const flexBlock = createStencil({
vars: {
gap: system.space.x1,
},
base: ({ gap }) => ({
display: 'flex',
alignItems: 'center',
gap,
code: {
fontFamily: system.fontFamily.mono,
padding: system.space.x1,
paddingInline: system.space.x2,
backgroundColor: system.color.bg.alt.softer,
borderRadius: system.shape.half,
},
}),
});
export const DownloadLLMFile = ({ rawFileLink, filename }) => {
const handleDownload = async () => {
try {
const response = await fetch(rawFileLink);
const content = await response.text();
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
}
catch (error) {
console.error('Failed to download file:', error);
}
};
return (_jsx(Card, { className: "sb-unstyled", cs: { boxShadow: 'none', borderStyle: 'dashed' }, children: _jsxs(Card.Body, { cs: { display: 'grid', gridTemplateColumns: '1fr auto', alignItems: 'center' }, children: [_jsxs("div", { ...flexBlock(), children: [_jsx(SystemIcon, { icon: fileIcon }), _jsx("code", { children: filename })] }), _jsxs("div", { ...flexBlock({ gap: system.space.x4 }), children: [_jsx(ExternalHyperlink, { href: rawFileLink, children: "See raw file" }), _jsx(SecondaryButton, { icon: downloadIcon, size: "small", onClick: handleDownload, children: "Download LLM File" })] })] }) }));
};