Skip to content

Commit

Permalink
Update repo link (#695)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Herbst <[email protected]>
  • Loading branch information
MatthewHerbst and MatthewHerbst authored Mar 12, 2024
1 parent 5b56731 commit d3fb22c
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 97 deletions.
146 changes: 73 additions & 73 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 gregnb, Matthew Herbst
Copyright (c) 2024 Matthew Herbst, Gregory Nowakowski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ For functional components, use the `useReactToPrint` hook, which accepts an obje

While printing on mobile browsers should work, printing within a WebView (when your page is opened by another app such as Facebook or Slack, but not by the full browser itself) is known to not work on many if not all WebViews. Some don't make the correct API available. Others make it available but cause printing to no-op when in WebView.

We are actively researching resolutions to this issue, but it likely requires changes by Google/Chromium and Apple/WebKit. See [#384](https://github.com/gregnb/react-to-print/issues/384) for more information. If you know of a way we can solve this, your help would be greatly appreciated.
We are actively researching resolutions to this issue, but it likely requires changes by Google/Chromium and Apple/WebKit. See [#384](https://github.com/MatthewHerbst/react-to-print/issues/384) for more information. If you know of a way we can solve this, your help would be greatly appreciated.

### Known Incompatible Browsers

Expand Down Expand Up @@ -191,7 +191,7 @@ export const AnotherExample = () => {
}
```

**Note ([401](https://github.com/gregnb/react-to-print/issues/401)):** In TypeScript, if you encounter `componentRef.current` error such as: `Type 'undefined' is not assignable to type 'ReactInstance | null'.`, add `null` inside the `useRef()`:
**Note ([401](https://github.com/MatthewHerbst/react-to-print/issues/401)):** In TypeScript, if you encounter `componentRef.current` error such as: `Type 'undefined' is not assignable to type 'ReactInstance | null'.`, add `null` inside the `useRef()`:

```ts
const componentRef = useRef(null);
Expand All @@ -217,11 +217,11 @@ const componentRef = useRef(null);
div.parent p { color:red; }
```

- The `connect` method from `react-redux` returns a functional component that cannot be assigned a reference to be used within the `content` props' callback in `react-to-print`. To use a component wrapped in `connect` within `content` create an intermediate class component that simply renders your component wrapped in `connect`. See [280](https://github.com/gregnb/react-to-print/issues/280) for more.
- The `connect` method from `react-redux` returns a functional component that cannot be assigned a reference to be used within the `content` props' callback in `react-to-print`. To use a component wrapped in `connect` within `content` create an intermediate class component that simply renders your component wrapped in `connect`. See [280](https://github.com/MatthewHerbst/react-to-print/issues/280) for more.

- Using a custom component as the return for the `trigger` props is possible, just ensure you pass along the `onClick` prop. See [248](https://github.com/gregnb/react-to-print/issues/248) for an example.
- Using a custom component as the return for the `trigger` props is possible, just ensure you pass along the `onClick` prop. See [248](https://github.com/MatthewHerbst/react-to-print/issues/248) for an example.

- When rendering multiple components to print, for example, if you have a list of charts and want each chart to have its own print icon, ideally you will wrap each component to print + print button in its own component, and just render a list of those components. However, if you cannot do that for some reason, in your `.map` ensure that each component gets a unique `ref` value passed to it, otherwise printing any of the components will always print the last component. See [323](https://github.com/gregnb/react-to-print/issues/323) for more.
- When rendering multiple components to print, for example, if you have a list of charts and want each chart to have its own print icon, ideally you will wrap each component to print + print button in its own component, and just render a list of those components. However, if you cannot do that for some reason, in your `.map` ensure that each component gets a unique `ref` value passed to it, otherwise printing any of the components will always print the last component. See [323](https://github.com/MatthewHerbst/react-to-print/issues/323) for more.

## FAQ

Expand All @@ -239,7 +239,7 @@ const handlePrint = useReactToPrint({
});
```

For examples of how others have done this, see [#484](https://github.com/gregnb/react-to-print/issues/484)
For examples of how others have done this, see [#484](https://github.com/MatthewHerbst/react-to-print/issues/484)

### Can the `ComponentToPrint` be a functional component?

Expand Down Expand Up @@ -344,7 +344,7 @@ The default page size is usually A4. Most browsers do not allow JavaScript or CS
}
```

### Set custom margin to the page ([29](https://github.com/gregnb/react-to-print/issues/29))
### Set custom margin to the page ([29](https://github.com/MatthewHerbst/react-to-print/issues/29))

To set custom margin to the page,

Expand All @@ -364,7 +364,7 @@ Now, within the JSX call this function within the style tags,

PS: This style tag should be inside the component that is being passed in as the content ref.

### Set landscape printing ([240](https://github.com/gregnb/react-to-print/issues/240))
### Set landscape printing ([240](https://github.com/MatthewHerbst/react-to-print/issues/240))

In the component that is passed in as the content ref, add the following:

Expand All @@ -374,7 +374,7 @@ In the component that is passed in as the content ref, add the following:
}
```

### Printing elements that are not displayed ([159](https://github.com/gregnb/react-to-print/issues/159))
### Printing elements that are not displayed ([159](https://github.com/MatthewHerbst/react-to-print/issues/159))

Instead of using `{ display: 'none'; }`, try using `{ overflow: hidden; height: 0; }`

Expand All @@ -384,7 +384,7 @@ The `pageStyle` prop should be a CSS string. For example: `".divider { break-aft

### Getting a blank page when printing

Many have found setting the following CSS helpful. See [#26](https://github.com/gregnb/react-to-print/issues/26) for more.
Many have found setting the following CSS helpful. See [#26](https://github.com/MatthewHerbst/react-to-print/issues/26) for more.

```css
@media print {
Expand All @@ -403,7 +403,7 @@ If you are getting a blank page while setting `removeAfterPrint` to `true`, try

### Styles incorrect in print dialog when using grid system

We often ([#327](https://github.com/gregnb/react-to-print/issues/327), [#343](https://github.com/gregnb/react-to-print/issues/343), [#382](https://github.com/gregnb/react-to-print/issues/382)) see issues reported where the developer is using Bootstrap or a similar grid system, and everything works great until the user goes to print and suddenly it seems the styles are off. We've found that often the issue is the grid library uses the smallest sized columns during printing, such as the `xs` size on Bootstrap's grid, a size developers often don't plan for. The simplest solution is to ensure your grid will adapt to this size appropriately, though this may not be acceptable since you may want the large view to print rather than the smaller view. Another solution is to [override the grid column definition](https://stackoverflow.com/questions/22199429/bootstrap-grid-for-printing/28152320). Some newer versions of libraries have specific tools for dealing with printing, for example, [Bootstrap 4's Display property](https://getbootstrap.com/docs/4.3/utilities/display/).
We often ([#327](https://github.com/MatthewHerbst/react-to-print/issues/327), [#343](https://github.com/MatthewHerbst/react-to-print/issues/343), [#382](https://github.com/MatthewHerbst/react-to-print/issues/382)) see issues reported where the developer is using Bootstrap or a similar grid system, and everything works great until the user goes to print and suddenly it seems the styles are off. We've found that often the issue is the grid library uses the smallest sized columns during printing, such as the `xs` size on Bootstrap's grid, a size developers often don't plan for. The simplest solution is to ensure your grid will adapt to this size appropriately, though this may not be acceptable since you may want the large view to print rather than the smaller view. Another solution is to [override the grid column definition](https://stackoverflow.com/questions/22199429/bootstrap-grid-for-printing/28152320). Some newer versions of libraries have specific tools for dealing with printing, for example, [Bootstrap 4's Display property](https://getbootstrap.com/docs/4.3/utilities/display/).

### Page Breaks

Expand Down Expand Up @@ -472,14 +472,14 @@ If your content rendered as print media does not automatically break multi-page
- A style of `position: absolute`, when rendered to print, may result in reformatted, rotated, or re-scaled content, causing unintended affects to print page layout and page breaks
- Using `flex` may interfere with page breaks, try using `display: block`

### Handling Scrolling ([603](https://github.com/gregnb/react-to-print/issues/603))
### Handling Scrolling ([603](https://github.com/MatthewHerbst/react-to-print/issues/603))

[![Edit react-to-print (Handling Scrolling)](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/react-to-print-handling-scrolling-n4mxyj?fontsize=14&hidenavigation=1&theme=dark)

If you need to print the content of a scrolling container, you may encounter the following issues:

- [Unable to control the scroll position](https://github.com/gregnb/react-to-print/issues/603#issue-1647664811), so the printed content may not be what you want.
- [Overflow content is truncated](https://github.com/gregnb/react-to-print/issues/603#issuecomment-1649604330), resulting in missing printed content.
- [Unable to control the scroll position](https://github.com/MatthewHerbst/react-to-print/issues/603#issue-1647664811), so the printed content may not be what you want.
- [Overflow content is truncated](https://github.com/MatthewHerbst/react-to-print/issues/603#issuecomment-1649604330), resulting in missing printed content.

To solve these problems, you need to modify the properties of the scrolling container when printing. You can pass a function to the `print` property, which will be called when printing. In this function, you can use the DOM API to query the scrolling container that needs to be modified, and then modify its properties to **control the scroll position**.

Expand Down
2 changes: 1 addition & 1 deletion examples/ComponentToPrint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ComponentToPrint extends React.PureComponent<Props, State> {
<div className="relativeCSS">
<link
// This tests that we properly ignore disabled nodes
// Learn more: https://github.com/gregnb/react-to-print/pull/537
// Learn more: https://github.com/MatthewHerbst/react-to-print/pull/537
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
disabled
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/gregnb/react-to-print.git"
"url": "git+https://github.com/MatthewHerbst/react-to-print.git"
},
"keywords": [
"react",
Expand All @@ -29,9 +29,9 @@
],
"license": "MIT",
"bugs": {
"url": "https://github.com/gregnb/react-to-print/issues"
"url": "https://github.com/MatthewHerbst/react-to-print/issues"
},
"homepage": "https://github.com/gregnb/react-to-print#readme",
"homepage": "https://github.com/MatthewHerbst/react-to-print#readme",
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0"
Expand Down
10 changes: 5 additions & 5 deletions src/components/ReactToPrint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class ReactToPrint extends React.Component<IReactToPrintProps> {
this.handleRemoveIframe();
}
} else {
this.logMessages(["Printing failed because the `contentWindow` of the print iframe did not load. This is possibly an error with `react-to-print`. Please file an issue: https://github.com/gregnb/react-to-print/issues/"]);
this.logMessages(["Printing failed because the `contentWindow` of the print iframe did not load. This is possibly an error with `react-to-print`. Please file an issue: https://github.com/MatthewHerbst/react-to-print/issues/"]);
}
}, 500);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ export class ReactToPrint extends React.Component<IReactToPrintProps> {
}

if (contentEl === undefined) {
this.logMessages(['To print a functional component ensure it is wrapped with `React.forwardRef`, and ensure the forwarded ref is used. See the README for an example: https://github.com/gregnb/react-to-print#examples']);
this.logMessages(['To print a functional component ensure it is wrapped with `React.forwardRef`, and ensure the forwarded ref is used. See the README for an example: https://github.com/MatthewHerbst/react-to-print#examples']);
return;
}

Expand All @@ -173,7 +173,7 @@ export class ReactToPrint extends React.Component<IReactToPrintProps> {
printWindow.style.left = `-${document.documentElement.clientWidth + 100}px`;
printWindow.id = "printWindow";
// Ensure we set a DOCTYPE on the iframe's document
// https://github.com/gregnb/react-to-print/issues/459
// https://github.com/MatthewHerbst/react-to-print/issues/459
printWindow.srcdoc = "<!DOCTYPE html>";

const contentNodes = findDOMNode(contentEl);
Expand Down Expand Up @@ -381,15 +381,15 @@ export class ReactToPrint extends React.Component<IReactToPrintProps> {
try {
// Accessing `sheet.cssRules` on cross-origin sheets can throw
// security exceptions in some browsers, notably Firefox
// https://github.com/gregnb/react-to-print/issues/429
// https://github.com/MatthewHerbst/react-to-print/issues/429
const cssLength = sheet.cssRules.length;
for (let j = 0; j < cssLength; ++j) {
if (typeof sheet.cssRules[j].cssText === "string") {
styleCSS += `${sheet.cssRules[j].cssText}\r\n`;
}
}
} catch (error) {
this.logMessages([`A stylesheet could not be accessed. This is likely due to the stylesheet having cross-origin imports, and many browsers block script access to cross-origin stylesheets. See https://github.com/gregnb/react-to-print/issues/429 for details. You may be able to load the sheet by both marking the stylesheet with the cross \`crossorigin\` attribute, and setting the \`Access-Control-Allow-Origin\` header on the server serving the stylesheet. Alternatively, host the stylesheet on your domain to avoid this issue entirely.`, node], 'warning');
this.logMessages([`A stylesheet could not be accessed. This is likely due to the stylesheet having cross-origin imports, and many browsers block script access to cross-origin stylesheets. See https://github.com/MatthewHerbst/react-to-print/issues/429 for details. You may be able to load the sheet by both marking the stylesheet with the cross \`crossorigin\` attribute, and setting the \`Access-Control-Allow-Origin\` header on the server serving the stylesheet. Alternatively, host the stylesheet on your domain to avoid this issue entirely.`, node], 'warning');
}

newHeadEl.setAttribute("id", `react-to-print-${i}`);
Expand Down

0 comments on commit d3fb22c

Please sign in to comment.