Skip to content

Commit 363d212

Browse files
author
Rick
committed
Release 1.2.0. Thanks @moret 👏
1 parent 74182f0 commit 363d212

File tree

7 files changed

+66
-74
lines changed

7 files changed

+66
-74
lines changed

README.md

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
![screenshot](https://i.imgur.com/7Pop4SZ.png?1)
22

3-
# React Inline Css
3+
# React Inline CSS
44

5-
Make your React components visually predictable. React Inline Css allows you to write traditional CSS stylesheets in your components, automatically namespacing them for you.
5+
Make your React components visually predictable. React Inline CSS allows you to write traditional CSS stylesheets in your components, automatically namespacing them for you.
66

77
Inspired by the [SUIT CSS](https://suitcss.github.io/) methodology.
88

9-
## Demo:
9+
## Demo
1010

1111
[Mao-mao-mao!](https://edealer.nl/mao)
1212

13-
## Example:
13+
## Example
1414

1515
You write:
1616

@@ -73,46 +73,49 @@ You get namespaced CSS that works on sub-components (comparable to HTML5 `<style
7373

7474
For a cascaded effect, see the `index.html` demo.
7575

76-
## Options
76+
## Installation
77+
78+
npm install --save react-inline-css
79+
80+
## Usage
81+
82+
Run `npm run watch` in your terminal and play with `examples.jsx` to get a feel of react-inline-css.
7783

78-
### Component Name
84+
### SASS / LESS
7985

80-
You can override the `&` as the default selector to the current component. This is useful if you want to require the css from an external file and make any precompilations steps with it. Here's an ES6 example with [SASS loader for Webpack](https://www.npmjs.com/package/sass-loader):
86+
You can override the `&` as the selector to the current component. This is useful if you want to require precompiled stylesheets from an external file. Here's an example with [SASS loader for Webpack](https://www.npmjs.com/package/sass-loader):
8187

82-
**component.js**
88+
**UserComponent.js**
8389
```javascript
84-
import React from 'react';
85-
import InlineCss from 'react-inline-css';
86-
let css = require('!raw!sass!./component.scss');
87-
88-
class Component extends React.Component {
89-
render() {
90-
return (
91-
<InlineCss componentName='base' stylesheet={css}>
92-
<div className='facebook'>Mao is no longer red!</div>
93-
<div className='google'>Mao is no longer red!</div>
94-
<div className='twitter'>Mao is no longer red!</div>
95-
</InlineCss>
96-
);
97-
}
98-
};
90+
import React from "react";
91+
import InlineCss from "react-inline-css";
92+
const stylesheet = require("!raw!sass!./component.scss"); // Precompile SASS
9993

100-
export default Transmit.createContainer(Component);
94+
class UserComponent extends React.Component {
95+
render () {
96+
return (
97+
<InlineCss componentName="UserComponent" stylesheet={stylesheet}>
98+
<div className="facebook">Mao is no longer red!</div>
99+
<div className="google">Mao is no longer red!</div>
100+
<div className="twitter">Mao is no longer red!</div>
101+
</InlineCss>
102+
);
103+
}
104+
};
101105
```
102106

103-
**component.css**
107+
**UserComponent.scss**
104108
```scss
105-
base {
109+
UserComponent {
106110
color: red;
107-
108111
.facebook {
109-
color: blue;
112+
color: blue;
110113
}
111114
.google {
112-
color: blue;
115+
color: blue;
113116
}
114117
.twitter {
115-
color: green;
118+
color: green;
116119
}
117120
}
118121
```
@@ -121,19 +124,14 @@ base {
121124

122125
![screenshot](https://i.imgur.com/e3ErqTz.png?1)
123126

124-
125-
## Installation
126-
127-
npm install --save react-inline-css
128-
129-
## Usage
130-
131-
Run `npm run watch` in your terminal and play with `examples.jsx` to get a feel of react-inline-css.
132-
133127
## Community
134128

135129
Let's start one together! After you ★Star this project, follow me [@Rygu](https://twitter.com/rygu)
136-
on Twitter.
130+
on Twitter.
131+
132+
### Contributors
133+
134+
- [Danilo Moret](https://github.com/moret)
137135

138136
## License
139137

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "react-inline-css",
33
"description": "Inline CSS in your React components, namespaced automatically.",
4-
"version": "1.1.1",
5-
"license": "BSD-3",
4+
"version": "1.2.0",
5+
"license": "BSD-3-Clause",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/RickWong/react-inline-css.git"

src/example/Profile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import InlineCss from "../react-inline-css";
66
*/
77
const Profile = React.createClass({
88
statics: {
9-
css: () => `
9+
css: (avatarSize) => `
1010
& .card {
1111
margin: 15px;
1212
padding: 15px;
1313
text-align: center;
1414
height: 200px;
1515
}
1616
& .card > img {
17-
width: 130px;
18-
height: 130px;
17+
width: ${avatarSize}px;
18+
height: ${avatarSize}px;
1919
}
2020
& .card > p {
2121
margin: 10px;
@@ -24,7 +24,7 @@ const Profile = React.createClass({
2424
},
2525
render: function () {
2626
return (
27-
<InlineCss stylesheet={Profile.css()}>
27+
<InlineCss stylesheet={Profile.css(130)}>
2828
<div className="card">
2929
<img src={this.props.image || 'mao.jpg'} />
3030
<p>{this.props.name || 'Default Mao'}</p>

src/example.js renamed to src/example/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
2-
import InlineCss from "./react-inline-css"
3-
import Profile from "./example/Profile";
4-
import FacebookProfile from "./example/FacebookProfile";
5-
import GoogleProfile from "./example/GoogleProfile";
6-
import TwitterProfile from "./example/TwitterProfile";
2+
import InlineCss from "./../react-inline-css"
3+
import Profile from "./Profile";
4+
import FacebookProfile from "./FacebookProfile";
5+
import GoogleProfile from "./GoogleProfile";
6+
import TwitterProfile from "./TwitterProfile";
77

88
/**
99
* @module Main
@@ -36,8 +36,8 @@ const Main = React.createClass({
3636
src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67"
3737
alt="Fork me on GitHub" />
3838
</a>
39-
<h2>React Inline Css</h2>
40-
<p>React Inline Css allows you to cascade CSS stylesheets on your components, automatically namespacing them.</p>
39+
<h2>React Inline CSS</h2>
40+
<p>React Inline CSS allows you to cascade CSS stylesheets on your components, automatically namespacing them.</p>
4141
<Profile />
4242
<FacebookProfile name="Facebook Mao" image="mao2.png" />
4343
<GoogleProfile name="Google Mao" image="mao3.png" />

src/react-inline-css.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ var InlineCss = React.createClass({
1212
displayName: "InlineCss",
1313
propTypes: {
1414
componentName: React.PropTypes.string,
15-
stylesheet: React.PropTypes.string.isRequired,
1615
namespace: React.PropTypes.string,
16+
stylesheet: React.PropTypes.string.isRequired,
1717
wrapper: React.PropTypes.string
1818
},
19-
_transformSheet: function (stylesheet, namespace, componentName) {
19+
_transformSheet: function (stylesheet, componentName, namespace) {
2020
return stylesheet.
2121
// Prettier output.
2222
replace(/}\s*/ig, '\n}\n').
@@ -30,19 +30,17 @@ var InlineCss = React.createClass({
3030
},
3131
render: function () {
3232
var componentName = this.props.componentName || "&";
33-
var Wrapper = this.props.wrapper || "div";
34-
var namespace = this.props.namespace || "InlineCss-" + refCounter++;
35-
var transformedSheet = this._transformSheet(
36-
this.props.stylesheet, namespace, componentName
37-
);
33+
var namespace = this.props.namespace || "InlineCss-" + refCounter++;
34+
var stylesheet = this._transformSheet(this.props.stylesheet, componentName, namespace);
35+
var Wrapper = this.props.wrapper || "div";
3836

3937
return React.createElement(
4038
Wrapper,
4139
{id: namespace},
4240
this.props.children,
4341
React.createElement("style", {
4442
scoped: true,
45-
dangerouslySetInnerHTML: {__html: transformedSheet}
43+
dangerouslySetInnerHTML: {__html: stylesheet}
4644
})
4745
);
4846
}

webpack.client-watch.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ config.cache = true;
55
config.debug = true;
66
config.devtool = "eval";
77

8-
config.entry.unshift(
9-
"webpack-dev-server/client?http://localhost:8080",
10-
"webpack/hot/only-dev-server"
11-
);
8+
config.entry.WDS = "webpack-dev-server/client?http://localhost:8080";
9+
config.entry.hot = "webpack/hot/only-dev-server";
1210

13-
config.module = {
14-
loaders: [
15-
{include: /\.json$/, loaders: ["json-loader"]},
16-
{include: /\.js$/, loaders: ["react-hot", "babel-loader"], exclude: /node_modules/}
17-
]
18-
};
11+
config.module.postLoaders = [
12+
{test: /\.js$/, loaders: ["react-hot"], exclude: /node_modules/}
13+
];
1914

2015
config.output.publicPath = "http://localhost:8080/dist/";
2116
config.output.hotUpdateMainFilename = "update/[hash]/update.json";

webpack.client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
entry: ["./src/example"],
1010
output: {
1111
path: path.join(__dirname, "static/dist"),
12-
filename: "example.js",
12+
filename: "[name].js",
1313
chunkFilename: "[name].[id].js",
1414
publicPath: "dist/"
1515
},
@@ -21,8 +21,9 @@ module.exports = {
2121
],
2222
module: {
2323
loaders: [
24-
{include: /\.json$/, loaders: ["json-loader"]},
25-
{include: /\.js$/, loaders: ["babel-loader"], exclude: /node_modules/}
24+
{test: /\.json$/, loaders: ["json-loader"]},
25+
{test: /\.js$/, loaders: ["babel-loader"], exclude: /node_modules/},
26+
{test: /\.scss$/, loaders: ["raw-loader", "sass-loader"], exclude: /node_modules/}
2627
]
2728
},
2829
resolve: {

0 commit comments

Comments
 (0)