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

Make "pageStyle" prop may also be a function #198

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ The component accepts the following props (note: `?` denotes an optional prop):
| **`onAfterPrint`** | `function?` | Callback function that triggers after print |
| **`onPrintError`** | `function(errorLocation: string, error: Error)?` | Callback function that will be called if there is a printing error serious enough that printing cannot continue. Currently limited to Promise rejections in `onBeforeGetContent` or `onBeforePrint`. Use this to attempt to print again. `errorLocation` will tell you in which callback the Promise was rejected. |
| **`removeAfterPrint`** | `boolean?` | Remove the print iframe after action. Defaults to `false`. |
| **`pageStyle`** | `string?` | Override default print window styling |
| **`pageStyle`** | `string?`, `function?` | Override default print window styling. If `function` then calling in runtime just before the print. |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be string?|function?

| **`bodyClass`** | `string?` | Class to pass to the print window body |

## FAQ
Expand Down
6 changes: 4 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IReactToPrintProps {
/** Callback function to listen for printing errors */
onPrintError?: (errorLocation: string, error: Error) => void;
/** Override default print window styling */
pageStyle?: string;
pageStyle?: string | (() => string);
/** Optional class to pass to the print window body */
bodyClass?: string;
/** Optional - remove the iframe after printing. */
Expand Down Expand Up @@ -162,7 +162,9 @@ export default class ReactToPrint extends React.Component<IReactToPrintProps> {
/* remove date/time from top */
const defaultPageStyle = pageStyle === undefined
? "@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }" // tslint:disable-line max-line-length
: pageStyle;
: typeof pageStyle === "function"
? pageStyle()
: pageStyle;

const styleEl = domDoc.createElement("style");
styleEl.appendChild(domDoc.createTextNode(defaultPageStyle));
Expand Down