bitshares / bitshares-ui

Fully featured Graphical User Interface / Reference Wallet for the BitShares Blockchain
https://wallet.bitshares.org
MIT License
518 stars 569 forks source link

[3] Implementing React Grid Layout #1640

Open startailcoon opened 6 years ago

startailcoon commented 6 years ago

With the usage of https://www.npmjs.com/package/react-grid-layout we can easily let the user rearenge the cards of data.

Part of discussion on #1477

@sschiessl-bcp, if you have time to work on a solution that can handle cards of data with a dynamic screen that can be aranged by easy passing the data to it, it would be perfect.

Test Code

A small test shows this code works well, but needs to be worked on to handle what we need.

import React from "react";
import ReactGridLayout from "react-grid-layout";

class DynamicGrid extends React.Component {
    render() {
        let elements = this.props.children.map(card => {
            return (
                <div key={card.i} style={{border: "1px solid #000000"}}>
                    {card.content}
                </div>
            );
        });

        return(
            <ReactGridLayout className="layout" layout={this.props.layout} cols={this.props.cols} rowHeight={this.props.rowHeight} width={this.props.width}>
                {elements}
            </ReactGridLayout>
        );
    }
};

export default DynamicGrid;
<DynamicGrid 
    cols="2"
    rowHeight="30"
    width="1200"
    layout={[
        {i: 1, x: 0, y: 0, w: 1, h: 5},
        {i: 2, x: 1, y: 0, w: 1, h: 5},
    ]}
    children={[
        {i: 1, content: marketsTab},
        {i: 2, content: buySellTab},
    ]}

/> 

Tabs

It would be very handy if the component could handle "merging and splitting of cards" and use the Ant Tabs for this.

sschiessl-bcp commented 6 years ago

Currently evaluating

https://www.npmjs.com/package/react-grid-layout

https://github.com/caplin/FlexLayout

https://www.npmjs.com/package/react-golden-layout https://golden-layout.com/

sschiessl-bcp commented 6 years ago
sschiessl-bcp commented 6 years ago

Testing https://www.npmjs.com/package/react-grid-layout image

Basic functionality is working, missing resize buttons

sschiessl-bcp commented 6 years ago

I have refined the view now, for a better drag&drop feeling I need to wait for React16 issues to be resolved within react-grid-layout.

Here is an example, rearranging disabled: image

Here is rearranging enabled: image

In code that looks like this: https://github.com/bitshares/bitshares-ui/blob/be868eee0afb501c4994aa64ac20cb2915988039/app/components/Dashboard/DashboardPage.jsx#L55 I decided to use placeholders for rearranging because the drop&drag handler was interfering with actual content. Thought?

The layout also stores in local storage now how the user arraged it.

sschiessl-bcp commented 6 years ago

This is intentionally not completed yet as the framework might evolve when it's actually being used, e.g. for a landing page