Skip to content

Commit 9915823

Browse files
committed
Refactor docs
1 parent d8c324d commit 9915823

File tree

1 file changed

+71
-55
lines changed

1 file changed

+71
-55
lines changed

README.md

Lines changed: 71 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,107 @@
1-
# CSS Modules: Values
1+
# postcss-icss-values [![Build Status][travis-img]][travis]
22

3-
Pass arbitrary values between your module files, transforms
3+
[PostCSS]: https://github.com/postcss/postcss
4+
[travis-img]: https://travis-ci.org/css-modules/postcss-icss-selectors.svg
5+
[travis]: https://travis-ci.org/css-modules/postcss-icss-selectors
46

5-
```css
6-
@value primary: #BF4040;
7-
@value secondary: #1F4F7F;
8-
```
7+
PostCSS plugin for css modules to pass arbitrary values between your module files.
98

10-
into
9+
## Usage
1110

12-
```css
13-
:export {
14-
primary: #BF4040;
15-
secondary: #1F4F7F;
16-
}
11+
```js
12+
postcss([ require('postcss-icss-values') ])
1713
```
1814

19-
### Usage
15+
See [PostCSS] docs for examples for your environment.
16+
17+
### Export value
2018

2119
```css
2220
/* colors.css */
21+
2322
@value primary: #BF4040;
24-
@value secondary: #1F4F7F;
23+
/* or without colon for preprocessors */
24+
@value secondary #1F4F7F;
2525

26-
.text-primary {
27-
color: primary;
26+
.panel {
27+
background: primary;
2828
}
2929

30-
.text-secondary {
31-
color: secondary;
30+
/* transforms to */
31+
32+
:export {
33+
primary: #BF4040;
34+
secondary: #1F4F7F
35+
}
36+
37+
.panel {
38+
background: #BF4040;
3239
}
3340
```
3441

42+
**If you are using Sass** along with this PostCSS plugin, do not use the colon `:` in your `@value` definitions. It will cause Sass to crash.
43+
44+
Note also you can _import_ multiple values at once but can only _define_ one value per line.
45+
3546
```css
36-
/* breakpoints.css */
37-
@value small: (max-width: 599px);
38-
@value medium: (min-width: 600px) and (max-width: 959px);
39-
@value large: (min-width: 960px);
47+
@value a: b, c: d; /* defines a as "b, c: d" */
4048
```
4149

50+
### Importing value
51+
4252
```css
43-
/* my-component.css */
44-
/* alias paths for other values or composition */
45-
@value colors: "./colors.css";
46-
/* import multiple from a single file */
47-
@value primary, secondary from colors;
48-
/* make local aliases to imported values */
49-
@value small as bp-small, large as bp-large from "./breakpoints.css";
50-
51-
.header {
52-
composes: text-primary from colors;
53-
box-shadow: 0 0 10px secondary;
53+
@value primary, secondary from './colors.css';
54+
55+
.panel {
56+
background: secondary;
5457
}
5558

56-
@media bp-small {
57-
.header {
58-
box-shadow: 0 0 4px secondary;
59-
}
59+
/* transforms to similar exports */
60+
61+
:import('./colors.css') {
62+
__value__primary__0: primary;
63+
__value__secondary__1: secondary
6064
}
61-
@media bp-large {
62-
.header {
63-
box-shadow: 0 0 20px secondary;
64-
}
65+
:export {
66+
primary: __value__primary__0; /* this long names will be mapped to imports by your loader */
67+
secondary: __value__secondary__1
6568
}
66-
```
6769

68-
**If you are using Sass** along with this PostCSS plugin, do not use the colon `:` in your `@value` definitions. It will cause Sass to crash.
70+
.panel {
71+
background: __value__secondary__1;
72+
}
73+
```
6974

70-
Note also you can _import_ multiple values at once but can only _define_ one value per line.
75+
### Importing value in JS
7176

7277
```css
73-
@value a: b, c: d; /* defines a as "b, c: d" */
78+
import { primary } from './colors.css';
79+
// will have similar effect
80+
console.log(primary); // -> #BF4040
7481
```
7582

76-
### Justification
83+
### Aliases
7784

78-
See [this PR](https://github.com/css-modules/css-modules-loader-core/pull/28) for more background
85+
Do not conflict between names you are able to import values with aliases
7986

80-
## License
87+
```css
88+
@value small as bp-small, large as bp-large from './breakpoints.css';
89+
@value (
90+
small as t-small,
91+
large as t-large
92+
) from './typo.css';
93+
94+
@media bp-small {
95+
.foo {
96+
font-size: t-small;
97+
}
98+
}
99+
```
81100

82-
ISC
101+
## Justification
83102

84-
## With thanks
103+
See [this PR](https://github.com/css-modules/css-modules-loader-core/pull/28) for more background
85104

86-
- Mark Dalgleish
87-
- Tobias Koppers
88-
- Josh Johnston
105+
## License
89106

90-
---
91-
Glen Maddern, 2015.
107+
MIT © Glen Maddern and Bogdan Chadkin, 2015

0 commit comments

Comments
 (0)