Commit fbedce4d authored by Danil Shashkov's avatar Danil Shashkov Committed by Tim Neutkens

Add with-linaria example (#6510)

Next.js with Zero-runtime CSS-in-JS
parent 5e4886cd
{
"presets": [
"next/babel",
"linaria/babel"
]
}
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
/node_modules
# testing
/coverage
# production
/build
/dist
/.next
# other
/.linaria-cache
# misc
.DS_Store
.env
npm-debug.log*
yarn-debug.log*
yarn-error.log*
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-emotion)
# Example app with [linaria](https://linaria.now.sh/)
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
```bash
npx create-next-app --example with-linaria with-linaria-app
# or
yarn create next-app --example with-linaria with-linaria-app
```
### Download manually
Download the example:
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-linaria
cd with-linaria
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn 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 to use [linaria](https://linaria.now.sh/) as the styling solution instead of [styled-jsx](https://github.com/zeit/styled-jsx).
We are creating three `div` elements with custom styles being shared across the elements. The styles includes the use of pseudo-selector and CSS animations.
const withCSS = require('@zeit/next-css')
module.exports = withCSS({
webpack (config, options) {
config.module.rules.push({
test: /\.js$/,
use: [
{
loader: 'linaria/loader',
options: {
sourceMap: process.env.NODE_ENV !== 'production'
}
}
]
})
return config
}
})
{
"name": "with-linaria",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@zeit/next-css": "1.0.1",
"linaria": "1.2.4",
"next": "8.0.3",
"react": "16.8.3",
"react-dom": "16.8.3"
},
"license": "ISC"
}
import React from 'react'
import Head from 'next/head'
import { styled } from 'linaria/react'
const Box = styled.div`
margin-top: 40px;
margin-left: 40px;
height: 200px;
width: 200px;
background-color: tomato;
animation: spin 2s linear infinite;
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
`
export default () => {
return (
<React.Fragment>
<Head>
<title>With Linaria</title>
</Head>
<Box>
Zero runtime CSS in JS
</Box>
</React.Fragment>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment