@@ -3,6 +3,7 @@ import { storiesOf } from '@storybook/react'
3
3
import { Code , Result } from '../components'
4
4
import MobileBreakpoint from '../components/MobileBreakpoint'
5
5
import withSizes from '../../src/withSizes'
6
+ import SizesProvider from '../../src/SizesProvider'
6
7
7
8
const mapSizesToProps = sizes => ( {
8
9
backgroundColor : sizes . width > 800 ? 'green' : 'blue' ,
@@ -24,6 +25,33 @@ const ExampleSizedComponent = withSizes(mapSizesToProps)(
24
25
)
25
26
)
26
27
28
+ class ForceFallbackExample extends React . Component {
29
+ state = {
30
+ forceFallback : true ,
31
+ }
32
+
33
+ componentDidMount ( ) {
34
+ setTimeout ( ( ) => {
35
+ this . setState ( { forceFallback : false } )
36
+ } , 5000 )
37
+ }
38
+
39
+ render ( ) {
40
+ const { forceFallback } = this . state
41
+
42
+ return (
43
+ < SizesProvider
44
+ config = { { fallbackHeight : 640 , fallbackWidth : 280 , forceFallback } }
45
+ >
46
+ < Result >
47
+ { forceFallback && < p > Forcing fallback to mobile</ p > }
48
+ < ExampleSizedComponent />
49
+ </ Result >
50
+ </ SizesProvider >
51
+ )
52
+ }
53
+ }
54
+
27
55
storiesOf ( 'Sizes' , module )
28
56
. add ( 'default behavior' , ( ) => (
29
57
< div >
@@ -54,11 +82,11 @@ const ExampleSizedComponent = withSizes(mapSizesToProps)(
54
82
</ Code >
55
83
</ div >
56
84
) )
57
-
58
85
. add ( 'mobileBreakpoint' , ( ) => (
59
86
< div >
60
87
< MobileBreakpoint breakpoint = { 300 } />
61
88
< MobileBreakpoint breakpoint = { 500 } />
62
89
< MobileBreakpoint breakpoint = { 700 } />
63
90
</ div >
64
91
) )
92
+ . add ( 'force fallback' , ( ) => < ForceFallbackExample /> )
0 commit comments