GridEditModal.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. showBgCols() {
  46. const cols = [];
  47. for (let i = 0; i < 12; i++) {
  48. // [bg-light:TODO support dark mode by GW-3037]
  49. cols.push(<div className="bg-light grid-bg-col col-1"></div>);
  50. }
  51. return cols;
  52. }
  53. showEditableCols() {
  54. const cols = [];
  55. for (let i = 0; i < 12; i++) {
  56. // [bg-light:TODO support dark mode by GW-3037]
  57. cols.push(<div className="bg-dark grid-bg-col col-1"></div>);
  58. }
  59. return cols;
  60. }
  61. render() {
  62. return (
  63. <Modal isOpen={this.state.show} toggle={this.cancel} size="xl">
  64. <ModalHeader tag="h4" toggle={this.cancel} className="bg-primary text-light">
  65. Edit Grid
  66. </ModalHeader>
  67. <ModalBody>
  68. <div className="container">
  69. <div className="row">
  70. <div className="col-3">
  71. <h5>Phone</h5>
  72. <div className="device-container"></div>
  73. <h5>Tablet</h5>
  74. <div className="device-container"></div>
  75. <h5>Desktop</h5>
  76. <div className="device-container"></div>
  77. <h5>Large Desktop</h5>
  78. <div className="device-container"></div>
  79. </div>
  80. <div className="col-9">
  81. <div className="row h-100">
  82. {this.showBgCols()}
  83. </div>
  84. <div className="row w-100 h-100 position-absolute grid-editable-row">
  85. {/* [Just an example to check if bg-cols and editable-cols fit] */}
  86. <div className="bg-dark grid-editable-col col-3"></div>
  87. <div className="bg-dark grid-editable-col col-5"></div>
  88. <div className="bg-dark grid-editable-col col-4"></div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </ModalBody>
  94. <ModalFooter className="grw-modal-footer">
  95. <div className="ml-auto">
  96. <button type="button" className="mr-2 btn btn-secondary" onClick={this.cancel}>Cancel</button>
  97. <button type="button" className="btn btn-primary" onClick={this.pasteCodedGrid}>Done</button>
  98. </div>
  99. </ModalFooter>
  100. </Modal>
  101. );
  102. }
  103. }
  104. GridEditModal.propTypes = {
  105. onSave: PropTypes.func,
  106. };