File tree 4 files changed +70
-6
lines changed
3_class_based_components/src
4 files changed +70
-6
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
+ import './SeasonDisplay.css' ;
2
3
3
4
// lat > 0 : Northen Hemisphere
4
5
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
+
5
17
const getSeason = ( lat , month ) => {
6
18
if ( month > 2 && month < 9 ) {
7
19
return lat > 0 ? 'summer' : 'winter'
@@ -13,13 +25,12 @@ const getSeason = (lat, month) => {
13
25
14
26
const SeasonDisplay = ( props ) => {
15
27
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 ]
18
29
return (
19
- < div >
20
- < i className = { `${ icon } icon` } />
30
+ < div className = { `season-display ${ season } ` } >
31
+ < i className = { `${ iconName } icon-left icon massive ` } />
21
32
< h1 > { text } </ h1 >
22
- < i className = { `${ icon } icon` } />
33
+ < i className = { `${ iconName } icon-right icon massive ` } />
23
34
</ div >
24
35
)
25
36
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
3
import SeasonDisplay from './SeasonDisplay' ;
4
+ import Spinner from './Spinner' ;
4
5
5
6
class App extends React . Component {
6
7
state = { lat : null , long : null , errMessage : '' }
@@ -19,7 +20,7 @@ class App extends React.Component {
19
20
if ( this . state . lat && ! this . state . errMessage ) {
20
21
return < SeasonDisplay lat = { this . state . lat } />
21
22
}
22
- return < div > Loading!! </ div >
23
+ return < Spinner message = 'Please accept the location request!!' / >
23
24
}
24
25
}
25
26
You can’t perform that action at this time.
0 commit comments