Skip to content

Commit 0155a62

Browse files
committed
Moved the CSS style JSON expressions into a new separate file 'webpack_in/styles.es'.
1 parent edba721 commit 0155a62

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

‎webpack_in/entry.jsx‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ import PropTypes from 'prop-types';
1010
import React from 'react';
1111
import ReactDOM from 'react-dom';
1212

13-
14-
const objStyleCommon = {
15-
margin: '1em',
16-
border: 'solid 2px green',
17-
textAlign: 'center'
18-
};
19-
20-
const objStyleContent = {
21-
padding: '1em'
22-
};
13+
import Styles from './styles.es';
2314

2415

2516
class ButtonWidget extends React.Component {
@@ -41,7 +32,7 @@ ButtonWidget.propTypes = {
4132
class HelloWidget extends React.Component {
4233
render() {
4334
return (
44-
<div style={{ ...objStyleCommon, ...objStyleContent }}>
35+
<div style={{ ...Styles.common, ...Styles.content }}>
4536
Hello! I'm a React app!!
4637
</div>
4738
);
@@ -59,8 +50,8 @@ class TextWidget extends React.Component {
5950

6051
render() {
6152
return (
62-
<div style={ objStyleCommon }>
63-
<div style={ objStyleContent }>{ this.state.text }</div>
53+
<div style={ Styles.common }>
54+
<div style={ Styles.content }>{ this.state.text }</div>
6455
<ButtonWidget caption="Change text..."
6556
onClick={() => {
6657
const strTextNew = prompt("Please enter text to display:",
@@ -163,8 +154,8 @@ class ListWidget extends React.Component {
163154
"");
164155

165156
return (
166-
<div style={ objStyleCommon }>
167-
<div style={ objStyleContent }>
157+
<div style={ Styles.common }>
158+
<div style={ Styles.content }>
168159
<ul style={{ display: 'inline-block', textAlign: 'left', listStyleType: 'none' }}>
169160
{ this.state.items.map((objItem, index) => (
170161
<ListItem key={ objItem.id }
@@ -387,7 +378,7 @@ class ColorSelector extends React.Component {
387378
};
388379

389380
return (
390-
<div style={ objStyleCommon }>
381+
<div style={ Styles.common }>
391382
<div style={{ margin: '1em auto',
392383
width: '70%',
393384
height: '3em',

‎webpack_in/styles.es‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file 'styles.es' is part of an example for building a multi-widget React front-end app
2+
// step by step as outlined in the tutorial blog at
3+
// http://maratbn.com/blogs/2018/07/02/react-multi-widget/
4+
5+
6+
export default {
7+
common: {
8+
margin: '1em',
9+
border: 'solid 2px green',
10+
textAlign: 'center'
11+
},
12+
content: {
13+
padding: '1em'
14+
}
15+
};

0 commit comments

Comments
 (0)