Skip to content

Commit 0f5acf3

Browse files
author
Vishal Upadhyay
committed
class based components
1 parent f79cef0 commit 0f5acf3

File tree

4 files changed

+70
-6
lines changed

4 files changed

+70
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.icon-left {
2+
position: absolute;
3+
top: 10px;
4+
left: 10px;
5+
}
6+
7+
.icon-right {
8+
position: absolute;
9+
bottom: 10px;
10+
right: 10px;
11+
}
12+
13+
.season-display {
14+
display: flex;
15+
justify-content: center;
16+
align-items: center;
17+
height: 100vh;
18+
}
19+
20+
.season-display.winter i {
21+
color: blue;
22+
}
23+
24+
.season-display.summer i {
25+
color: red;
26+
}
27+
28+
.winter {
29+
background-color: aliceblue;
30+
}
31+
32+
.summer {
33+
background-color: orange;
34+
}

3_class_based_components/src/SeasonDisplay.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import React from 'react';
2+
import './SeasonDisplay.css';
23

34
// lat > 0 : Northen Hemisphere
45

6+
const seasonConfig = {
7+
summer: {
8+
text: 'Let\'s hit the beach!',
9+
iconName: 'snowflake'
10+
},
11+
winter: {
12+
text: 'Burr its cold!',
13+
iconName: 'snowflake'
14+
}
15+
}
16+
517
const getSeason = (lat, month) => {
618
if (month>2 && month<9){
719
return lat>0 ? 'summer' : 'winter'
@@ -13,13 +25,12 @@ const getSeason = (lat, month) => {
1325

1426
const SeasonDisplay = (props) => {
1527
const season = getSeason(props.lat, new Date().getDate())
16-
const text = season === 'winter' ? 'Burr, its chilly' : 'Lets hit the beach'
17-
const icon = season === 'winter' ? 'snowflake' : 'sun'
28+
const {text, iconName} = seasonConfig[season]
1829
return (
19-
<div>
20-
<i className={`${icon} icon`} />
30+
<div className={`season-display ${season}`}>
31+
<i className={`${iconName} icon-left icon massive`} />
2132
<h1>{text}</h1>
22-
<i className={`${icon} icon`} />
33+
<i className={`${iconName} icon-right icon massive`} />
2334
</div>
2435
)
2536
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
3+
const Spinner = (props) => {
4+
return (
5+
<div className="ui active dimmer">
6+
<div className="ui big text loader">
7+
{props.message}
8+
</div>
9+
</div>
10+
)
11+
}
12+
13+
// for default message
14+
Spinner.defaultProps = {
15+
message: 'Loading...'
16+
}
17+
18+
export default Spinner

3_class_based_components/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import SeasonDisplay from './SeasonDisplay';
4+
import Spinner from './Spinner';
45

56
class App extends React.Component {
67
state = { lat: null, long: null, errMessage: '' }
@@ -19,7 +20,7 @@ class App extends React.Component {
1920
if (this.state.lat && !this.state.errMessage) {
2021
return <SeasonDisplay lat={this.state.lat} />
2122
}
22-
return <div>Loading!!</div>
23+
return <Spinner message='Please accept the location request!!' />
2324
}
2425
}
2526

0 commit comments

Comments
 (0)