minutemailer / react-popup

React popup component
http://minutemailer.github.io/react-popup/
MIT License
208 stars 71 forks source link

emit id on close #47

Closed z-vr closed 6 years ago

z-vr commented 6 years ago

This is useful because SHOW emits an id, and so should CLOSE -- that way it's possible to know all open and closed popups. e.g.,

constructor(props) {
    super(props);
    this.state = {
      openPopups: [],
    };
    Popup.addShowListener((pid) => {
      if (!this.state.openPopups.includes(pid)) { // this is because SHOW is also emitted when a popup is opened from the queue. 
        this.setState(({ openPopups }) => ({
          openPopups: [...openPopups, pid],
        }));
      }
    });
    Popup.addCloseListener((pid) => {
      this.setState(({ openPopups }) => ({
        openPopups: openPopups.filter(id => id !== pid),
      }));
    });
  }
tbleckert commented 6 years ago

Ah thanks for this, close should obviously emit and ID as well. I'll merge it in right away. I'm making it a part of the v1.0.0 milestone. So it will go out together with some other stuff on February 15th.