Skip to content

Commit df44633

Browse files
authored
Merge pull request #4 from ModusCreateOrg/mixins-2
Updated mixins example per Grgur
2 parents 4da4853 + 733ea2e commit df44633

File tree

6 files changed

+115
-92
lines changed

6 files changed

+115
-92
lines changed

05-mixins/c-maskable-example/src/App.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import React, { Component } from 'react';
2-
import Comments from './Comments'
2+
import Mask from './Mask';
3+
import NetworkView from './NetworkView';
34
import './App.css';
45

56
class App extends Component {
6-
render() {
7+
render () {
78
return (
8-
<Comments/>
9+
<Mask render={({onBeforeLoad, onLoad}) => (
10+
<NetworkView
11+
onBeforeLoad={onBeforeLoad} onLoad={onLoad}
12+
/>
13+
)}/>
914
);
1015
}
1116
}

05-mixins/c-maskable-example/src/Comments.js

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React, { Component } from 'react'
2+
3+
const style = {
4+
wrap : {
5+
display : 'inline-block',
6+
position : 'relative'
7+
},
8+
modal : {
9+
position : 'absolute',
10+
top : 0,
11+
left : 0,
12+
right : 0,
13+
bottom : 0,
14+
background : 'rgba(0, 0, 0, .3)',
15+
display : 'flex',
16+
alignItems : 'center',
17+
justifyContent : 'center'
18+
},
19+
msg : {
20+
padding : '8px 16px',
21+
border : '1px solid #555',
22+
background : 'rgba(0, 0, 0, .1)',
23+
color : '#333'
24+
}
25+
};
26+
27+
class Mask extends Component {
28+
state = {
29+
mask: this.props.mask,
30+
maskMsg: this.props.maskMsg
31+
}
32+
onBeforeLoad = () => {
33+
this.setState({
34+
mask: true,
35+
maskMsg: 'loading...'
36+
});
37+
}
38+
onLoad = () => {
39+
this.setState({
40+
mask: null,
41+
maskMsg: null
42+
});
43+
}
44+
render() {
45+
const { onBeforeLoad, onLoad } = this;
46+
const { mask, maskMsg } = this.state;
47+
48+
return (
49+
<div style={style.wrap}>
50+
{this.props.render({onBeforeLoad, onLoad})}
51+
{mask && <div style={style.modal}>
52+
{maskMsg && <div style={style.msg}>{maskMsg}</div>}
53+
</div>}
54+
</div>
55+
);
56+
}
57+
}
58+
59+
export default Mask;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, {Component} from 'react'
2+
3+
class NetworkView extends Component {
4+
state = {
5+
ip: this.props.ip,
6+
mask: this.props.mask,
7+
router: this.props.router
8+
}
9+
10+
static defaultProps = {
11+
onBeforeLoad: () => {},
12+
onLoad: () => {}
13+
}
14+
componentDidMount () {
15+
if (!this.props.ip) {
16+
this.load();
17+
}
18+
}
19+
load () {
20+
this.props.onBeforeLoad();
21+
setTimeout(() => {
22+
this.setState({
23+
ip: '192.168.1.2',
24+
mask: '255.255.255.0',
25+
router: '192.168.1.1'
26+
});
27+
this.props.onLoad()
28+
}, 3000);
29+
}
30+
onLoad () {}
31+
render () {
32+
const { ip, mask, router } = this.state;
33+
34+
return (
35+
<div style={{width: "300px", padding: "12px" }}>
36+
<h1>TCP/IP</h1>
37+
IP: {ip}<br/>
38+
Network Mask: {mask}<br/>
39+
Router: {router}
40+
</div>
41+
);
42+
}
43+
}
44+
45+
export default NetworkView;

05-mixins/c-maskable-example/src/maskable.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

16-buttons/d-segmented-button/src/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React, { Component } from 'react';
2-
import SegmentedBtn from './SegmentedBtn';
2+
import SegmentedButton from './SegmentedButton';
33
import './App.css';
44

55
const App = () => {
66
return (
7-
<SegmentedBtn>
7+
<SegmentedButton>
88
<button value="one">One</button>
99
<button value="two">Two</button>
1010
<button value="three">Three</button>
11-
</SegmentedBtn>
11+
</SegmentedButton>
1212
);
1313
}
1414

0 commit comments

Comments
 (0)