Spaces:
Paused
Paused
File size: 996 Bytes
ab2ded1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import {
getExtension,
isSupportedPreviewDocumentType,
} from '@/utils/document-util';
import React from 'react';
interface IProps extends React.PropsWithChildren {
link?: string;
preventDefault?: boolean;
color?: string;
documentName: string;
documentId?: string;
prefix?: string;
}
const NewDocumentLink = ({
children,
link,
preventDefault = false,
color = 'rgb(15, 79, 170)',
documentId,
documentName,
prefix = 'file',
}: IProps) => {
let nextLink = link;
const extension = getExtension(documentName);
if (!link) {
nextLink = `/document/${documentId}?ext=${extension}&prefix=${prefix}`;
}
return (
<a
target="_blank"
onClick={
!preventDefault || isSupportedPreviewDocumentType(extension)
? undefined
: (e) => e.preventDefault()
}
href={nextLink}
rel="noreferrer"
style={{ color, wordBreak: 'break-all' }}
>
{children}
</a>
);
};
export default NewDocumentLink;
|