未验证 提交 134bcf8d 编写于 作者: E Eugene C 提交者: GitHub

[EXAMPLE] with-cssed (#16735)

Adding an example with [cssed](https://github.com/okotoki/cssed). A custom styling solution, which extracts CSS from template literals into separate files. 
上级 2acb53bd
{
"presets": [
"next/babel"
],
"plugins": [
"babel-plugin-macros"
]
}
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel
# cssed compilation artifacts
.*.module.css
# Example app with cssed
This example shows how to use [cssed](https://github.com/okotoki/cssed), a CSS-in-JS library, with Next.js.
We are creating `div` element with local scoped styles. The styles includes the use of pseudo-selector.
## Deploy your own
Deploy the example using [Vercel](https://vercel.com):
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/with-cssed)
## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
```bash
npx create-next-app --example with-cssed with-cssed-app
# or
yarn create next-app --example with-cssed with-cssed-app
```
Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
export const dark = '#333'
export const light = '#ddd'
{
"name": "with-cssed",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@types/react": "^16.9.48",
"babel-plugin-macros": "^2.8.0",
"cssed": "^1.1.2",
"next": "latest",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"license": "MIT"
}
import { css } from 'cssed/macro'
import Head from 'next/head'
import { useState } from 'react'
import { dark, light } from '../lib/theme'
const styles = css`
.box {
height: 200px;
width: 200px;
margin: 0 auto;
margin-top: 40px;
display: flex;
align-items: center;
justify-content: center;
}
.dark {
background-color: ${dark};
}
.dark::before {
content: '🌚';
}
.light {
background-color: ${light};
}
.light::before {
content: '🌞';
}
`
export default function Home() {
const [isDark, setDark] = useState(false)
return (
<>
<Head>
<title>With cssed</title>
</Head>
<div
onClick={() => setDark(!isDark)}
className={styles.box + ' ' + (isDark ? styles.dark : styles.light)}
>
Cssed demo
</div>
</>
)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册