-
Notifications
You must be signed in to change notification settings - Fork 4k
/
VisibilityExampleCallbackFrequency.js
134 lines (126 loc) · 4.3 KB
/
VisibilityExampleCallbackFrequency.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import _ from 'lodash'
import React, { Component, createRef } from 'react'
import {
Button,
Checkbox,
Divider,
Grid,
Image,
Label,
Ref,
Segment,
Sticky,
Visibility,
} from 'semantic-ui-react'
export default class VisibilityExampleCallbackFrequency extends Component {
state = {
continuous: false,
log: [],
logCount: 0,
once: true,
}
contextRef = createRef()
updateLog = (eventName) => () =>
this.setState((prevState) => ({
log: [
`${new Date().toLocaleTimeString()}: ${eventName}`,
...prevState.log,
].slice(0, 20),
logCount: prevState.logCount + 1,
}))
clearLog = () => this.setState({ log: [], logCount: 0 })
toggleOnce = () => this.setState((prevState) => ({ once: !prevState.once }))
toggleContinuous = () =>
this.setState((prevState) => ({ continuous: !prevState.continuous }))
render() {
const { continuous, log, logCount, once } = this.state
return (
<Ref innerRef={this.contextRef}>
<Grid columns={2}>
<Grid.Column>
<Visibility
continuous={continuous}
once={once}
onTopVisible={this.updateLog('onTopVisible')}
onTopPassed={this.updateLog('onTopPassed')}
onBottomVisible={this.updateLog('onBottomVisible')}
onBottomPassed={this.updateLog('onBottomPassed')}
onTopVisibleReverse={this.updateLog('onTopVisibleReverse')}
onTopPassedReverse={this.updateLog('onTopPassedReverse')}
onBottomVisibleReverse={this.updateLog('onBottomVisibleReverse')}
onBottomPassedReverse={this.updateLog('onBottomPassedReverse')}
onPassing={this.updateLog('onPassing')}
onPassingReverse={this.updateLog('onPassingReverse')}
onOnScreen={this.updateLog('onOnScreen')}
onOffScreen={this.updateLog('onOffScreen')}
>
<Segment>
{_.map(
[
'/images/wireframe/centered-paragraph.png',
'/images/wireframe/short-paragraph.png',
'/images/wireframe/media-paragraph.png',
'/images/wireframe/paragraph.png',
'/images/wireframe/centered-paragraph.png',
'/images/wireframe/short-paragraph.png',
'/images/wireframe/media-paragraph.png',
'/images/wireframe/paragraph.png',
'/images/wireframe/centered-paragraph.png',
'/images/wireframe/short-paragraph.png',
'/images/wireframe/media-paragraph.png',
'/images/wireframe/paragraph.png',
],
(src, index, images) => (
<React.Fragment key={index}>
<Image src={src} />
{index !== images.length - 1 && <Divider />}
</React.Fragment>
),
)}
</Segment>
</Visibility>
</Grid.Column>
<Grid.Column>
<Sticky context={this.contextRef}>
<Segment.Group>
<Segment>
<Checkbox
checked={once}
label='Once'
onChange={this.toggleOnce}
toggle
/>
<Divider />
<Checkbox
checked={continuous}
label='Continuous'
onChange={this.toggleContinuous}
toggle
/>
</Segment>
<Segment>
<Button
compact
size='small'
floated='right'
onClick={this.clearLog}
>
Clear
</Button>
Event Log <Label circular>{logCount}</Label>
</Segment>
<Segment secondary>
<pre>
{log.map((e, i) => (
<div key={i}>{e}</div>
))}
</pre>
</Segment>
</Segment.Group>
</Sticky>
</Grid.Column>
</Grid>
</Ref>
)
}
}