reactjs - Using 'material-ui' with react-rails gem? -
i use material-ui component library in rails 4 app. using react-rails gem add .jsx compilation asset pipeline. have added material-ui via rails-assets in gemfile so:
source 'https://rails-assets.org' gem 'rails-assets-material-ui' end
and have required library in application.js file so:
//= require material-ui
however keep getting error "couldn't find file 'material-ui". how can use material-ui component library in rails app react-rails gem?
ok here have working far...
to gemfile have added:
gem 'react-rails' gem "browserify-rails"
this gives our react library, helpers , jsx compilation ability use require() sytax require modules in our js. browserify-rails allows require npm modules in rails assets via package.json file.
we can add material-ui library our app via package.json file...
"dependencies" : { "browserify": "~> 10.2.4", "browserify-incremental": "^3.0.1", "material-ui": "0.13.1" },
the material ui library uses require syntax join different jsx component files in right order why need use browserify-rails.
next keep our react code made new directory in asset/javascripts called /react...
react l /components l react.js l react-libraries.js l theme.js
now part of 'material-ui' dependencies have react library. means @ moment have 2 copies of library. 1 'react-rails' gem , 1 'material-ui' library dependencies 'browserify-rails'. lets use 1 'material-ui' dependencies , leave 1 'react-rails'.
in react.js:
//= require ./react-libraries //= require react_ujs //= require_tree ./components
then in react-libraries.js
//react library react = require('react'); //material design library materialui = require('material-ui/lib'); injecttapeventplugin = require('react-tap-event-plugin'); injecttapeventplugin(); //material design library custom theme myrawtheme = require('./theme'); thememanager = require('material-ui/lib/styles/theme-manager');
then want include of in asset pipeline with...
//= require react/react
in application.js.
now can write components in jsx files in /react/components/ may want namespace components with...
//custom components namespace components = {};
in react-libraries.js
you can customise theme in theme.js this...
colors = require('material-ui/lib/styles/colors'); colormanipulator = require('material-ui/lib/utils/color-manipulator'); spacing = require('material-ui/lib/styles/spacing'); module.exports = { spacing: spacing, fontfamily: 'roboto, sans-serif', palette: { primary1color: colors.grey300, primary2color: colors.grey300, primary3color: colors.lightblack, accent1color: '#01a9f4', accent2color: colors.grey100, accent3color: colors.grey500, textcolor: colors.darkblack, alternatetextcolor: colors.white, canvascolor: colors.white, bordercolor: colors.grey300, disabledcolor: colormanipulator.fade(colors.darkblack, 0.3) } };
hope helps :)
Comments
Post a Comment