Skip to content

Commit 115e839

Browse files
committed
Update docs
1 parent c356a2b commit 115e839

File tree

3 files changed

+195
-69
lines changed

3 files changed

+195
-69
lines changed

README.md

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,129 @@ React Toolbox is a set of [React](http://facebook.github.io/react/) components t
1212

1313
React Toolbox can be installed as an [npm package](https://www.npmjs.org/package/react-toolbox):
1414

15-
```
15+
```bash
1616
npm install --save react-toolbox
1717
```
1818

19-
## Usage
19+
## Prerequisites
20+
21+
React Toolbox uses [CSS Modules](https://github.com/css-modules/css-modules) and [SASS](http://sass-lang.com/) to provide default stylesheets. If you want to import components bundled with stylesheets, your module bundler should be able to require SASS modules. You can use whatever module bundler you want as long as it can require SASS files from `node_modules`, but we recommend [webpack](). If you are experiencing require errors, make sure your configuration satisfies the requirements.
22+
23+
Of course this is a set of React components so you should be familiar with [React](). If you are willing to customize your components via themes, you may want to take a look to [react-css-themr]() which is used to make styling easier.
2024

21-
Although there are other ways to use React Toolbox, the recommended way is to create a webpack workflow with [babel-loader](https://github.com/babel/babel-loader), [css-loader](https://github.com/webpack/css-loader) and [sass-loader](https://github.com/jtangelder/sass-loader). A good starting point is [React Hot Webpack Boilerplate](https://github.com/gaearon/react-hot-boilerplate).
25+
## Basic usage
2226

23-
Once you have the workflow ready, you can just require and use the components:
27+
The minimal example requires a `Button` bundled with styles:
2428

25-
```jsx
29+
```
2630
import React from 'react';
27-
import Button from 'react-toolbox/lib/button';
31+
import ReactDOM from 'react-dom';
32+
import { Button } from 'react-toolbox/lib/button';
2833
29-
const CustomButton = () => (
30-
<Button label="Hello world" raised accent />
34+
ReactDOM.render(
35+
<Button label="Hello World!" />,
36+
document.getElementById('app')
3137
);
32-
33-
export default CustomButton;
3438
```
3539

36-
The previous code creates a React button component based on React Toolbox button. It's important to notice that requiring a module from the exposed root of the package will also import the **SASS** of the component.
40+
Take into account that any required style will be bundled in the final CSS so you probably would want to require components one by one instead of requiring directly from the root index.
3741

38-
## Roboto Font and Material Design Icons
42+
## Importing components
3943

40-
React Toolbox assumes that you are importing [Roboto Font](https://www.google.com/fonts/specimen/Roboto) and [Material Design Icons](https://www.google.com/design/icons/).
44+
First let's take a look on how the components are structured in the project. The [components](https://github.com/react-toolbox/react-toolbox/tree/dev/components) folder contains a folder for each component or set of related components. For example, the `app_bar`:
4145

42-
In order to import the fonts for you, we'd need to include them in the CSS which is considered a bad practice. If you are not including them in your app, go to the linked sites and follow the instructions.
46+
```
47+
|- /app_bar
48+
|---- AppBar.js
49+
|---- _config.scss
50+
|---- index.js
51+
|---- readme.md
52+
|---- theme.scss
53+
```
54+
55+
There you can see a component definition file, a readme, an index file, a theme stylesheet and a configuration file holding the SASS variables to configure the stylesheet. Depending on whether you want the styles to be directly bundled or not, you can import components in two different ways:
56+
57+
- **Bundled component**: the component requires the corresponding `theme.scss` for you so it will be included in the final bundle. Also, the local classnames will be injected in the component automatically. To import a bundled component you have to require from the `index.js` file. For example: `import {AppBar} from 'react-toolbox/lib/app_bar'`.
58+
59+
- **Raw component**: the component is required alone, without any CSS. In this case you are responsible from providing a theme. To import a raw component you have to require directly from the component definition. For example: `import AppBar from 'react-toolbox/lib/app_bar/AppBar'`.
4360

4461
## Customization
4562

46-
Since React Toolbox styles are written in CSS, it's pretty easy to customize your components. We have several ways:
63+
Since you can import raw components and then inject a theme via props or context, you can use whatever you want to provide styles. We give you some SASS stylesheets but you can configure them at import time or even port them to CSS Next or whatever. Furthermore, you can provide extra theming classes that will be mixed in the component so you can even target DOM elements in subcomponents from a parent. Let's see some examples.
4764

48-
### Via React Toolbox Loader
65+
### Customization via SASS Loader
4966

50-
Thanks to the power of SASS, all components in React Toolbox are configured from a variables file. The best way to customize your build is to create a custom configuration SASS file overriding configuration variables like colors or sizes.
67+
Every component in React Toolbox has a `_config.scss` partial and [some parent partials](https://github.com/react-toolbox/react-toolbox/tree/dev/components) defining configuration variables that are used in each `theme.scss`. Since all variables are defined as `!default`, you can prepend variable overrides with a custom `theme.scss` file to each SASS stylesheet required in the project.
5168

52-
With [toolbox-loader](https://github.com/react-toolbox/toolbox-loader) you can tell webpack where your configuration file is and it will prepend your config to each SASS build. This will result in your customized CSS for React Toolbox Components. For now you can browse the configuration files and override what you want.
69+
If you are importing bundled components, you can use something like [sass-loader](https://github.com/jtangelder/sass-loader) to prepend your custom configuration files to every sass stylesheet by using the `data` option. For example, in your webpack config:
5370

54-
### Via `className` property
71+
```js
72+
sassLoader: {
73+
data: '@import "' + path.resolve(__dirname, 'theme/_theme.scss') + '";'
74+
}
75+
```
76+
77+
### Customization via Theme Property
5578

56-
Generally each component will have a `className` prop so you can pass the class name you want to keep in the root node of the resulting markup. All markup is styled with the lowest specificity level so you can just nest one level in your CSS and the result will be applied. Consider this example:
79+
Every component in React Toolbox have a **classname API** that can be browsed from the documentation. Also, they accept a `theme` property intended to provide a [CSS Module import object](https://github.com/css-modules/css-modules) that will be used by the component to assign local classnames to its DOM nodes.
5780

58-
```jsx
59-
const CustomButton = () => (
60-
<Button className='customized' label='Custom button' />
81+
React Toolbox uses [react-css-themr](github.com/javivelasco/react-css-themr) to make theming easier. Feel free to take a look to the documentation to learn how you can use themes for the components. For example, imagine you want to create a green success button whose icons are red:
82+
83+
```
84+
// SuccessButton.js
85+
import { Button } from 'react-toolbox/lib/button';
86+
import successTheme from './success-theme.scss';
87+
88+
const SuccessButton = (props) => (
89+
<Button theme={successButtonTheme} {...props} />
6190
);
91+
92+
export default SuccessButton;
6293
```
6394

64-
If you browse the resulting markup you will see *data attributes* like `data-react-toolbox="label"` so you can avoid directly styling tag names. You can now write your CSS:
95+
```
96+
// success-theme.scss
97+
.primary {
98+
background: green;
99+
}
65100
66-
```css
67-
.customized > [data-react-toolbox="label"] {
68-
color: green;
69-
font-weight: bold;
101+
.icon {
102+
color: red
70103
}
71104
```
72105

106+
The given classes will be added to the component and, since they are defined *after* the original CSS they would take priority. Note that you can also boost priority by assigning a `className`. Check more examples at [react-css-themr](www.github.com/javivelasco/react-css-themr) documentation.
107+
108+
### Customization via Theme Context
109+
110+
Alternatively, you can provide CSS Modules object to React Toolbox components using context. This is useful in case you want to create a custom theme without creating wrappers for each raw component. To use this customization you need to install react-css-themr and then use the **theme keys** specified in each component documentation. For example:
111+
112+
```
113+
import React from 'react';
114+
import ReactDOM from 'react-dom';
115+
import { ThemeProvider } from 'react-css-themr';
116+
import Button from 'react-toolbox/lib/button/Button';
117+
import App from './App.js';
118+
119+
const theme = {
120+
RTButton: require('./theme/button-style')
121+
};
122+
123+
const ThemedApp = (children) => (
124+
<ThemeProvider theme={theme}>
125+
<App />
126+
</ThemeProvider>
127+
)
128+
129+
ReactDOM.render(<ThemedApp />, document.getElementById('app'));
130+
```
131+
132+
## Roboto Font and Material Design Icons
133+
134+
React Toolbox assumes that you are importing [Roboto Font](https://www.google.com/fonts/specimen/Roboto) and [Material Design Icons](https://www.google.com/design/icons/).
135+
136+
In order to import the fonts for you, we'd need to include them in the CSS which is considered a bad practice. If you are not including them in your app, go to the linked sites and follow the instructions.
137+
73138
## TypeScript
74139

75140
A TypeScript definition file `react-toolbox.d.ts` is available. It is referenced in `package.json` and should be picked up by the TypeScript compiler when importing from the npm package.
Lines changed: 95 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,130 @@
11
# Installation, usage and customization
22

3-
React Toolbox is a set of [React](http://facebook.github.io/react/) components that implement [Google's Material Design specification](https://www.google.com/design/spec/material-design/introduction.html). It's powered by [CSS Modules](https://github.com/css-modules/css-modules) and harmoniously integrates with your [Webpack](http://webpack.github.io/) workflow. You can take a tour through our documentation website and try the components live!
3+
React Toolbox is a set of [React](http://facebook.github.io/react/) components that implement [Google's Material Design specification](https://www.google.com/design/spec/material-design/introduction.html). It's powered by [CSS Modules](https://github.com/css-modules/css-modules) and harmoniously integrates with your [webpack](http://webpack.github.io/) workflow. You can take a tour through our documentation website and try the components live!
44

55
## Installation
66

7-
React Toolbox can be installed as an [npm package](https://www.npmjs.org/package/react-toolbox);
7+
React Toolbox can be installed as an [npm package](https://www.npmjs.org/package/react-toolbox):
88

9-
```
9+
```bash
1010
npm install --save react-toolbox
1111
```
1212

13-
## Usage
13+
## Prerequisites
14+
15+
React Toolbox uses [CSS Modules](https://github.com/css-modules/css-modules) and [SASS](http://sass-lang.com/) to provide default stylesheets. If you want to import components bundled with stylesheets, your module bundler should be able to require SASS modules. You can use whatever module bundler you want as long as it can require SASS files from `node_modules`, but we recommend [webpack](). If you are experiencing require errors, make sure your configuration satisfies the requirements.
16+
17+
Of course this is a set of React components so you should be familiar with [React](). If you are willing to customize your components via themes, you may want to take a look to [react-css-themr]() which is used to make styling easier.
1418

15-
Although there are other ways to use React Toolbox, the recommended way is to create a Webpack workflow with [Babel Loader](https://github.com/babel/babel-loader), [CSS Loader](https://github.com/webpack/css-loader) and [SASS Loader](https://github.com/jtangelder/sass-loader). A good starting point is [React Hot Webpack Boilerplate](https://github.com/gaearon/react-hot-boilerplate).
19+
## Basic usage
1620

17-
Once you have the workflow ready, you can just require and use the components:
21+
The minimal example requires a `Button` bundled with styles:
1822

19-
```jsx
23+
```
2024
import React from 'react';
21-
import Button from 'react-toolbox/lib/button';
25+
import ReactDOM from 'react-dom';
26+
import { Button } from 'react-toolbox/lib/button';
2227
23-
const CustomButton = () => (
24-
<Button label="Hello world" raised accent />
28+
ReactDOM.render(
29+
<Button label="Hello World!" />,
30+
document.getElementById('app')
2531
);
26-
27-
export default CustomButton;
2832
```
2933

30-
The previous code creates a React button component based on React toolbox button. It's important to notice that requiring a module from the exposed root of the package will import the **SASS** of the component.
34+
Take into account that any required style will be bundled in the final CSS so you probably would want to require components one by one instead of requiring directly from the root index.
3135

32-
## Roboto Font and Material Design Icons
36+
## Importing components
3337

34-
React Toolbox assumes that you are importing [Roboto Font](https://www.google.com/fonts/specimen/Roboto) and [Material Design Icons](https://www.google.com/design/icons/).
38+
First let's take a look on how the components are structured in the project. The [components](https://github.com/react-toolbox/react-toolbox/tree/dev/components) folder contains a folder for each component or set of related components. For example, the `app_bar`:
3539

36-
In order to import the fonts for you, we'd need to include them in the CSS which is considered a bad practice. If you are not including them in your app to the linked sites and follow the instructions.
40+
```
41+
|- /app_bar
42+
|---- AppBar.js
43+
|---- _config.scss
44+
|---- index.js
45+
|---- readme.md
46+
|---- theme.scss
47+
```
48+
49+
There you can see a component definition file, a readme, an index file, a theme stylesheet and a configuration file holding the SASS variables to configure the stylesheet. Depending on whether you want the styles to be directly bundled or not, you can import components in two different ways:
50+
51+
- **Bundled component**: the component requires the corresponding `theme.scss` for you so it will be included in the final bundle. Also, the local classnames will be injected in the component automatically. To import a bundled component you have to require from the `index.js` file. For example: `import {AppBar} from 'react-toolbox/lib/app_bar'`.
52+
53+
- **Raw component**: the component is required alone, without any CSS. In this case you are responsible from providing a theme. To import a raw component you have to require directly from the component definition. For example: `import AppBar from 'react-toolbox/lib/app_bar/AppBar'`.
3754

3855
## Customization
3956

40-
Since React Toolbox styles are written in CSS it's pretty easy to customize your components. We have several ways:
57+
Since you can import raw components and then inject a theme via props or context, you can use whatever you want to provide styles. We give you some SASS stylesheets but you can configure them at import time or even port them to CSS Next or whatever. Furthermore, you can provide extra theming classes that will be mixed in the component so you can even target DOM elements in subcomponents from a parent. Let's see some examples.
58+
59+
### Customization via SASS Loader
4160

42-
### Via React Toolbox Loader
61+
Every component in React Toolbox has a `_config.scss` partial and [some parent partials](https://github.com/react-toolbox/react-toolbox/tree/dev/components) defining configuration variables that are used in each `theme.scss`. Since all variables are defined as `!default`, you can prepend variable overrides with a custom `theme.scss` file to each SASS stylesheet required in the project.
4362

44-
Thanks to the power of SASS, all components in React Toolbox are configured from a variables file. The best way to customize your build is to create a custom configuration SASS file overriding configuration variables like colors or sizes.
63+
If you are importing bundled components, you can use something like [sass-loader](https://github.com/jtangelder/sass-loader) to prepend your custom configuration files to every sass stylesheet by using the `data` option. For example, in your webpack config:
4564

46-
With [toolbox-loader](https://github.com/react-toolbox/toolbox-loader) you can tell webpack where your configuration file is and it will prepend your config to each SASS build. This will result in your customized CSS for React Toolbox Components. For now you can browse the configuration files and override what you want.
65+
```js
66+
sassLoader: {
67+
data: '@import "' + path.resolve(__dirname, 'theme/_theme.scss') + '";'
68+
}
69+
```
4770

48-
### Via `className` property
71+
### Customization via Theme Property
4972

50-
Generally each component will have a `className` prop so that you can apply a class name to the root node of the resulting markup. All markup is styled with the lowest specificity level so you can just nest one level in your CSS and the result will be applied. Consider this example:
73+
Every component in React Toolbox have a **classname API** that can be browsed from the documentation. Also, they accept a `theme` property intended to provide a [CSS Module import object](https://github.com/css-modules/css-modules) that will be used by the component to assign local classnames to its DOM nodes.
5174

52-
```jsx
53-
const CustomButton = () => (
54-
<Button className='customized' label='Custom button' />
75+
React Toolbox uses [react-css-themr](github.com/javivelasco/react-css-themr) to make theming easier. Feel free to take a look to the documentation to learn how you can use themes for the components. For example, imagine you want to create a green success button whose icons are red:
76+
77+
```
78+
// SuccessButton.js
79+
import { Button } from 'react-toolbox/lib/button';
80+
import successTheme from './success-theme.scss';
81+
82+
const SuccessButton = (props) => (
83+
<Button theme={successButtonTheme} {...props} />
5584
);
85+
86+
export default SuccessButton;
5687
```
5788

58-
If you browse the resulting markup you will see *data attributes* like `data-role="label"` which can be used to style components without using tag name selectors. You can now write your CSS:
89+
```
90+
// success-theme.scss
91+
.primary {
92+
background: green;
93+
}
5994
60-
```css
61-
.customized > [data-react-toolbox="label"] {
62-
color: green;
63-
font-weight: bold;
95+
.icon {
96+
color: red
6497
}
6598
```
99+
100+
The given classes will be added to the component and, since they are defined *after* the original CSS they would take priority. Note that you can also boost priority by assigning a `className`. Check more examples at [react-css-themr](www.github.com/javivelasco/react-css-themr) documentation.
101+
102+
### Customization via Theme Context
103+
104+
Alternatively, you can provide CSS Modules object to React Toolbox components using context. This is useful in case you want to create a custom theme without creating wrappers for each raw component. To use this customization you need to install react-css-themr and then use the **theme keys** specified in each component documentation. For example:
105+
106+
```
107+
import React from 'react';
108+
import ReactDOM from 'react-dom';
109+
import { ThemeProvider } from 'react-css-themr';
110+
import Button from 'react-toolbox/lib/button/Button';
111+
import App from './App.js';
112+
113+
const theme = {
114+
RTButton: require('./theme/button-style')
115+
};
116+
117+
const ThemedApp = (children) => (
118+
<ThemeProvider theme={theme}>
119+
<App />
120+
</ThemeProvider>
121+
)
122+
123+
ReactDOM.render(<ThemedApp />, document.getElementById('app'));
124+
```
125+
126+
## Roboto Font and Material Design Icons
127+
128+
React Toolbox assumes that you are importing [Roboto Font](https://www.google.com/fonts/specimen/Roboto) and [Material Design Icons](https://www.google.com/design/icons/).
129+
130+
In order to import the fonts for you, we'd need to include them in the CSS which is considered a bad practice. If you are not including them in your app, go to the linked sites and follow the instructions.

0 commit comments

Comments
 (0)