Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonathanconway/react-layout-wrappers
Layout wrappers for React 🎁
https://github.com/jonathanconway/react-layout-wrappers
flexbox layout react reactjs
Last synced: 23 days ago
JSON representation
Layout wrappers for React 🎁
- Host: GitHub
- URL: https://github.com/jonathanconway/react-layout-wrappers
- Owner: jonathanconway
- License: mit
- Created: 2018-12-01T12:55:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-29T22:38:24.000Z (about 6 years ago)
- Last Synced: 2025-01-01T23:48:51.230Z (23 days ago)
- Topics: flexbox, layout, react, reactjs
- Language: TypeScript
- Homepage:
- Size: 266 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# React Layout Wrappers
[![license](https://badgen.now.sh/badge/license/MIT)](./LICENSE)
A small collection of wrappers for implementing layout in your React application.
Inspired by Microsoft's WPF layout components.
The wrappers:
* [Stack](#stack)
* [Wrap](#wrap)
* [Dock](#dock)
* [Grid](#grid)
* [Canvas](#canvas)
* [UniformGrid](#uniform-grid)# Overview
When you start putting together a user interface, in any language or framework, one of the first things you'll need to do is lay out the elements. You'll need to position, size and space them in various configurations, depending on what works best for the interface you're trying to develop.
React Layout aims to be your one-stop-shop for laying our your UI components in React. It does this by providing a small number of flexible and composable 'wrapper' components, in which you can place your components (including other wrapper components), in order to declaratively specify their layout.
This is (hopefully) simpler and less tedious and repetitive than writing custom CSS (e.g. FlexBox) or attempting to fit some other layout system (e.g. Bootstrap) into your React app. These methods were suitable for the contexts they were being used in (web pages styled with HTML and CSS), but are not so suitable for building component-based web apps in React.
In React Layout, all the layout components are simply React components, so you can easily fit them in alongside whatever other React components you're using (or just standard DOM elements in React). You can look at your hierarchy of components and easily determine how they will be laid out.
# Installation
NPM:
```
npm install --save react-layout-wrappers
```Yarn:
```
yarn add react-layout-wrappers
```# Components
### Overview
Stack is a container that stacks its children next to each other, one after another.
### Props
#### `orientation: 'horizontal' | 'vertical'`
* `vertical` (default) Lays out the children vertically
* `horizontal` Lays out the children horizontally#### `direction: 'left-to-right' | 'right-to-left'`
* `left-to-right` Lays out the components in order, from left to right (if horizontal) or from top to bottom (if vertical)
* `right-to-left` Reverse of the above; right to left (if horizontal) or bottom to top (if vertical)#### `children: StackChild[]`
An array of StackChild elements to be rendered inside the Stack.
### Example
```jsx
import React from 'react';
import { Stack } from 'react-layout-wrappers';const StackExample = () => (
Heading
Paragraph
Button
);
```
### Overview
Wrap is a container in which children appear next to each other, one after another. When they get to the end, it starts a new row or column.
### Props
#### `orientation: 'horizontal' | 'vertical'`
* `horizontal` (default) Lays out the children horizontally / length-wise.
* `vertical` Lays out the children vertically / height-wise.#### `direction: 'left-to-right' | 'right-to-left'`
* `left-to-right` Lays out the components in order, from left to right (if horizontal) or from top to bottom (if vertical)
* `right-to-left` Reverse of the above; right to left (if horizontal) or bottom to top (if vertical)
#### `children: WrapChild[]`An array of WrapChild elements to be rendered inside the Wrap.
### Example
```jsx
import React from 'react';
import { Wrap } from 'react-layout-wrappers';const WrapExample = () => (
{Array(7).fill(null).map((_, i) =>
Tag {i + 1}
)}
);
```
### Overview
Dock is a container in which each child gravitates to one of its four edges.
### Props
#### `lastChildFill: boolean`
If true, makes the last DockChild in `children` fill all of the remaining space.
#### `children: DockChild[]`
An array of DockChild elements to be rendered inside the Dock.
Each DockChild can be given props, to define where it sits in the Dock.
* `dock: 'top' | 'right' | 'bottom' | 'left'` Which edge of the Dock to pull the element toward.
### Example
```jsx
import React from 'react';
import { Dock } from 'react-layout-wrappers';const DockExample = () => (
One
Two
Three
Four
Five
);
```
### Overview
Grid is a container that slots its children into cells, defined by rows and columns.
### Props
#### `rowDefinitions: [{ height }]`
Defines how many rows are in the grid (the number of elements in the array) and settings for each individual row:
* `height: number` (optional) Defines the height of each row.
#### `columnDefinitions: [{ width }]`
Defines how many columns are in the grid (the number of elements in the array) and settings for each individual column:
* `width: number` (optional) Defines the width of each column.
#### `children: GridChild[]`
An array of GridChild elements to be rendered inside the Grid.
Each GridChild can be given props, to define where and how it sits in the Grid.
* `gridRow: number` (optional) Which row to position the element in (1-based).
* `gridColumn: number` (optional) Which column to position the element in (1-based).
* `gridRowSpan: number` (optional) How many rows the element takes up (defaults to 1).
* `gridColumnSpan: number` (optional) How many columns the element takes up (defaults to 1).### Example
```jsx
import React from 'react';
import { Grid } from 'react-layout-wrappers';const GridExamples = () => (
Btn 1
Btn 2
Btn 3
Btn 4
Btn 1
Btn 2
Btn 3
Btn 1
Btn 2
Btn 3
Btn 4
);
```
### Overview
Canvas is a container that lets you place its children at co-ordinates on a 2D plane.
### Props
#### `children: CanvasChild[]`
An array of CanvasChild elements to be rendered inside the Canvas.
Each CanvasChild can be given props, to define where and how it sits on the Canvas.
* `canvasTop: number | string` (optional) Top position of the element. 0 means the very top, greater means farther from the top and closer to the bottom.
* `canvasRight: number | string` (optional) Right position of the element. 0 means the very right, greater means farther from the right and closer to the left.
* `canvasBottom: number | string` (optional) Bottom position of the element. 0 means the very bottom, greater means farther from the bottom and closer to the top.
* `canvasLeft: number | string` (optional) Left position of the element. 0 means the very left, greater means farther from the left and closer to the right.
* `canvasZIndex: number` (optional) Position of the element on the Z-Index (that is, order of overlapping, where part or all of the element overlaps with other elements). Greater means closer to the front, relative to the Z-Index of other elements. Lesser means farther to the back.### Example
```jsx
import React from 'react';
import { Canvas } from 'react-layout-wrappers';const CanvasExample = () => (
Btn 1
Btn 2
Btn 3
Btn 4
Btn 5
Btn 6
);
```
### Overview
UniformGrid is a container that slots its children into cells, defined by rows and columns. It is like [Grid](#grid), except that it just renders its children onto the grid in the order they are passed, rather than allowing you to set each individual's location independently.
#### `rows: number`
Number of rows in the grid.
#### `columns: number`
Number of columns in the grid.
#### `children: UniformGridChild[]`
An array of UniformGridChild elements to be rendered inside the UniformGrid.
### Example
```jsx
import React from 'react';
import { UniformGrid } from 'react-layout-wrappers';const UniformGridExample = () => (
{Array(8).fill(null).map((_, i) =>
Item {i + 1}
)}
);
```# Resources
## Books
* [Illustrated WPF (Daniel Solis, 2009)](https://www.amazon.com/Illustrated-WPF-Experts-Voice-NET/dp/1430219106)
---
Copyright © 2018
Jonathan Conway
MIT License.
---