Size Utils

Introduction

NPM version Dependency Status

A collection of dynamically generated size-related utility classes.

Class names follow the Emmet abbreviation syntax, with colons (':') replaced by two dashes (--) to follow BEM naming conventions.

Available classes

  • .u-w--<amount>: width
  • .u-w--auto: width: auto
  • .u-miw--<amount>: min-width
  • .u-miw--none: min-width: none
  • .u-maw--<amount>: max-width
  • .u-maw--none: max-width: none

  • .u-h--<amount>: height

  • .u-h--auto: height: auto
  • .u-mih--<amount>: min-height
  • .u-mih--none: min-height: none
  • .u-mah--<amount>: max-height
  • .u-mah--none: max-height: none

Where <amount> can be either a unitless number representing a number of typographic rhythm units as defined in $jigsass-sizes, a percentage, or a length specified in pixels, ems or rems, auto or none.

Installation

Using npm:

npm i -S jigsass-utils-size

Usage

Import JigSass Utils Size into your main scss file near its very end, together with all other utilities (utilities should always be the last to be imported).

@import 'path/to/jigsass-utils-size/scss/index';

Like all other JigSass Utils, JigSass Size does not automatically generate any CSS when imported. You would need to explicitly indicate that each individual size class should actually be generated in each component or object it is used in (clarification: This will include style declarations inside .foo and .bar):

// _c.foo.scss
.foo {
  @include jigsass-util(u-w, $modifier: 360px); // <-- width: 360px

  ...
}
// _c.bar.scss
.bar {
  @include jigsass-util(u-miw, $modifier: 600px);  // <-- min-width: 600px
  @include jigsass-util(
    u-miw, $modifier: 1200px,
    $from: large
  ); // <-- max-width: 1200px from large bp and on.

  ...
}

Doing so helps us a great deal with portability, as no matter where we import component or object partials, the correct utility classes will be generated. Think of it as a poor man's dependency management.

Developer communication is also assisted by including "dependencies" wherever they are required, as anyone going through a partial, can easily understand how it should be marked up with just a glance.

As far as bloat goes, just don't worry about it - the actual styles will only be generated once, at the location in the cascade where the Jigsass Size partial was imported into the main file.

JigSass Size classes are responsive-enabled, using JigSass MQ and the breakpoints defined in the $jigsass-breakpoints variable.

Based on the breakpoint arguments passed to jigsass-util when including a Size class, responsive modifiers are generated according to the following logic:

.u-w--<modifier>[-[-from-<breakpoint-name>][-until-<breakpoint-name>][-misc-<breakpoint-name>]]

So, assuming the medium, large and landscape breakpoints are defined in $jigsass-breakpoints as 600px, 1024px and (orientation: landscape) respectively,

@include jigsass-util(u-h, $modifier: 50);

will generate the .u-h--50 class, which is not limited to any media-query.

@include jigsass-util(u-h, $modifier: 10, $until: medium);

will generate the .u-h--10--until-medium class, which will be in effect at (max-width: 37.49em) and will override styles in the default class until that point.

@include jigsass-util(u-mih, $modifier: 300px, $from: large, $misc: landscape);

will generate the .u-mih--200px--from-large-when-landscape class, which will go into effect at (min-width: 64em) and (orientation: landscape) and will override styles in the default class under these conditions.

License: MIT

u-w--50

A utility class to set the width of an element.

Include with:

@include jigsass-util(u-w, $modifier: 50 [, $from, $until, $misc]);

Example

  <div class='fpo  u-w--50'>
    This element has a width of
    50 rhythm units.
  </div>

u-w--100

A utility class to set the width of an element.

Include with:

@include jigsass-util(u-w, $modifier: 100 [, $from, $until, $misc]);

Example

  <div class='fpo  u-w--100'>
    This element has a width of
    100 rhythm units.
  </div>

u-w--150

A utility class to set the width of an element.

Include with:

@include jigsass-util(u-w, $modifier: 150 [, $from, $until, $misc]);

Example

  <div class='fpo  u-w--150'>
    This element has a width of
    150 rhythm units.
  </div>

u-w--200

A utility class to set the width of an element.

Include with:

@include jigsass-util(u-w, $modifier: 200 [, $from, $until, $misc]);

Example

  <div class='fpo  u-w--200'>
    This element has a width of
    200 rhythm units.
  </div>

u-miw--50

A utility class to set the min-width of an element.

Include with:

@include jigsass-util(u-miw, $modifier: 50 [, $from, $until, $misc]);

Example

  <div class='fpo  u-miw--50'>
    This element has a min-width of
    50 rhythm units.
  </div>

u-miw--100

A utility class to set the min-width of an element.

Include with:

@include jigsass-util(u-miw, $modifier: 100 [, $from, $until, $misc]);

Example

  <div class='fpo  u-miw--100'>
    This element has a min-width of
    100 rhythm units.
  </div>

u-miw--150

A utility class to set the min-width of an element.

Include with:

@include jigsass-util(u-miw, $modifier: 150 [, $from, $until, $misc]);

Example

  <div class='fpo  u-miw--150'>
    This element has a min-width of
    150 rhythm units.
  </div>

u-miw--200

A utility class to set the min-width of an element.

Include with:

@include jigsass-util(u-miw, $modifier: 200 [, $from, $until, $misc]);

Example

  <div class='fpo  u-miw--200'>
    This element has a min-width of
    200 rhythm units.
  </div>

u-maw--50

A utility class to set the max-width of an element.

Include with:

@include jigsass-util(u-maw, $modifier: 50 [, $from, $until, $misc]);

Example

  <div class='fpo  u-maw--50'>
    This element has a max-width of
    50 rhythm units.
  </div>

u-maw--100

A utility class to set the max-width of an element.

Include with:

@include jigsass-util(u-maw, $modifier: 100 [, $from, $until, $misc]);

Example

  <div class='fpo  u-maw--100'>
    This element has a max-width of
    100 rhythm units.
  </div>

u-maw--150

A utility class to set the max-width of an element.

Include with:

@include jigsass-util(u-maw, $modifier: 150 [, $from, $until, $misc]);

Example

  <div class='fpo  u-maw--150'>
    This element has a max-width of
    150 rhythm units.
  </div>

u-maw--200

A utility class to set the max-width of an element.

Include with:

@include jigsass-util(u-maw, $modifier: 200 [, $from, $until, $misc]);

Example

  <div class='fpo  u-maw--200'>
    This element has a max-width of
    200 rhythm units.
  </div>

u-h--50

A utility class to set the height of an element.

Include with:

@include jigsass-util(u-h, $modifier: 50 [, $from, $until, $misc]);

Example

  <div class='fpo  u-h--50'>
    This element has a height of
    50 rhythm units.
  </div>

u-h--100

A utility class to set the height of an element.

Include with:

@include jigsass-util(u-h, $modifier: 100 [, $from, $until, $misc]);

Example

  <div class='fpo  u-h--100'>
    This element has a height of
    100 rhythm units.
  </div>

u-h--150

A utility class to set the height of an element.

Include with:

@include jigsass-util(u-h, $modifier: 150 [, $from, $until, $misc]);

Example

  <div class='fpo  u-h--150'>
    This element has a height of
    150 rhythm units.
  </div>

u-h--200

A utility class to set the height of an element.

Include with:

@include jigsass-util(u-h, $modifier: 200 [, $from, $until, $misc]);

Example

  <div class='fpo  u-h--200'>
    This element has a height of
    200 rhythm units.
  </div>

u-mih--50

A utility class to set the min-height of an element.

Include with:

@include jigsass-util(u-mih, $modifier: 50 [, $from, $until, $misc]);

Example

  <div class='fpo  u-mih--50'>
    This element has a min-height of
    50 rhythm units.
  </div>

u-mih--100

A utility class to set the min-height of an element.

Include with:

@include jigsass-util(u-mih, $modifier: 100 [, $from, $until, $misc]);

Example

  <div class='fpo  u-mih--100'>
    This element has a min-height of
    100 rhythm units.
  </div>

u-mih--150

A utility class to set the min-height of an element.

Include with:

@include jigsass-util(u-mih, $modifier: 150 [, $from, $until, $misc]);

Example

  <div class='fpo  u-mih--150'>
    This element has a min-height of
    150 rhythm units.
  </div>

u-mih--200

A utility class to set the min-height of an element.

Include with:

@include jigsass-util(u-mih, $modifier: 200 [, $from, $until, $misc]);

Example

  <div class='fpo  u-mih--200'>
    This element has a min-height of
    200 rhythm units.
  </div>

u-mah--50

A utility class to set the max-height of an element.

Include with:

@include jigsass-util(u-mah, $modifier: 50 [, $from, $until, $misc]);

Example

  <div class='fpo  u-mah--50'>
    This element has a max-height of
    50 rhythm units.
  </div>

u-mah--100

A utility class to set the max-height of an element.

Include with:

@include jigsass-util(u-mah, $modifier: 100 [, $from, $until, $misc]);

Example

  <div class='fpo  u-mah--100'>
    This element has a max-height of
    100 rhythm units.
  </div>

u-mah--150

A utility class to set the max-height of an element.

Include with:

@include jigsass-util(u-mah, $modifier: 150 [, $from, $until, $misc]);

Example

  <div class='fpo  u-mah--150'>
    This element has a max-height of
    150 rhythm units.
  </div>

u-mah--200

A utility class to set the max-height of an element.

Include with:

@include jigsass-util(u-mah, $modifier: 200 [, $from, $until, $misc]);

Example

  <div class='fpo  u-mah--200'>
    This element has a max-height of
    200 rhythm units.
  </div>