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

add onBeforePrint callback #8

Closed
MikeSha opened this issue Mar 30, 2018 · 4 comments
Closed

add onBeforePrint callback #8

MikeSha opened this issue Mar 30, 2018 · 4 comments
Assignees

Comments

@MikeSha
Copy link
Contributor

MikeSha commented Mar 30, 2018

I don't know if it is in the scope of this library, but I think it could be very nice to have such callback. For example, I have some collection of data and. For each item I have a button "Print Invoice". It would be very nice to update "Printable" component data instead of render it for each item.

Something like this:

static propTypes = {
/** Copy styles over into print window. default: true /
copyStyles: PropTypes.bool,
/
* Trigger action used to open browser print /
trigger: PropTypes.func.isRequired,
/
* Content to be printed /
content: PropTypes.func.isRequired,
/
* if you need to do something with the data for printable component
right before the print */
onBeforePrint: PropTypes.func,
};

static defaultProps = {
copyStyles: true,
onBeforePrint: () => {},
};

...

handlePrint = () => {

const {
  content,
  copyStyles,
  onBeforePrint,
} = this.props;

onBeforePrint();

let printWindow = window.open("", "Print", "status=no, toolbar=no, scrollbars=yes", "false");

...

}

I haven't checked it yet and I'm not sure if it's necessary for this library.

Sorry for every day comments here :) I have a project where I'll need to print a lot of data and while I researched print-connected libraries for React, I've found your library potentially the most useful for this project.

@gregnb
Copy link
Collaborator

gregnb commented Mar 30, 2018

I think this is a great idea but let's also add one after printing so:

onBeforePrint
onAfterPrint

@gregnb
Copy link
Collaborator

gregnb commented Mar 30, 2018

I'm going to take this one up because the afterPrint is a little bit of work but I'm interested in this one :)

@gregnb gregnb self-assigned this Mar 30, 2018
@gregnb
Copy link
Collaborator

gregnb commented Mar 31, 2018

Ok this is now complete in 1.1.12

@gregnb gregnb closed this as completed Mar 31, 2018
@fstepien
Copy link

fstepien commented Apr 6, 2018

I am wondering if the onBeforePrint function can be used to run print if it returns true, and stop printing if it returns false? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants