GridEditModal.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {
  4. Modal, ModalHeader, ModalBody, ModalFooter,
  5. } from 'reactstrap';
  6. import geu from './GridEditorUtil';
  7. export default class GridEditModal extends React.PureComponent {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. show: false,
  12. gridHtml: '',
  13. };
  14. this.init = this.init.bind(this);
  15. this.show = this.show.bind(this);
  16. this.hide = this.hide.bind(this);
  17. this.cancel = this.cancel.bind(this);
  18. this.pasteCodedGrid = this.pasteCodedGrid.bind(this);
  19. }
  20. init(gridHtml) {
  21. const initGridHtml = gridHtml;
  22. this.setState({ gridHtml: initGridHtml }, function() {
  23. // display gridHtml for re-editing
  24. console.log(this.state.gridHtml);
  25. });
  26. }
  27. show(gridHtml) {
  28. this.init(gridHtml);
  29. this.setState({ show: true });
  30. }
  31. hide() {
  32. this.setState({ show: false });
  33. }
  34. cancel() {
  35. this.hide();
  36. }
  37. pasteCodedGrid() {
  38. // dummy data
  39. const convertedHTML = geu.convertRatiosAndSizeToHTML([1, 5, 6], 'sm');
  40. const pastedGridData = `::: editable-row\n<div class="container">\n\t<div class="row">\n${convertedHTML}\n\t</div>\n</div>\n:::`;
  41. // display converted html on console
  42. console.log(convertedHTML);
  43. if (this.props.onSave != null) {
  44. this.props.onSave(pastedGridData);
  45. }
  46. this.cancel();
  47. }
  48. showBgCols() {
  49. const cols = [];
  50. for (let i = 0; i < 12; i++) {
  51. // [bg-light:TODO support dark mode by GW-3037]
  52. cols.push(<div className="bg-light grid-bg-col col-1"></div>);
  53. }
  54. return cols;
  55. }
  56. showEditableCols() {
  57. const cols = [];
  58. for (let i = 0; i < 12; i++) {
  59. // [bg-light:TODO support dark mode by GW-3037]
  60. cols.push(<div className="bg-dark grid-bg-col col-1"></div>);
  61. }
  62. return cols;
  63. }
  64. render() {
  65. return (
  66. <Modal isOpen={this.state.show} toggle={this.cancel} size="xl">
  67. <ModalHeader tag="h4" toggle={this.cancel} className="bg-primary text-light">
  68. Edit Grid
  69. </ModalHeader>
  70. <ModalBody>
  71. <div className="container">
  72. <div className="row">
  73. <div className="col-3">
  74. <h5>Phone</h5>
  75. <div className="device-container"></div>
  76. <h5>Tablet</h5>
  77. <div className="device-container"></div>
  78. <h5>Desktop</h5>
  79. <div className="device-container"></div>
  80. <h5>Large Desktop</h5>
  81. <div className="device-container"></div>
  82. </div>
  83. <div className="col-9">
  84. <div className="row h-100">
  85. {this.showBgCols()}
  86. </div>
  87. <div className="row w-100 h-100 position-absolute grid-editable-row">
  88. {/* [Just an example to check if bg-cols and editable-cols fit] */}
  89. <div className="bg-dark grid-editable-col col-3"></div>
  90. <div className="bg-dark grid-editable-col col-5"></div>
  91. <div className="bg-dark grid-editable-col col-4"></div>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </ModalBody>
  97. <ModalFooter className="grw-modal-footer">
  98. <div className="ml-auto">
  99. <button type="button" className="mr-2 btn btn-secondary" onClick={this.cancel}>Cancel</button>
  100. <button type="button" className="btn btn-primary" onClick={this.pasteCodedGrid}>Done</button>
  101. </div>
  102. </ModalFooter>
  103. </Modal>
  104. );
  105. }
  106. }
  107. GridEditModal.propTypes = {
  108. onSave: PropTypes.func,
  109. };