diff --git a/examples/with-cssed/.babelrc b/examples/with-cssed/.babelrc new file mode 100644 index 0000000000000..00628a7afac18 --- /dev/null +++ b/examples/with-cssed/.babelrc @@ -0,0 +1,8 @@ +{ + "presets": [ + "next/babel" + ], + "plugins": [ + "babel-plugin-macros" + ] +} diff --git a/examples/with-cssed/.gitignore b/examples/with-cssed/.gitignore new file mode 100644 index 0000000000000..f18e7c34e1d62 --- /dev/null +++ b/examples/with-cssed/.gitignore @@ -0,0 +1,37 @@ +# 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 diff --git a/examples/with-cssed/README.md b/examples/with-cssed/README.md new file mode 100644 index 0000000000000..787d92ed42991 --- /dev/null +++ b/examples/with-cssed/README.md @@ -0,0 +1,23 @@ +# 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)). diff --git a/examples/with-cssed/lib/theme.js b/examples/with-cssed/lib/theme.js new file mode 100644 index 0000000000000..368b046f1a382 --- /dev/null +++ b/examples/with-cssed/lib/theme.js @@ -0,0 +1,2 @@ +export const dark = '#333' +export const light = '#ddd' diff --git a/examples/with-cssed/package.json b/examples/with-cssed/package.json new file mode 100644 index 0000000000000..9a6236ea3c0ce --- /dev/null +++ b/examples/with-cssed/package.json @@ -0,0 +1,18 @@ +{ + "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" +} diff --git a/examples/with-cssed/pages/index.js b/examples/with-cssed/pages/index.js new file mode 100644 index 0000000000000..0dda7c0f2fb8d --- /dev/null +++ b/examples/with-cssed/pages/index.js @@ -0,0 +1,47 @@ +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 ( + <> + + With cssed + +
setDark(!isDark)} + className={styles.box + ' ' + (isDark ? styles.dark : styles.light)} + > + Cssed demo +
+ + ) +}