Files
FastGPT/packages/web/components/common/Markdown/MarkdownTable.tsx
T
Archer fea1c4ed14 perf: workflow node past;feat: table export (#6250)
* perf: workflow node past

* feat: table export

* feat: table export
2026-01-12 21:07:44 +08:00

54 lines
1.3 KiB
TypeScript

import React, { useRef, useCallback } from 'react';
import { Box, IconButton } from '@chakra-ui/react';
import { useTranslation } from 'next-i18next';
import { exportTableToCSV } from './utils';
import MyIcon from '../Icon';
type MarkdownTableProps = {
children: React.ReactNode;
};
/**
* Custom table component for Markdown with CSV export functionality
*/
const MarkdownTable = ({ children }: MarkdownTableProps) => {
const { t } = useTranslation();
const tableRef = useRef<HTMLTableElement>(null);
const handleExport = useCallback(() => {
if (tableRef.current) {
const timestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '-');
exportTableToCSV(tableRef.current, `table-${timestamp}`);
}
}, []);
return (
<Box
ref={tableRef}
as="table"
_hover={{
'.export-button': {
display: 'flex'
}
}}
>
<IconButton
className="export-button"
icon={<MyIcon name="export" w={'14px'} />}
size={'xs'}
display="none"
variant={'whiteBase'}
onClick={handleExport}
position="absolute"
top={1}
right={2}
zIndex={1}
aria-label={''}
/>
{children}
</Box>
);
};
export default React.memo(MarkdownTable);