|
1 | 1 | # patternplate-transform-cssmodules |
2 | | -[patternplate](/sinnerschrader/patternplate) transform to enable usage of [css modules](/css-modules/css-modules). |
| 2 | + |
| 3 | +[patternplate](/sinnerschrader/patternplate) |
| 4 | +transform to enable usage of |
| 5 | +[css modules](https://github.com/css-modules/css-modules). |
| 6 | + |
| 7 | +:warning: **This transform is intended to be used in conjunction with |
| 8 | + [patternplate-transform-cssmodules-symbols](https://github.com/nerdlabs/patternplate-transform-cssmodules-symbols) |
| 9 | + to produce markup using the transformed css source** |
| 10 | + |
| 11 | +See the [Configuration](#configuration) section for details. |
3 | 12 |
|
4 | 13 | ## Installation |
| 14 | + |
5 | 15 | ```shell |
6 | | -npm install --save patternplate-transform-cssmodules |
| 16 | +npm install --save patternplate-transform-cssmodules patternplate-transform-cssmodules-symbols |
7 | 17 | ``` |
| 18 | + |
8 | 19 | ## Configuration |
| 20 | + |
9 | 21 | ```javascript |
10 | 22 | // file: configuration/patternplate-server/patterns.js |
11 | 23 | module.exports = { |
12 | 24 | formats: { |
13 | 25 | css: { |
14 | 26 | name: 'Style', |
15 | 27 | transforms: ['cssmodules'] |
| 28 | + }, |
| 29 | + jsx: { |
| 30 | + name: 'Markup', |
| 31 | + transforms: ['cssmodules-symbols', 'react', 'react-to-markup'] |
16 | 32 | } |
17 | 33 | } |
18 | 34 | }; |
| 35 | +``` |
19 | 36 |
|
| 37 | +```javascript |
20 | 38 | // file: configuration/patternplate-server/transforms.js |
21 | 39 | module.exports = { |
| 40 | + 'cssmodules-symbols': { |
| 41 | + inFormat: 'jsx', |
| 42 | + outFormat: 'jsx' |
| 43 | + }, |
22 | 44 | cssmodules: { |
23 | 45 | inFormat: 'css', |
24 | 46 | outFormat: 'css' |
25 | 47 | } |
26 | 48 | }; |
27 | 49 | ``` |
| 50 | + |
| 51 | +## Usage |
| 52 | + |
| 53 | +### Sources |
| 54 | + |
| 55 | +```javascript |
| 56 | +// atoms/button/index.jsx |
| 57 | +import styles from 'style://Pattern'; |
| 58 | +import cx from 'classnames'; |
| 59 | + |
| 60 | +const className = cx(styles.default, { |
| 61 | + [styles.disabled]: this.props.disabled |
| 62 | +}); |
| 63 | + |
| 64 | +<button className={className}> |
| 65 | + {this.props.children} |
| 66 | +</button> |
| 67 | +``` |
| 68 | + |
| 69 | +```css |
| 70 | +/* atoms/button/index.css */ |
| 71 | +.default { |
| 72 | + padding: 5px 10px; |
| 73 | + background: blue; |
| 74 | + color: white; |
| 75 | +} |
| 76 | +.disabled { |
| 77 | + background: grey; |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +### Transformed |
| 82 | + |
| 83 | +```javascript |
| 84 | +// <Button>Lorem Ipsum dolor si amnet</Button> |
| 85 | +<button class="_button_4erg9ut2"> |
| 86 | + Lorem Ipsum dolor si amnet |
| 87 | +</button> |
| 88 | + |
| 89 | +// <Button>Lorem Ipsum dolor si amnet</Button> |
| 90 | +<button class="_button_4erg9ut2 _button_iert9832"> |
| 91 | + Lorem Ipsum dolor si amnet |
| 92 | +</button> |
| 93 | +``` |
| 94 | + |
| 95 | +```css |
| 96 | +/* atoms/button/index.css */ |
| 97 | +._button_4erg9ut2 { |
| 98 | + padding: 5px 10px; |
| 99 | + background: blue; |
| 100 | + color: white; |
| 101 | +} |
| 102 | +._button_iert9832 { |
| 103 | + background: grey; |
| 104 | +} |
| 105 | +``` |
0 commit comments