New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frontity Flow component - Html2React experiment 馃И #67
Conversation
Deploy preview for website ready! Built with commit 477a06a |
I've added a second example, which shows in more detail the problem that I'm trying to solve. |
@michalczaplinski, I want to make sure I understood the experiment. We have this layout: <div class="switch">
<div class="switch-button"></div>
<div class="switch-value"></div>
</div> and when the user clicks the |
@luisherranz that's right. Or maybe we want to render some text inside the Like: |
Ok, thanks :) This is my take:
Does it makes sense? |
And for the Something like: export const switchElement: Processor = {
name: "switch",
test: ({ node }) =>
node.type === "element" &&
node.props?.className?.split(" ").includes("switch"),
processor: ({ node }) => {
// `node.match` would return the elements that match the query
const switchButtonNodes = node.match("div.switchButton");
const switchContentNodes = node.match("div.content");
// Replace `div` by our components in that nodes
const switchButtons = switchButtonNodes.map(node => ({
...node,
component: SwitchButton
}));
const switchContent = switchContentNodes.map(node => ({
...node,
component: SwitchContent
}))
return {
component: Switch,
children: [
// Add the nodes to `children` so they will be rendered by Html2React
...switchButtons,
...switchContent,
]
};
},
}; EDIT: this way you won't need to nest |
Thanks guys! 馃檪 I see what you both mean. I know that I could use React context to pass state around the component tree. Actually I didn't think about using To me it seems like we're intentionally missing out on one of the best features of react here (the ability to pass different props to child components depending on some condition). And instead we're accomplishing the same but in a worse way 馃槄. If you squint your eyes this whole part looks almost like a react component in it's own right: processor: ({ node }) => {
// `node.match` would return the elements that match the query
const switchButtonNodes = node.match("div.switchButton");
const switchContentNodes = node.match("div.content");
// Replace `div` by our components in that nodes
const switchButtons = switchButtonNodes.map(node => ({
...node,
component: SwitchButton
}));
const switchContent = switchContentNodes.map(node => ({
...node,
component: SwitchContent
}))
return {
component: Switch,
children: [
// Add the nodes to `children` so they will be rendered by Html2React
...switchButtons,
...switchContent,
]
};
}, We should be able to just use JSX and props to accomplish the same task in a way that is more familiar to react developers! I ll move the discussion to a Feature Discussion because I still think we can do better 馃檪 |
We are moving this conversation to: https://community.frontity.org/t/gutenberg-frontity-integration/1467 |
This branch shows an experiment that I attempted in order to allow to compose and style the gutenberg blocks with a more developer-friendly API.
https://www.loom.com/share/6c650ffbae2a4a8c9025a900d311db86
This experiment was prompted by the requirements for the Frontity Flow component of the website: #51