Skip to content

Instantly share code, notes, and snippets.

@maddrag0n
Created February 23, 2018 23:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maddrag0n/fe8c8b2d694f28bc30d4605357b204ac to your computer and use it in GitHub Desktop.
Save maddrag0n/fe8c8b2d694f28bc30d4605357b204ac to your computer and use it in GitHub Desktop.
react-styleguidist setup for material-ui, react-bootstrap, babel module-resolver, TapEventPlugin
const path = require('path');
module.exports = {
assetsDir: 'static/',
components: 'app/{components,containers}/**/*.jsx',
getComponentPathLine(componentPath) {
const name = path.basename(componentPath, '.jsx')
const dir = path.dirname(componentPath).replace('app/', '');
return `import ${name} from '${dir}/${name}';`
},
getExampleFilename(componentPath) {
return componentPath.replace(/\.jsx?$/, '.examples.md');
},
sections: [
{
name: 'UI Components',
components: 'app/components/**/*.jsx',
},
{
name: 'UI Containers',
components: 'app/containers/**/*.jsx',
},
],
showUsage: true,
styleguideComponents: {
Wrapper: path.join(__dirname, 'app/styleguidist/StyleguidistMuiWrapper'),
},
skipComponentsWithoutExample: true,
webpackConfig: {
module: {
loaders: [
{
test: /\.(js|jsx)?$/,
exclude: [/node_modules/],
loader: 'babel-loader',
query: {
cacheDirectory: true,
babelrc: true,
},
},
]
},
},
};
// @flow
import React from 'react';
import type { Element as ReactElement } from 'react';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import RsgWrapper from 'react-styleguidist/lib/rsg-components/Wrapper';
import injectTapEventPlugin from 'react-tap-event-plugin';
import $ from 'jquery';
injectTapEventPlugin();
const muiTheme = getMuiTheme({});
const RsgMuiWrapper = ({ children, ...rest }: { children: ReactElement<*>, }) => (
<RsgWrapper {...rest}>
<MuiThemeProvider muiTheme={muiTheme}>
{children}
</MuiThemeProvider>
</RsgWrapper>
);
export default RsgMuiWrapper;
// bootstrap css for react-bootstrap
if (typeof window !== 'undefined') {
$('<link data-description="bootstrap styles" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />')
.appendTo('head');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment