-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.js
More file actions
100 lines (90 loc) · 2.16 KB
/
dev.js
File metadata and controls
100 lines (90 loc) · 2.16 KB
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
/* eslint-disable unicorn/no-abusive-eslint-disable */
import * as React from 'react'
import { render } from 'react-dom'
import InView from './src'
import { bool, func, number } from 'prop-types'
import marked from 'marked'
const colors = [
'#f47467',
'#95dd12',
'#24c0ed',
'#0af1ba',
'#decced',
'#bdf6c0',
'#e7ee28',
'#e08388',
'#62fd1e',
'#eaa30a',
]
class Box extends React.Component {
static propTypes = {
isInView: bool,
i: number.isRequired,
updateNumber: func.isRequired,
}
// eslint-disable-next-line
componentWillReceiveProps(nextProps) {
if (nextProps.isInView && !this.props.isInView) {
this.props.updateNumber(this.props.i + 1)
}
}
render() {
const { i } = this.props
return (
<section className="box" style={{ backgroundColor: colors[i] }}>
<h3>slide number {i + 1}</h3>
</section>
)
}
}
class Demo extends React.Component {
state = { docs: '', n: 1 }
// eslint-disable-next-line
componentWillMount() {
window
.fetch(
'https://raw.githubusercontent.com/jane/react-now-you-see-me/master/README.md'
)
.then((a) => a.text())
.then((t) => {
this.setState({ docs: marked(t) })
})
// eslint-disable-next-line no-console
.catch(console.error)
}
updateNumber = (n) => {
this.setState({ n })
}
render() {
return (
<main className="wrapper">
<article
dangerouslySetInnerHTML={{ __html: this.state.docs }}
className="md"
/>
<h3>slide number {this.state.n} is in view</h3>
<div
style={{
display: 'flex',
flexDirection: 'row',
flexWrap: 'nowrap',
overflow: 'scroll',
}}
>
{new Array(10).fill().map((_, i) => (
<InView key={i} threshold={0}>
{(isInView) => (
<Box
updateNumber={this.updateNumber}
i={i}
isInView={isInView}
/>
)}
</InView>
))}
</div>
</main>
)
}
}
render(<Demo />, document.getElementById('root'))