4.0.0 • Published 5 years ago

z-grid v4.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

z-grid

Build SemVer License

A 12-column grid system for your web application. The package is intended to be used in a web page.

Table of contents

Install

The package is available to download through npm:

npm install z-grid --save

Import as HTML/CSS component

The simple case

The package will be located inside the node_modules folder, you can import it into the HTML document as follows:

<link rel="stylesheet" href="node_modules/z-grid/dist/style.module.css">

When bundling an web app

For bundlers that support CSS, like Webpack, you can use it like this:

require('z-grid/dist/style.module.css');

Import as a Stateless Functional Component (SFC)

The package does not include the renderer, you can use any renderer that supports SFCs. You could use React, Preact, Inferno, etc.

Notice: This package contains CSS styling, you may need a bundler that's capable of requiring CSS files like Webpack with css-loader.

Once you have chosen the renderer you can include the package in your project as follows:

// Assuming the React renderer is being used
const React = require('react');
const render = require('react-dom').render;

// Passing the render function when importing
const ZGrid = require('z-grid').ZGrid(React.createElement);
const ZColumn = require('z-grid').ZColumn(React.createElement);

// Render it on page, using JSX here :)
render(<ZGrid><ZColumn>Hello!</ZColumn></ZGrid>, document.body);

How to use

CSS component

Just add the HTML structure and CSS classes to reproduce the UI component.

Class hierarchy

Recommended HTML tagsParentClassDescriptionType
div, section, main, article, navroot.z-gridRoot containerBlock
Any containing z.gridroot.z-grid--verticalMakes the grid vertical instead of horizontalModifier
Any containing z.gridroot.z-grid--reverseReverses the grid start direction, starts it on the right for LTR and left for RTLModifier
Any containing z.gridroot.z-grid--centerCenters the grid horizontally within the outer elementModifier
Any containing z.gridroot.z-grid--cross-centerCenters the grid vertically within the parent elementModifier
Any containing z.gridroot.z-grid--stretchStretch the columns to fill all the available vertical spaceModifier
Any containing z.gridroot.z-grid--gutterEnables the grid gutters, adds spacing between columnsModifier
div, section, article, ul, ol, li.z-grid.z-grid__colA grid columnElement
Any containing .z-grid__col.z-grid.z-grid__col--1-12One grid unit, column will occupy 1/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--2-12This column will occupy 2/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--3-12This column will occupy 3/12 (quarter) of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--4-12This column will occupy 4/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--5-12This column will occupy 5/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--6-12This column will occupy 6/12 (half) of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--7-12This column will occupy 7/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--8-12This column will occupy 8/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--9-12This column will occupy 9/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--10-12This column will occupy 10/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--11-12This column will occupy 11/12 of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--12-12This column will occupy 12/12 (all) of the grid spaceModifier
Any containing .z-grid__col.z-grid.z-grid__col--sm-*-12Same as .z-grid__col--*-12 classes, but only effective for screens wider than 35.5remModifier
Any containing .z-grid__col.z-grid.z-grid__col--md-*-12Same as .z-grid__col--*-12 classes, but only effective for screens wider than 48remModifier
Any containing .z-grid__col.z-grid.z-grid__col--lg-*-12Same as .z-grid__col--*-12 classes, but only effective for screens wider than 64remModifier
Any containing .z-grid__col.z-grid.z-grid__col--xl-*-12Same as .z-grid__col--*-12 classes, but only effective for screens wider than 80remModifier
Any containing .z-grid__col.z-grid.z-grid__col--fitSpecial column that will stretch to fit the remaining space availableModifier
Any containing .z-grid__col.z-grid.z-grid__col--centerCenter this column within the gridModifier
Any containing .z-grid__col.z-grid.z-grid__col--endPut this column at the end of the gridModifier
Any containing .z-grid__col.z-grid.z-grid__col--importantOverrides the order of the grid, put this column firstModifier

Full working example:

<div class="z-grid z-grid--gutter">
  <div class="z-grid__col--6-12">Half</div>
  <div class="z-grid__col--6-12">Half</div>
</div>

Stateless Functional Component

Render the HTML by using the SFCs and passing props.

ZGrid

Supported Props
Prop nameExpected TypeDescription
elementstringThe name of the HTML tag the grid should render as root element, defaults to div
childrenOne or more ZColumnThe columns to render
gutterbooleanSet to true to enable the gutters
centerbooleanSet to true to center the grid within the parent element
crossCenterbooleanSet to true to center the grid vertically within the parent element
reversebooleanSet to true to start the grid from the end, right in LTR and left in RTL
stretchbooleanSet to true to stretch the columns to fill the remaining space in the grid

ZColumn

Supported Props
Prop nameExpected TypeDescription
elementstringThe name of the HTML tag the grid should render as root element, defaults to div
childrenHTMLElementThe column content
fillnumberNumber of grid units this column should occupy, max 12
smnumberNumber of grid units this column should occupy when grid width > 35.5rem
mdnumberNumber of grid units this column should occupy when grid width > 48rem
lgnumberNumber of grid units this column should occupy when grid width > 64rem
xlnumberNumber of grid units this column should occupy when grid width > 80rem
fitbooleanSet to true to make this column fill the rest of the grid space
centerbooleanSet to true to center this column within the grid
endbooleanSet to true to make this column appear in the end of the grid
importantbooleanSet to true to make this column override the grid order and appear first

Full example (JSX):

<ZGrid gutter>
  <ZColumn fill={6}>Half</ZColumn>
  <ZColumn fill={6}>Half</ZColumn>
</ZGrid>

LICENSE

MIT

3.2.1

5 years ago

3.2.3

5 years ago

4.0.0

5 years ago

3.1.0

5 years ago

3.0.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago