All Projects → google → easy-grid

google / easy-grid

Licence: Apache-2.0 License
easy-grid is a React component factory that provides a declarative layout mechanism for utilizing CSS grid layouts.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to easy-grid

csslayout
A collection of popular layouts and patterns made with CSS. Now it has 100+ patterns and continues growing!
Stars: ✭ 7,297 (+22703.13%)
Mutual labels:  grid-layout
tb-grid
tb-grid is a super simple and lightweight 12 column responsive grid system utilizing css grid.
Stars: ✭ 19 (-40.62%)
Mutual labels:  grid-layout
diorama
An image layout algorithm
Stars: ✭ 17 (-46.87%)
Mutual labels:  grid-layout
powergrid
Powerful grid system with CSS grid layout. Works in all modern browsers and IE11.
Stars: ✭ 18 (-43.75%)
Mutual labels:  grid-layout
grid-garden
Solutions to CSS Grid Garden
Stars: ✭ 79 (+146.88%)
Mutual labels:  grid-layout
youtube-css-grid
Layout do YouTube com CSS Grid Layout
Stars: ✭ 30 (-6.25%)
Mutual labels:  grid-layout
onlineResume
Harry's personal website
Stars: ✭ 15 (-53.12%)
Mutual labels:  grid-layout
ReactSimpleFlexGrid
A way to quickly add a Grid Layout to your React app 🚀
Stars: ✭ 185 (+478.13%)
Mutual labels:  grid-layout
SNCollectionViewLayout
Collection View Layouts is a set of custom flow layouts for iOS which imitate general data grid approaches for mobile apps.
Stars: ✭ 100 (+212.5%)
Mutual labels:  grid-layout
hexo-theme-griddy
Hexo theme for artist & photographer showing their work that created with Bulma CSS Framework
Stars: ✭ 22 (-31.25%)
Mutual labels:  grid-layout
grid-container
A grid for the future, CSS Grid Layout + Web Components (Custom Elements v1 + Shadow DOM v1)
Stars: ✭ 51 (+59.38%)
Mutual labels:  grid-layout
flex-box-grid
Responsive, mobile first Flexbox Grid
Stars: ✭ 39 (+21.88%)
Mutual labels:  grid-layout
DPVideoMerger-Swift
Multiple videos merge in one video with manage scale & aspect ratio and also merge videos to grid matrix layout for Swift.
Stars: ✭ 49 (+53.13%)
Mutual labels:  grid-layout
gridbugs-ru
Перевод списка багов в CSS Grid Layout, курируемого Рейчел Эндрю
Stars: ✭ 27 (-15.62%)
Mutual labels:  grid-layout
Stylizer
Stylizer is a flexible Css framework based on the visual aspect, the framework offers you a clean and easy work.
Stars: ✭ 44 (+37.5%)
Mutual labels:  grid-layout
effectiveweb.training
Repository for Effective Web Online Course / airhacks.io
Stars: ✭ 17 (-46.87%)
Mutual labels:  grid-layout
ginger
A minimal flexbox grid system named after a cute dog.
Stars: ✭ 31 (-3.12%)
Mutual labels:  grid-layout
aioneframework
Aione Framework: All-in-one lightweight mobile first front-end framework to design websites, web applications, mobile applications, progressive web applications having large number of examples, documentation, tutorials, community support, components.
Stars: ✭ 13 (-59.37%)
Mutual labels:  grid-layout
i-Cut
🔨 个人技术栈
Stars: ✭ 18 (-43.75%)
Mutual labels:  grid-layout
grid-layout
grid-layout is a layout engine which implements grid, can use in canvas/node-canvas
Stars: ✭ 43 (+34.38%)
Mutual labels:  grid-layout

easy-grid for React

This is not an official Google product.

easy-grid is a React component factory that provides a declarative layout mechanism for utilizing CSS grid layouts. It uses ASCII layout descriptions to generate layout components that arrange child components according to the defined grid.

Code Rendered
code-one render-one
code-two render-two

Getting Started

Prerequisites

Make sure you have the npm package manager installed on your development machine.

Installing

Clone the git repository to a local directory:

git clone [email protected]:google/easy-grid.git
cd easy-grid

Run npm install and then run the examples:

npm install
npm run examples

This will start a browser pointing at 'index.html' in the examples subdirectory.

To play around with the library, make changes to the examples.js React app and re-run npm run examples.

Running the tests

npm test

Deployment

To use the library in a production environment, simply run:

npm install --save easy-grid

Importing

easy-grid exports a grid factory method:

import grid from 'easy-grid';

Emotion

To use with emotion

import grid from 'easy-grid/emotion';

Usage

The exported grid method is used to create layout components based on an ASCII representations of the desired layout grid. For instance:

const TwoByTwoLayout = grid`
    1fr   1fr
1fr A     A,B
1fr A     A,B
`

defines a React component, TwoByTwoLayout, that will distribute it's child elements along a two by two grid. element "A" will take up the entire grid, while element "B" will overlap element "A" and take up the right half of the grid. The two rows will each have the same height, namely half the height of the parent element. Likewise, the two columns will each have the same width, or half the width of the parent component.

Grid Definition Syntax

Grids are defined by a back-tick ` string. Spaces and new-lines are non-trivial as they are used to parse the grid definition from the string.

Row and column header definitions use the syntax defined for grid-template-rows:

Type Syntax Usage
Flex nfr Using a flex-value allows rows and columns to be defined by distributing space proportionally between them.
Percentage n% Percentage values define the size of a column or row relative to its parent container.
Length npx, nem, etc. All standard length values can be used to give rows or columns fixed heights and widths respectively.

Column Headers

The first line of the string is a space-delimited definition of column headers. A component can be defined by only using column headers. For instance,

const ColumnsOnly = grid`
	1fr 2fr 1fr
`

defines a ColumnsOnly component that will arrange its children in 3 columns. The first and last column will be half the size of the middle column.

Row Headers

Each line after the first line defines a new row in the grid. The first element in the space-deilimited row definition defines the height of that row, and is called the row header. However, similar to column-only grid definitions, row-only grid defintions can be created by only specifying row headers on each new line. For instance,

const RowsOnly = grid`
	10px
	50px
	100px
`

defines a RowsOnly component that will give each of its three child components heights of 10 pixels, 50 pixels and 100 pixels respectively.

Grid Areas

Using a combination of column headers and row headers, a grid is defined. The cells of the grid should be used to define grid areas. Grid areas are continuous square areas defined by an arbitrary identifier being placed in a grid cell. For example, the following grid defines two grid areas, one denoted by "A" and one denoted by "B".

const SomeGrid = grid`
      1fr    2fr    3fr
1fr   A      A,B    A,B
2fr   A      A,B    A,B
`

Grid area defintions use commas to separate multiple overlapping grid areas identifiers in a given grid cell.

Overlap

Grid areas can overlap, as seen in the example above. This overlap defines a z-ordering. When rendered, an area will be drawn on top of any area it overlaps. Grid areas are alphabetically ordered. Later areas will be rendered on top of earlier ones. A grid cell containing grid area defintions A,D,C will be ordered as A,C,D and will render area D on top of area C on top of area A.

Empty Cells

Empty grid cells can be denoted by ... For instance,

const SpacerGrid = grid`
       25%   50%   25%
25%    ..    ..    ..
50%    ..    A     ..
25%    ..    ..    ..
`

defines a SpacerGrid component that has a single grid area with a 10px border around it.

Grid Component

As mentioned above, the result of calling the grid factory method with a grid definition is a React component. The returned component has the following expectations:

  • The number of child components should exactly equal the number of defined grid areas.
  • The child components should be ordered according to the alphabeticall ordering of grid area identifiers or should use the item property.
const Simple = grid`
      1fr    1fr
1fr   A      A
1fr   B      B
`

/** Error: not enough children */
<Simple>
	<Child/>
</Simple>

/** The first child is grid area "A", the second is grid area "B" */
<Simple>
	<ChildA/>
	<ChildB/>
</Simple>

/** The second child is grid area "A", the first is grid area "B" */
<Simple>
	<Child item="B"/>
	<Child item="A"/>
</Simple>

Grid components can also be styled via the className property. If your project is using styled components, the returned grid component can also be styled using the styled method:

const Simple = grid`
     1fr  1fr
1fr   A    A
1fr   B    B
`

const StyledSimple = styled(Simple)`
	background-color: red;
`

Built With

  • React - A JavaScript library for building user interfaces.
  • Styled Components - An awesome framework for styled React elements and components.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the Apache 2 License - see the LICENSE file for details.

Acknowledgments

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].