1

How do I correctly use the default styling of React-Toolbox?

I would like to try this library, but have lost hours trying to configure the scss/css. I can import and render react-toolbox components, but they are not styled.
Roboto font and material work fine using <link> tags in public/index.html

According to the brief installation steps, I have included css-loader, sass-loader, and babel.

I copied the example project from https://github.com/react-toolbox/react-toolbox-example. I removed the extra style sheets, such as style.scss in a couple places, to pare down and reduce confusion. I noticed the example project also includes <link rel="stylesheet" href="react-toolbox.css"> (which I do not see in the install steps, docs, or README). That <link> is required, removing it de-styles the example. (Side Query: How and where does that end css file build/get served? It's not in the directory even after serving locally with npm.)

So, I copied all/most of index.jsx, package.json, and webpack.config.js from the example, and added that stylesheet <link>, matching the filename to the example and my config.

I am importing commons with import 'react-toolbox/lib/commons'.

The style link and the import seem to have no effect. I have no errors from npm/webpack when running npm start. One of the similar github issues has a comment expressing surprise there was no webpack error for a similar problem.

I've also tried [3] (see comment), though I don't understand what that does. That poster implied it's not ideal, and I haven't seen that pattern elsewhere.

I understand this may duplicate React-toolbox how to include the styles correctly. My rep is too low to comment there, and that question is currently unanswered. As related issues seem common, I hope a community answer would be helpful.

In the various issues, it sounds like it was usually just a webpack config issue. If that's the case, I'd like to know what the correct config is please. I suspect I'm missing a single line or so somewhere, or missing something simple about modern front end with React and Webpack in general that may be assumed or common knowledge by most; I'm new to these tools.

I'm about ready to just import a different component library, but I like what I've read about React-Toolbox in comparison, it seems mobile friendly, and I would like to at least try it.

package.json: (name, license, description omitted)

 {
    "scripts": {
        "start": "webpack-dev-server -d --config webpack.dev.config.js --content-base public/ --progress --colors",
        "build": "webpack -d --config webpack.dev.config.js --profile --progress --colors"
    },
    "engines": {
        "node": "0.10.x"
    },
    "dependencies": {
        "autoprefixer": "^6.2.3",
        "babel-core": "^6.4.0",
        "babel-eslint": "^4.1.6",
        "babel-loader": "^6.2.1",
        "babel-plugin-react-transform": "^2.0.0",
        "babel-preset-es2015": "^6.3.13",
        "babel-preset-react": "^6.3.13",
        "classnames": "^2.2.3",
        "css-loader": "^0.9.1",
        "extract-text-webpack-plugin": "^1.0.1",
        "j-toker": "0.0.10-beta3",
        "jquery": "2.2.0",
        "jsuri": "^1.3.0",
        "jsx-loader": "^0.12.2",
        "node-sass": "^3.4.2",
        "normalize.css": "^3.0.3",
        "postcss-loader": "^0.8.0",
        "react": "^0.14.6",
        "react-addons-css-transition-group": "^0.14.6",
        "react-dom": "^0.14.6",
        "react-router": "^1.0.3",
        "react-toolbox": "^0.14.0",
        "react-transform-catch-errors": "^1.0.1",
        "react-transform-hmr": "^1.0.1",
        "sass-loader": "^3.1.2",
        "style-loader": "^0.8.3",
        "toolbox-loader": "0.0.3",
        "webpack": "^1.12.11",
        "webpack-dev-server": "^1.8.0",
        "webpack-hot-middleware": "^2.6.0"
    }
}

webpack.config.js:

const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  entry: [
    'webpack-hot-middleware/client',
    './app/client/index.jsx'
  ],
  output: {
    path: path.join(__dirname, 'build'),
    filename: 'react-toolbox.js',
    publicPath: '/'
  },
  resolve: {
    extensions: ['', '.jsx', '.scss', '.js', '.json'],
    modulesDirectories: [
      'node_modules',
      path.resolve(__dirname, './node_modules')
    ]
  },
  module: {
    loaders: [
      {
        test: /(\.js|\.jsx)$/,
        exclude: /(node_modules)/,
        loader: 'babel',
        query: {
           presets:['es2015','react']
        }
      },
      {
        test: /(\.scss|\.css)$/,
        loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass?sourceMap!toolbox')
      }
    ]
  },
  toolbox: {
    theme: path.join(__dirname, 'app/client/toolbox-theme.scss')
  },
  postcss: [autoprefixer],
  plugins: [
    new ExtractTextPlugin('react-toolbox.css', { allChunks: true }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development')
    })
  ]
};

index.jsx:

import 'react-toolbox/lib/commons';

import React from 'react';
import ReactDOM from 'react-dom';

import ToolboxApp from 'react-toolbox/lib/app';
import {Button, IconButton} from 'react-toolbox/lib/button';
import Checkbox from 'react-toolbox/lib/checkbox';
import Header from './components/layout/Header';

ReactDOM.render((
    <ToolboxApp>
        <Header />
        <Button className="button" icon="add" floating accent/>
        <IconButton onClick={function(){alert('clicked')}} icon='favorite' accent />
    </ToolboxApp>
), document.getElementById('app'));
Venugopal
  • 1,888
  • 1
  • 17
  • 30
stubbly
  • 47
  • 1
  • 6
  • Due to new user question link restrictions: Install: http://react-toolbox.com/#/install [3]Github issue resolve in loader suggestion: https://github.com/react-toolbox/react-toolbox/issues/121#issuecomment-162258230 – stubbly Jan 14 '16 at 01:00

1 Answers1

2

I copied most of the example repo at https://github.com/react-toolbox/react-toolbox-example into my app/client directory, on a new branch. I had to adjust very little, and it seems to work. While this doesn't answer where I went wrong with configs or file structure, and I may have to repeat some effort, I can move forward.

This question may benefit from better suggestions how to add React-Toolbox to an existing project, without replacing existing folders/files.

stubbly
  • 47
  • 1
  • 6