Skip to content

Commit 4dbcacb

Browse files
author
Kye Hohenberger
committed
πŸ‘©β€πŸš€
0 parents  commit 4dbcacb

13 files changed

+433
-0
lines changed

β€Ž.babelrc

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"modules": false,
7+
"loose": true
8+
}
9+
],
10+
"stage-2",
11+
"react"
12+
],
13+
"env": {
14+
"test": {
15+
"presets": [
16+
[
17+
"env",
18+
{
19+
"loose": true
20+
}
21+
],
22+
"stage-2",
23+
"react"
24+
]
25+
}
26+
}
27+
}

β€Ž.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/coverage
2+
/demo/dist
3+
/dist
4+
/lib
5+
/es
6+
/node_modules
7+
/umd
8+
/es
9+
npm-debug.log
10+
.idea

β€Ž.travis.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: node_js
2+
3+
node_js:
4+
- "7"
5+
6+
cache:
7+
directories:
8+
- node_modules
9+
10+
before_install:
11+
- npm install codecov
12+
13+
after_success:
14+
- cat ./coverage/lcov.info | ./node_modules/codecov/bin/codecov
15+
16+
cache:
17+
directories:
18+
- node_modules

β€ŽCONTRIBUTING.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Prerequisites
2+
3+
[Node.js](http://nodejs.org/) >= v7 must be installed.
4+
5+
## Installation
6+
7+
- Running `npm install` in the module's root directory will install everything you need for development.
8+
9+
## Running Tests
10+
11+
- `npm test` will run the tests once.
12+
13+
- `npm run test:coverage` will run the tests and produce a coverage report in `coverage/`.
14+
15+
- `npm run test:watch` will run the tests on every change.
16+
17+
## Building
18+
19+
- `npm run build` will build the module for publishing to npm.
20+
21+
- `npm run clean` will delete built resources.

β€ŽLICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Kye Hohenberger
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

β€ŽREADME.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# emotion
2+
3+
#### `css` prop for all
4+
5+
[![npm version](https://badge.fury.io/js/emotion.svg)](https://badge.fury.io/js/emotion)
6+
[![Build Status](https://travis-ci.org/tkh44/emotion.svg?branch=master)](https://travis-ci.org/tkh44/emotion)
7+
[![codecov](https://codecov.io/gh/tkh44/emotion/branch/master/graph/badge.svg)](https://codecov.io/gh/tkh44/emotion)
8+
9+
10+
- [Install](#install)
11+
12+
## Install
13+
14+
```bash
15+
npm install -S emotion
16+
```
17+
18+
## `emotion/glam`
19+
20+
```jsx harmony
21+
const Name = ({ color, name }) => <h1 css={`color: ${color};`}>{name}</h1>
22+
```
23+
24+
is converted to
25+
26+
```jsx harmony
27+
const Name = ({ color, name }) => <h1 className={css`color: ${color};`}>{name}</h1>
28+
```
29+
30+
**.babelrc**
31+
```json
32+
{
33+
"plugins": [
34+
'emotion/glam',
35+
'glam/babel'
36+
]
37+
}
38+
```
39+
40+
**Similar to importing React when using jsx, `import css from 'glam'` must be at the top of your source files.**

β€Žglam.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./src/glam/babel')

β€Žpackage.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "emotion",
3+
"version": "1.1.0",
4+
"description": "css prop for all",
5+
"files": [
6+
"src",
7+
"glam.js"
8+
],
9+
"scripts": {
10+
"test": "standard src test && jest --coverage",
11+
"test:watch": "jest --watch --coverage",
12+
"release": "npm run test && npm version patch && npm publish && git push --tags"
13+
},
14+
"dependencies": {
15+
"babel-plugin-syntax-jsx": "^6.18.0",
16+
},
17+
"devDependencies": {
18+
"babel-core": "^6.24.1",
19+
"babel-cli": "^6.24.1",
20+
"babel-eslint": "^7.2.3",
21+
"babel-jest": "^19.0.0",
22+
"babel-loader": "^7.0.0",
23+
"babel-preset-env": "^1.4.0",
24+
"babel-preset-react": "^6.24.1",
25+
"babel-preset-stage-0": "^6.24.1",
26+
"jest": "^20.0.1",
27+
"jest-glamor-react": "^1.3.0",
28+
"glam": "^4.0.3",
29+
"react": "^15.5.4",
30+
"react-addons-test-utils": "^15.5.1",
31+
"react-dom": "^15.5.4",
32+
"react-test-renderer": "^15.5.4",
33+
"standard": "^10.0.2",
34+
},
35+
"author": "Kye Hohenberger",
36+
"homepage": "https://github.com/tkh44/emotion#readme",
37+
"license": "MIT",
38+
"repository": {
39+
"type": "git",
40+
"url": "git+https://github.com/tkh44/emotion.git"
41+
},
42+
"directories": {
43+
"test": "tests"
44+
},
45+
"keywords": [
46+
"styles",
47+
"emotion",
48+
"react",
49+
"css",
50+
"css-in-js"
51+
],
52+
"eslintConfig": {
53+
"extends": "standard",
54+
"parser": "babel-eslint"
55+
},
56+
"standard": {
57+
"parser": "babel-eslint",
58+
"ignore": [
59+
"/dist/"
60+
]
61+
},
62+
"bugs": {
63+
"url": "https://github.com/tkh44/emotion/issues"
64+
}
65+
}

β€Žsrc/glam/__tests__/.babelrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"presets": [
3+
"env",
4+
"stage-0",
5+
"react"
6+
],
7+
"plugins": [
8+
[
9+
"../babel.js",
10+
{
11+
"sync": true
12+
}
13+
],
14+
['glam/babel', { sync: true } ],
15+
]
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`emotion/glam babel basic 1`] = `"<div className={\\"a\\" + \\" \\" + css\`color: brown;\`}></div>;"`;
4+
5+
exports[`emotion/glam babel className as expression 1`] = `"<div className={varia + \\" \\" + css\`color: brown;\`}></div>;"`;
6+
7+
exports[`emotion/glam babel className as expression string 1`] = `"<div className={\`test__class\` + \\" \\" + css\`color: brown;\`} this={\`hello\`}></div>;"`;
8+
9+
exports[`emotion/glam babel emptyClassName 1`] = `"<div className={\\"\\" + \\" \\" + css\`color: brown;\`}></div>;"`;
10+
11+
exports[`emotion/glam babel no css attr 1`] = `"<div></div>;"`;
12+
13+
exports[`emotion/glam babel noClassName 1`] = `"<div className={css\`color: brown;\`}></div>;"`;
14+
15+
exports[`emotion/glam real basic 1`] = `
16+
<p
17+
className="css-jk0pkr"
18+
>
19+
hello world
20+
</p>
21+
`;
22+
23+
exports[`emotion/glam real nested 1`] = `
24+
<div
25+
className="a css-jf1v9l"
26+
>
27+
<p
28+
className="foo css-14jcta0"
29+
>
30+
Hello
31+
</p>
32+
<p
33+
className="foo css-1fpqmhj"
34+
>
35+
World
36+
</p>
37+
<p
38+
className=" css-7jbqmo vars-1mtfi0j"
39+
>
40+
hello world
41+
</p>
42+
</div>
43+
`;

β€Žsrc/glam/__tests__/index.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* eslint-disable jsx-quotes */
2+
/* eslint-env jest */
3+
import React from 'react'
4+
import renderer from 'react-test-renderer'
5+
import plugin from '../babel'
6+
import css from 'glam';
7+
8+
const babel = require('babel-core')
9+
10+
describe('emotion/glam', () => {
11+
describe('babel', () => {
12+
test('basic', () => {
13+
const basic = '(<div className="a" css={`color: brown;`}></div>)'
14+
const {code} = babel.transform(basic, {plugins: [plugin]})
15+
expect(code).toMatchSnapshot()
16+
})
17+
18+
test('no css attr', () => {
19+
const basic = '(<div></div>)'
20+
const {code} = babel.transform(basic, {plugins: [plugin]})
21+
expect(code).toMatchSnapshot()
22+
})
23+
24+
test('noClassName', () => {
25+
const basic = '(<div css={`color: brown;`}></div>)'
26+
const {code} = babel.transform(basic, {plugins: [plugin]})
27+
expect(code).toMatchSnapshot()
28+
})
29+
30+
test('emptyClassName', () => {
31+
const basic = '(<div className="" css={`color: brown;`}></div>)'
32+
const {code} = babel.transform(basic, {plugins: [plugin]})
33+
expect(code).toMatchSnapshot()
34+
})
35+
36+
test('className as expression', () => {
37+
const basic = '(<div className={variable} css={`color: brown;`}></div>)'
38+
const {code} = babel.transform(basic, {plugins: [plugin]})
39+
expect(code).toMatchSnapshot()
40+
})
41+
42+
test('className as expression string', () => {
43+
const basic = '(<div className={`test__class\`} css={`color: brown;`} this={`hello\`}></div>)'
44+
const {code} = babel.transform(basic, {plugins: [plugin]})
45+
expect(code).toMatchSnapshot()
46+
})
47+
})
48+
49+
describe('real', () => {
50+
test('basic', () => {
51+
const tree = renderer
52+
.create(
53+
<p css={`color: red;`}>
54+
hello world
55+
</p>
56+
)
57+
.toJSON()
58+
59+
expect(tree).toMatchSnapshot()
60+
})
61+
62+
test('nested', () => {
63+
const props = { online: false, radius: 5 }
64+
65+
const tree = renderer
66+
.create(
67+
<div className="a" css={`color: brown;`}>
68+
<p className="foo" css={`color: blue;`}>Hello</p>
69+
<p className="foo" css={`color: green;`}>World</p>
70+
<p
71+
className={` ${css`
72+
color: red;
73+
border-radius: ${props.radius};
74+
&:hover {
75+
font-weight: bold;
76+
color: ${props.online ? 'green' : 'gray'};
77+
}
78+
`}`}
79+
>
80+
hello world
81+
</p>
82+
</div>
83+
)
84+
.toJSON()
85+
86+
expect(tree).toMatchSnapshot()
87+
})
88+
})
89+
})

β€Žsrc/glam/__tests__/index.js.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* do not edit this file */
2+
.css-jk0pkr { color: red; }
3+
.css-jf1v9l { color: brown; }
4+
.css-14jcta0 { color: blue; }
5+
.css-1fpqmhj { color: green; }
6+
.css-7jbqmo { color: red;
7+
border-radius: var(--css-7jbqmo-0); }
8+
.css-7jbqmo:hover { font-weight: bold; color: var(--css-7jbqmo-1); }

0 commit comments

Comments
 (0)