sprite.less 2.79 KB
/*
LESS variables are information about icon's compiled state, stored under its original file name

.icon-home {
  width: @icon-home-width;
}

The large array-like variables contain all information about a single icon
@icon-home: x y offset_x offset_y width height total_width total_height image_path name;

At the bottom of this section, we provide information about the spritesheet itself
@spritesheet: width height image @spritesheet-sprites;
*/
@btn-modal-name: 'btn-modal';
@btn-modal-x: 0px;
@btn-modal-y: 0px;
@btn-modal-offset-x: 0px;
@btn-modal-offset-y: 0px;
@btn-modal-width: 61px;
@btn-modal-height: 26px;
@btn-modal-total-width: 61px;
@btn-modal-total-height: 71px;
@btn-modal-image: '../img/sprite.png';
@btn-modal: 0px 0px 0px 0px 61px 26px 61px 71px '../img/sprite.png' 'btn-modal';
@logo-modal-name: 'logo-modal';
@logo-modal-x: 0px;
@logo-modal-y: 31px;
@logo-modal-offset-x: 0px;
@logo-modal-offset-y: -31px;
@logo-modal-width: 40px;
@logo-modal-height: 40px;
@logo-modal-total-width: 61px;
@logo-modal-total-height: 71px;
@logo-modal-image: '../img/sprite.png';
@logo-modal: 0px 31px 0px -31px 40px 40px 61px 71px '../img/sprite.png' 'logo-modal';
@spritesheet-width: 61px;
@spritesheet-height: 71px;
@spritesheet-image: '../img/sprite.png';
@spritesheet-sprites: @btn-modal @logo-modal;
@spritesheet: 61px 71px '../img/sprite.png' @spritesheet-sprites;

/*
The provided classes are intended to be used with the array-like variables

.icon-home {
  .sprite-width(@icon-home);
}
.icon-email {
  .sprite(@icon-email);
}

Example usage in HTML:

`display: block` sprite:
<div class="icon-home"></div>

To change `display` (e.g. `display: inline-block;`), we suggest using a common CSS class:

// CSS
.icon {
  display: inline-block;
}

// HTML
<i class="icon icon-home"></i>
*/
.sprite-width(@sprite) {
  width: extract(@sprite, 5);
}

.sprite-height(@sprite) {
  height: extract(@sprite, 6);
}

.sprite-position(@sprite) {
  @sprite-offset-x: extract(@sprite, 3);
  @sprite-offset-y: extract(@sprite, 4);
  background-position: @sprite-offset-x @sprite-offset-y;
}

.sprite-image(@sprite) {
  @sprite-image: extract(@sprite, 9);
  @sprite-image-bare: ~`"@{sprite-image}".slice(1, -1)`;
  background-image: url(@sprite-image-bare);
}

.sprite(@sprite) {
  .sprite-image(@sprite);
  .sprite-position(@sprite);
  .sprite-width(@sprite);
  .sprite-height(@sprite);
}

/*
The `.sprites` mixin generates identical output to the CSS template
  but can be overridden inside of LESS

This must be run when you have at least 2 sprites.
  If run with a single sprite, then there will be reference errors.

.sprites(@spritesheet-sprites);
*/
.sprites(@sprites, @i: 1) when (@i <= length(@sprites)) {
  @sprite: extract(@sprites, @i);
  @sprite-name: e(extract(@sprite, 10));
  .@{sprite-name} {
    .sprite(@sprite);
  }
  .sprites(@sprites, @i + 1);
}