-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add devkit base with gh-pages deploy on merge #59
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
coverage/ | ||
node_modules/ | ||
devkit/.next | ||
devkit/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,7 @@ buck-out/ | |
./index.js | ||
# env | ||
.env.* | ||
|
||
# nextjs | ||
devkit/.next | ||
devkit/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
rules: { | ||
'require-jsdoc': 'off', | ||
'valid-jsdoc': 'off' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import App, { Container } from 'next/app'; | ||
import Head from 'next/head'; | ||
import { MuiThemeProvider } from '@material-ui/core/styles'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import JssProvider from 'react-jss/lib/JssProvider'; | ||
import getPageContext from '../src/getPageContext'; | ||
|
||
class Devkit extends App { | ||
constructor(props) { | ||
super(props); | ||
this.pageContext = getPageContext(); | ||
} | ||
|
||
componentDidMount() { | ||
// Remove the server-side injected CSS. | ||
const jssStyles = document.querySelector('#jss-server-side'); | ||
if (jssStyles && jssStyles.parentNode) { | ||
jssStyles.parentNode.removeChild(jssStyles); | ||
} | ||
} | ||
|
||
render() { | ||
const { Component, pageProps } = this.props; | ||
return ( | ||
<Container> | ||
<Head> | ||
<title>My page</title> | ||
</Head> | ||
{/* Wrap every page in Jss and Theme providers */} | ||
<JssProvider | ||
registry={this.pageContext.sheetsRegistry} | ||
generateClassName={this.pageContext.generateClassName} | ||
> | ||
{/* MuiThemeProvider makes the theme available down the React | ||
tree thanks to React context. */} | ||
<MuiThemeProvider | ||
theme={this.pageContext.theme} | ||
sheetsManager={this.pageContext.sheetsManager} | ||
> | ||
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */} | ||
<CssBaseline /> | ||
{/* Pass pageContext to the _document though the renderPage enhancer | ||
to render collected styles on server side. */} | ||
<Component pageContext={this.pageContext} {...pageProps} /> | ||
</MuiThemeProvider> | ||
</JssProvider> | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
export default Devkit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Document, { Head, Main, NextScript } from 'next/document'; | ||
import flush from 'styled-jsx/server'; | ||
|
||
class MyDocument extends Document { | ||
render() { | ||
const { pageContext } = this.props; | ||
|
||
return ( | ||
<html lang="en" dir="ltr"> | ||
<Head> | ||
<meta charSet="utf-8" /> | ||
{/* Use minimum-scale=1 to enable GPU rasterization */} | ||
<meta | ||
name="viewport" | ||
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no" | ||
/> | ||
{/* PWA primary color */} | ||
<meta | ||
name="theme-color" | ||
content={pageContext.theme.palette.primary.main} | ||
/> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</html> | ||
); | ||
} | ||
} | ||
|
||
MyDocument.getInitialProps = ctx => { | ||
// Resolution order | ||
// | ||
// On the server: | ||
// 1. app.getInitialProps | ||
// 2. page.getInitialProps | ||
// 3. document.getInitialProps | ||
// 4. app.render | ||
// 5. page.render | ||
// 6. document.render | ||
// | ||
// On the server with error: | ||
// 1. document.getInitialProps | ||
// 2. app.render | ||
// 3. page.render | ||
// 4. document.render | ||
// | ||
// On the client | ||
// 1. app.getInitialProps | ||
// 2. page.getInitialProps | ||
// 3. app.render | ||
// 4. page.render | ||
|
||
// Render app and page and get the context of the page with collected side effects. | ||
let pageContext; | ||
const page = ctx.renderPage(Component => { | ||
const WrappedComponent = props => { | ||
pageContext = props.pageContext; | ||
return <Component {...props} />; | ||
}; | ||
|
||
WrappedComponent.propTypes = { | ||
pageContext: PropTypes.object.isRequired | ||
}; | ||
|
||
return WrappedComponent; | ||
}); | ||
|
||
return { | ||
...page, | ||
pageContext, | ||
// Styles fragment is rendered after the app and page rendering finish. | ||
styles: ( | ||
<> | ||
<style | ||
id="jss-server-side" | ||
// eslint-disable-next-line react/no-danger | ||
dangerouslySetInnerHTML={{ | ||
__html: pageContext.sheetsRegistry.toString() | ||
}} | ||
/> | ||
{flush() || null} | ||
</> | ||
) | ||
}; | ||
}; | ||
|
||
export default MyDocument; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
|
||
const styles = theme => ({ | ||
root: { | ||
textAlign: 'center', | ||
paddingTop: theme.spacing.unit * 20 | ||
} | ||
}); | ||
|
||
const Index = ({ classes }) => ( | ||
<div className={classes.root}> | ||
<Typography variant="h4" gutterBottom> | ||
What is this developer kit | ||
</Typography> | ||
<Typography variant="subtitle1" gutterBottom> | ||
and why is it free? | ||
</Typography> | ||
</div> | ||
); | ||
|
||
Index.propTypes = { | ||
classes: PropTypes.object.isRequired | ||
}; | ||
|
||
export default withStyles(styles)(Index); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { SheetsRegistry } from 'jss'; | ||
import { | ||
createMuiTheme, | ||
createGenerateClassName | ||
} from '@material-ui/core/styles'; | ||
import purple from '@material-ui/core/colors/purple'; | ||
import green from '@material-ui/core/colors/green'; | ||
|
||
// A theme with custom primary and secondary color. | ||
// It's optional. | ||
const theme = createMuiTheme({ | ||
palette: { | ||
primary: { | ||
light: purple[300], | ||
main: purple[500], | ||
dark: purple[700] | ||
}, | ||
secondary: { | ||
light: green[300], | ||
main: green[500], | ||
dark: green[700] | ||
} | ||
}, | ||
typography: { | ||
useNextVariants: true | ||
} | ||
}); | ||
|
||
function createPageContext() { | ||
return { | ||
theme, | ||
// This is needed in order to deduplicate the injection of CSS in the page. | ||
sheetsManager: new Map(), | ||
// This is needed in order to inject the critical CSS. | ||
sheetsRegistry: new SheetsRegistry(), | ||
// The standard class name generator. | ||
generateClassName: createGenerateClassName() | ||
}; | ||
} | ||
|
||
export default function getPageContext() { | ||
// Make sure to create a new context for every server-side request so that data | ||
// isn't shared between connections (which would be bad). | ||
if (!process.browser) { | ||
return createPageContext(); | ||
} | ||
|
||
// Reuse context on the client-side. | ||
if (!global.__INIT_MATERIAL_UI__) { | ||
global.__INIT_MATERIAL_UI__ = createPageContext(); | ||
} | ||
|
||
return global.__INIT_MATERIAL_UI__; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only file that had real my code in it, but it's still basically nothing.