From 856978918eb51cff43edcba264eb4403cf4b029b Mon Sep 17 00:00:00 2001 From: Arana Jhonny Date: Mon, 2 Jan 2017 02:35:14 -0400 Subject: [PATCH] Add cxs example. (#613) * add cxs example * fix example location --- README.md | 2 +- examples/with-cxs/README.md | 30 ++++++++++++++++++++++++++++ examples/with-cxs/package.json | 15 ++++++++++++++ examples/with-cxs/pages/_document.js | 25 +++++++++++++++++++++++ examples/with-cxs/pages/index.js | 28 ++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 examples/with-cxs/README.md create mode 100644 examples/with-cxs/package.json create mode 100644 examples/with-cxs/pages/_document.js create mode 100644 examples/with-cxs/pages/index.js diff --git a/README.md b/README.md index efc5ae24..c2711e13 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ export default () => (

Examples - +

It's possible to use any existing CSS-in-JS solution. The simplest one is inline styles: diff --git a/examples/with-cxs/README.md b/examples/with-cxs/README.md new file mode 100644 index 00000000..49dcee6d --- /dev/null +++ b/examples/with-cxs/README.md @@ -0,0 +1,30 @@ + +# Example app with cxs + +## 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-cxs +cd with-cxs +``` + +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 [cxs](https://github.com/jxnblk/cxs/). + +For this purpose we are extending the `` and injecting the server side rendered styles into the ``. diff --git a/examples/with-cxs/package.json b/examples/with-cxs/package.json new file mode 100644 index 00000000..4e86cacb --- /dev/null +++ b/examples/with-cxs/package.json @@ -0,0 +1,15 @@ +{ + "name": "with-cxs", + "version": "1.0.0", + "scripts": { + "dev": "next", + "build": "next build", + "start": "next start" + }, + "dependencies": { + "cxs": "^3.0.0", + "next": "^2.0.0-beta" + }, + "author": "", + "license": "ISC" +} diff --git a/examples/with-cxs/pages/_document.js b/examples/with-cxs/pages/_document.js new file mode 100644 index 00000000..3a04d58c --- /dev/null +++ b/examples/with-cxs/pages/_document.js @@ -0,0 +1,25 @@ +import Document, { Head, Main, NextScript } from 'next/document' +import cxs from 'cxs' + +export default class MyDocument extends Document { + static async getInitialProps ({ renderPage }) { + const page = renderPage() + let style = cxs.getCss() + return { ...page, style } + } + + render () { + return ( + + + My page +