Skip to content

Won't work on nested/reusable components? #397

@maotora

Description

@maotora

Hi, great work on this plugin.

I have reusable components for most (if not all) html elements, when I try to align with react-grid-layout they don't work.

They don't follow any of the layout, margin props which makes it really hard to deal with.

However, when i switch to normal html elements react-grid-layout works.

Here is an example.

//- Say, this is my nav-bar component.
export default class Nav extends Component {
    render() {

    var layout = [
            {i: 'a', x: 0, y: 0, w: 1, h: 2, static: true},
            {i: 'b', x: 2, y: 0, w: 1, h: 2, static: true},
            {i: 'c', x: 4, y: 0, w: 1, h: 2, static: true},
            {i: 'd', x: 6, y: 0, w: 1, h: 2, static: true},
            {i: 'e', x: 8, y: 0, w: 1, h: 2, static: true}
        ];

        return (
            
            <ReactGridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200} margin={[1, 1]} >
                <Div divStyle="navItem" key="a" href="/">
                    Home
                </Div>
                <Div divStyle="navItem" key="b" href="blog">
                    Blog
                </Div>
                <Div divStyle="navItem" key="c" href="about">
                    About
                </Div>
                <Div divStyle="navItem" key="d" href="media">
                    Media
                </Div>
                <Div divStyle="navItem" key="e" href="contact">
                    Contacts
                </Div>

            </ReactGridLayout>
        )
    };
}

//- And this is the Div component that wraps the html <div> element and adds some styles
//- with react-css-modules.
@CSSModules(styles)
class Div extends Component {
    
    render() {

        return (
            
            <div styleName={this.props.divStyle} >
                <a href={this.props.href}> {this.props.children} </a>
            </div>
        );
    }
}

Here is a screenshot of this approach.
windowed_2016-11-03_21h43s43

As you can see, it completely ignored most (if not all) of the props i passed here

<ReactGridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200} margin={[1, 1]} >

which includes the layout array that had x: n .

Here is a link to the project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleThe label to apply when a pull request or an issue is stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions