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

chore: adds compiled css example #22786

Merged
merged 4 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions examples/with-compiled-css/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["next/babel"],
"plugins": ["@babel/plugin-syntax-jsx"]
}
itsdouges marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 34 additions & 0 deletions examples/with-compiled-css/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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
21 changes: 21 additions & 0 deletions examples/with-compiled-css/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Example app with [Compiled](https://github.com/atlassian-labs/compiled) (CSS-in-JS)

This example features how to use [Compiled](https://github.com/atlassian-labs/compiled) as the build time CSS-in-JS styling solution instead of [styled-jsx](https://github.com/zeit/styled-jsx).

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-compiled-css&project-name=with-compiled-css&repository-name=with-compiled-css)

## 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-compiled-css with-compiled-css-app
# or
yarn create next-app --example with-compiled-css with-compiled-css-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
19 changes: 19 additions & 0 deletions examples/with-compiled-css/components/class-names-box.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ClassNames } from '@compiled/react'
import { error } from '../style/colors'

export const BoxStyles = ({ children }) => (
<ClassNames>
{({ css }) =>
children({
className: css`
display: flex;
width: 100px;
height: 100px;
border: 1px solid ${error};
padding: 8px;
flex-direction: column;
`,
})
}
</ClassNames>
)
11 changes: 11 additions & 0 deletions examples/with-compiled-css/components/styled-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { styled } from '@compiled/react'

export const Button = styled.button`
color: ${(props) => props.color};
background-color: transparent;
padding: 6px 8px;
border-radius: 3px;
width: 100%;
font-family: sans-serif;
border: 1px solid ${(props) => props.color};
`
10 changes: 10 additions & 0 deletions examples/with-compiled-css/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
webpack: (config) => {
config.module.rules.push({
test: /\.js$/,
use: ['@compiled/webpack-loader'],
})

return config
},
}
17 changes: 17 additions & 0 deletions examples/with-compiled-css/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "with-compiled-css",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@compiled/react": "^0.6.7",
"@compiled/webpack-loader": "^0.6.7",
"next": "latest",
"react": "^17.0.1",
"react-dom": "^17.0.1"
}
}
32 changes: 32 additions & 0 deletions examples/with-compiled-css/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import '@compiled/react'
import { BoxStyles } from '../components/class-names-box'
import { Button } from '../components/styled-button'
import { secondary, primary } from '../style/colors'

const IndexPage = () => (
<BoxStyles>
{(props) => (
<div {...props}>
<Button color={secondary}>Styled button</Button>

<div
css={{
marginTop: 8,
flexGrow: 1,
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontFamily: 'sans-serif',
color: primary,
border: `1px solid ${primary}`,
}}
>
CSS prop
</div>
</div>
)}
</BoxStyles>
)

export default IndexPage
3 changes: 3 additions & 0 deletions examples/with-compiled-css/style/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const primary = 'blue'
export const secondary = 'purple'
export const error = 'red'