PostCSS JS Mixins

PostCSS plugin for custom mixin syntax
/* before */ /* after */ /* before */ /* after */
Usage
const syntax = ;const mixins = ; ;
See PostCSS docs for examples for your environment.
Options
mixins
Type: Object
Default: {}
Register mixins that you want to reference in your style sheets.
const decl = ;const isEmpty = ; mixins: /** * Example of creating a shorthand with default value */ { return ; } ;
units
Type: Object
Default: { default: 'rem', lineHeight: 'em' }
These units will be appended intelligently when number values are passed without a unit. For example, the font-size
property will have the unit appended, but opacity will not.
Writing Mixins
Mixins are written solely in JavaScript. They can return a declaration, a rule, or an array of declarations/rules.
Declaration
Declarations take a CSS property and it's value as arguments.
const decl = ; // Create single declaration;
Rule
Rules take a selector and an array of Declaration
objects.
const rule = ; // Create single declaration;
Methods
createMany
Matches indexes from two arrays to produce declarations for each. This is used when order matters for your mixin arguments.
// Create multiple declarations { return decl;}
);
createManyFromObj
Takes an object with property: value
pairs and an optional prefix to prepend to each property value.
// Create multiple declarations from an object { return decl;}
); /* Output */
Helper Methods
Helper methods have been provided in order to make writing mixins easier.
const helpers = ;const darken lighten = ;
List of Helper Methods
- darken
- lighten
- calcOpacity
- hexToRgba
- isColor
- isEmpty
- isNumber
- isObject
- isPercentage
- isProvided
- isString
- isUnit
- prefix
- setDefaultUnits
- toDashCase
- toDegrees
- type
- unit
Note: This plugin uses TinyColor which has a large number of other color helper methods that can easily be exposed if requested.