Skip to content

Commit e164074

Browse files
impronunciablerauchg
authored andcommitted
Added glamor css (vercel#38)
* Added glamor css * Using pseudoclasses instead of calling functions * Updated readme using style instead of default import for css
1 parent ba14964 commit e164074

File tree

16 files changed

+87
-109
lines changed

16 files changed

+87
-109
lines changed

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ We use [glamor](https://github.com/threepointone/glamor) to provide a great buil
4444

4545
```jsx
4646
import React from 'react'
47-
import css from 'next/css'
47+
import { style } from 'next/css'
4848

4949
export default () => (
5050
<div className={style}>
5151
Hello world
5252
</div>
5353
)
5454

55-
const style = css({
55+
const style = style({
5656
main: {
5757
background: 'red',
5858
':hover': {

bench/fixtures/basic/pages/css.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { Component } from 'react'
2-
import { StyleSheet, css } from 'next/css'
2+
import { style } from 'next/css'
33

44
export default class CrazyCSS extends Component {
55
spans () {
66
const out = []
77
for (let i = 0; i < 1000; i++) {
8-
out.push(<span key={i} class={css(styles[`padding-${i}`])}>This is ${i}</span>)
8+
out.push(<span key={i} class={spanStyles[`padding-${i}`]}>This is ${i}</span>)
99
}
1010
return out
1111
}
@@ -17,7 +17,5 @@ export default class CrazyCSS extends Component {
1717

1818
const spanStyles = {}
1919
for (let i = 0; i < 1000; i++) {
20-
spanStyles[`padding-${i}`] = { padding: i }
20+
spanStyles[`padding-${i}`] = style({ padding: i })
2121
}
22-
23-
const styles = StyleSheet.create(spanStyles)

client/next.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { createElement } from 'react'
22
import { render } from 'react-dom'
33
import HeadManager from './head-manager'
4-
import { StyleSheet } from '../lib/css'
4+
import { rehydrate } from '../lib/css'
55
import Router from '../lib/router'
66
import DefaultApp from '../lib/app'
77
import evalScript from '../lib/eval-script'
88

99
const {
10-
__NEXT_DATA__: { app, component, props, classNames, err }
10+
__NEXT_DATA__: { app, component, props, ids, err }
1111
} = window
1212

1313
const App = app ? evalScript(app).default : DefaultApp
@@ -19,5 +19,5 @@ const headManager = new HeadManager()
1919
const container = document.getElementById('__next')
2020
const appProps = { Component, props, router, headManager }
2121

22-
StyleSheet.rehydrate(classNames)
22+
rehydrate(ids)
2323
render(createElement(App, appProps), container)

examples/basic-css/pages/index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import React from 'react'
2-
import { css, StyleSheet } from 'next/css'
2+
import { style } from 'next/css'
33

44
export default () => (
5-
<div className={css(styles.main)}>
5+
<div className={styles}>
66
<p>Hello World</p>
77
</div>
88
)
99

10-
const styles = StyleSheet.create({
11-
main: {
12-
font: '15px Helvetica, Arial, sans-serif',
13-
background: '#eee',
14-
padding: '100px',
15-
textAlign: 'center',
16-
transition: '100ms ease-in background',
17-
':hover': {
18-
background: '#ccc'
19-
}
10+
const styles = style({
11+
font: '15px Helvetica, Arial, sans-serif',
12+
background: '#eee',
13+
padding: '100px',
14+
textAlign: 'center',
15+
transition: '100ms ease-in background',
16+
':hover': {
17+
background: '#ccc'
2018
}
2119
})
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React from 'react'
2-
import { css, StyleSheet } from 'next/css'
2+
import { style } from 'next/css'
33

44
export default ({ children }) => (
5-
<p className={css(styles.main)}>{children}</p>
5+
<p className={styles}>{children}</p>
66
)
77

8-
const styles = StyleSheet.create({
9-
main: {
10-
font: '13px Helvetica, Arial',
11-
margin: '10px 0'
12-
}
8+
const styles = style({
9+
font: '13px Helvetica, Arial',
10+
margin: '10px 0'
1311
})
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import React from 'react'
2-
import { css, StyleSheet } from 'next/css'
2+
import { style } from 'next/css'
33

44
export default ({ title, children }) => (
5-
<div className={css(styles.main)}>
6-
<h1 className={css(styles.title)}>{ title }</h1>
5+
<div className={mainStyle}>
6+
<h1 className={titleStyle}>{ title }</h1>
77
{ children }
88
</div>
99
)
1010

11-
const styles = StyleSheet.create({
12-
main: {
13-
font: '15px Helvetica, Arial',
14-
border: '1px solid #eee',
15-
padding: '0 10px'
16-
},
11+
const mainStyle = style({
12+
font: '15px Helvetica, Arial',
13+
border: '1px solid #eee',
14+
padding: '0 10px'
15+
})
1716

18-
title: {
19-
fontSize: '16px',
20-
fontWeight: 'bold',
21-
margin: '10px 0'
22-
}
17+
const titleStyle = style({
18+
fontSize: '16px',
19+
fontWeight: 'bold',
20+
margin: '10px 0'
2321
})

examples/nested-components/pages/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react'
22
import P from '../components/paragraph'
33
import Post from '../components/post'
4-
import { css, StyleSheet } from 'next/css'
4+
import { style } from 'next/css'
55

66
export default () => (
7-
<div className={css(styles.main)}>
7+
<div className={styles.main}>
88
<Post title='My first blog post'>
99
<P>Hello there</P>
1010
<P>This is an example of a componentized blog post</P>
@@ -26,23 +26,23 @@ export default () => (
2626
</div>
2727
)
2828

29-
const Hr = () => <hr className={css(styles.hr)} />
29+
const Hr = () => <hr className={styles.hr} />
3030

31-
const styles = StyleSheet.create({
32-
main: {
31+
const styles = {
32+
main: style({
3333
margin: 'auto',
3434
maxWidth: '420px',
3535
padding: '10px'
36-
},
36+
}),
3737

38-
hr: {
38+
hr: style({
3939
width: '100px',
4040
borderWidth: 0,
4141
margin: '20px auto',
4242
textAlign: 'center',
43-
':before': {
43+
'::before': {
4444
content: '"***"',
4545
color: '#ccc'
4646
}
47-
}
48-
})
47+
})
48+
}

lib/css.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('aphrodite')
1+
module.exports = require('glamor')

lib/document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default ({ head, css, html, data, dev, staticMarkup }) => {
55
return <html>
66
<head>
77
{(head || []).map((h, i) => React.cloneElement(h, { key: i }))}
8-
<style data-aphrodite='' dangerouslySetInnerHTML={{ __html: css.content }} />
8+
<style dangerouslySetInnerHTML={{ __html: css }} />
99
</head>
1010
<body>
1111
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />

lib/eval-script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import ReactDOM from 'react-dom'
33
import App from '../lib/app'
44
import Link from '../lib/link'
5-
import Css from '../lib/css'
5+
import * as Css from '../lib/css'
66
import Head from '../lib/head'
77

88
const modules = new Map([

0 commit comments

Comments
 (0)