0.9.0 • Published 4 years ago

nice-react-layout v0.9.0

Weekly downloads
22
License
MIT
Repository
github
Last release
4 years ago

Stable Release last commit license DeepScan grade

logo Nice React Layout

A set of React components to create complex flexbox-based layouts without knowing what flexbox is. https://ekros.github.io/nice-react-layout/

Installation

yarn add nice-react-layout

Motivation

The aim of this project is to have a reduced set of components to create flexbox-based layouts abstracting the knowledge needed to understand how flexbox works. This library is very useful for web apps with lots of panels.

Features

  • Easy to learn: Just combine layouts and panels.
  • Create collapsible sidebars with ease.
  • Automagically colorize panels with random colors to speed-up prototyping.
  • Resizable panels. Just add separators to your layouts.
  • Swap panels position using Drag and drop!

Simple example

Drag and Drop

Basic Usage

Components can be imported using ES6 modules syntax:

import {
  HorizontalLayout,
  VerticalLayout,
  Panel,
  Separator,
  Spacer,
  View
} from "nice-react-layout";

Creating a simple layout is as easy as this:

<HorizontalLayout mockup>
  <Panel />
  <Panel />
</HorizontalLayout>

It renders an horizontal layout with two panels of the same size (they have proportion=1 by default). Thanks to the 'mockup' prop it paints every panel with a random color, easing the layout prototyping process. Layouts get all the available space by default (in the parent element). If you want your layout to fill the viewport you can use the component. Like this:

<View>
  <HorizontalLayout mockup>
    <Panel />
    <Panel />
  </HorizontalLayout>
</View>
<HorizontalLayout mockup>
  <Panel proportion={1} />
  <Panel proportion={4} />
</HorizontalLayout>
<HorizontalLayout mockup>
  <Panel proportion={1} />
  <Separator />
  <Panel proportion={4} />
</HorizontalLayout>
<HorizontalLayout mockup>
  <Panel proportion={1} />
  <Separator />
  <Panel proportion={4}>
    <VerticalLayout mockup>
      <Panel />
      <Separator />
      <Panel />
    </VerticalLayout>
  </Panel>
</HorizontalLayout>

To enable drag-and-drop feature, use the draggable and droppable props:

<HorizontalLayout mockup>
  <Panel draggable droppable />
  <Panel draggable droppable />
</HorizontalLayout>

For a complete example with every feature, see the src/demo/App.js file. Or just run yarn start.

Components

View

The top-level component. It gets all the available viewport space. Use it if you want your layout to fill the viewport or pass width / height props.

Props
PropDescription
widthview width (100vw by default)
heightview height (100vh by default)

HorizontalLayout

It creates an horizontal layout. This is shorthand component for:

<Layout orientation="horizontal" />

VerticalLayout

It creates vertical layout layout. This is a shorthand component for:

<Layout orientation="vertical" />

Layout

Creates a layout.

Props
PropDescription
classNameTop-level element class name
collapseSizeCollapsible panels size when collapsed
customCssCustom layout CSS object
mockupRender in mockup mode
onResizeReturns (layout, collapsedPanels) on resize
orientation'vertical' or 'horizontal'
reverseRender layout in reverse order

Panel

Here is where your content goes. If you are familiar with flexbox, this is like a "flex item" with a flex value of 1 by default. If not, don't worry, you don't need to know that :)

Props
PropDescription
centeredCenter panel content
classNameTop-level element class name
collapsibleThe panel can be collapsed
collapsedIs the panel collapsed?
collapseButtonClassAdds a class to the collapse button
collapseButtonContentA String or element
collapseButtonCollapsedContentA String or element
collapseButtonStyleInject inline CSS to the collapse button
collapsePanelCalled when collapse button is clicked
collapseSwitchCustom collapse element (renders button if not provided)
columnsNumber of columns (uses CSS multiple columns)
customCssCustom panel CSS object (injects it as an inline style)
draggableEnable dragging
droppableOther panels can be dropped here
minHeightMinimum panel height
minWidthMinimum panel width
mockupRender in mockup mode
orientation'vertical' or 'horizontal'
proportionProportion it uses from the available space (default = 1)
reverseRender layout in reverse order
showSizeShow panel size while dragging adjacent separators
sidebarDon't do much by it self. It is a requirement for sidebar props like 'collapsible'

Separator

It separates panels and allows them to be resized. This is optional.

Props
PropDescription
customCssCustom separator CSS object (injects it as an inline style)
defaultDblClickPosPosition where the separator goes when double-clicked
disabledIs disabled?
onSeparatorDoubleClickAction called when the separator is double-clicked
onSeparatorMouseDownAction called when the mouse is over the separator

Spacer

It renders a blank space. Useful when you need to leave spaces between panels.

Props
PropDescription
sizeSeparator size in pixels

Like this project? ★ us on Github :)

0.9.0

4 years ago

0.8.0

5 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.8

6 years ago

0.6.7

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago