GridEditModal.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {
  4. Modal, ModalHeader, ModalBody, ModalFooter,
  5. } from 'reactstrap';
  6. export default class GridEditModal extends React.PureComponent {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. show: false,
  11. gridHtml: '',
  12. };
  13. this.init = this.init.bind(this);
  14. this.show = this.show.bind(this);
  15. this.hide = this.hide.bind(this);
  16. this.cancel = this.cancel.bind(this);
  17. this.pasteCodedGrid = this.pasteCodedGrid.bind(this);
  18. }
  19. init(gridHtml) {
  20. const initGridHtml = gridHtml;
  21. this.setState({ gridHtml: initGridHtml }, function() {
  22. // display gridHtml for re-editing
  23. console.log(this.state.gridHtml);
  24. });
  25. }
  26. show(gridHtml) {
  27. this.init(gridHtml);
  28. this.setState({ show: true });
  29. }
  30. hide() {
  31. this.setState({ show: false });
  32. }
  33. cancel() {
  34. this.hide();
  35. }
  36. pasteCodedGrid() {
  37. // dummy data
  38. const pastedGridData = `::: editable-row\n<div class="container">\n <div class="row">
  39. <div class="col-sm-6 col-md-5 col-lg-12">dummy</div>\n </div>\n</div>\n:::`;
  40. if (this.props.onSave != null) {
  41. this.props.onSave(pastedGridData);
  42. }
  43. this.cancel();
  44. }
  45. render() {
  46. return (
  47. <Modal isOpen={this.state.show} toggle={this.cancel} size="xl">
  48. <ModalHeader tag="h4" toggle={this.cancel} className="bg-primary text-light">
  49. Create Bootstrap 4 Grid
  50. </ModalHeader>
  51. <ModalBody>
  52. <div className="container">
  53. <div className="row">
  54. </div>
  55. </div>
  56. </ModalBody>
  57. <ModalFooter className="grw-modal-footer">
  58. <div className="ml-auto">
  59. <button type="button" className="mr-2 btn btn-secondary" onClick={this.cancel}>Cancel</button>
  60. <button type="button" className="btn btn-primary" onClick={this.pasteCodedGrid}>Done</button>
  61. </div>
  62. </ModalFooter>
  63. </Modal>
  64. );
  65. }
  66. }
  67. GridEditModal.propTypes = {
  68. onSave: PropTypes.func,
  69. };