Forked react-toolbox with some fixes
 
 
 
 
Go to file
Javi Velasco 81acda7162 Migrate styles to PostCSS (#666)
* Add postcss-next postcss-include and reporter

* Add stylelint

* Add CSS colors

* Add CSS custom media queries

* Use dashes for CSS colors

* Add base CSS variables

* Remove AppBar SASS dependency from spec page

* Migrate AppBar style to PostCSS

* Migrate Avatar style to PostCSS

* Migrate Ripple style to PostCSS

* Remove unneeded media CSS import in Avatar

* Add shadows to CSS variables

* Migrate Button style to PostCSS

* Update webpack test config and linting from npm

* Migrate Input style to PostCSS

* Add missing input config variables for Dropdown and Autocomplete

* Migrate Chip style to PostCSS

* Migrate Autocomplete style to PostCSS

* Migrate Dropdown style to PostCSS

* Migrate animations to PostCSS

* Migrate Card style to PostCSS

* Migrate Checkbox style to PostCSS

* Migrate DataPicker style to PostCSS

* Migrate Dialog style to PostCSS

* Migrate Drawer style to PostCSS

* Add postcss-mixins and postcss-each

* Migrate Layout style to PostCSS

* Fix bug in button theme

* Bugfix in avatar css

* Add some missing nesting notations

* Migrate Link style to PostCSS

* Migrate List style to PostCSS

* Migrate Menu style to PostCSS

* Migrate Navigation style to PostCSS

* Migrate Overlay style to PostCSS

* Migrate ProgressBar style to PostCSS

* Migrate Radio style to PostCSS

* Migrate Slider style to PostCSS

* Migrate Snackbar style to PostCSS

* Migrate Switch style to PostCSS

* Migrate Table style to PostCSS

* Migrate Tabs style to PostCSS

* Migrate TimePicker to PostCSS

* Migrate Tooltip styles to PostCSS

* Update webpack config for testing and tests

* Migrate commons to PostCSS

* Remove sass from main project

* Bye from docs to sass

* Build with CSS

* Remove unneded deps for sass in docs subproject

* Fix tests

* use 4p shadow in AppBar as spec indicates

* Fixed typo in list/config.css

* Fix tests

* Fix linter errors

* Latest build

* Release 2.0.0-beta.0

* Remove sass lint

* fixes old sass var in css config

* Update linter

* New Table implementation

* Fix old sass var in list/config.css

See da0c47041e.

* Remove normalize.css from commons.css

* Update dependencies

* Latest build

* Input ready to accept visible hint

* Prepare slider and progress to be disabled

* Render Snackbar using Portal

* Refactor Dialog, Drawer and Overlay to be used in Layout

* Add inner layer to AppBar

* New layout

* Use Layout in spec

* Latest build

* remove layout playground example

* add smTablet and lgTablet to NavDrawer in Layout readme

* add default prop className to Layout, NavDrawer and Sidebar

* fix css linter errors in card and slider

* Typings for Table component

* Add missing Drawer identifier

* Update lib build

* Adds onQueryChange callback property to Autocomplete

The onQueryChange callback is called when the value of the query changes in Autocomplete.
It is called with the new query value.

* Fix #966

* Fix #965

* Fixes #976

* Updated css-related dependencies

Removed usages of `addDependencyTo` since it's deprecated and not needed anymore.
See https://github.com/postcss/postcss-import#adddependencyto

* Enabled HMR for styles by disabling extracting them to a CSS file

* Remove lib from repo

* Remove lib

* Fixes #1021

* Build using Gulp

* Export ThemeProvider from react-css-themr

* Add CHANGELOG to release command

* Release 2.0.0-beta.1

* Remove immutability helper

* Update dependencies

* Fix Tooltip trying to render after it's been unmounted

* Fixes #1038

* Release 2.0.0-beta.2

* Add ramda, refactor utils and remove slide animation modules

* Remove separate slide animations modules

* Remove box-sizing reset and body rule

* Remove commons.css

* Release 2.0.0-beta.4

* Update dependencies

* Fixes #1061

* More aggresive guard condition for multiple autocomplete

* Fix typeof check in isBrowser function

* Fixes an issue when specs are opened with browsers that do not support Object.entries().

* Import from ramda using the 'import XXX from "ramda/src/XXX"' pattern so that bundle sizes will be smaller for not including the whole ramda package.

* Fix #1032

* Fix tests

* Update yarn.lock

* Fixes #1064
2017-01-05 02:42:18 +01:00
components Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
docs Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
spec Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
tools Get rid of jsx extensions 🔮 2016-04-10 21:23:04 +02:00
.babelrc Add themr to AppBar 2016-05-15 13:23:55 +02:00
.bumpedrc Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
.editorconfig Migrate button, ripple and font icon styles to sass and add sass tooling 2015-10-02 17:39:26 +02:00
.eslintignore use react-transform 2015-10-29 13:33:21 +08:00
.eslintrc Added logic to show selected chips even if they don't exist in source (showSelectedWhenNotInSource). Object is now accepted in value prop and should match source. WIP. 2016-11-30 13:43:15 +00:00
.gitignore Fix #898 2016-11-22 08:46:32 +01:00
.lintstagedrc [chore] Added lint-staged along with the config. 2016-10-26 15:53:25 +02:00
.npmignore add .npmgnore 2015-11-25 09:38:00 -05:00
.nvmrc Update node version 2016-05-21 18:00:25 +02:00
.stylelintrc Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
.travis.yml Removed semvar lock from travis ci node versions 2016-09-25 10:09:41 -07:00
CHANGELOG.md Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
LICENSE README initial version 2015-11-01 17:52:07 +01:00
README.md Fixes #964 2016-11-27 12:51:20 +01:00
gulpfile.js Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
index.d.ts Moved modules to separate files. 2016-07-18 17:25:48 +02:00
karma.conf.js Fixed linting issues 2015-12-23 23:58:43 -07:00
package.json Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
server.js Add internal ip to easily test other devices 2016-11-05 12:23:32 +01:00
tests.webpack.js Get rid of jsx extensions 🔮 2016-04-10 21:23:04 +02:00
webpack.config.development.js Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
webpack.config.test.js Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00
yarn.lock Migrate styles to PostCSS (#666) 2017-01-05 02:42:18 +01:00

README.md

npm version Build Status NPM Status react-toolbox channel on discord Donate

React Toolbox is a set of React components that implement Google's Material Design specification. It's powered by CSS Modules and harmoniously integrates with your webpack workflow, although you can use any other module bundler. You can take a tour through our documentation website and try the components live!

Installation

React Toolbox can be installed as an npm package:

$ npm install --save react-toolbox

Prerequisites

React Toolbox uses CSS Modules by default to import stylesheets written in SASS. In case you want to import the components already bundled with CSS, your module bundler should be able to require these SASS modules.

Although we recommend webpack, you are free to use whatever module bundler you want as long as it can compile and require SASS files located in your node_modules. If you are experiencing require errors, make sure your configuration satisfies this requirement.

Of course this is a set of React components so you should be familiar with React. If want to customize your components via themes, you may want to take a look to react-css-themr which is used by React Toolbox to make component easily themeable.

Basic usage

In this minimal example, we import a Button with styles already bundled:

import React from 'react';
import ReactDOM from 'react-dom';
import { Button } from 'react-toolbox/lib/button';

ReactDOM.render(
  <Button label="Hello World!" />,
  document.getElementById('app')
);

Take into account that any required style will be included in the final CSS so your final would include Button styles in this case. It's more convenient to import components this way (or with raw imports) because if you require from the project root, every stylesheet of React Toolbox will be included, even if you don't use it.

Importing components

First let's take a look on how the components are structured in the project. The components folder contains a folder for each component or set of related components. For example, the app_bar:

 |- /app_bar
 |---- AppBar.js
 |---- _config.scss
 |---- index.js
 |---- readme.md
 |---- theme.scss

As you can see in the previous block, each folder includes: a Javascript file for each component/subcomponent; a README with documentation, an index Javascript file that imports and injects styles and dependencies for you, a default theme SASS stylesheet and a configuration partial with configuration variables. Depending on whether you want the styles to be directly bundled or not, you can import components in two different ways.

Bundled component

You import from the index file so the imported component comes with all dependencies and themes already required and injected for you. This means that the CSS for each dependency will be bundled in your final CSS automatically and the component markup includes the classnames to be styled. For example:

import { AppBar } from 'react-toolbox/lib/app_bar';

Raw component

You import from the component definition so the imported component is bundled with its dependencies but it does not require any style for you. This means that no CSS will be bundled and the component markup will not include any classname. It's your responsibility to provide a theme to the component to be properly style and you can do it via properties or context. For example:

import { AppBar } from 'react-toolbox/lib/app_bar/AppBar.js';

Customizing components

Every component accepts a theme property intended to provide a CSS Module import object that will be used by the component to assign local classnames to its DOM nodes. Therefore, each one implements a documented classname API so if you want to customize a component, you just need to provide a theme object with the appropriated classname mapping.

If the component has already a theme injected, the properties you pass will be merged with the injected. In this way, you can add classnames to the nodes of a specific component and use them to add or to override styles. For example, if you want to customize the AppBar to be purple:

import React from 'react';
import { AppBar } from 'react-toolbox/lib/app_bar';
import theme from './PurpleAppBar.scss';

const PurpleAppBar = (props) => (
  <AppBar {...props} theme={theme} />
);

export default PurpleAppBar;

.appBar {
  background-color: #800080;
}

In this case we are adding styles to an AppBar component that already has some styles injected. It works because the component background by default has the same priority as the one we added. There will be cases where the original rule is more restrictive. For those cases you would need to boost priority using the same restrictions as in the original stylesheet. Feel free to take a look into the original themes or just check the selectors you want to override in DevTools.

If the component has no styles injected, you should provide a theme object implementing the full API. You are free to require the CSS Module you want but take into account that every classname is there for a reason. You can either provide a theme via prop or via context as we will see later.

Theming

You can afford theming in multiple ways. First of all, you have to understand that React Toolbox stylesheets are written in SASS and configured using the config files we saw earlier. Also you may want to check colors and globals files to get an overview on the variables you have to override to get the results you want.

In most scenarios you can get more customized themes by overriding those variables and compiling stylesheets with them. For example, you can create a _theme.scss SASS file:

@import "~react-toolbox/lib/colors";

$color-primary: $palette-blue-500;
$color-primary-dark: $palette-blue-700;

This file should be prepended to each stylesheet compilation which can be achieved in multiple ways.

Using SASS Loader

If you are using Webpack as module bundler, you are probably using sass-loader as well. What we want to do is to prepend to each SASS file compilation a bunch of variables to override and this can be done with the data option. For example:

sassLoader: {
  data: '@import "' + path.resolve(__dirname, 'theme/_theme.scss') + '";'
}

In this case we are prepending the theme import to each SASS compilation so the primary color will be changed in every single stylesheet. If you are not using webpack maybe your loader still has a similar option, otherwise don't worry, there are solutions.

Using SASS imports and props

Remember that you can import components without styles and provide those styles using the theme property. For example, a theme for a button customized with the previous theme file would be like:

@import "theme.scss";
@import "~react-toolbox/lib/button/theme";

Then, when you use a button you can inject the appropriated theme:

import { Button } from 'react-toolbox/lib/button/Button';
import buttonTheme from './theme/button.scss';

const ThemedButton = (props) => (
  <Button theme={buttonTheme}  {...props} />
);

export default ThemedButton;

With this technique you have to create wrappers for every component and this is not cool at all... but don't worry, we can provide the theme via context to avoid this.

Using SASS imports and context

This is a good moment to check out react-css-themr if you still didn't. Every component in React Toolbox has a key assigned that can be used to provide a default CSS Module. You can create a theme like:

export default {
  RTRipple: require('./ripple.scss'),
  RTButton: require('./button.scss')
}

Check for each component what key uses. Then, when you have a theme object fully imported and customized for each component your application uses, you can use it like we list here:

import React from 'react';
import { render } from 'react-dom';
import { ThemeProvider } from 'react-css-themr';
import theme from './theme/theme.js';
import App from './App.js';

render(
  <ThemeProvider theme={theme}>
    <App />
  </ThemeProvider>
, document.getElementById('app'))

A couple of things here. First you need to use raw components to get this styles properly applied. Second, you have to add dependency themes by yourself. For example, the Button requires Ripple so you have to provide styles for both of them.

Also, recall that all components accepts a theme verifying required classNames but there may be some missing. If any property is missing you can check the selectors you want to override straight in the DevTools.

Roboto Font and Material Design Icons

React Toolbox assumes that you are importing Roboto Font and Material Design Icons.

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.

Server Side Rendering

The only requirement for SSR is to be able to require ES6 and CSS Modules in the backend. To make it possible you can check projects like CSS Modules register hook or Webpack Isomorphic tools. Also, make sure you can import from node_modules.

Examples

For now we have a repository example demonstrating configuration and some basic customization. For now it's not using SSR rendering but it shouldn't be difficult to implement an example so it will come soon. Feel free to PR your example project or to add some use cases to the repository.

TypeScript

TypeScript external module definition files are included, and should not require any manual steps to utilize. They will be picked up by the TypeScript compiler when importing from the npm package.

Note that to comply with the official recommendation for npm typings, a triple-slash reference to react.d.ts is NOT included. You will need to reference react.d.ts somewhere in your project.

Authors and Contributors

The project is being initially developed and maintained by Javier Velasco and Javier Jiménez and the contribution scene is just getting warm. We want to create reference components so any contribution is very welcome.

To work in the project you'd need a node version supporting ES6 syntax. Although the project is built using Babel we use some ES6 features in the development server. Also, the package has been tested with node 4.2.1. Consider using nvm or n to handle different node versions!

To start the documentation site locally, you'll need to install the dependencies from both the main package and the docs subproject:

$ git clone https://github.com/react-toolbox/react-toolbox.git
$ cd react-toolbox/
$ npm install
$ cd docs/
$ npm install
$ npm start

Local documentation will then be available at http://localhost:8081/.

Extensions

We don't officially support components that are not covered by Google Material Design. If you want to implement some complementary component feel free to open a PR adding your a link in this section. For now you can check on github: react-toolbox-additions and on npm: react-toolbox-additions.

License

This project is licensed under the terms of the MIT license.