0.1.7 ā€¢ Published 2 years ago

@pixore/subdivide v0.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Layout system inspired by blender's subdivide layout using React.js

Table of content:

Introduction

Subdivide is based on the layout system created for Blender, in which every area can be split into more areas or be merged with a sibling area.

Installation

npm install @pixore/subdivide

Basic Usage

import React from 'react';
import { render } from 'react-dom';

import Subdivide from '@pixore/subdivide';

const MasterPanel = () => <span>hello world!</span>;

const App = () => {
  return <Subdivide component={MasterPanel} />;
};

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

Note the MasterPanel component, usually, this component should be able to turn into any other panel using a select input or a similar mechanism.

And that's it! You can check more examples in the examples folder

Preservable Layout

The layout is described by a simple object, it can be serializable and use it as the initial state a preservable layout can be achievable:

import React from 'react';
import { render } from 'react-dom';
import Subdivide, {
  ConfigProvider,
  useContainer,
  LayoutState,
} from '../../src';

const MasterPanel = () => <span>Just like you leave it :)</span>;

const getInitialState = () => {
  try {
    const json = localStorage.getItem('state');
    return JSON.parse(json);
  } catch (error) {
    return undefined;
  }
};

const initialState = getInitialState();

const App = () => {
  const onLayoutChange = (state) => {
    localStorage.setItem('state', JSON.stringify(state));
  };

  return (
    <ConfigProvider initialState={initialState} onLayoutChange={onLayoutChange}>
      <Subdivide component={MasterPanel} />
    </ConfigProvider>
  );
};

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

Api

Components

Subdivide

PropTypeDefalt Value
componentReact.ReactNoden/a
widthnumber100%
heightnumber100%
topnumber0
leftnumber0
selfPositionbooleantrue

ConfigProvider alias of Config.Provider

PropTypeDefalt Value
initialStateState
onLayoutChange(state: State) => void
classNamesOptionalClassNames
cornerSizenumber
splitRationumber

Hooks

useContainer

Use to access to the container data, and update its state. Check how it's used in the examples: ColorPane, preservable, stats

useConfig

Mostly for internal usage

useClassNames

Mostly for internal usage

Author

šŸ‘¤ Jose Albizures by Pixore

šŸ™ Thanks!

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ā­ļø if this project helped you!

šŸ“ License

Copyright Ā© 2020 Jose Albizures. This project is MIT licensed.


This README was generated with ā¤ļø by readme-md-generator

0.1.7

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.3

3 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago