1.1.5 • Published 8 months ago

mixin-dictionary v1.1.5

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

Mixin Dictionary

Mixin Dictionary is a package based on Style Dictionary that allows creating mixins from design tokens for LESS and SCSS.

Installation

$ npm install mixin-dictionary --save-dev
# or
$ yarn add mixin-dictionary --dev

Usage

$ mixin-dictionary
FlagShort FlagDescription
--config [path]-cSet the config file to use. Must be a .json file

CSS

At the moment, CSS does not yet have the ability to use mixins.

Example

As an example of usage, you can look at the pbstyles style library.

config.json

{
  "platforms": ["css", "less", "scss"],
  "source": ["tokens/**/*.json"],
  "output": "./styles",
  "mediaAliases": ["screen", "breakpoint"]
}
PropertyTypeDescription
platformsArraySets of platform files to be built. By default is ""css", "less", "scss"".
sourceArrayAn array of file path globs to design token files. Exactly like Style Dictionary.
outputStringBase path to build the files, must end with a trailing slash. By default is "./styles".
mediaAliasesArrayAliases for media queries category. By default is ""screen", "breakpoint"".

Example of a mixin

{
  "font": {
    "h64": {
      "font-size": {
        "value": "64px",
        "mixin": "h64"
      },
      "line-height": {
        "value": "1.25",
        "mixin": "h64"
      },
      "font-weight": {
        "value": "700",
        "mixin": "h64"
      }
    }
  }
}

SCSS

$font-h64-font-size: 64px;
$font-h64-line-height: 1.25;
$font-h64-font-weight: 700;

@mixin h64 {
  font-size: $font-h64-font-size;
  line-height: $font-h64-line-height;
  font-weight: $font-h64-font-weight;
}

LESS

@font-h64-font-size: 64px;
@font-h64-line-height: 1.25;
@font-h64-font-weight: 700;

.h64() {
  font-size: @font-h64-font-size;
  line-height: @font-h64-line-height;
  font-weight: @font-h64-font-weight;
}

Example of a media query mixin

{
  "screen": {
    "lg": {
      "max": {
        "value": "1440px",
        "mixin": "lg"
      },
      "min": {
        "value": "921px",
        "mixin": "lg"
      }
    }
  }
}

SCSS

$screen-lg-max: 1440px;
$screen-lg-min: 921px;

@mixin lg {
  @media all and (max-width: $screen-lg-max) and (min-width: $screen-lg-min) {
    @content;
  }
}

LESS

@screen-lg-max: 1440px;
@screen-lg-min: 921px;

.lg(@content) {
  @media all and (max-width: @screen-lg-max) and (min-width: @screen-lg-min) {
    @content;
  }
}
1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

12 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago