postcss-custom-values
Version:
[![NPM Version][npm-img]][npm-url] [![Build Status][cli-img]][cli-url] [![Support Chat][git-img]][git-url]
94 lines (73 loc) • 2.4 kB
Markdown
is a work in progress and not recommended for production_
With [PostCSS Custom Values] you can create your own CSS values such as keywords and units.
```pcss
/* Create a keyword which can be used with any property */
@value long {
value: 500px;
};
/* Create a keyword restricted to certain properties */
@value small property(padding, margin) {
value: 20px;
};
@value small property(font-size) {
value: 12px;
};
/* Create a custom unit using <tokens> */
@value <number>gu {
value: calc($0 * 4px);
};
.example {
position: absolute;
top: long;
width: long;
font-size: small;
padding: small;
margin: 5gu 10px 10gu 1em;
}
```
Output:
```css
.example {
position: absolute;
top: 500px;
width: 500px;
font-size: 12px;
padding: 20px;
margin: calc(5 * 4px) 10px calc(10 * 4px) 1em;
}
```
Tokens can be placed anywhere within the value identifier.
```pcss
@value layout_<side> {...}
@value <number>gu {...}
@value _<integer>_ {...}
```
Data is captured by the token and can be used to calculate the value by referencing it using `$0`.
```pcss
@value space_<integer> {
value: calc($0 * 10px);
}
```
Below are a list of the currently available tokens.
| Key | Description |
|-------------|----------------------------------------------------------|
| `<number>` | Any number including decimal points and negative numbers |
| `<integer>` | Only whole numbers including negative integers |
| `<side>` | top, right, bottom or left |
```bash
npm install postcss-custom-values --save-dev
```
[ ]: https://img.shields.io/travis/mindthetic/postcss-custom-values.svg
[ ]: https://travis-ci.org/mindthetic/postcss-custom-values
[ ]: https://img.shields.io/badge/support-chat-blue.svg
[ ]: https://gitter.im/postcss/postcss
[ ]: https://img.shields.io/npm/v/postcss-custom-values.svg
[ ]: https://www.npmjs.com/package/postcss-custom-values
[ ]: https://github.com/postcss/postcss
[ ]: https://github.com/mindthetic/postcss-custom-values
[![NPM Version][npm-img]][npm-url]
[![Build Status][cli-img]][cli-url]
[![Support Chat][git-img]][git-url]
_This