Git Product home page Git Product logo

gel-grid's Introduction

GEL Grid

A flexible code implementation of the GEL Grid.
Forms part of the GEL Foundations

What is this?

An implementation of the GEL Grid Guidelines. The Grid provides a way of creating flexible and unique layouts whilst also maintaining consistent margins, gutters and containing widths across the BBC, online.

This is implementation of the grid is built using flexbox with an inline-block fallback older browsers. This allows us to support browsers IE8 and above.

It can used in two forms, by simply adding the relevant classes to your markup:

<div class="gel-layout">
    <div class="gel-layout__item gel-1/2"></div>
    <div class="gel-layout__item gel-1/2"></div>
</div>

Or using a Sass mixin:

.my-component {
    @include gel-layout;
}

.my-component__item {
    @include gel-layout-item;
    @include gel-columns(1/2);
}

Installation

The easiest way to get started with the GEL Grid component is to use the compiled version of the grid included within this repository.

If you're a more advanced user and want to integrate the GEL Grid component within your codebase, use one of the following options:

Install using NPM

$ npm install --save gel-grid
// your-app/main.scss
@import 'node_modules/gel-sass-tools/sass-tools';
@import 'node_modules/sass-mq/mq';
@import 'node_modules/gel-grid/grid';

Install manually

You can install this component manually by downloading the content of this Git repo into your project and use a Sass @import to include it in your project.

Note: you will manually need to manage the dependencies below, without these this component will fail to compile.

Compiled CSS

If you require just the built css, it is automatically built to the gel-grid.css repository.

Dependencies

In order to use the component you will need the following components available:

Usage

A collection of grid utility classes can be output by defining $gel-grid-enable--markup-output: true; before you @import the main grid partial.

Example:

$gel-grid-enable--markup-output: true;

@import "gel-grid/grid";

This will allow you to create grids using specific markup within your page. With the grid markup enabled, its possible to create grids like so:

<div class="gel-wrap">
    <div class="gel-layout">
        <div class="gel-layout__item gel-1/2 gel-1/4@m"></div>
        <div class="gel-layout__item gel-1/2 gel-1/4@m"></div>
        <div class="gel-layout__item gel-1/2 gel-1/4@m"></div>
        <div class="gel-layout__item gel-1/2 gel-1/4@m"></div>
    </div>
</div>

This would create a grid with each item being 50% wide. At the medium GEL breakpoint (600px), the width of each item changes to 25%.

Core Grid Classes

  • gel-wrap - the outer grid wrapper, defines the maximum width of the grid and applies page margins
  • gel-layout - a grid row
  • gel-layout__item - an item within the grid, applies gutters between items. Width can be controlled using width classes

Modifier Classes

  • gel-layout--flush - removes gutters between items
  • gel-layout--rev - reversed order of layout items, e.g. items 1, 2, 3, 4 in your markup will display in order 4, 3, 2, 1 on your page
  • gel-layout--middle - align layout items to the vertical centers of each other
  • gel-layout--bottom - align layout items to the vertical bottoms of each other
  • gel-layout--right - make the layout items fill up from the right hand side
  • gel-layout--center - make the layout items fill up from the center outward
  • gel-layout--auto - cause layout items to take up a non-explicit amount of width

Flexbox Only

  • gel-layout--equal - cause each layout item to be of equal height
  • gel-layout--fit - allows each layout items to size itself automatically by dividing the space equally between the total number of items

Widths

Widths can be applied to grid items using a collection of utility classes which are automatically generated when the grid markup is enabled. The utility classes allow widths to be changed at different breakpoints.

The width utility classes are entirely fraction based allowing you to size grid elements proportionally. By default the following fractional groups are output: whole, halves, thirds, quarters, fifths, eighths, tenths, twelfths and twenty-fourths.

The class structure is as follows:

  • .gel-1/1 - 100%
  • .gel-1/2 - 50%
  • .gel-2/3 - 66.666666667%
  • .gel-10/12 - 83.333333333%

In order to reduce page weight we do not output whole fractions for each group as this can be simply normalised to one whole (.gel-1/1). Also, mathematically identical fractions should be normalised to the lowest denominator (for example instead of .gel-2/4 or .gel-6/12 use .gel-1/2)

Breakpoints

It is possible to apply width classes at specific breakpoints by applying a breakpoint specific suffix to the end of the class. That might look something like this:

<div class="gel-layout">
    <div class="gel-layout__item gel-1/1 gel-1/2@m gel-1/4@l"></div>
</div>

Here the item would be 100% wide by default, then 50% wide from 600px and 25% for anything beyond 900px.

The following breakpoint suffixes are available by default:

  • @s - 400px
  • @m - 600px
  • @l - 900px
  • @xl - 1008px
  • @xxl - 1280px

More information:

Specificity

Utility classes like these width classes always need to win when it comes to specificity, otherwise they're not doing their job correctly. You should never need to override a utility class, if you do you're doing something wrong. E.g. if you'd used a class of gel-1/2 you would never want it to be anything other than 50%. If you want something other than 50% you should have used a different class.

To help enforce this way of thinking all width utilities classes proactively carry the !important keyword to boost their specificity.

More information:

Sass Mixins

The GEL grid component exposes a collection of Sass Mixins which can be called within your Sass. Should you need to create a more bespoke component which is not possible using the standard utility classes.

Example

.my-component {
    @include gel-layout;
}

.my-component__item {
    @include gel-layout-item;
    @include gel-columns(1/2);

    @if $enhanced {
        @include mq($from: gel-bp-m) {
            @include gel-columns(1/4);
        }
    }
}

Available Mixins

  • @include gel-wrap - create the outer grid wrapper
  • @include gel-layout - defines a single grid row
  • @include gel-layout-item - a single grid item
  • @include gel-columns($span, $columns) - outputs a width for the requested number of columns, accepts either a fraction or number of columns

Available Functions:

  • gel-columns($span, $columns) - returns a width value for the requested number of columns, accepts either a fraction or number of columns

Flexbox

The grid is developed using flexbox giving us a flexible, powerful grid solution. Flexbox is not fully supported in all browsers and has seen a number of development iterations. With this in mind we have intentionally targeted specific implementations of flexbox and avoided some older more troublesome implementations.

For browsers which do not support flexbox we fallback to an inline-block grid which offers ~80% of the features available in the flexbox grid.

We recommend you include some JavaScript based Feature Detection which can apply a top level class to signify if flexbox is supported or not. This will increase the features available to older browsers. The specific class applied can be controlled using the $gel-grid-flexbox-feature-detection-class option.

The following features are only supported by the flexbox grid and will degrade gracefully:

More information:

1280px

The GEL Grid guideline has been updated to include a wider 1280px breakpoint. By default the grid supports this breakpoint. It can be displayed by setting the $gel-grid-enable--1280-breakpoint to false.

It is also possible to toggle the 1280px breakpoint on and off based on the presence of a specific class. If a class name is supplied e.g. $gel-grid-1280-toggle-class: 'b-pw-1280'; then all wider 1280px styles will be scoped in this class.

More information:

Box Sizing

The GEL Grid consistences of a combination of fixed gutters and margins with fluid width columns. This combination of fixed and fluid units is achieved using box-sizing: border-box.

If you do not have border-box defined globally on your project you will need to enable the $gel-grid-enable--box-sizing flag to enable a bundled fix.

More information:

inline-block & white-space

The GEL Grid is constructed using flexbox with an inline-block fallback for older browsers. Using inline-block allows us to achieve a lot of the same complex layout technique that flexbox offers and provides a more powerful and flexible grid than is possible with more traditional techniques likes the use of floats.

One challenge to the using of display: inline-block; is the white-space which is introduced between inline-block elements. This space is a representation of the space between elements in the HTML. In order for the grid to work correctly this space needs to be removed.

There are a few ways you can do this:

HTML Fix

The best way to get around this issue is to remove the space between elements in your HTML. This could be done by minifying your markup or by using HTML comments to comment out the space:

<div class="gel-layout">
    <div class="gel-layout__item gel-1/2"></div><!--
 --><div class="gel-layout__item gel-1/2"></div>
</div>

If you're building you're grid using something like ReactJS you will not have this problem with space between elements as a result of how the markup is generated by the ReactJS library.

CSS Fix

It is possible to collapse the space using CSS. An optional CSS fix can be enabled by setting the $gel-grid-enable--whitespace-fix flag to true.

Note: This is included as an optional fix as it is not 100% guaranteed to work. There are certain edge cases where this solution falls down. The only 100% guaranteed and recommended solution is to remove the space in the HTML.

Configuration

The following configurable options are available:

General Configuration

  • $gel-grid-namespace: 'gel-'; - the default namespace applied to all grid classes
  • $gel-grid-breakpoint-namespace: 'gel-bp-'; - the default namespace applied to breakpoint variables from GEL Sass Tools
  • $gel-grid-1280-toggle-class: null - an optional scoping class to wrap all 1280px grid style in. Allows the wider grid to be used in a products that do not fully support the wider grid yet
  • $gel-grid-breakpoints - a Sass map containing a list of breakpoints width classes should be generated for
  • $gel-grid-breakpoints--1280 - a Sass map containing a list of breakpoints which relate specifically to the 1280 breakpoint
  • $gel-grid-default-columns: 12 - the default number of columns the grid should be based on
  • $gel-grid-columns - a Sass list containing a list of which fractions utility classes will be generated for
  • $gel-grid-flexbox-feature-detection-class: 'no-flexbox' - The class applied by a feature detection script to signify there the current browser doesn't support Flexbox

Output Configuration

  • $gel-grid-enable--markup-output: false; - output a collection of utility classes
  • $gel-grid-enable--1280-breakpoint: true; - toggle the support for the wider 1280px grid
  • $gel-grid-enable--box-sizing: false; - enable built in box-sizing rules if box-sizing: border-box; is not already defined
  • $gel-grid-enable--whitespace-fix: false; - enable a built CSS fix to collapse the whitespace between inline-block items, this fix is not guaranteed to work 100% of the time

Grid Bookmarklet

The following Grid Bookmarklets can be used to overlay the grid in the browser to check visual alignment of elements:

Who is using this?

The following teams are currently using this component: GEL, News, Sport, Live, Search, BBC Food, Taster & Academy, IPS Web (R&D) and Subtitle Guidelines.

If your team is using this component, let us know and we'll add you to the list.

Credits

The foundations of this grid is based on the great work of Harry Roberts and his Inuit CSS Grid

License

The MIT License (MIT)

Copyright 2016 British Broadcasting Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gel-grid's People

Contributors

chrisbashton avatar crouchygt avatar eemmzz avatar greenc05 avatar itsaljones avatar mousius avatar randombitsuk avatar sareh avatar shaunbent avatar slakah avatar tsouk avatar wildlyinaccurate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gel-grid's Issues

$gel-grid-enable--box-sizing: true; not enough for the grid

I have the following main.scss:

$gel-grid-enable--markup-output: true;
$gel-grid-enable--box-sizing: true;

@import '~gel-sass-tools/sass-tools';
@import '~sass-mq/mq';
@import '~gel-grid/grid';

But the grid does not render correctly like this.

I have to add the universal box-sizing in order for the sizing to work correctly:

html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

Is there something else I am missing in order to get this to work without adding additional styles?

Why is min-width 25em used in media query for gel-layout

Why is min-width 25em used in the following media query:

@media (min-width: 25em) {
  .gel-wrap {
    padding-left: 16px;
    padding-right: 16px;
  }
}

As this is the smallest breakpoint, it will be applied to everything or am I missing something?

The docs ay 8px is used for padding on smaller devices but I don't see this as true.

You could apply a table, table-cell fallback for non-supported browsers

Currently there is no fallback for browsers that do not support flexbox for equal.

You could make .equal this:

.gel-layout--equal {
  display: table;
  table-layout: fixed;
  width: 100%;
  display: flex;
}

.gel-layout--equal > .gel-layout__item {
    display: table-cell;
    display: -webkit-flex;
    display: flex;
} 

Would you be open to a PR that did this?

Confusion around Grandstand repo connection

Hi there,

I've been looking to implement the GEL Grid on a site I'm working on. I started by using the html from the demo page in this repo, with the thinking that if everything in the demo worked then I it would contain most / all of the functional classes that I would need to use.

However, I came across the gs-u-mt0@l class in the demo but couldn't find the relevant scss in this repo or in the GEL Sass Tools repo. Only when I googled round did I find the relevant scss in the Grandstand repo - which hadn't been mentioned in the README of this repo.

Am I right in thinking that I'd need to include the whole Grandstand repo to ensure that these classes are available? Also are there likely to be other repos that have classes / functions employed in the demo that should be included in my project too?

Also I just wanted to say thanks for putting this out in the wild, really useful having this sort of resource available.

Cheers,
Josh

autoprefixer disabled for whole build

Because of /* autoprefixer: off */ statement in lib/_tools.scss autoprefixer is disabled for the entire generated css file when gel-grid is used. Any ideas?

Compile errors after install with npm and bower

Hey,

I have tried a number of times to install the packages with npm and bower. I keep getting this error:( Error: File to import not found or unreadable: node_modules/gel-sass-tools/sass-tools. ) whenever I try to compile my main.scss file.

Any help / hotfix for this would be great.

R

Edit:

Fixed the problem, there is a comment error on gel-sass-tools/lib/tools/_rem.scss line 55.

Padding when using gel-1/2

Because of the padding on gel-layout__item you get overflow
If you are going to split by 50% you can not have padding or margin as well e.g.

<div className='gel-layout'>
  <div className='gel-layout__item gel-1/2'></div>
  <div className='gel-layout__item gel-1/2'></div>
</div>

will produce overflow with the second item being on the second line.

Either I am using the API wrong or you need to fix this as I don't want to have to override this

Readme says there is a compiled version of the SASS in the repo

The Readme file says that:

"The easiest way to get started with the GEL Grid component is to use the compiled version of the grid included within this repository."

But I can't see a compiled version anywhere. It looks like the only CSS file in the repo currently is a test file: https://github.com/bbc/gel-grid/search?l=css

If a pre-compiled version no longer makes sense (maybe due to the number of options in the SASS) then it would be good to update the readme.

RTL Support

News/World Service need the ability to support RTL text and layouts.

We can use gel-layout--rev to reverse the layouts of the grid but this includes a forced text-align.

We need to introduce a new modifier class of gel-layout--rtl which applies: direction: rtl; and applies text-align: start; to the gel-layout__items.

Here is a codepen of this in action: http://codepen.io/shaunbent/pen/MyqKBQ

inline-block fighting space

Hi guys :)

I mentioned that you were using display:inline-block in the grid and you were using the letter-spacing magic number trick to avoid white space between blocks.

I know that it can be source of errors because this magic number (-0.31em) is based on Arial or Helvetica font. So the grid can break when these cases are coming:

  • Arial or Helvetica isn't found on the user machine.
  • The developer wants to use the BBC grid but also wants not to use Arial or Helvetica as a default font.

For example, just try to replace "Arial, Helvetica, freesans, sans-serif" by "Verdana, Arial, Helvetica, freesans, sans-serif" in the CSS on the body tag. It would break in Chrome.

Solutions exists: Pure.css from Yahoo had this problem: http://blog.purecss.io/post/60789414532/how-we-improved-grids-in-pure-0-3-0

But I'm not very fan of their technique for old browsers. I would rather use floats which is safer and cross-browser in my opinion. Like Bootstrap does.

Cheers!
Seb

Hide classes

In iPlayer we have had the need to add some classes which show / hide grid columns based on breakpoint.

The current implementation we have is a simple 'display: none' and then breakpoint specific classes for reshowing. This has been problematic as the reshowing classes have traditionally been display: block, which doesn't work well when you want to reset to any other display type...

My proposal would be:

<div class="gel-layout">
    <div class="gel-grid__item  gel-1/2 gel-1/4@m gel-hide-gte@l"></div>
    <div class="gel-grid__item  gel-1/4@l gel-hide-lte@m"></div>
</div>
@mixin gel-hide-until ($mq) {
  @include mq($until: $mq) {
    display: none !important;
  }
}

@mixin gel-hide-from ($mq) {
  @include mq($from: $mq) {
    display: none !important;
  }
}

.gel-hide-lte {
  &\@s {
    @include gel-hide-until(gel-bp-m);
  }

  &\@m {
    @include gel-hide-until(gel-bp-l);
  }

  &\@l {
    @include gel-hide-until(gel-bp-xl);
  }

  &\@xl {
    @include gel-hide-until(gel-bp-xxl);
  }
}

.gel-hide-gte {
  &\@m {
    @include gel-hide-from(gel-bp-m);
  }

  &\@l {
    @include gel-hide-from(gel-bp-l);
  }

  &\@xl {
    @include gel-hide-from(gel-bp-xl);
  }

  &\@xxl {
    @include gel-hide-from(gel-bp-xxl);
  }
}

This solution would only ever hide with no need for reshowing.

Integrate CI

We've done this for Typography so should probably do the same for the Grid.

Flexbox

We want to transition this grid implementation to use flexbox by default and fallback to inline-block where flexbox is not supported. This should give us an even more powerful and flexible grid solution whilst offering a few new cool features.

I've got a quick spike of what this might look like here: http://codepen.io/shaunbent/pen/obrBxb?editors=1100

Not compatible with RTL languages

I may be missing something, but the following CSS in gel-grid is breaking our RTL typography.

.gel-layout {
    direction: ltr;
    text-align: left;
}

.gel-layout__item {
    text-align: left;
}

Historically our Visual Journalism projects have been able to have a single class at the body level (.bbc-news-vj-direction--rtl { direction: rtl; }) and our RTL projects have "just worked". Now that we're using GEL grid in our projects, we'll have to specify overrides for the classes above.

Is there a strong reason why we need the text-align and direction properties defined in the grid itself?

Dart Sass Error - Using / for division is deprecated

Full error that is shown in the terminal when starting an app that uses dart sass and gel-grid:

https://github.com/bbc/gel-grid/blob/1d48de58ea4c4040530a8a79f8262b0f20bd0fe2/lib/_tools.scss

DEPRECATION WARNING: Using / for division is deprecated and will be removed in Dart Sass 2.0.0.

Recommendation: math.div($i, $column)

More info and automated migrator: https://sass-lang.com/d/slash-div

    ╷
454 │                 $width: round(($i / $column) * 10000000) / 10000000;
    │                                ^^^^^^^^^^^^
    ╵
    node_modules/gel-grid/lib/_tools.scss 454:32  -gel-widths()
    node_modules/gel-grid/lib/_tools.scss 375:9   gel-output-widths()
    node_modules/gel-grid/_grid.scss 26:5         @import
    src/styles/app.scss 8:9                       root stylesheet

Incorrect 1280 breakpoints

We have the 1008px (@xl) breakpoint listed as a breakpoint which only applies when we're using a 1280px grid.

I think this is a bug. If we apply an adjustment at this breakpoint we'd want it to apply regardless of if the next 1280px (@xxl) breakpoint is enabled or not.

As the @xl breakpoint is currently listed as a 1280px breakpoint it gets scoped in the b-pw-1280 class so these styles don't apply on non 1280 pages, when I think they should really.

cc: @wildlyinaccurate

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.