@@ -51,6 +51,12 @@ export default class AdaptiveLoad extends Component {
51
51
webpSize : PropTypes . number ,
52
52
/** function which decides if image should be downloaded */
53
53
shouldAutoDownload : PropTypes . func ,
54
+ /** URL of the image in webp format */
55
+ webp : PropTypes . oneOfType ( [
56
+ PropTypes . string ,
57
+ PropTypes . func ,
58
+ PropTypes . bool ,
59
+ ] ) ,
54
60
55
61
// for testing
56
62
/** If you will not pass this value, component will detect onLine status based on browser API, otherwise will use passed value */
@@ -191,7 +197,7 @@ export default class AdaptiveLoad extends Component {
191
197
} )
192
198
}
193
199
194
- load = async userTriggered => {
200
+ load = userTriggered => {
195
201
const { loadState} = this . state
196
202
if ( ssr || loaded === loadState || loading === loadState ) return
197
203
this . loadStateChange ( loading , userTriggered )
@@ -260,19 +266,21 @@ export default class AdaptiveLoad extends Component {
260
266
case loading :
261
267
return overThreshold ? icons . loading : icons . noicon
262
268
case initial :
263
- return ! onLine
264
- ? icons . offline
265
- : userTriggered || ! shouldAutoDownload
269
+ if ( onLine ) {
270
+ return userTriggered || ! shouldAutoDownload
266
271
? icons . load
267
272
: icons . noicon
273
+ } else {
274
+ return icons . offline
275
+ }
268
276
case error :
269
- return ! onLine ? icons . offline : icons . error
277
+ return onLine ? icons . error : icons . offline
270
278
default :
271
279
throw new Error ( `Wrong state: ${ loadState } ` )
272
280
}
273
281
}
274
282
275
- onEnter = async ( ) => {
283
+ onEnter = ( ) => {
276
284
if ( this . state . inViewport ) return
277
285
this . setState ( { inViewport : true } )
278
286
if ( this . shouldAutoDownload ( ) ) this . load ( false )
0 commit comments