vue-fraction-grid
Flexbox based responsive fraction grid system for Vue.js
Live Demo and Full Documentation
... ... ...
Installation
Install the package using yarn
or npm
:
$ yarn add vue-fraction-grid # or $ npm install --save vue-fraction-grid
Global
Load the plugin by calling Vue.use()
:
Vue
Now you have access in your templates to <container>
, <grid>
and <grid-item>
components.
Local
You may prefer to explicitly import the components in your templates:
<template> <container> <grid> <grid-item size="1/2"> ... </grid-item> <grid-item size="1/2"> ... </grid-item> </grid> </container></template> <script>import Container from 'vue-fraction-grid/components/Container'import Grid from 'vue-fraction-grid/components/Grid'import GridItem from 'vue-fraction-grid/components/GridItem' export default { components: { Container, Grid, GridItem }}</script>
CDN
Load the script file from CDN:
Settings
Vue
Configure grid by passing options as a second argument of Vue.use()
. Configuration is merged to defaults that are listed above.
Available settings:
container - Default containers width. Works with any valid CSS values like: '1440px',
'52em', '100vw' etc. Set it to '100%' to use full-width fluid grid. Because
this is the maximum value, the grid will scale nicely for smaller viewports.
gutter - Gutter width. Works with any valid CSS values like '30px', '1rem' etc.
approach - 'mobile-first' or 'desktop-first'. Choose which approach of responsive web design
do you prefer. Breakpoint rules are based on this option.
breakpoints - List the grid breakpoints. Key is the breakpoint name for `:rwd` prop.
Value is the size and can include one or two CSS values separated
with a space.
Components
Container
Syntax:
Center content of the site in the container:
...
Override container's maximum width with width
prop. This is useful when you need more than one container's type e.g. regular and full-width.
...
...
Grid
Syntax:
The most common usage and simple example of the grid:
... ...
Nest grids however you like, the gutter is always the same. There is no need to wrap nested grids with containers.
... ... ...
Horizontal alignment of grid items. This works simillar to justify-content
attribute.
...
...
...
...
...
Vertical alignment of grid items. This works simillar to align-items
attribute.
...
...
...
Remove gutter from grid items.
...
Align content of the first item to the left and content of the second item to the right.
...
Set the grid items direction. This works simillar to flex-direction
attribute.
...
...
...
Set the grid items wrap. This works simillar to flex-wrap
attribute.
...
...
Mix props however you want to.
...
Grid Item
Syntax:
Use any size written in the fraction format. Grid item should be nested directly in the grid. Items fractions don't have to sum to 1. Denominator can't be equal 0!
...
Fill the grid with a grid item by setting its size to 1/1
:
...
Hide the grid item by setting its size to 0/1
:
...
Use grow
and shrink
props instead of size
. They work simillar to flex-grow
and flex-shrink
attributes. Never mix size, grow and shrink into a single item!
...
...
Responsive Design
Responsive design is based on two options from settings: approach
and breakpoints
.
If you set approach to mobile-first
breakpoints with a single value will respond to media queries using min-width
attribute. If you use desktop-first
instead, breakpoints will respond to max-width
.
Breakpoints with two values respond to (min-width: <length>) and (max-width: <length>)
query.
Following configuration:
Vue
Is translated to this declaration from CSS:
{/* compact */{/* tablet */
API
Change the direction of a grid for specific breakpoints.
...
...
Change size of a grid item for specific breakpoints.
...
Mix responsive design props for grid and items.
... ... ...
Development
-
Clone the repository:
$ git clone git@github.com:bkzl/vue-fraction-grid.git -
Run scripts from package.json using
npm run
/yarn run
in the main directory:demo - Start demo page with implementation of all examples test - Run tests using Jest lint - Lint JS and CSS code of components, utils and installation docs - Start docs locally deploy - Deploy docs to GitHub Pages dist - Create an optimized bundle in UMD format
Code is open sourced on GitHub. Up to date changelog is available under the releases section.
I appreciate any comments, feedback, and information about potential issues. Have you experienced a bug or noticed a mistake in documentation? Please add a new issue. Thanks!