-
Have been toying with the landing page example for a few days, I added multi page support and basic data binding to the text control, <RepeatingContainer data={['A','B','C','D']}>
<Button>{context}</Button>
<RepeatingContainer />
// final rendered component should be
<Button>A</Button>
<Button>B</Button>
<Button>C</Button>
<Button>D</Button> In Edit mode you should only see one child, so you only need to design one child, but out of edit mode the child controls should be repeating. I copied Container control and i guess i should modify the render function, instead of:
do something like: if(editMode){
renderChildSomeHow(data[0]); // in edit mode render one instance of child component, and pass some mocked data, for design purposes
}
else{
data.map( (item) => {
renderChildSomeHow(item); // out of edit mode, render child multiple times and pass the corresponding array item
})
} Can't figure this out with my current knowledge of all the frameworks involved, so I'm asking for guidance. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Well, seems I have been able to pull this on my own :) I modified container initialization, get editor state and inspect the children let child: ReactNode = null;
if(React.Children.count(children) > 0){
child = React.Children.only(children);
}
const { enabled } = useEditor((state) => ({
enabled: state.options.enabled,
})); now in the render function {
child != null ? ( enabled ? child : data.map((item) => child)) : <span>No child</span>
} Still not finished, but seems i can get there from here, now i guess i will have to fiddle with React.createElement or something to pass the array element as prop to the child component |
Beta Was this translation helpful? Give feedback.
-
@cederron @heyjaypray
but your original question was: "In Edit mode you should only see one child, so you only need to design one child". So, I assume what you want is having Repeater as a canvas and letting user drop things (e.g. Child) into it, which will be repated but when you drag&drop a Repeater component and then a Child component into it, this don't we need some cloning using CraftJS nodes similar to what's discussed here? |
Beta Was this translation helpful? Give feedback.
Well, seems I have been able to pull this on my own :)
it was simpler than expected.
I modified container initialization, get editor state and inspect the children
now in the render function
Still not finished, but seems i can get there from here, now i guess i will have to fiddle with React.createElement or something to pass the array element as prop to the child component