Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

sergeysova/postcss-define-units

Repository files navigation

PostCSS Define Units

Build Status

PostCSS plugin define custom units.

So simple. Use --define property. Unit define globally.

There are two ways to define a unit. First one is just a unit representation. Second one is an expression.

Expression must be surrounded by the parenthesis and it also should be ended with css unit, like so: (value * 10)px. Where value is a variable that holds a user defined unit value. Code inside parenthesies is just a JavScript, so you could use any of it functionality.

.foo {
  --define: dp 4px;
  --define: tt 2px;
  --define: ms (Math.pow(1.618, value))rem; // Modular scale expression
  padding: 8dp 1tt;
  font-size: 2ms;
  width: calc(30px + 2dp + 2tt)
}

Result:

.foo {
  padding: 32px 2px;
  font-size: 2.617924rem;
  width: calc(30px + 8px + 4px)
}

Usage

postcss([ require('postcss-define-units') ])