Skip to content

Commit

Permalink
[examples] Take ownership on the next.js example (mui#7703)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Aug 8, 2017
1 parent dba3ef6 commit 3d7df36
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 35 deletions.
43 changes: 19 additions & 24 deletions .eslintrc.spellcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module.exports = {
root: true,
plugins: ['spellcheck'],
rules: {
'spellcheck/spell-checker': [1,
'spellcheck/spell-checker': [
1,
{
'comments': true,
'strings': true,
'identifiers': true,
'lang': 'en_US',
'skipWords': [
comments: true,
strings: true,
identifiers: true,
lang: 'en_US',
skipWords: [
'100vh',
'100vw',
'10px',
Expand Down Expand Up @@ -249,7 +250,7 @@ module.exports = {
'webfontloader',
'Webkit',
'webpack',
'webpack\'s',
"webpack's",
'Wifi',
'wifi',
'winston',
Expand Down Expand Up @@ -292,7 +293,6 @@ module.exports = {
'uglify',
'webdriver',


//file extensions
'css',
'html',
Expand All @@ -304,7 +304,6 @@ module.exports = {
'scss',
'tpl',


// programming gibberish
'addon',
'addons',
Expand Down Expand Up @@ -455,7 +454,6 @@ module.exports = {
'iso',
'utc',


// names provided by external source code dependencies or standard
// library
//
Expand All @@ -472,15 +470,14 @@ module.exports = {
'scrollwheel', // in Google Map options
'sref', // in [ui-sref]
'starttag', // a config name in gulp-plugin-inject
'stringify', // in JSON.stringify
'stringify', // in JSON.stringify
'stylers', // https://developers.google.com/maps/documentation/javascript/styling#overview
'substr', // in String#substr
'thru', // in _.thru
'thru', // in _.thru
'transclude', // in angular directive
'transclusion', // in angular directive
'unshift', // in Array#unshift


// Moment.js date format strings
'YYYY',
'YY',
Expand All @@ -502,7 +499,6 @@ module.exports = {
'ss',
'zz',


// Lorem ipsum 1st sentence
'Lorem',
'ipsum',
Expand All @@ -513,7 +509,6 @@ module.exports = {
'adipiscing',
'elit',


// Related to Google Maps
//
'coords', // South-east etc.
Expand Down Expand Up @@ -541,28 +536,28 @@ module.exports = {
'foo',
'bar',
'baz',
'quux'
'quux',
],
'skipIfMatch': [
skipIfMatch: [
'http(s)?://[^s]*',
// Auxiliary werbs
// see: https://github.com/aotaduy/eslint-plugin-spellcheck/issues/7
'(\\s|^)\\w+\'t(\\s | $)',
"(\\s|^)\\w+'t(\\s | $)",
// ordinals
// https://github.com/aotaduy/eslint-plugin-spellcheck/issues/8
'(\\s|^|\\w+)\\d+(st|nd|rd|th)(\\s|[A-Z][a-zA-Z]+|$)',
// pre/post prefixes both in kebab case and camel case
'(\\s|^)(pre|post)([-\\w]|[A-Z])[a-zA-Z]+(\\s|$)',
// mimetypes
'^[-\\w]+\/[-\\w\\.]+$',
'^[-\\w]+/[-\\w\\.]+$',
// xml tags
'<(?:\/)?[\\w-]+>',
'<(?:/)?[\\w-]+>',
// cryptographic octal hashes
'^[0-9a-f]{5,999}$',
// hex colors
'^#[0-9a-f]{3,6}$'
]
}
]
'^#[0-9a-f]{3,6}$',
],
},
],
},
};
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.*/node_modules/react-event-listener/src/.*
.*/node_modules/fbjs/lib/partitionObjectByKey.js
.*/node_modules/jss/lib/.*\.js\.flow
.*/node_modules/mitt/src/.*\.js
.*/node_modules/react-swipeable-views/src/.*
.*/node_modules/eslint-plugin-jsx-a11y/src/.*
.*/scripts/*
Expand Down
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/yarn.lock
20 changes: 19 additions & 1 deletion examples/create-react-app/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Create React App example

This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).
## How to use

Download the example [or clone the repo](https://github.com/callemall/material-ui):

```bash
curl https://codeload.github.com/callemall/material-ui/tar.gz/v1-beta | tar -xz --strip=2 next.js-master/examples/create-react-app
cd create-react-app
```

Install it and run:

```bash
npm install
npm run start
```

## The idea behind the example

[Create React App](https://github.com/facebookincubator/create-react-app) with no build configuration.
8 changes: 4 additions & 4 deletions examples/create-react-app/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "create-react-app",
"version": "0.1.0",
"version": "1.0.0",
"private": true,
"dependencies": {
"material-ui": "next",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-scripts": "1.0.10"
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest"
},
"scripts": {
"start": "react-scripts start",
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.next
21 changes: 20 additions & 1 deletion examples/nextjs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/callemall/material-ui/tree/v1-beta/examples/nextjs)
# Next.js example

The example is [hosted on their repository](https://github.com/zeit/next.js/tree/v3-beta/examples/with-material-ui-next).
## How to use

Download the example [or clone the repo](https://github.com/callemall/material-ui):

```bash
curl https://codeload.github.com/callemall/material-ui/tar.gz/v1-beta | tar -xz --strip=2 next.js-master/examples/nextjs
cd nextjs
```

Install it and run:

```bash
npm install
npm run dev
```

## The idea behind the example

[Next.js](https://github.com/zeit/next.js) is a framework for server-rendered React apps.
77 changes: 77 additions & 0 deletions examples/nextjs/components/withRoot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// @flow weak

import React, { Component } from 'react';
import { JssProvider } from 'react-jss';
import { withStyles, createStyleSheet, MuiThemeProvider } from 'material-ui/styles';
import { getContext, setContext } from '../styles/context';

// Apply some reset
const styleSheet = createStyleSheet(theme => ({
'@global': {
html: {
background: theme.palette.background.default,
WebkitFontSmoothing: 'antialiased', // Antialiasing.
MozOsxFontSmoothing: 'grayscale', // Antialiasing.
},
body: {
margin: 0,
},
},
}));

let AppWrapper = props => props.children;

AppWrapper = withStyles(styleSheet)(AppWrapper);

function withRoot(BaseComponent) {
class WithRoot extends Component {
static getInitialProps(ctx) {
// Reset the context for handling a new request.
setContext();

if (BaseComponent.getInitialProps) {
return BaseComponent.getInitialProps(ctx);
}

return {};
}

componentDidMount() {
// Remove the server-side injected CSS.
const jssStyles = document.querySelector('#jss-server-side');
if (jssStyles && jssStyles.parentNode) {
jssStyles.parentNode.removeChild(jssStyles);
}
}

render() {
const context = getContext();

if (process.browser) {
return (
<MuiThemeProvider theme={context.theme}>
<AppWrapper>
<BaseComponent {...this.props} />
</AppWrapper>
</MuiThemeProvider>
);
}

return (
<JssProvider registry={context.sheetsRegistry} jss={context.jss}>
<MuiThemeProvider theme={context.theme} sheetsManager={context.sheetsManager}>
<AppWrapper>
<BaseComponent {...this.props} />
</AppWrapper>
</MuiThemeProvider>
</JssProvider>
);
}
}

WithRoot.displayName = `withRoot(${BaseComponent.displayName})`;

return WithRoot;
}

export default withRoot;
16 changes: 16 additions & 0 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "next.js",
"version": "1.0.0",
"private": true,
"dependencies": {
"material-ui": "next",
"next": "latest",
"react": "latest",
"react-dom": "latest"
},
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
}
58 changes: 58 additions & 0 deletions examples/nextjs/pages/_document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable flowtype/require-valid-file-annotation */

import React from 'react';
import Document, { Head, Main, NextScript } from 'next/document';
import { getContext } from '../styles/context';

export default class MyDocument extends Document {
static getInitialProps(ctx) {
const page = ctx.renderPage();
// Get the context with the collected side effects.
const context = getContext();
return {
...page,
styles: (
<style
id="jss-server-side"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: context.sheetsRegistry.toString() }}
/>
),
};
}

render() {
const context = getContext();
return (
<html lang="en">
<Head>
<title>My page</title>
<meta charSet="utf-8" />
{/* Use minimum-scale=1 to enable GPU rasterization */}
<meta
name="viewport"
content={
'user-scalable=0, initial-scale=1, ' +
'minimum-scale=1, width=device-width, height=device-height'
}
/>
{/*
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
*/}
<link rel="manifest" href="/static/manifest.json" />
{/* PWA primary color */}
<meta name="theme-color" content={context.theme.palette.primary[500]} />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
);
}
}
Loading

0 comments on commit 3d7df36

Please sign in to comment.