-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add aphrodite example * fix props * Update README.md
- Loading branch information
1 parent
0a3313d
commit 1d700d0
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
# Example app with aphrodite | ||
|
||
## 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-aphrodite | ||
cd with-aphrodite | ||
``` | ||
|
||
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 [Aphrodite](https://github.com/Khan/aphrodite/). | ||
|
||
For this purpose we are extending the `<Document />` and injecting the server side rendered styles into the `<head>`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "with-aphrodite", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"aphrodite": "^1.1.0", | ||
"next": "^2.0.0-beta" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Document, { Head, Main, NextScript } from 'next/document' | ||
import { StyleSheetServer } from 'aphrodite' | ||
|
||
export default class MyDocument extends Document { | ||
static async getInitialProps ({ renderPage }) { | ||
const { html, css } = StyleSheetServer.renderStatic(() => renderPage()) | ||
return { ...html, css } | ||
} | ||
|
||
render () { | ||
return ( | ||
<html> | ||
<Head> | ||
<title>My page</title> | ||
<style dangerouslySetInnerHTML={{ __html: this.props.css.content }} /> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</html> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import { StyleSheet, css } from 'aphrodite' | ||
|
||
export default () => ( | ||
<div className={css(styles.root)}> | ||
<h1 className={css(styles.title)}>My page</h1> | ||
</div> | ||
) | ||
|
||
const styles = StyleSheet.create({ | ||
root: { | ||
width: 80, | ||
height: 60, | ||
background: 'white', | ||
':hover': { | ||
background: 'black' | ||
} | ||
}, | ||
|
||
title: { | ||
marginLeft: 5, | ||
color: 'black', | ||
fontSize: 22, | ||
':hover': { | ||
color: 'white' | ||
} | ||
} | ||
}) |