GridEditModal.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. };
  12. this.show = this.show.bind(this);
  13. this.hide = this.hide.bind(this);
  14. this.cancel = this.cancel.bind(this);
  15. this.pasteCodedGrid = this.pasteCodedGrid.bind(this);
  16. }
  17. show() {
  18. this.setState({ show: true });
  19. }
  20. hide() {
  21. this.setState({ show: false });
  22. }
  23. cancel() {
  24. this.hide();
  25. }
  26. pasteCodedGrid() {
  27. // dummy data
  28. const pastedGridData = `::: editable-row\n<div class="container">\n <div class="row">
  29. <div class="col-sm-6 col-md-5 col-lg-12">dummy</div>\n </div>\n</div>\n:::`;
  30. if (this.props.onSave != null) {
  31. this.props.onSave(pastedGridData);
  32. }
  33. this.cancel();
  34. }
  35. showBgCols() {
  36. const cols = [];
  37. for (let i = 0; i < 12; i++) {
  38. // [bg-light:TODO support dark mode by GW-3037]
  39. cols.push(<div className="bg-light grid-bg-col col-1"></div>);
  40. }
  41. return cols;
  42. }
  43. showEditableCols() {
  44. const cols = [];
  45. for (let i = 0; i < 12; i++) {
  46. // [bg-light:TODO support dark mode by GW-3037]
  47. cols.push(<div className="bg-dark grid-bg-col col-1"></div>);
  48. }
  49. return cols;
  50. }
  51. render() {
  52. return (
  53. <Modal isOpen={this.state.show} toggle={this.cancel} size="xl">
  54. <ModalHeader tag="h4" toggle={this.cancel} className="bg-primary text-light">
  55. Edit Grid
  56. </ModalHeader>
  57. <ModalBody>
  58. <div className="container">
  59. <div className="row">
  60. <div className="col-3">
  61. <h5>Phone</h5>
  62. <div className="device-container"></div>
  63. <h5>Tablet</h5>
  64. <div className="device-container"></div>
  65. <h5>Desktop</h5>
  66. <div className="device-container"></div>
  67. <h5>Large Desktop</h5>
  68. <div className="device-container"></div>
  69. </div>
  70. <div className="col-9">
  71. <div className="row h-100">
  72. {this.showBgCols()}
  73. </div>
  74. <div className="row w-100 h-100 position-absolute grid-editable-row">
  75. {/* [Just an example to check if bg-cols and editable-cols fit] */}
  76. <div className="bg-dark grid-editable-col col-3"></div>
  77. <div className="bg-dark grid-editable-col col-5"></div>
  78. <div className="bg-dark grid-editable-col col-4"></div>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. </ModalBody>
  84. <ModalFooter className="grw-modal-footer">
  85. <div className="ml-auto">
  86. <button type="button" className="mr-2 btn btn-secondary" onClick={this.cancel}>Cancel</button>
  87. <button type="button" className="btn btn-primary" onClick={this.pasteCodedGrid}>Done</button>
  88. </div>
  89. </ModalFooter>
  90. </Modal>
  91. );
  92. }
  93. }
  94. GridEditModal.propTypes = {
  95. onSave: PropTypes.func,
  96. };