Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXAMPLE] with-cssed #16735

Merged
merged 9 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/with-cssed/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"next/babel"
],
"plugins": [
"babel-plugin-macros"
]
}
37 changes: 37 additions & 0 deletions examples/with-cssed/.gitignore
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions examples/with-cssed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Example app with [cssed](https://github.com/okotoki/cssed)

This example features how to use [cssed](https://github.com/okotoki/cssed) as the styling solution instead of [styled-jsx](https://github.com/zeit/styled-jsx).

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)).
2 changes: 2 additions & 0 deletions examples/with-cssed/lib/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const dark = '#333'
export const light = '#ddd'
19 changes: 19 additions & 0 deletions examples/with-cssed/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"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",
"devDependencies": {}
lfades marked this conversation as resolved.
Show resolved Hide resolved
}
47 changes: 47 additions & 0 deletions examples/with-cssed/pages/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Head>
<title>With cssed</title>
</Head>
<div
onClick={() => setDark(!isDark)}
className={styles.box + ' ' + (isDark ? styles.dark : styles.light)}
>
Cssed demo
</div>
</>
)
}