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
693ba44a
Commit
693ba44a
authored
May 14, 2019
by
Vojtech Miksu
Committed by
Luis Fernando Alvarez D
May 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update with-styletron example, add debug mode and useStyletron (#7290)
parent
4309c87f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
47 deletions
+60
-47
package.json
examples/with-styletron/package.json
+4
-5
_app.js
examples/with-styletron/pages/_app.js
+6
-8
_document.js
examples/with-styletron/pages/_document.js
+15
-8
index.js
examples/with-styletron/pages/index.js
+23
-8
styletron.js
examples/with-styletron/styletron.js
+12
-18
No files found.
examples/with-styletron/package.json
View file @
693ba44a
...
@@ -8,10 +8,9 @@
...
@@ -8,10 +8,9 @@
},
},
"dependencies"
:
{
"dependencies"
:
{
"next"
:
"latest"
,
"next"
:
"latest"
,
"react"
:
"^16.7.0"
,
"react"
:
"^16.8.0"
,
"react-dom"
:
"^16.7.0"
,
"react-dom"
:
"^16.8.0"
,
"styletron"
:
"^3.0.4"
,
"styletron-engine-atomic"
:
"^1.1.2"
,
"styletron-engine-atomic"
:
"^1.0.8"
,
"styletron-react"
:
"^5.0.1"
"styletron-react"
:
"^4.3.5"
}
}
}
}
examples/with-styletron/pages/_app.js
View file @
693ba44a
import
App
,
{
Container
}
from
'next/app'
import
React
from
'react'
import
React
from
'react'
import
App
,
{
Container
}
from
'next/app'
import
{
Provider
as
StyletronProvider
}
from
'styletron-react'
import
{
Provider
as
StyletronProvider
}
from
'styletron-react'
import
getStyletron
from
'../styletron'
import
{
styletron
,
debug
}
from
'../styletron'
class
MyApp
extends
App
{
export
default
class
MyApp
extends
App
{
render
()
{
render
()
{
const
{
Component
}
=
this
.
props
const
{
Component
,
pageProps
}
=
this
.
props
return
(
return
(
<
Container
>
<
Container
>
<
StyletronProvider
value
=
{
getStyletron
()}
>
<
StyletronProvider
value
=
{
styletron
}
debug
=
{
debug
}
debugAfterHydration
>
<
Component
/>
<
Component
{...
pageProps
}
/
>
<
/StyletronProvider
>
<
/StyletronProvider
>
<
/Container
>
<
/Container
>
)
)
}
}
}
}
export
default
MyApp
examples/with-styletron/pages/_document.js
View file @
693ba44a
import
Document
,
{
Head
,
Main
,
NextScript
}
from
'next/document'
import
Document
,
{
Head
,
Main
,
NextScript
}
from
'next/document'
import
{
flush
}
from
'../styletron'
import
{
Provider
as
StyletronProvider
}
from
'styletron-react'
import
{
styletron
}
from
'../styletron'
export
default
class
MyDocument
extends
Document
{
class
MyDocument
extends
Document
{
static
getInitialProps
({
renderPage
})
{
static
getInitialProps
(
props
)
{
const
page
=
renderPage
()
const
page
=
props
.
renderPage
(
App
=>
props
=>
(
const
styletron
=
flush
()
<
StyletronProvider
value
=
{
styletron
}
>
const
stylesheets
=
styletron
?
styletron
.
getStylesheets
()
:
[]
<
App
{...
props
}
/
>
<
/StyletronProvider
>
))
const
stylesheets
=
styletron
.
getStylesheets
()
||
[]
return
{
...
page
,
stylesheets
}
return
{
...
page
,
stylesheets
}
}
}
...
@@ -16,8 +20,9 @@ export default class MyDocument extends Document {
...
@@ -16,8 +20,9 @@ export default class MyDocument extends Document {
{
this
.
props
.
stylesheets
.
map
((
sheet
,
i
)
=>
(
{
this
.
props
.
stylesheets
.
map
((
sheet
,
i
)
=>
(
<
style
<
style
className
=
'_styletron_hydrate_'
className
=
'_styletron_hydrate_'
dangerouslySetInnerHTML
=
{{
__html
:
sheet
}}
dangerouslySetInnerHTML
=
{{
__html
:
sheet
.
css
}}
media
=
{
sheet
.
attrs
?
sheet
.
attrs
.
media
:
null
}
media
=
{
sheet
.
attrs
.
media
}
data
-
hydrate
=
{
sheet
.
attrs
[
'data-hydrate'
]}
key
=
{
i
}
key
=
{
i
}
/
>
/
>
))}
))}
...
@@ -30,3 +35,5 @@ export default class MyDocument extends Document {
...
@@ -30,3 +35,5 @@ export default class MyDocument extends Document {
)
)
}
}
}
}
export
default
MyDocument
examples/with-styletron/pages/index.js
View file @
693ba44a
import
{
styled
}
from
'styletron-react'
// DOCUMENTATION: http://styletron.org
const
Title
=
styled
(
'div'
,
{
import
{
styled
,
useStyletron
}
from
'styletron-react'
// statically styled component
const
Title
=
styled
(
'h1'
,
{
color
:
'red'
,
color
:
'red'
,
fontSize
:
'
50
px'
fontSize
:
'
82
px'
})
})
export
default
()
=>
(
// dynamically styled component
const
SubTitle
=
styled
(
'h2'
,
({
$size
})
=>
({
color
:
'blue'
,
fontSize
:
`
${
$size
}
px`
}))
export
default
()
=>
{
// an alternative hook based API
const
[
css
]
=
useStyletron
()
return
(
<
div
>
<
div
>
<
Title
>
My
page
<
/Title
>
<
Title
>
Title
<
/Title
>
<
SubTitle
$size
=
{
50
}
>
Subtitle
<
/SubTitle
>
<
p
className
=
{
css
({
fontSize
:
'32px'
})}
>
Styled
by
hook
<
/p
>
<
/div
>
<
/div
>
)
)
}
examples/with-styletron/styletron.js
View file @
693ba44a
const
isServer
=
typeof
window
===
'undefined'
import
{
Client
,
Server
}
from
'styletron-engine-atomic'
import
{
DebugEngine
}
from
'styletron-react'
let
styletron
const
getHydrateClass
=
()
=>
document
.
getElementsByClassName
(
'_styletron_hydrate_'
)
export
default
function
getStyletron
()
{
export
const
styletron
=
if
(
isServer
&&
!
styletron
)
{
typeof
window
===
'undefined'
const
Styletron
=
require
(
'styletron-engine-atomic'
).
Server
?
new
Server
()
styletron
=
new
Styletron
()
:
new
Client
({
}
else
if
(
!
styletron
)
{
hydrate
:
getHydrateClass
()
const
Styletron
=
require
(
'styletron-engine-atomic'
).
Client
})
const
styleElements
=
document
.
getElementsByClassName
(
'_styletron_hydrate_'
)
styletron
=
new
Styletron
(
styleElements
)
}
return
styletron
}
export
function
flush
()
{
export
const
debug
=
const
_styletron
=
styletron
process
.
env
.
NODE_ENV
===
'production'
?
void
0
:
new
DebugEngine
()
styletron
=
null
return
_styletron
}
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