Skip to content

Commit e046965

Browse files
streamichMicheleBertoli
authored andcommitted
Added css-light (#68)
* feat: added css-light * fix: typo * chore: review comments * style: newline in gitignore
1 parent 2202260 commit e046965

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ For example, if a package supports the css file extraction you can run the autop
2525
| [classy](https://github.com/inturn/classy) | 0.3.0 | |||| |
2626
| [csjs](https://github.com/rtsao/csjs) | 1.0.0 | ||| | |
2727
| [css-constructor](https://github.com/siddharthkp/css-constructor) | 0.1.1 |||| | |
28+
| [css-light](https://github.com/streamich/css-light) | 1.1.0 | |||||
2829
| [css-loader](https://github.com/webpack/css-loader) | 0.15.6 | ||| ||
2930
| [css-ns](https://github.com/jareware/css-ns) | 1.0.0 | ||| ||
3031
| [cssobj](https://github.com/cssobj/cssobj) | 0.2.21 ||||| |

css-light/base.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Component} from 'react';
2+
import {css, inject} from 'css-light';
3+
4+
export class Comp extends Component {
5+
componentWillMount() {
6+
if (this.css) {
7+
if (!this.css['@@once']) {
8+
this.css['@@once'] = 1;
9+
inject(css(this.css()));
10+
}
11+
}
12+
}
13+
}

css-light/button.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {createElement as h} from 'react';
2+
import {render} from 'react-dom';
3+
import {Comp} from "./base";
4+
5+
class Button extends Comp {
6+
css = () => ({
7+
'.container': {
8+
ta: 'center',
9+
'.button': {
10+
bg: 'red',
11+
w: '320px',
12+
pad: '20px',
13+
bdrad: '5px',
14+
bd: 'none',
15+
outline: 'none',
16+
'&:hover': {
17+
col: '#fff',
18+
},
19+
'&:active': {
20+
pos: 'relative',
21+
top: '2px',
22+
},
23+
},
24+
},
25+
'@media (max-width: 480px)': {
26+
'.container .button': {
27+
w: '160px',
28+
},
29+
},
30+
});
31+
32+
render() {
33+
return (
34+
h('div', {className: 'container'},
35+
h('button', {className: 'button'}, 'Click me!')
36+
)
37+
);
38+
}
39+
}
40+
41+
render(h(Button), document.getElementById('content'));

css-light/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>css-light - CSS in JS</title>
5+
</head>
6+
<body>
7+
<div id="content"></div>
8+
<script src="bundle.js"></script>
9+
</body>
10+
</html>

css-light/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "css-light-css-in-js",
3+
"version": "1.0.0",
4+
"description": "css-light - CSS in JS",
5+
"scripts": {
6+
"build": "webpack ./button.js bundle.js"
7+
},
8+
"author": "Vadim Dalecky",
9+
"license": "MIT",
10+
"dependencies": {
11+
"react": "^16.0.0",
12+
"react-dom": "^16.0.0",
13+
"css-light": "1.1.0"
14+
},
15+
"devDependencies": {
16+
"babel-loader": "^5.1.3",
17+
"webpack": "^1.9.9"
18+
}
19+
}

css-light/webpack.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
module: {
3+
loaders: [{
4+
test: /\.jsx?$/,
5+
exclude: /(node_modules|bower_components)/,
6+
loader: 'babel?stage=0'
7+
}]
8+
}
9+
};

0 commit comments

Comments
 (0)