Skip to content

Commit

Permalink
Fred/Generator Fix
Browse files Browse the repository at this point in the history
Give choice to add ThemeProvider and headers
  • Loading branch information
kwfk authored and adowski committed Dec 3, 2019
1 parent f3625d3 commit af511ba
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
6 changes: 6 additions & 0 deletions internals/generators/class/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ module.exports = {
default: true,
message: 'Do you want styles?',
},
{
type: 'confirm',
name: 'wantTheme',
default: false,
message: 'Do you want to wrap your component with ThemeProvider?',
},
{
type: 'confirm',
name: 'wantLoadable',
Expand Down
17 changes: 14 additions & 3 deletions internals/generators/class/index.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,34 @@
import React from 'react';
{{#if wantStyles}}
import PropTypes from 'prop-types';
import theme from 'utils/theme';
{{else}}
// import PropTypes from 'prop-types';
{{/if}}
{{#if wantHeaders}}
import { Helmet } from 'react-helmet';
{{/if}}
{{#if wantStyles}}
import { withStyles, ThemeProvider } from '@material-ui/core/styles';
import styles from './styles';
import { withStyles, {{#if wantTheme }}ThemeProvider{{/if}} } from '@material-ui/core/styles';
{{else}}
{{#if wantTheme}}
import { ThemeProvider } from '@material-ui/core/styles';
{{/if}}
{{/if}}
{{#if wantTheme}}
import theme from 'utils/theme';
{{/if}}

{{#if wantStyles}}
import styles from './styles';
{{/if}}

class {{ properCase name }} extends React.Component {
render() {
{{#if wantStyles}}const { classes } = this.props;{{/if}}
return (
{{#if wantTheme}}
<ThemeProvider theme={theme}>
{{/if}}
<div{{#if wantStyles}} className={ classes.root }{{/if}}>
{{#if wantHeaders}}
<Helmet>
Expand All @@ -34,7 +43,9 @@ return (
</Helmet>
{{/if}}
</div>
{{#if wantTheme}}
</ThemeProvider>
{{/if}}
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions internals/generators/functional/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ module.exports = {
return 'The name is required';
},
},
{
type: 'confirm',
name: 'wantHeaders',
default: false,
message: 'Do you want headers?',
},
{
type: 'confirm',
name: 'memo',
Expand All @@ -38,6 +44,12 @@ module.exports = {
default: true,
message: 'Do you want styles?',
},
{
type: 'confirm',
name: 'wantTheme',
default: false,
message: 'Do you want to wrap your component with ThemeProvider?',
},
{
type: 'confirm',
name: 'wantLoadable',
Expand Down
26 changes: 24 additions & 2 deletions internals/generators/functional/index.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ import PropTypes from 'prop-types';
{{else}}
// import PropTypes from 'prop-types';
{{/if}}
{{#if wantHeaders}}
import { Helmet } from 'react-helmet';
{{/if}}
{{#if wantStyles}}
import { withStyles } from '@material-ui/core/styles';
import { withStyles, {{#if wantTheme }}ThemeProvider{{/if}} } from '@material-ui/core/styles';
{{else}}
{{#if wantTheme}}
import { ThemeProvider } from '@material-ui/core/styles';
{{/if}}
{{/if}}
{{#if wantTheme}}
import theme from 'utils/theme';
{{/if}}

{{#if wantStyles}}
Expand All @@ -24,8 +34,20 @@ import styles from './styles';

function {{ properCase name }}({{#if wantStyles}}{ classes }{{/if}}) {
return (
<div{{#if wantStyles}} className={ classes.root }{{/if}}>
{{#if wantTheme}}
<ThemeProvider theme={theme}>
{{/if}}
<div{{#if wantStyles}} className={ classes.root }{{/if}}>
{{#if wantHeaders}}
<Helmet>
<title>{{properCase name}}</title>
<meta name="description" content="Description of {{properCase name}}" />
</Helmet>
{{/if}}
</div>
{{#if wantTheme}}
</ThemeProvider>
{{/if}}
);
}

Expand Down

0 comments on commit af511ba

Please sign in to comment.