|
1 |
| -# CSS Modules: Values |
| 1 | +# postcss-icss-values [![Build Status][travis-img]][travis] |
2 | 2 |
|
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 |
4 | 6 |
|
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. |
9 | 8 |
|
10 |
| -into |
| 9 | +## Usage |
11 | 10 |
|
12 |
| -```css |
13 |
| -:export { |
14 |
| - primary: #BF4040; |
15 |
| - secondary: #1F4F7F; |
16 |
| -} |
| 11 | +```js |
| 12 | +postcss([ require('postcss-icss-values') ]) |
17 | 13 | ```
|
18 | 14 |
|
19 |
| -### Usage |
| 15 | +See [PostCSS] docs for examples for your environment. |
| 16 | + |
| 17 | +### Export value |
20 | 18 |
|
21 | 19 | ```css
|
22 | 20 | /* colors.css */
|
| 21 | + |
23 | 22 | @value primary: #BF4040;
|
24 |
| -@value secondary: #1F4F7F; |
| 23 | +/* or without colon for preprocessors */ |
| 24 | +@value secondary #1F4F7F; |
25 | 25 |
|
26 |
| -.text-primary { |
27 |
| - color: primary; |
| 26 | +.panel { |
| 27 | + background: primary; |
28 | 28 | }
|
29 | 29 |
|
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; |
32 | 39 | }
|
33 | 40 | ```
|
34 | 41 |
|
| 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 | + |
35 | 46 | ```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" */ |
40 | 48 | ```
|
41 | 49 |
|
| 50 | +### Importing value |
| 51 | + |
42 | 52 | ```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; |
54 | 57 | }
|
55 | 58 |
|
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 |
60 | 64 | }
|
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 |
65 | 68 | }
|
66 |
| -``` |
67 | 69 |
|
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 | +``` |
69 | 74 |
|
70 |
| -Note also you can _import_ multiple values at once but can only _define_ one value per line. |
| 75 | +### Importing value in JS |
71 | 76 |
|
72 | 77 | ```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 |
74 | 81 | ```
|
75 | 82 |
|
76 |
| -### Justification |
| 83 | +### Aliases |
77 | 84 |
|
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 |
79 | 86 |
|
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 | +``` |
81 | 100 |
|
82 |
| -ISC |
| 101 | +## Justification |
83 | 102 |
|
84 |
| -## With thanks |
| 103 | +See [this PR](https://github.com/css-modules/css-modules-loader-core/pull/28) for more background |
85 | 104 |
|
86 |
| -- Mark Dalgleish |
87 |
| -- Tobias Koppers |
88 |
| -- Josh Johnston |
| 105 | +## License |
89 | 106 |
|
90 |
| ---- |
91 |
| -Glen Maddern, 2015. |
| 107 | +MIT © Glen Maddern and Bogdan Chadkin, 2015 |
0 commit comments