import React from 'react'; import PropTypes from 'prop-types'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import geu from './GridEditorUtil'; export default class GridEditModal extends React.Component { constructor(props) { super(props); this.state = { colsRatios: [6, 6], responsiveSize: 'mobile', show: false, gridHtml: '', }; this.init = this.init.bind(this); this.show = this.show.bind(this); this.hide = this.hide.bind(this); this.cancel = this.cancel.bind(this); this.pasteCodedGrid = this.pasteCodedGrid.bind(this); this.showGridPattern = this.showGridPattern.bind(this); this.checkResposiveSize = this.checkResposiveSize.bind(this); } async checkResposiveSize(responsiveSize) { await this.setState({ responsiveSize }); } async checkColsRatios(colsRatios) { console.log(colsRatios); await this.setState({ colsRatios }); } showGridPattern() { const colsRatios = this.state.colsRatios; const createdCol = colsRatios.map((colsRatio) => { return `- ${colsRatio} `; }); return createdCol.join('').slice(1); } init(gridHtml) { const initGridHtml = gridHtml; this.setState({ gridHtml: initGridHtml }, function() { // display gridHtml for re-editing console.log(this.state.gridHtml); }); } show(gridHtml) { this.init(gridHtml); this.setState({ show: true }); } hide() { this.setState({ show: false }); } cancel() { this.hide(); } pasteCodedGrid() { // dummy data const convertedHTML = geu.convertRatiosAndSizeToHTML([1, 5, 6], 'sm'); const pastedGridData = `::: editable-row\n
\n\t
\n${convertedHTML}\n\t
\n
\n:::`; // display converted html on console console.log(convertedHTML); if (this.props.onSave != null) { this.props.onSave(pastedGridData); } this.cancel(); } render() { return ( Create Bootstrap 4 Grid
{ this.checkResposiveSize('mobile') }} checked={this.state.responsiveSize === 'mobile'} />
{ this.checkResposiveSize('tablet') }} checked={this.state.responsiveSize === 'tablet'} />
{ this.checkResposiveSize('desktop') }} checked={this.state.responsiveSize === 'desktop'} />

Preview

); } } function GridDivisionMenu() { const gridDivisions = geu.mappingAllGridDivisionPatterns; return (
{gridDivisions.map((gridDivion, i) => { return (
{i + 2}分割
{gridDivion.map((gridOneDivision) => { return ( { this.checkColsRatios(gridOneDivision) }}>
{gridOneDivision.map((gtd) => { const className = `bg-info col-${gtd} border`; return {gtd}; })}
); })}
); })}
); } GridEditModal.propTypes = { onSave: PropTypes.func, };