Need help with creating custom 2 column layout using React component. #4968
Unanswered
Pranav4399
asked this question in
Q&A
Replies: 2 comments 6 replies
-
Your react component doesn't allow children inside. Row component const Row = ({ children }) => {
return <div ....>{children}</div>
} Column component const Column = ({ children }) => {
return <div ....>{children}</div>
} And your block would be something like this: editor.BlockManager.add('doublecolumn', {
// ...
content: `
<Row>
<Column></Column>
<Column></Column>
</Row>
`
}); |
Beta Was this translation helpful? Give feedback.
6 replies
-
Thank you @Julia-Alberici ❤️ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. Thanks for creating this great library. For our use case, we have requirements to create a custom 2-column layout through react component. But doing so is preventing any child control(Textbox, Link, Map etc.) to be added within that. I'm attaching the code of the 2-column layout react component and the addType method below as well.
DoubleColumn.js (React Component)
import React, { useState } from "react"; const DoubleColumn = () => { return ( <div style={{minHeight: '100px', display: 'flex', width: '100%'}}> <div style={{border: '1px solid green', width: '50%'}} data-gjs-type="default" className="row-cell" draggable="true"></div> <div style={{border: '1px solid red', width: '50%'}} data-gjs-type="default" className="row-cell" draggable="true"></div> {/* <div id="i96i" data-gjs-type="default" draggable="true" data-highlightable="1" class="row-cell"></div> */} </div> ) } export default DoubleColumn;
Code added in Plugin file
editor.Components.addType('DoubleColumn', { extend: 'react-component', model: { defaults: { component: DoubleColumn, stylable: true, resizable: false, editable: true, draggable: true, droppable: true, attributes: { style: 'height: 100px;' }, traits: [ { label: 'MLS ID', name: 'mlsid' } ] } }, isComponent: (el) => el.tagName === 'DOUBLECOLUMN' });
editor.BlockManager.add('doublecolumn', { label: "<div class='gjs-fonts gjs-f-b1'>2 Column</div>", category: 'Section Components', content: '<DoubleColumn></DoubleColumn>' });
This is how the component renders in the DOM normally -

When I try to drag an textbox into one of the child divs, the gjs-selected-parent attribute is getting applied to the parent div as seen below -

The main reason for this requirement is because we require the code of every form created in GrapeJS to be converted to JSON format. The existing column layouts show code in HTML format but we require them to be rendered as react component code as well similar to how custom components behave. I've also attached the difference between HTML code and React Code below -
All the code I've mentioned are written on top of this code already present in this great repository - https://github.com/beepsoft/grapesjs-react-components-by-artf
Please let me know if this use case is possible. Thanks & Cheers.
Beta Was this translation helpful? Give feedback.
All reactions