1.3.4 • Published 4 months ago

grid-spriter v1.3.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

GridSpriter

A mixin to help using svg sprites.

Installation

yarn add grid-spriter

Constructor

@include GridSpriter($name, $col, $row, $params);
ParameterTypeIs requiredDefaultDescription
$namestringThe name of your sprite set
$colnumberThe number of columns in your sprite grid
$rownumberThe number of rows in your sprite grid
$paramsmap()A map of optional parameters.

Optional parameters

ParameterTypeDefaultDescription
pathstring'/assets/images/sprites/'The base path to your sprite image
formatstring'svg'The extension of your sprite image
defmapnullA map with icon indexes as keys and icon names as values
modeslist'is', 'prepend', 'append'The modes for which to generate class definitions
typestring'mask'The type of images to use

Output

// Generated classes will look like this
// .#{$mode}-#{$name}-#{$id}-icon[-mask][::before|::after] {}

// For example if you used the mixin like so
$twitchParams: (
  def: (1: 'follow'), 
  modes: ['is', 'append']
);

@include GridSpriter('twitch', 3, 2, $twitchParams);

// The resulting classes would look like this
.is-twitch-follow-icon-mask {}
.append-twitch-follow-icon-mask::after {}

Usage

Any element or pseudo-element containing a sprite image must have a set width and height. Any pseudo-element containing a sprite image must have a set content. An empty string will do. Any element or pseudo-element containing a sprite image as a mask must have a set background or background-color.

The default path for images is /assets/images/sprites/, the default format is svg. In our example, the image must be located at /assets/images/sprites/twitch.svg.

@import 'grid-spriter';

$twitchParams: (
  def: (0: 'follow', 1: 'sub'),
  modes: ['is', 'prepend']
);

@include GridSpriter('twitch', 3, 2, $twitchParams);

// Twitch follow icon as background image
// The class can be anything as long as its target element also has a GridSpriter generated class
.is-twitch-follow-icon { 
  width: 64px;
  height: 64px;
}

// Twitch sub icon as a before pseudo-element with mask image
.prepend-twitch-sub-icon-mask::before {
  content: '';
  display: inline-block;
  width: 64px;
  height: 64px;
  background-color: #6441A5;
}
<!-- twitch follow icon as background image -->
<div class="is-twitch-follow-icon"></div>

<!-- twitch follow icon as mask image -->
<div class="is-twitch-follow-icon-mask"></div>

<!-- twitch follow icon as a before pseudo-element with background image -->
<div class="prepend-twitch-follow-icon"></div>
1.3.4

4 months ago

1.3.3

4 months ago

1.3.2

4 months ago

1.2.0

7 months ago

1.3.1

6 months ago

1.2.2

7 months ago

1.3.0

6 months ago

1.2.1

7 months ago

1.1.0

2 years ago

1.0.0

3 years ago