Skip to content

Commit 8f72cff

Browse files
committed
Initial commit
0 parents  commit 8f72cff

File tree

14 files changed

+210
-0
lines changed

14 files changed

+210
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# CSS Modules Example
2+
3+
A small working example of **CSS Modules**, using [Webpack]'s [css-loader] in [module mode].
4+
5+
## Run the example
6+
7+
```bash
8+
$ npm install
9+
$ npm start & open http://localhost:8080
10+
```
11+
12+
## License
13+
14+
[MIT]
15+
16+
[Webpack]: http://webpack.github.io
17+
[css-loader]: https://github.com/webpack/css-loader
18+
[module mode]: https://github.com/webpack/css-loader/#module-mode
19+
[MIT]: http://markdalgleish.mit-license.org

package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "css-modules-example",
3+
"version": "1.0.0",
4+
"description": "A small working example of CSS Modules, using Webpack's css-loader in module mode.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "webpack",
8+
"start": "webpack-dev-server"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/markdalgleish/css-modules-example"
13+
},
14+
"author": "Mark Dalgleish",
15+
"license": "MIT",
16+
"bugs": {
17+
"url": "https://github.com/markdalgleish/css-modules-example/issues"
18+
},
19+
"homepage": "https://github.com/markdalgleish/css-modules-example",
20+
"devDependencies": {
21+
"babel-core": "^5.2.17",
22+
"babel-loader": "^5.0.0",
23+
"css-loader": "^0.14.0",
24+
"ejs": "^2.3.1",
25+
"extract-text-webpack-plugin": "^0.8.0",
26+
"node-libs-browser": "^0.5.0",
27+
"react": "^0.13.3",
28+
"react-to-html-webpack-plugin": "^2.1.0",
29+
"style-loader": "^0.12.2",
30+
"webpack": "^1.9.8",
31+
"webpack-dev-server": "^1.8.2"
32+
}
33+
}

src/components/App.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { Component } from 'react';
2+
3+
import HelloWorld from './HelloWorld/HelloWorld';
4+
import FooBar from './FooBar/FooBar';
5+
6+
export default class App extends Component {
7+
8+
render() {
9+
return (
10+
<div>
11+
<h1>CSS Modules Example</h1>
12+
13+
<p>On this page we have two components: <strong>HelloWorld</strong> and <strong>FooBar</strong>.</p>
14+
<p>Both of these components have locally scoped CSS that inherit from a common set of CSS Modules.</p>
15+
<p>Since CSS Modules can be composed, the resulting markup is optimised to reuse classes between components.</p>
16+
17+
<HelloWorld />
18+
<br />
19+
<FooBar />
20+
21+
</div>
22+
);
23+
}
24+
25+
};

src/components/FooBar/FooBar.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.root {
2+
extends: box from "styles/layout.css";
3+
border-color: blue;
4+
}
5+
6+
.text {
7+
extends: heading from "styles/typography.css";
8+
color: blue;
9+
}

src/components/FooBar/FooBar.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import styles from './FooBar.css';
2+
3+
import React from 'react';
4+
5+
export default class Demo extends React.Component {
6+
7+
render() {
8+
return (
9+
<div className={styles.root}>
10+
<p className={styles.text}>FooBar</p>
11+
</div>
12+
);
13+
}
14+
15+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.root {
2+
extends: box from "styles/layout.css";
3+
border-color: red;
4+
}
5+
6+
.text {
7+
extends: heading from "styles/typography.css";
8+
color: red;
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import styles from './HelloWorld.css';
2+
3+
import React from 'react';
4+
5+
export default class Demo extends React.Component {
6+
7+
render() {
8+
return (
9+
<div className={styles.root}>
10+
<p className={styles.text}>HelloWorld</p>
11+
</div>
12+
);
13+
}
14+
15+
};

src/components/styles/layout.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.box {
2+
border-width: 2px;
3+
border-style: solid;
4+
padding: 0 20px;
5+
margin: 0 6px;
6+
max-width: 400px;
7+
}

0 commit comments

Comments
 (0)