在reactjs应用程序中打开一个弹出窗口

hit*_*esh 0 reactjs

嗨,我想打开一个类似于当有人单击“注册链接”时该网站打开的弹出窗口https://www.eventshigh.com/detail/Bangalore/625f39dbdb5b8e4fb5b78a073922f221-6th-save-the-queen-corporate?src=ecbox

我想将属性传递给子元素,该子元素将在弹出窗口中打开,然后将子元素中采取的操作捕获到父元素中。

有人可以告诉我我们如何做到最好。

mde*_*gis 5

他们打电话给Modal

您可以检查react-modal库。

这是一个简单的示例,该示例在应用中使用react-modal,在模式内容中具有一些自定义样式和可聚焦的输入元素:

import React from 'react';
import ReactDOM from 'react-dom';
import Modal from 'react-modal';

const customStyles = {
  content : {
    top                   : '50%',
    left                  : '50%',
    right                 : 'auto',
    bottom                : 'auto',
    marginRight           : '-50%',
    transform             : 'translate(-50%, -50%)'
  }
};

// Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/)
Modal.setAppElement('#yourAppElement')

class App extends React.Component {
  constructor() {
    super();

    this.state = {
      modalIsOpen: false
    };

    this.openModal = this.openModal.bind(this);
    this.afterOpenModal = this.afterOpenModal.bind(this);
    this.closeModal = this.closeModal.bind(this);
  }

  openModal() {
    this.setState({modalIsOpen: true});
  }

  afterOpenModal() {
    // references are now sync'd and can be accessed.
    this.subtitle.style.color = '#f00';
  }

  closeModal() {
    this.setState({modalIsOpen: false});
  }

  render() {
    return (
      <div>
        <button onClick={this.openModal}>Open Modal</button>
        <Modal
          isOpen={this.state.modalIsOpen}
          onAfterOpen={this.afterOpenModal}
          onRequestClose={this.closeModal}
          style={customStyles}
          contentLabel="Example Modal"
        >

          <h2 ref={subtitle => this.subtitle = subtitle}>Hello</h2>
          <button onClick={this.closeModal}>close</button>
          <div>I am a modal</div>
          <form>
            <input />
            <button>tab navigation</button>
            <button>stays</button>
            <button>inside</button>
            <button>the modal</button>
          </form>
        </Modal>
      </div>
    );
  }
}

ReactDOM.render(<App />, appElement);
Run Code Online (Sandbox Code Playgroud)

您可以在这里看到更多示例