1
1
import React from 'react' ;
2
+ import PropTypes from 'prop-types' ;
2
3
import { storiesOf } from '@storybook/react' ;
3
4
import { action } from '@storybook/addon-actions' ;
4
5
import { AsyncUnveil , Unveil } from '../src/' ;
6
+ import './ball-spin-clockwise.min.css' ;
5
7
import './styles.css' ;
6
8
7
- const RichContent = props => {
8
- console . log ( 'render rich content' ) ;
9
- console . log ( props ) ;
9
+ class AsyncComponent extends React . Component {
10
+ static propTypes = {
11
+ notifyResize : PropTypes . func ,
12
+ } ;
13
+
14
+ state = {
15
+ height : 100 ,
16
+ complete : false ,
17
+ } ;
18
+
19
+ componentDidMount ( ) {
20
+ this . timeoutId = setTimeout ( ( ) => {
21
+ this . setState (
22
+ {
23
+ height : 400 ,
24
+ complete : true ,
25
+ } ,
26
+ ( ) => {
27
+ this . props . notifyResize ( ) ;
28
+ }
29
+ ) ;
30
+ } , 1000 ) ;
31
+ }
32
+
33
+ componentWillUnmount ( ) {
34
+ clearTimeout ( this . timeoutId ) ;
35
+ }
36
+
37
+ render ( ) {
38
+ return (
39
+ < div
40
+ style = { {
41
+ height : this . state . height ,
42
+ border : '1px solid #49d7cb' ,
43
+ background : '#bffcee' ,
44
+ display : 'flex' ,
45
+ justifyContent : 'center' ,
46
+ alignItems : 'center' ,
47
+ } }
48
+ >
49
+ { this . state . complete ? (
50
+ 'done async stuff!'
51
+ ) : (
52
+ < div className = "la-ball-spin-clockwise la-2x" >
53
+ < div />
54
+ < div />
55
+ < div />
56
+ < div />
57
+ < div />
58
+ < div />
59
+ < div />
60
+ < div />
61
+ </ div >
62
+ ) }
63
+ </ div >
64
+ ) ;
65
+ }
66
+ }
10
67
68
+ const RichContent = props => {
11
69
return (
12
70
< React . Fragment >
13
71
< h1 > An Essay I Wrote for Philosophy Class :)</ h1 >
14
- < img
15
- width = "100%"
16
- onLoad = { ( ) => {
17
- console . log ( 'done loading' ) ;
18
- console . log ( props ) ;
19
- props . notifyResize ( ) ;
20
- } }
21
- src = "https://placeimg.com/720/240/tech"
22
- />
72
+ { props . withImage ? (
73
+ < img width = "100%" src = "https://placeimg.com/720/240/tech" />
74
+ ) : null }
23
75
< p >
24
76
One of the greatest philosophical questions is whether or not machines
25
77
can “think”, brought up by Alan Turing almost a century ago. This
@@ -119,29 +171,46 @@ const RichContent = props => {
119
171
} ;
120
172
121
173
storiesOf ( 'React Unveil' , module )
122
- . add ( 'test' , ( ) => {
123
- // render async, no polling
124
- // some observer injected into it
174
+ . add ( 'with default configuration using ' , ( ) => {
125
175
return (
126
176
< AsyncUnveil >
177
+ < RichContent withImage />
178
+ </ AsyncUnveil >
179
+ ) ;
180
+ } )
181
+ . add ( 'without Async wrapper' , ( ) => {
182
+ return (
183
+ < Unveil >
184
+ < RichContent />
185
+ </ Unveil >
186
+ ) ;
187
+ } )
188
+ . add ( 'Async wrapper no img test' , ( ) => {
189
+ return (
190
+ < AsyncUnveil poll >
127
191
< RichContent />
128
192
</ AsyncUnveil >
129
193
) ;
130
194
} )
131
- . add ( 'with default props' , ( ) => (
132
- < Unveil >
133
- < RichContent />
134
- </ Unveil >
135
- ) )
195
+ . add ( 'img test' , ( ) => {
196
+ return (
197
+ < AsyncUnveil >
198
+ < img
199
+ onLoad = { ( ) => console . log ( 'der' ) }
200
+ src = "https://placeimg.com/720/240/tech"
201
+ />
202
+ </ AsyncUnveil >
203
+ ) ;
204
+ } )
136
205
. add ( 'with async content with polling' , ( ) => (
137
- < Unveil >
138
- < AsyncComponent onComplete = { undefined } />
139
- </ Unveil >
206
+ < AsyncUnveil poll >
207
+ < AsyncComponent />
208
+ </ AsyncUnveil >
140
209
) )
141
- . add ( 'with async content without polling ' , ( ) => (
142
- < Unveil >
143
- < AsyncComponent onComplete = { undefined } />
144
- </ Unveil >
210
+ . add ( 'with async ' , ( ) => (
211
+ < AsyncUnveil >
212
+ < AsyncComponent />
213
+ </ AsyncUnveil >
145
214
) )
146
215
. add ( 'with children shorter than maxHeight' , ( ) => (
147
216
< Unveil >
@@ -162,36 +231,36 @@ storiesOf('React Unveil', module)
162
231
const More = expand => ( ) => < div > Show More</ div > ;
163
232
const Less = collapse => ( ) => < div > Show More</ div > ;
164
233
return (
165
- < Unveil >
166
- < RichContent />
167
- </ Unveil >
234
+ < AsyncUnveil >
235
+ < RichContent withImage />
236
+ </ AsyncUnveil >
168
237
) ;
169
238
} )
170
239
. add ( 'with custom styles' , ( ) => (
171
- < Unveil
240
+ < AsyncUnveil
172
241
style = { {
173
242
border : '1px solid blue' ,
174
243
padding : 4 ,
175
244
} }
176
245
>
177
246
< RichContent />
178
- </ Unveil >
247
+ </ AsyncUnveil >
179
248
) )
180
249
. add ( 'with initially expanded state' , ( ) => (
181
- < Unveil expanded >
182
- < RichContent />
183
- </ Unveil >
250
+ < AsyncUnveil expanded >
251
+ < RichContent withImage />
252
+ </ AsyncUnveil >
184
253
) )
185
254
. add ( 'with callbacks' , ( ) => (
186
- < Unveil
255
+ < AsyncUnveil
187
256
onMoreClick = { ( ) => alert ( 'Clicked more!' ) }
188
257
onLessClick = { ( ) => alert ( 'Clicked less!' ) }
189
258
>
190
- < RichContent />
191
- </ Unveil >
259
+ < RichContent withImage />
260
+ </ AsyncUnveil >
192
261
) )
193
262
. add ( 'without show less button' , ( ) => (
194
- < Unveil less = { null } >
195
- < RichContent />
196
- </ Unveil >
263
+ < AsyncUnveil less = { ( ) => < div /> } >
264
+ < RichContent withImage />
265
+ </ AsyncUnveil >
197
266
) ) ;
0 commit comments