Skip to content

Commit 3973317

Browse files
greggbKye Hohenberger
authored and
Kye Hohenberger
committed
readme and doc consolidation updates (#408)
* quickstart for vanilla and react * Consolidate docs * fix typo * Add code markers * Clean up Babel doc * Remove semicolons * Don't duplicate babel install docs * Remove redundant docs * tag as babel required * Remove semicolons for consistency * Formatting * Cleanup doc section in main readme * remove absolute links within repo * remove deprecated file * Move to next PR * Update link to repo * Delete unnecessary files * extractStatic note
1 parent 3f58674 commit 3973317

21 files changed

+249
-207
lines changed

README.md

+62-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
### All documentation on master is for version 8. The documentation for version 7 is located under the [`v7.3.2` tag](https://github.com/emotion-js/emotion/tree/v7.3.2).
21

32
<p align="center" style="color: #343a40">
4-
<img src="https://cdn.rawgit.com/tkh44/emotion/master/emotion.png" alt="emotion" height="200" width="200">
3+
<img src="https://cdn.rawgit.com/tkh44/emotion/master/emotion.png" alt="emotion" height="150" width="150">
54
<h1 align="center">emotion</h1>
65
</p>
76
<p align="center" style="font-size: 1.2rem;">The Next Generation of CSS-in-JS</p>
@@ -15,27 +14,75 @@
1514
![react size](http://img.badgesize.io/https://unpkg.com/react-emotion/dist/DO-NOT-USE.min.js?label=react%20size)
1615
[![slack](https://emotion.now.sh/badge.svg)](http://emotion.now.sh/)
1716

18-
emotion is a high performance, lightweight css-in-js library.
19-
The core idea comes from Sunil Pai’s [glam](https://github.com/threepointone/glam) library and its philosophy is laid out [here](https://gist.github.com/threepointone/0ef30b196682a69327c407124f33d69a).
20-
The basic idea is simple.
21-
You shouldn’t have to sacrifice runtime performance for good developer experience when writing CSS. emotion
22-
minimizes the runtime cost of css-in-js dramatically by parsing your styles with PostCSS during compilation instead of at runtime.
23-
24-
-- [Introduction Article](https://medium.com/@tkh44/emotion-ad1c45c6d28b)
17+
emotion is a high performance, lightweight css-in-js library. emotion minimizes the runtime cost of css-in-js dramatically by parsing your styles at build time and utilizing [insertRule](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule) on the client.
2518

2619
---
20+
### Quick Start
21+
Get up and running with a single import.
22+
```bash
23+
npm install --save emotion
24+
```
2725

28-
### [Install](https://github.com/tkh44/emotion/tree/master/docs/install.md)
26+
```javascript
27+
import { css } from 'emotion';
2928

30-
### Demos
31-
32-
- [Code Sandbox](https://codesandbox.io/s/pk1qjqpw67)
33-
- [emotion website](https://github.com/tkh44/emotion/tree/master/packages/site) [[Demo Here](https://emotion.sh)]
29+
const app = document.getElementById('root');
30+
const myStyle = css`
31+
color: rebeccapurple;
32+
`
33+
app.classList.add(myStyle);
34+
```
35+
### React with [Optional Babel Plugin](docs/babel.md)
36+
```bash
37+
npm install --save emotion react-emotion babel-plugin-emotion
38+
```
39+
_Note: use `preact-emotion` in place of `react-emotion` if using [Preact](https://github.com/developit/preact)_
40+
41+
```javascript
42+
import styled, { css } from 'react-emotion';
43+
44+
const Container = styled('div')`
45+
background: #333;
46+
`
47+
const myStyle = css`
48+
color: rebeccapurple;
49+
`
50+
const app = () => (
51+
<Container>
52+
<p className={myStyle}>Hello World</p>
53+
</Container>
54+
);
55+
```
56+
57+
[Demo Code Sandbox](https://codesandbox.io/s/pk1qjqpw67)
58+
59+
### Examples
60+
61+
- [emotion website](packages/site) [[Demo Here](https://emotion.sh)]
3462
- [next-hnpwa-guide-kit](https://github.com/tkh44/next-hnpwa-guide-kit) [[Demo Here](https://hnpwa.life)]
3563
- **open a PR and add yours!**
3664

37-
### [Documentation](https://github.com/tkh44/emotion/tree/master/docs)
65+
### About
66+
67+
The core idea comes from Sunil Pai’s [glam](https://github.com/threepointone/glam) library and its philosophy is laid out [here](https://gist.github.com/threepointone/0ef30b196682a69327c407124f33d69a).
68+
69+
-- [Introduction Article](https://medium.com/@tkh44/emotion-ad1c45c6d28b)
70+
71+
### Documentation
72+
#### API
73+
- Styling components with [`styled`](docs/styled.md)
74+
75+
- Create composable styles with [`css` classes and props](docs/css.md)
76+
77+
- [`composition`](docs/composition.md)
78+
79+
- [`keyframes`](docs/keyframes.md)
80+
- [`fontFace`](docs/font-face.md)
81+
- [`injectGlobal`](docs/inject-global.md)
3882

83+
#### Doc files
84+
- [All docs](docs/)
85+
- [Version 7 docs](https://github.com/emotion-js/emotion/tree/v7.3.2)
3986
### Ecosystem
4087

4188
- [emotion-vue](https://github.com/egoist/emotion-vue)

docs/README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
- [Configurable Imports](https://github.com/emotion-js/emotion/tree/master/docs/configurable-imports.md) Useful when migrating from another css-in-js library such as styled-components or styled-jsx
88
- [Preact](https://github.com/emotion-js/emotion/tree/master/docs/preact.md)
99
- [Nested Selectors](https://github.com/emotion-js/emotion/tree/master/docs/nested.md)
10-
- [Pseudo Selectors ](https://github.com/emotion-js/emotion/tree/master/docs/pseudo.md)
11-
- [Media Queries](https://github.com/emotion-js/emotion/tree/master/docs/media.md)
1210
- [Composition](https://github.com/emotion-js/emotion/tree/master/docs/composition.md)
13-
- [Styling Any Component](https://github.com/emotion-js/emotion/tree/master/docs/styling-any-component.md)
1411
- [`styled.withComponent`](https://github.com/emotion-js/emotion/tree/master/docs/styled-with-component.md)
15-
- [Dynamic Props For `styled` Components](https://github.com/emotion-js/emotion/tree/master/docs/props.md)
1612
- [Using Javascript Objects for Styles](https://github.com/emotion-js/emotion/tree/master/docs/objects.md)
1713
- [`styled` With Object Styles](https://github.com/emotion-js/emotion/tree/master/docs/styled-with-object.md) (glamorous api)
18-
- [Styling Elements Via `css` Prop in JSX](https://github.com/emotion-js/emotion/tree/master/docs/css-prop.md)
14+
- [Styling Elements Via `css` Prop in JSX](https://github.com/emotion-js/emotion/tree/master/docs/css#CSS-Prop.md)
1915
- [Injecting Global Styles](https://github.com/emotion-js/emotion/tree/master/docs/inject-global.md)
2016
- [Custom Fonts](https://github.com/emotion-js/emotion/tree/master/docs/font-face.md)
2117
- [Keyframe Animations](https://github.com/emotion-js/emotion/tree/master/docs/keyframes.md)
@@ -24,5 +20,5 @@
2420
- [Source Maps](https://github.com/emotion-js/emotion/tree/master/docs/source-maps.md)
2521
- [Extracting Static Styles](https://github.com/emotion-js/emotion/tree/master/docs/extract-static.md)
2622
- [Using `withProps` To Attach Props](https://github.com/emotion-js/emotion/tree/master/docs/with-props.md) (styled-components `.attrs` api)
27-
- [Usage with babel-macros](https://github.com/tkh44/emotion/tree/master/docs/babel-macros.md)
23+
- [Usage with babel-macros](https://github.com/emotion-js/emotion/tree/master/docs/babel.md#usage-with-babel-macros)
2824
- [TypeScript](https://github.com/emotion-js/emotion/tree/master/docs/typescript.md)

docs/babel-macros.md

-10
This file was deleted.

docs/babel.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Usage with Babel
2+
3+
The Babel Plugin is highly recommended, but not required in version 8 and above.
4+
5+
See the [installation instructions](install.md).
6+
7+
### Features which are enabled with the babel plugin
8+
9+
### styled.element Syntax
10+
`styled('div')` will work without the plugin
11+
12+
### Minification
13+
Any leading/trailing space between properties in your `css` and `styled` blocks is removed. This can reduce the size of your final bundle.
14+
15+
### Dead Code Elimination
16+
Uglifyjs will use the injected `/*#__PURE__*/` flag comments to mark your `css` and `styled` blocks as candidates for dead code elimination.
17+
18+
### Static Extraction
19+
Generated CSS that is eligible for extraction can be moved to an external css file.
20+
21+
### Source Maps
22+
When enabled, navigate directly to the style declaration in your javascript file.
23+
24+
### css as Prop
25+
Convenient helper for calling `css` and appending the generated className during compile time.
26+
27+
## Babel Macros
28+
29+
Instead of using emotion's babel plugin, you can use emotion with [`babel-macros`](https://github.com/kentcdodds/babel-macros). Add `babel-macros` to your babel config and import whatever you want from emotion but add `/macro` to the end. The macro is currently the same as inline mode. Currently every API except for the css prop is supported by the macro.
30+
31+
```jsx
32+
import styled from 'react-emotion/macro'
33+
import { css, keyframes, fontFace, injectGlobal, flush, hydrate } from 'emotion/macro'
34+
```
35+
36+
For some context, check out this [issue](https://github.com/facebookincubator/create-react-app/issues/2730).

docs/css-prop.md

-30
This file was deleted.

docs/css.md

+41-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
## CSS
22

3-
`css` takes in styles and returns a class name. It is the foundation of emotion.
3+
`css` accepts styles as a template literal, object, or array of objects and returns a class name. It is the foundation of emotion.
44

5-
```jsx
5+
```jsx harmony
66
import { css } from 'emotion'
7+
import { lighten, modularScale } from 'polished'
78

9+
// Write your css as normal.
810
const flex = css`
911
display: flex;
1012
`
@@ -13,42 +15,54 @@ const justifyCenter = css`
1315
justifyContent: center;
1416
`
1517

16-
<div className={justifyCenter}>
17-
Centered Content
18-
</div>
19-
```
20-
21-
### Objects as Styles
22-
23-
`css` can also take an object or array of objects as a parameter.
24-
This allows you to use your existing object styles in the emotion ecosystem.
25-
Another great benefit is that you can now use [polished](https://polished.js.org/) with emotion.
26-
27-
```jsx harmony
28-
import { css } from 'emotion'
29-
import { lighten, modularScale } from 'polished'
30-
18+
// As an object
3119
const cssA = {
20+
// Easily use [polished](https://polished.js.org/)
3221
color: lighten(0.2, '#000'),
3322
"font-size": modularScale(1),
3423
[hiDPI(1.5)]: {
3524
"font-size": modularScale(1.25)
3625
}
3726
}
3827

39-
const cssB = css`
40-
${cssA};
41-
height: 64px;
42-
`
43-
4428
const H1 = styled('h1')`
45-
${cssB};
29+
${cssA};
4630
font-size: ${modularScale(4)};
4731
`
4832

4933
const H2 = styled(H1)`font-size:32px;`
34+
<div className={justifyCenter}>
35+
<H2 scale={2} className={'legacy__class'}>
36+
Centered Content
37+
</H2>
38+
</div>
39+
```
40+
41+
## CSS Prop
42+
###### [requires babel plugin](babel.md)
43+
A shortcut for calling the css function and appending the result to the className prop. Done at compile time.
44+
_Note: CSS props are not compatible with babel's `"transform-react-inline-elements"` plugin. If you include it in your `.babelrc` no transformation will take place and your styles will silently fail._
5045

51-
<H2 scale={2} className={'legacy__class'}>
52-
hello world
53-
</H2>
54-
```
46+
```jsx
47+
function SomeComponent (props) {
48+
// Create styles as if you're calling css and the class will be applied to the component
49+
return (<div css={`
50+
color: blue;
51+
font-size: ${props.fontSize}px;
52+
53+
&:hover {
54+
color: green;
55+
}
56+
57+
& .some-class {
58+
font-size: 20px;
59+
}
60+
`}>
61+
This will be blue until hovered.
62+
<div className="some-class">
63+
This font size will be 20px
64+
</div>
65+
</div>)
66+
}
67+
68+
```

docs/extract-static.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
## Extract Static
2+
###### [requires babel plugin](babel.md)
23

34
Extract styles with no interpolations into external css files.
45

6+
While there are some beneficial use cases for `extractStatic`, emotion's inherent performance since version 8 makes the added complexity of this feature somewhat disadvantageous.
7+
58

69
**does NOT work with object styles**
710

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</h1>
77
<p align="center" style="font-size: 1.2rem;">high performance css-in-js</p>
88

9-
[github](https://github.com/tkh44/emotion)
9+
[github](https://github.com/emotion-js/emotion)
1010
[npm](https://npm.im/emotion)
1111

1212
In order to learn more about emotion lets build this guide together. By following along below, we can get this markdown looking good.

docs/install.md

+30-12
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,53 @@
1-
[github](https://github.com/tkh44/emotion)
2-
[npm](https://npm.im/emotion)
3-
41
## Install
52

63
```bash
74
npm install --save emotion react-emotion babel-plugin-emotion
85
```
96

10-
**.babelrc**
7+
All `emotion` APIs are available from the `react-emotion` package.
8+
9+
```javascript
10+
import styled, { css, injectGlobal } from 'react-emotion';
11+
```
12+
13+
### .babelrc
14+
15+
[More information on the babel plugin](babel.md)
16+
17+
_`"emotion"` must be the **first plugin** in your babel config `plugins` list._
18+
19+
Takes optional configs:
20+
- [extractStatic](babel.md#Static-Extraction) _{boolean}_
21+
- [sourceMap](babel.md#Static-Extraction) _{boolean}_
1122
```json
1223
{
1324
"plugins": [
14-
"emotion"
25+
["emotion"]
1526
]
1627
}
1728
```
18-
19-
**Notes:**
20-
- Make sure `"emotion"` is the first plugin.
21-
- If you are using Babel's env option in your `.babelrc` file, ensure that emotion is first in every environment's list of plugins.
29+
If using Babel's env option emotion must also be first for each environment.
2230
```json
2331
{
2432
"env": {
2533
"production": {
26-
"plugins": ["emotion", "some-other-plugin"]
34+
"plugins": [
35+
"emotion",
36+
[...all other babel plugins...]
37+
]
2738
}
2839
},
2940
"plugins": ["emotion"]
3041
}
3142
```
43+
### Preact
3244

33-
### Preact
45+
Import `preact-emotion` instead of `react-emotion` and use it the same way you would with React.
3446

35-
If you're using [Preact](https://github.com/developit/preact) instead of [React](https://github.com/facebook/react), install [`preact-emotion`](./preact.md). The babel setup remains the same.
47+
```jsx
48+
import styled from 'preact-emotion'
49+
50+
const SomeComponent = styled.div`
51+
display: flex;
52+
`
53+
```

docs/media.md

-1
This file was deleted.

0 commit comments

Comments
 (0)