Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
1da00949
Commit
1da00949
authored
Jul 24, 2017
by
Arunoda Susiripala
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v3-beta' of github.com:zeit/next.js into v3-beta
parents
7965cb29
c84bf2ea
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
56 deletions
+71
-56
App.js
examples/with-material-ui-next/components/App.js
+12
-11
package.json
examples/with-material-ui-next/package.json
+2
-1
_document.js
examples/with-material-ui-next/pages/_document.js
+8
-6
context.js
examples/with-material-ui-next/styles/context.js
+49
-0
createDefaultContext.js
...ples/with-material-ui-next/styles/createDefaultContext.js
+0
-38
No files found.
examples/with-material-ui-next/components/App.js
View file @
1da00949
import
React
,
{
Component
}
from
'react'
import
React
,
{
Component
}
from
'react'
import
PropTypes
from
'prop-types'
import
PropTypes
from
'prop-types'
import
{
JssProvider
}
from
'react-jss'
import
{
withStyles
,
createStyleSheet
,
MuiThemeProvider
}
from
'material-ui/styles'
import
{
withStyles
,
createStyleSheet
,
MuiThemeProvider
}
from
'material-ui/styles'
import
{
get
DefaultContext
}
from
'../styles/createDefaultC
ontext'
import
{
get
Context
}
from
'../styles/c
ontext'
// Apply some reset
const
styleSheet
=
createStyleSheet
(
'App'
,
theme
=>
({
const
styleSheet
=
createStyleSheet
(
'App'
,
theme
=>
({
'@global'
:
{
'@global'
:
{
html
:
{
html
:
{
background
:
theme
.
palette
.
background
.
default
,
background
:
theme
.
palette
.
background
.
default
,
fontFamily
:
theme
.
typography
.
fontFamily
,
WebkitFontSmoothing
:
'antialiased'
,
// Antialiasing.
WebkitFontSmoothing
:
'antialiased'
,
// Antialiasing.
MozOsxFontSmoothing
:
'grayscale'
// Antialiasing.
MozOsxFontSmoothing
:
'grayscale'
// Antialiasing.
},
},
body
:
{
body
:
{
margin
:
0
margin
:
0
},
a
:
{
color
:
'inherit'
}
}
}
}
}))
}))
...
@@ -34,13 +32,16 @@ class App extends Component {
...
@@ -34,13 +32,16 @@ class App extends Component {
}
}
render
()
{
render
()
{
const
{
styleManager
,
theme
}
=
getDefaultContext
()
const
context
=
getContext
()
return
(
return
(
<
MuiThemeProvider
styleManager
=
{
styleManager
}
theme
=
{
theme
}
>
<
JssProvider
registry
=
{
context
.
sheetsRegistry
}
jss
=
{
context
.
jss
}
>
<
AppWrapper
>
<
MuiThemeProvider
theme
=
{
context
.
theme
}
sheetsManager
=
{
context
.
sheetsManager
}
>
{
this
.
props
.
children
}
<
AppWrapper
>
<
/AppWrapper
>
{
this
.
props
.
children
}
<
/MuiThemeProvider
>
<
/AppWrapper
>
<
/MuiThemeProvider
>
<
/JssProvider
>
)
)
}
}
}
}
...
...
examples/with-material-ui-next/package.json
View file @
1da00949
...
@@ -5,7 +5,8 @@
...
@@ -5,7 +5,8 @@
"material-ui"
:
"next"
,
"material-ui"
:
"next"
,
"next"
:
"latest"
,
"next"
:
"latest"
,
"react"
:
"^15.5.4"
,
"react"
:
"^15.5.4"
,
"react-dom"
:
"^15.5.4"
"react-dom"
:
"^15.5.4"
,
"react-jss"
:
"^7.0.2"
},
},
"scripts"
:
{
"scripts"
:
{
"dev"
:
"next"
,
"dev"
:
"next"
,
...
...
examples/with-material-ui-next/pages/_document.js
View file @
1da00949
import
React
from
'react'
import
React
from
'react'
import
Document
,
{
Head
,
Main
,
NextScript
}
from
'next/document'
import
Document
,
{
Head
,
Main
,
NextScript
}
from
'next/document'
import
{
get
DefaultContext
,
setDefaultContext
}
from
'../styles/createDefaultC
ontext'
import
{
get
Context
,
setContext
}
from
'../styles/c
ontext'
export
default
class
MyDocument
extends
Document
{
export
default
class
MyDocument
extends
Document
{
static
async
getInitialProps
(
ctx
)
{
static
async
getInitialProps
(
ctx
)
{
setDefaultContext
()
// Reset the context for handling a new request.
setContext
()
const
page
=
ctx
.
renderPage
()
const
page
=
ctx
.
renderPage
()
const
styleContext
=
getDefaultContext
()
// Get the context with the collected side effects.
const
context
=
getContext
()
return
{
return
{
...
page
,
...
page
,
styles
:
<
style
id
=
'jss-server-side'
dangerouslySetInnerHTML
=
{{
__html
:
styleContext
.
styleManager
.
sheetsT
oString
()
}}
/
>
styles
:
<
style
id
=
'jss-server-side'
dangerouslySetInnerHTML
=
{{
__html
:
context
.
sheetsRegistry
.
t
oString
()
}}
/
>
}
}
}
}
render
()
{
render
()
{
const
styleContext
=
getDefaul
tContext
()
const
context
=
ge
tContext
()
return
(
return
(
<
html
lang
=
'en'
>
<
html
lang
=
'en'
>
<
Head
>
<
Head
>
...
@@ -29,7 +31,7 @@ export default class MyDocument extends Document {
...
@@ -29,7 +31,7 @@ export default class MyDocument extends Document {
}
}
/
>
/
>
{
/* PWA primary color */
}
{
/* PWA primary color */
}
<
meta
name
=
'theme-color'
content
=
{
styleC
ontext
.
theme
.
palette
.
primary
[
500
]}
/
>
<
meta
name
=
'theme-color'
content
=
{
c
ontext
.
theme
.
palette
.
primary
[
500
]}
/
>
<
link
<
link
rel
=
'stylesheet'
rel
=
'stylesheet'
href
=
'https://fonts.googleapis.com/css?family=Roboto:300,400,500'
href
=
'https://fonts.googleapis.com/css?family=Roboto:300,400,500'
...
...
examples/with-material-ui-next/styles/context.js
0 → 100644
View file @
1da00949
import
{
create
}
from
'jss'
import
preset
from
'jss-preset-default'
import
{
SheetsRegistry
}
from
'react-jss'
import
createPalette
from
'material-ui/styles/palette'
import
createMuiTheme
from
'material-ui/styles/theme'
import
{
purple
,
green
}
from
'material-ui/colors'
import
createGenerateClassName
from
'material-ui/styles/createGenerateClassName'
const
theme
=
createMuiTheme
({
palette
:
createPalette
({
primary
:
purple
,
accent
:
green
})
})
// Configure JSS
const
jss
=
create
(
preset
())
jss
.
options
.
createGenerateClassName
=
createGenerateClassName
function
createContext
()
{
return
{
jss
,
theme
,
// This is needed in order to deduplicate the injection of CSS in the page.
sheetsManager
:
new
WeakMap
(),
// This is needed in order to inject the critical CSS.
sheetsRegistry
:
new
SheetsRegistry
()
}
}
export
function
setContext
()
{
// Singleton hack as there is no way to pass variables from _document.js to pages yet.
global
.
__INIT_MATERIAL_UI__
=
createContext
()
}
export
function
getContext
()
{
// Make sure to create a new store for every server-side request so that data
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
return
global
.
__INIT_MATERIAL_UI__
}
// Reuse context on the client-side
if
(
!
global
.
__INIT_MATERIAL_UI__
)
{
global
.
__INIT_MATERIAL_UI__
=
createContext
()
}
return
global
.
__INIT_MATERIAL_UI__
}
examples/with-material-ui-next/styles/createDefaultContext.js
deleted
100644 → 0
View file @
7965cb29
import
MuiThemeProvider
from
'material-ui/styles/MuiThemeProvider'
import
createPalette
from
'material-ui/styles/palette'
import
createMuiTheme
from
'material-ui/styles/theme'
import
{
purple
,
green
}
from
'material-ui/colors'
const
createDefaultContext
=
()
=>
MuiThemeProvider
.
createDefaultContext
({
theme
:
createMuiTheme
({
palette
:
createPalette
({
primary
:
purple
,
accent
:
green
})
})
})
// Singleton hack as there is no way to pass variables from _document.js to pages yet.
let
context
=
null
export
function
setDefaultContext
()
{
context
=
createDefaultContext
()
}
export
function
getDefaultContext
()
{
// Make sure to create a new store for every server-side request so that data
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
return
context
}
// Reuse store on the client-side
if
(
!
context
)
{
context
=
createDefaultContext
()
}
return
context
}
export
default
createDefaultContext
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment