Skip to content

Commit 4adec8a

Browse files
committed
doc: update README
1 parent db40f45 commit 4adec8a

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ test::
2222
ci::
2323
@$(BIN)/mocha $(MOCHA_OPTS) --watch --watch-extensions json,md $(TESTS)
2424

25+
doctoc:
26+
@$(BIN)/doctoc --title '**Table of Contents**' ./README.md
27+
2528
version-major version-minor version-patch:: lint check test build
2629
@npm version $(@:version-%=%)
2730

README.md

+64-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
[![Travis build status](https://img.shields.io/travis/andreypopp/react-css-components/master.svg)](https://travis-ci.org/andreypopp/react-css-components)
44
[![npm](https://img.shields.io/npm/v/react-css-components.svg)](https://www.npmjs.com/package/react-css-components)
55

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+
622
## Motivation
723

824
Define React presentational components with CSS.
@@ -53,8 +69,42 @@ import {Label} from './styles.react.css'
5369

5470
<Label /> // => <div className="<autogenerated classname>">...</div>
5571
```
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+
56102
## Variants
57103

104+
Variants is a mechanism which allows to define styling variants for a component.
105+
106+
### Named variants
107+
58108
You can define additional styling variants for your components:
59109
```css
60110
Label {
@@ -71,10 +121,13 @@ They are compiled as CSS classes which then can be controlled from JS via
71121
```js
72122
<Label variant={{emphasis: true}} /> // sets both classes with `color` and `font-weight`
73123
```
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:
75130

76-
You can define variants which are based on some JavaScript expression against
77-
props:
78131
```css
79132
Label {
80133
color: red;
@@ -84,13 +137,20 @@ Label:prop(mode == "emphasis") {
84137
font-weight: bold;
85138
}
86139
```
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+
88147
```js
89148
<Label mode="emphasis" /> // sets both classes with `color` and `font-weight`
90149
```
91150

92151
## TODO
93152

94153
* [ ] Document how to add PostCSS transform to build pipeline (think autoprefixer).
154+
* [ ] Document how to do CSS extraction.
95155

96156
[CSS modules]: https://github.com/css-modules/css-modules

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"babel-core": "^6.7.6",
6060
"babel-generator": "^6.7.5",
6161
"babel-preset-prometheusresearch": "^0.1.0",
62+
"doctoc": "^1.1.1",
6263
"eslint": "^2.7.0",
6364
"eslint-config-prometheusresearch": "^0.2.0",
6465
"eslint-plugin-react": "^4.3.0",

0 commit comments

Comments
 (0)