3
3
[ ![ Travis build status] ( https://img.shields.io/travis/andreypopp/react-css-components/master.svg )] ( https://travis-ci.org/andreypopp/react-css-components )
4
4
[ ![ npm] ( https://img.shields.io/npm/v/react-css-components.svg )] ( https://www.npmjs.com/package/react-css-components )
5
5
6
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
7
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
8
+ ** Table of Contents**
9
+
10
+ - [ Motivation] ( #motivation )
11
+ - [ Installation & Usage] ( #installation-&-usage )
12
+ - [ Base components] ( #base-components )
13
+ - [ DOM components] ( #dom-components )
14
+ - [ Composite components] ( #composite-components )
15
+ - [ Variants] ( #variants )
16
+ - [ Named variants] ( #named-variants )
17
+ - [ Variants controlled with JS expression] ( #variants-controlled-with-js-expression )
18
+ - [ TODO] ( #todo )
19
+
20
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
21
+
6
22
## Motivation
7
23
8
24
Define React presentational components with CSS.
@@ -53,8 +69,42 @@ import {Label} from './styles.react.css'
53
69
54
70
< Label / > // => <div className="<autogenerated classname>">...</div>
55
71
```
72
+
73
+ ## Base components
74
+
75
+ ### DOM components
76
+
77
+ By default React CSS Components produces styled ` <div /> ` components. You can
78
+ change that by defining ` base: ` property:
79
+
80
+ ``` css
81
+ FancyButton {
82
+ base : button;
83
+ color : red ;
84
+ }
85
+ ```
86
+
87
+ ### Composite components
88
+
89
+ In fact any React components which accepts ` className ` props can be used as a
90
+ base. That's means that React CSS Components can be used as theming tool for any
91
+ UI library.
92
+
93
+ Example:
94
+
95
+ ``` css
96
+ DangerButton {
97
+ base : react-ui-library/components/Button;
98
+ color : red ;
99
+ }
100
+ ```
101
+
56
102
## Variants
57
103
104
+ Variants is a mechanism which allows to define styling variants for a component.
105
+
106
+ ### Named variants
107
+
58
108
You can define additional styling variants for your components:
59
109
``` css
60
110
Label {
@@ -71,10 +121,13 @@ They are compiled as CSS classes which then can be controlled from JS via
71
121
``` js
72
122
< Label variant= {{emphasis: true }} / > // sets both classes with `color` and `font-weight`
73
123
```
74
- ## Prop variants
124
+ ### Variants controlled with JS expression
125
+
126
+ You can define variants which are conditionally applied if JS expression against
127
+ props evaluates to a truthy value.
128
+
129
+ Example:
75
130
76
- You can define variants which are based on some JavaScript expression against
77
- props:
78
131
``` css
79
132
Label {
80
133
color : red ;
@@ -84,13 +137,20 @@ Label:prop(mode == "emphasis") {
84
137
font-weight : bold ;
85
138
}
86
139
```
87
- They are compiled as CSS classes which then can be controlled from JS:
140
+
141
+ Note that any free variable reference a member of ` props ` , thus in JS ` mode `
142
+ becomes ` props.mode ` in the example above.
143
+
144
+ They are compiled as CSS classes as well. JS expressions within ` prop(..) ` are
145
+ used to determine if corresponding CSS classes should be applied to DOM:
146
+
88
147
``` js
89
148
< Label mode= " emphasis" / > // sets both classes with `color` and `font-weight`
90
149
```
91
150
92
151
## TODO
93
152
94
153
* [ ] Document how to add PostCSS transform to build pipeline (think autoprefixer).
154
+ * [ ] Document how to do CSS extraction.
95
155
96
156
[ CSS modules ] : https://github.com/css-modules/css-modules
0 commit comments