FlexLayout icon indicating copy to clipboard operation
FlexLayout copied to clipboard

First example

Open EAzari opened this issue 5 years ago • 4 comments

Hi, I tried to run the first test, but it doesn't work

In react package (npx create-react-app my-app) I changed App.js and index.js in this way:

App.js

import React from 'react';
import FlexLayout from 'flexlayout-react';
// import logo from './logo.svg';
// import './App.css';

var json = {
  global: {tabEnableClose:false},
  borders:[
      {
        "type": "border",
        "location":"bottom",
        "size": 100,
        "children": [
            {
            "type": "tab",
            "name": "four",
            "component": "text"
            }
          ]
      },
      {
        "type": "border",
        "location":"left",
        "size": 100,
        "children": []
       }
  ],
  layout: {
      "type": "row",
      "weight": 100,
      "children": [
          {
              "type": "tabset",
              "weight": 50,
              "selected": 0,
              "children": [
                  {
                      "type": "tab",
                      "name": "One",
                      "component": "text"
                  }
              ]
          },
          {
              "type": "tabset",
              "weight": 50,
              "selected": 0,
              "children": [
                  {
                      "type": "tab",
                      "name": "Two",
                      "component": "text"
                  },
                  {
                      "type": "tab",
                      "name": "Three",
                      "component": "text"
                  }
              ]
          }
      ]
  }
};

class App extends React.Component {

  constructor(props) {
    super(props);
    this.state = {model: FlexLayout.Model.fromJson(json)};
  }

  factory(node) {
      var component = node.getComponent();
      if (component === "text") {
          return (<div className="panel">Panel {node.getName()}</div>);
      }
  }

  render() {
      return (
          <FlexLayout.Layout
              model={this.state.model}
              factory={this.factory.bind(this)}/>
      );
  }
}

export default App;

index.js

import React from 'react';
import ReactDOM from 'react-dom';
// import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content=""
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <link rel="stylesheet" href="node_modules/flexlayout-react/style/light.css" />
    <title>Test</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

But it doesn't work

Could you please write a complete wiki about FlexLayout, personally I think you build a great solution, but the documentation and also support parts are weak

EAzari avatar Aug 18 '20 22:08 EAzari

Code looks OK, what error are you getting?

Have you got css for your root element to give it a size? e.g.

<style>
    html,body
    {
        height: 100%;
        margin: 0;
        padding: 0;
        overflow:hidden;
        font-size: 12px;
        font-family: Arial, sans-serif;
    }

    #root {
        left: 10px;
        top: 10px;
        right: 10px;
        bottom: 10px;
        position: absolute;
        overflow: hidden;
        background-color: white;
    }
</style>

nealus avatar Aug 19 '20 08:08 nealus

@nealus vscode doesn't show any error, I use terminal (npm start), but I see just a page without any content I included this css root in index.html:

<link rel="stylesheet" href="node_modules/flexlayout-react/style/light.css" /> 

EAzari avatar Aug 19 '20 09:08 EAzari

try adding the above <style>...</style> in the <head> element, your #root needs to have a size, I think that is the problem, if not then you need to look at any messages in the browser console (via the developer tools, F12 on windows, option + command + i on mac)

nealus avatar Aug 19 '20 09:08 nealus

I incliuded the style in index.html, but nothing changed Also, I don't have any problem in terminal

EAzari avatar Aug 19 '20 09:08 EAzari