Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable PDFDownloadLink to Receive Anchor Props #2071

Merged
merged 4 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/renderer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,14 @@ declare namespace ReactPDF {
*/
class PDFViewer extends React.Component<PDFViewerProps> {}

interface PDFDownloadLinkProps {
document: React.ReactElement<DocumentProps>;
interface PDFDownloadLinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
/** PDF filename. Alias for anchor tag `download` attribute. */
fileName?: string;
style?: Style | Style[];
className?: string;
document: React.ReactElement<DocumentProps>;
children?:
| React.ReactNode
| ((params: BlobProviderParams) => React.ReactNode);
onClick?: Function;
onClick?(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>, instance: UsePDFInstance): void;
}

/**
Expand Down
16 changes: 7 additions & 9 deletions packages/renderer/src/dom/PDFDownloadLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import React, { useEffect } from 'react';
import usePDF from './usePDF';

export const PDFDownloadLink = ({
style,
children,
className,
document: doc,
fileName = 'document.pdf',
document,
diegomura marked this conversation as resolved.
Show resolved Hide resolved
children,
onClick,
href: _filteredOutHref,
...rest
}) => {
const [instance, updateInstance] = usePDF({ document: doc });

const [instance, updateInstance] = usePDF({ document });
diegomura marked this conversation as resolved.
Show resolved Hide resolved
useEffect(updateInstance, [children]);

if (!doc) {
if (!document) {
diegomura marked this conversation as resolved.
Show resolved Hide resolved
console.warn('You should pass a valid document to PDFDownloadLink');
return null;
}
Expand All @@ -35,11 +34,10 @@ export const PDFDownloadLink = ({

return (
<a
style={style}
href={instance.url}
download={fileName}
className={className}
onClick={handleClick}
{...rest}
>
{typeof children === 'function' ? children(instance) : children}
</a>
Expand Down