mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Added glamor example and pointing warning to css migration guide (#500)
This commit is contained in:
parent
74d4d22f84
commit
01e1883f79
|
@ -98,6 +98,7 @@ export default () => (
|
|||
<ul>
|
||||
<li><a href="./examples/with-styled-components">Styled components</a></li>
|
||||
<li><a href="./examples/with-styletron">Styletron</a></li>
|
||||
<li><a href="./examples/with-glamor">Glamor</a></li>
|
||||
</ul>
|
||||
</details></p>
|
||||
|
||||
|
|
30
examples/with-glamor/README.md
Normal file
30
examples/with-glamor/README.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
# Example app with glamor
|
||||
|
||||
## How to use
|
||||
|
||||
Download the example (or clone the repo)[https://github.com/zeit/next.js.git]:
|
||||
|
||||
```bash
|
||||
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-glamor
|
||||
cd with-glamor
|
||||
```
|
||||
|
||||
Install it and run:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
|
||||
|
||||
```bash
|
||||
now
|
||||
```
|
||||
|
||||
## The idea behind the example
|
||||
|
||||
This example features how yo use a different styling solution than [styled-jsx](https://github.com/zeit/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [glamor](https://github.com/threepointone/glamor).
|
||||
|
||||
For this purpose we are extending the `<Document />` and injecting the server side rendered styles into the `<head>`.
|
15
examples/with-glamor/package.json
Normal file
15
examples/with-glamor/package.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "with-glamor",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"dev": "next",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"glamor": "^2.20.12",
|
||||
"next": "^2.0.0-beta"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
25
examples/with-glamor/pages/_document.js
Normal file
25
examples/with-glamor/pages/_document.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
import Document, { Head, Main, NextScript } from 'next/document'
|
||||
import { renderStatic } from 'glamor/server'
|
||||
|
||||
export default class MyDocument extends Document {
|
||||
static async getInitialProps ({ renderPage }) {
|
||||
const page = renderPage()
|
||||
let styles = renderStatic(() => page.html)
|
||||
return { ...page, ...styles }
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<html>
|
||||
<Head>
|
||||
<title>My page</title>
|
||||
<style dangerouslySetInnerHTML={{ __html: this.props.css }} />
|
||||
</Head>
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
}
|
11
examples/with-glamor/pages/index.js
Normal file
11
examples/with-glamor/pages/index.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import React from 'react'
|
||||
import { style } from 'glamor'
|
||||
|
||||
export default () => <h1 {...styles.title}>My page</h1>
|
||||
|
||||
const styles = {
|
||||
title: style({
|
||||
color: 'red',
|
||||
fontSize: 50
|
||||
})
|
||||
}
|
|
@ -3,7 +3,7 @@ const css = require('glamor')
|
|||
|
||||
for (const [k, v] of Object.entries(css)) {
|
||||
if (typeof v === 'function') {
|
||||
css[k] = deprecated(v, 'Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.')
|
||||
css[k] = deprecated(v, 'Warning: \'next/css\' is deprecated. Please refer to the migration guide: https://github.com/zeit/next.js/wiki/Migrating-from-next-css')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue