@@ -8,93 +8,139 @@ import {
8
8
} from 'react-router-dom' ;
9
9
import { connect } from 'react-redux' ;
10
10
import { ThemeProvider } from 'styled-components' ;
11
+ import { CSSTransition } from 'react-transition-group' ;
11
12
12
13
import whitetheme from '../config/theme/whitetheme' ;
13
14
import darktheme from '../config/theme/darktheme' ;
14
15
import GlobalStyles from './components/GlobalStyles' ;
16
+ import Modal from './components/Modal' ;
15
17
16
18
import Home from './pages/Home' ;
17
19
import About from './pages/About' ;
18
20
import Topics from './pages/Topics' ;
19
21
import Page404 from './pages/Page404' ;
20
22
21
- const App = ( {
22
- themes,
23
- changeTheme,
24
- } ) => {
25
- let theme = { } ;
23
+ class App extends React . Component {
24
+ static loadTheme = ( themes ) => {
25
+ let theme = { } ;
26
26
27
- if ( themes . selected . id === 'white_theme' ) {
28
- theme = whitetheme ;
29
- } else if ( themes . selected . id === 'dark_theme' ) {
30
- theme = darktheme ;
27
+ if ( themes . selected . id === 'white_theme' ) {
28
+ theme = whitetheme ;
29
+ } else if ( themes . selected . id === 'dark_theme' ) {
30
+ theme = darktheme ;
31
+ }
32
+
33
+ return theme ;
34
+ }
35
+
36
+ constructor ( props ) {
37
+ super ( props ) ;
38
+
39
+ this . state = {
40
+ showModal : false ,
41
+ } ;
31
42
}
32
43
33
- return (
34
- < ThemeProvider theme = { theme } >
35
- < div >
36
- < GlobalStyles theme = { theme } />
37
- < Router >
38
- { /* Please update the code below for your project requirements */ }
39
- < div >
40
- < ul >
41
- < li >
42
- < Link to = "/" > Home</ Link >
43
- </ li >
44
- < li >
45
- < Link to = "/about" > About</ Link >
46
- </ li >
47
- < li >
48
- < Link to = "/topics" > Topics</ Link >
49
- </ li >
50
- < li >
51
- < Link to = "/link-does-not-exist" > 404</ Link >
52
- </ li >
53
- </ ul >
54
-
55
- < hr />
56
-
57
- < Switch >
58
- < Route exact path = "/" component = { Home } />
59
- < Route path = "/about" component = { About } />
60
- < Route path = "/topics" component = { Topics } />
61
- < Route component = { Page404 } />
62
- </ Switch >
63
-
64
- < hr />
65
-
66
- < h3 > Theme</ h3 >
67
- < ul >
68
- {
69
- themes . data . map ( ( { id, name } ) => (
70
- < li key = { id } >
71
- < button
72
- disabled = { id === themes . selected . id }
73
- onClick = { ( ) => changeTheme ( id ) }
74
- >
75
- { name }
76
- </ button >
77
- </ li >
78
- ) )
79
- }
80
- </ ul >
81
-
82
- < hr />
83
-
84
- < h3 > Images from simply from: < code > ~./assets/[image]</ code > </ h3 >
85
- < img src = "/assets/social-sprite.png" alt = "social icon sprites" />
86
- </ div >
87
- </ Router >
88
- </ div >
89
- </ ThemeProvider >
44
+ onModalClose = ( ) => this . setState ( { showModal : false } ) ;
45
+
46
+ renderModal = ( ) => (
47
+ this . state . showModal ? (
48
+ < Modal onClose = { this . onModalClose } >
49
+ < div >
50
+ < header > < h2 > Modal header</ h2 > </ header >
51
+ < hr />
52
+ < article >
53
+ < p > This is an example of a modal!</ p >
54
+ < p > < code > Esc</ code > works too, if onClose is passed ;)</ p >
55
+ </ article >
56
+ < hr />
57
+ < footer > < button onClick = { this . onModalClose } > Close</ button > </ footer >
58
+ </ div >
59
+ </ Modal >
60
+ ) : null
90
61
) ;
91
- } ;
62
+
63
+ render ( ) {
64
+ const {
65
+ themes,
66
+ changeTheme,
67
+ } = this . props ;
68
+ const theme = App . loadTheme ( themes ) ;
69
+
70
+ return (
71
+ < ThemeProvider theme = { theme } >
72
+ < div >
73
+ < GlobalStyles theme = { theme } />
74
+ < Router >
75
+ { /* Please update the code below for your project requirements */ }
76
+ < div >
77
+ < ul >
78
+ < li >
79
+ < Link to = "/" > Home</ Link >
80
+ </ li >
81
+ < li >
82
+ < Link to = "/about" > About</ Link >
83
+ </ li >
84
+ < li >
85
+ < Link to = "/topics" > Topics</ Link >
86
+ </ li >
87
+ < li >
88
+ < Link to = "/link-does-not-exist" > 404</ Link >
89
+ </ li >
90
+ </ ul >
91
+
92
+ < hr />
93
+
94
+ < Switch >
95
+ < Route exact path = "/" component = { Home } />
96
+ < Route path = "/about" component = { About } />
97
+ < Route path = "/topics" component = { Topics } />
98
+ < Route component = { Page404 } />
99
+ </ Switch >
100
+
101
+ < hr />
102
+
103
+ < h3 > Modal example (React Portal)</ h3 >
104
+ { this . renderModal ( ) }
105
+ < button
106
+ disabled = { this . state . showModal }
107
+ onClick = { ( ) => this . setState ( { showModal : true } ) }
108
+ >
109
+ Open modal
110
+ </ button >
111
+
112
+ < h3 > Theme</ h3 >
113
+ < ul >
114
+ {
115
+ themes . data . map ( ( { id, name } ) => (
116
+ < li key = { id } >
117
+ < button
118
+ disabled = { id === themes . selected . id }
119
+ onClick = { ( ) => changeTheme ( id ) }
120
+ >
121
+ { name }
122
+ </ button >
123
+ </ li >
124
+ ) )
125
+ }
126
+ </ ul >
127
+
128
+ < hr />
129
+
130
+ < h3 > Images from simply from: < code > ~./assets/[image]</ code > </ h3 >
131
+ < img src = "/assets/social-sprite.png" alt = "social icon sprites" />
132
+ </ div >
133
+ </ Router >
134
+ </ div >
135
+ </ ThemeProvider >
136
+ ) ;
137
+ }
138
+ }
92
139
93
140
App . propTypes = {
94
141
themes : PropTypes . object . isRequired ,
95
142
changeTheme : PropTypes . func . isRequired ,
96
143
} ;
97
- App . displayName = App ;
98
144
99
145
/**
100
146
* Wrap App with redux to access
0 commit comments