Skip to content

Commit ce0a2f7

Browse files
palafoxernestotimneutkens
authored andcommitted
Add Material-UI example (vercel#1771)
* Add Material-UI example * Fix linting on material-ui example
1 parent d08e027 commit ce0a2f7

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

examples/with-material-ui/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Material-UI example
2+
3+
## How to use
4+
5+
Download the example [or clone the repo](https://github.com/zeit/next.js):
6+
7+
```bash
8+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-material-ui
9+
cd with-material-ui
10+
```
11+
12+
Install it and run:
13+
14+
```bash
15+
npm install
16+
npm run dev
17+
```
18+
19+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
20+
21+
```bash
22+
now
23+
24+
## The idea behind the example
25+
26+
This example features how you use [material-ui](https://github.com/callemall/material-ui) (Material components that implement Google's Material Design) with Next.js.
27+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"dependencies": {
3+
"material-ui": "^0.17.4",
4+
"next": "latest",
5+
"react": "^15.5.4",
6+
"react-dom": "^15.5.4",
7+
"react-tap-event-plugin": "^2.0.1"
8+
},
9+
"scripts": {
10+
"dev": "next",
11+
"build": "next build",
12+
"start": "next start"
13+
}
14+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import React, {Component} from 'react'
2+
import RaisedButton from 'material-ui/RaisedButton'
3+
import Dialog from 'material-ui/Dialog'
4+
import {deepOrange500} from 'material-ui/styles/colors'
5+
import FlatButton from 'material-ui/FlatButton'
6+
import getMuiTheme from 'material-ui/styles/getMuiTheme'
7+
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
8+
import injectTapEventPlugin from 'react-tap-event-plugin'
9+
10+
// Needed for onTouchTap
11+
// http://stackoverflow.com/a/34015469/988941
12+
try {
13+
if (typeof window !== 'undefined') {
14+
injectTapEventPlugin()
15+
}
16+
} catch (e) {
17+
// do nothing
18+
}
19+
20+
const styles = {
21+
container: {
22+
textAlign: 'center',
23+
paddingTop: 200
24+
}
25+
}
26+
27+
const _muiTheme = getMuiTheme({
28+
palette: {
29+
accent1Color: deepOrange500
30+
}
31+
})
32+
33+
class Main extends Component {
34+
static getInitialProps ({ req }) {
35+
const userAgent = req ? req.headers['user-agent'] : navigator.userAgent
36+
const isServer = !!req
37+
return {isServer, userAgent}
38+
}
39+
40+
constructor (props, context) {
41+
super(props, context)
42+
43+
this.state = {
44+
open: false
45+
}
46+
}
47+
48+
handleRequestClose = () => {
49+
this.setState({
50+
open: false
51+
})
52+
}
53+
54+
handleTouchTap = () => {
55+
this.setState({
56+
open: true
57+
})
58+
}
59+
60+
render () {
61+
const standardActions = (
62+
<FlatButton
63+
label='Ok'
64+
primary={Boolean(true)}
65+
onTouchTap={this.handleRequestClose}
66+
/>
67+
)
68+
69+
const { userAgent } = this.props
70+
/* https://github.com/callemall/material-ui/issues/3336 */
71+
const muiTheme = getMuiTheme(getMuiTheme({userAgent: userAgent}), _muiTheme)
72+
73+
return (
74+
<MuiThemeProvider muiTheme={muiTheme}>
75+
<div style={styles.container}>
76+
<Dialog
77+
open={this.state.open}
78+
title='Super Secret Password'
79+
actions={standardActions}
80+
onRequestClose={this.handleRequestClose}
81+
>
82+
1-2-3-4-5
83+
</Dialog>
84+
<h1>Material-UI</h1>
85+
<h2>example project</h2>
86+
<RaisedButton
87+
label='Super Secret Password'
88+
secondary={Boolean(true)}
89+
onTouchTap={this.handleTouchTap}
90+
/>
91+
</div>
92+
</MuiThemeProvider>
93+
)
94+
}
95+
}
96+
97+
export default Main

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy