GridEditModal.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. </ModalBody>
  53. <ModalFooter className="grw-modal-footer">
  54. <div className="ml-auto">
  55. <button type="button" className="mr-2 btn btn-secondary" onClick={this.cancel}>Cancel</button>
  56. <button type="button" className="btn btn-primary" onClick={this.pasteCodedGrid}>Done</button>
  57. </div>
  58. </ModalFooter>
  59. </Modal>
  60. );
  61. }
  62. }
  63. GridEditModal.propTypes = {
  64. onSave: PropTypes.func,
  65. };