Skip to content

Commit

Permalink
(feature) add more styling examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vinogradov committed Oct 7, 2017
1 parent 1795566 commit be2dad1
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 37 deletions.
5 changes: 4 additions & 1 deletion src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ import './examples/react/index';
// import './examples/redux/separate-files';
// import './examples/redux/separate-files-redux-actions';
// import './examples/router';
// import './examples/sass/Component1';
// import './examples/styles/cssmodules-className';
// import './examples/styles/cssmodules-className-sass';
// import './examples/styles/cssmodules-styleName';
// import './examples/styles/scss';
13 changes: 6 additions & 7 deletions src/examples/react/__tests__/__snapshots__/hello.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ exports[`renders correctly 1`] = `
<img
alt=""
src=""
styleName="logo"
style={
Object {
"width": "20px",
}
}
/>
<div>
Hello
<span
styleName="name"
>
John
</span>
John
</div>
<button
onClick={[Function]}
styleName="submit-button"
>
toggle:
ON
Expand Down
17 changes: 0 additions & 17 deletions src/examples/react/hello.css

This file was deleted.

7 changes: 3 additions & 4 deletions src/examples/react/hello.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import './hello.css';
import logo from './logo.svg';

export class Hello extends React.Component {
Expand All @@ -23,9 +22,9 @@ export class Hello extends React.Component {
render() {
return (
<div>
<img src={logo} styleName="logo" alt="" />
<div>Hello <span styleName="name">{this.props.name}</span></div>
<button styleName="submit-button" onClick={this.onClickHandler}>
<img style={{width: '20px'}} src={logo} alt="" />
<div>Hello {this.props.name}</div>
<button onClick={this.onClickHandler}>
toggle: {this.state.toggle ? 'ON' : 'OFF'}
</button>
</div>
Expand Down
16 changes: 16 additions & 0 deletions src/examples/styles/cssmodules-className-sass/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom';
import style from './style.sass';

function CssModulesClassNameSass() {
return (
<div className={style.parent}>
<div className={style.child} />
</div>
);
}

ReactDOM.render(
<CssModulesClassNameSass />,
document.querySelector('#app')
);
7 changes: 7 additions & 0 deletions src/examples/styles/cssmodules-className-sass/style.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$backgroundColor: yellow

.parent
.child
background-color: $backgroundColor
width: 100px
height: 100px
14 changes: 14 additions & 0 deletions src/examples/styles/cssmodules-className/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import style from './style.css';

function CssModulesClassName() {
return (
<div className={style.myBlock} />
);
}

ReactDOM.render(
<CssModulesClassName />,
document.querySelector('#app')
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.foo {
.primaryColor {
background-color: red;
}

.myBlock {
composes: primaryColor;
width: 100px;
height: 100px;
background-color: red;
}
16 changes: 16 additions & 0 deletions src/examples/styles/cssmodules-styleName/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './style.css';

// see react-css-modules in webpack config

function CssModulesStyleName() {
return (
<div styleName="myBlock" />
);
}

ReactDOM.render(
<CssModulesStyleName />,
document.querySelector('#app')
);
9 changes: 9 additions & 0 deletions src/examples/styles/cssmodules-styleName/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.primaryColor {
background-color: green;
}

.myBlock {
composes: primaryColor;
width: 100px;
height: 100px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './style.scss';

export function Component1() {
return <div className="foo">Component1</div>;
function Scss() {
return (
<div className="parent">
<div className="child" />
</div>
);
}

ReactDOM.render(
<Component1 />,
<Scss />,
document.querySelector('#app')
);
9 changes: 9 additions & 0 deletions src/examples/styles/scss/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$backgroundColor: blue;

.parent {
.child {
background-color: $backgroundColor;
width: 100px;
height: 100px;
}
}
35 changes: 32 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ module.exports = (env) => {
];

const CSS_MODULES_CLASS_NAME_TEMPLATE = '[local]-[hash:base64:5]';
const CSS_MODULES_CONFIG = `modules&importLoaders=1&localIdentName=${CSS_MODULES_CLASS_NAME_TEMPLATE}`;
const CSS_MODULES_CONFIG = {
modules: true,
sourceMap: false,
importLoaders: 1,
localIdentName: CSS_MODULES_CLASS_NAME_TEMPLATE
};
const plugins = getPlugins(DEFAULT_PLUGINS, IS_PRODUCTION, IS_ANALYZE);

return {
Expand Down Expand Up @@ -164,14 +169,38 @@ module.exports = (env) => {
include: SRC_ABSOLUTE_PATH, // other paths are ignored
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: `css-loader?${IS_PRODUCTION ? 'minimize&' : ''}${CSS_MODULES_CONFIG}`
use: {
loader: 'css-loader',
options: {
...CSS_MODULES_CONFIG,
minimize: IS_PRODUCTION
}
}
})
}, {
test: /\.scss$/,
include: SRC_ABSOLUTE_PATH, // other paths are ignored
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: `css-loader${IS_PRODUCTION ? '?minimize' : ''}!sass-loader`
use: [{
loader: 'css-loader',
options: {
minimize: IS_PRODUCTION
}
}, 'sass-loader']
})
}, {
test: /\.sass$/,
include: SRC_ABSOLUTE_PATH, // other paths are ignored
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
...CSS_MODULES_CONFIG,
minimize: IS_PRODUCTION
}
}, 'sass-loader']
})
}, {
test: new RegExp(`\\.(${BIN_FILE_TYPES})$`),
Expand Down

0 comments on commit be2dad1

Please sign in to comment.