ReactModalExample.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2014 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import React from 'react'
  19. import Modal from 'react-modal'
  20. const modalOverrides = {
  21. overlay : {
  22. backgroundColor: 'rgba(0,0,0,0.5)'
  23. },
  24. content : {
  25. position: 'static',
  26. top: '0',
  27. left: '0',
  28. right: 'auto',
  29. bottom: 'auto',
  30. borderRadius: '0',
  31. border: 'none',
  32. padding: '0'
  33. }
  34. };
  35. var ReactModalExample = React.createClass({
  36. getInitialState() {
  37. return {
  38. modalIsOpen: false
  39. }
  40. },
  41. openModal() {
  42. this.setState({modalIsOpen: true});
  43. },
  44. closeModal() {
  45. this.setState({modalIsOpen: false});
  46. },
  47. handleSubmit(e) {
  48. e.preventDefault();
  49. this.setState({modalIsOpen: false});
  50. alert('Submitted');
  51. },
  52. render() {
  53. return (
  54. <div className="ReactModalExample">
  55. <button type="button" className="btn btn-primary" onClick={this.openModal}>{this.props.label || 'Trigger Modal'}</button>
  56. <Modal isOpen={this.state.modalIsOpen}
  57. onRequestClose={this.closeModal}
  58. className={this.props.className}
  59. overlayClassName={this.props.overlayClassName}
  60. style={modalOverrides}>
  61. <div className="ReactModal__Layout">
  62. <div className="ReactModal__Header">
  63. <div className="ReactModal__Header-Title">
  64. <h4>Modal Title Goes Here</h4>
  65. </div>
  66. <div className="ReactModal__Header-Actions">
  67. <button className="Button Button--icon-action" type="button" onClick={this.closeModal}>
  68. <i className="icon-x"></i>
  69. <span className="screenreader-only">Close</span>
  70. </button>
  71. </div>
  72. </div>
  73. <div className="ReactModal__Body">
  74. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus deserunt doloremque, explicabo illo
  75. ipsum libero magni odio officia optio perferendis ratione repellat suscipit tempore. Commodi hic sed.
  76. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus deserunt doloremque, explicabo illo
  77. ipsum libero magni odio officia optio perferendis ratione repellat suscipit tempore. Commodi hic sed.
  78. </div>
  79. <div className="ReactModal__Footer">
  80. <div className="ReactModal__Footer-Actions">
  81. <button type="button" className="btn btn-default" onClick={this.closeModal}>Cancel</button>
  82. <button type="submit" className="btn btn-primary" onClick={this.handleSubmit}>Submit</button>
  83. </div>
  84. </div>
  85. </div>
  86. </Modal>
  87. </div>
  88. );
  89. }
  90. });
  91. export default ReactModalExample