-
The code below works, but I was wondering if I can define the component children with JSX (the commented code). I couldn't use JSX react fragments to wrap the children in it, and I don't want to put an unnecessary // const components = (
// <span>Component with styles</span>
// <div class="cmp-css-a">Component A</div>
// <div class="cmp-css-b">Component B</div>
// );
const components = `
<span>Component with styles</span>
<div class="cmp-css-a">Component A</div>
<div class="cmp-css-b">Component B</div>
`;
export const plugin = (editor) => {
editor.DomComponents.addType('g-text', {
model: {
defaults: {
attributes: { class: 'cmp-css' },
components: components,
styles: `
.cmp-css { color: red }
.cmp-css-a { color: green }
.cmp-css-b { color: blue }
@media (max-width: 992px) {
.cmp-css{ color: darkred; }
.cmp-css-a { color: darkgreen }
.cmp-css-b { color: darkblue }
}
`,
},
},
});
}; Basically I want to have multiple elements together as a component, I'm not sure if it's a good idea or not yet. Should I use blocks or a component with multiple children? I want to put an |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
A component is always defined with a wrapper but a block could be an array of components (or like an HTML you have defined) but I'd always suggest using a single component to define your block. |
Beta Was this translation helpful? Give feedback.
A component is always defined with a wrapper but a block could be an array of components (or like an HTML you have defined) but I'd always suggest using a single component to define your block.
About JSX, did you follow this guide?