-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.tsx
48 lines (42 loc) · 1.27 KB
/
index.tsx
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
import React, { useState } from 'react';
import Graphic from '../Graphic';
import { loremIpsum } from 'lorem-ipsum';
import Scrollyteller, { PanelDefinition } from '../../../../.';
type MarkerData = {
index: number;
number: number;
};
interface AppProps {}
// Generate some example panels for use in the <Scrollyteller> component.
const text = loremIpsum({ count: 7, units: 'paragraph' });
const pars = text.split('\n').map((t, i) => <p key={i}>{t}</p>);
const panels: PanelDefinition<MarkerData>[] = text.split('\n').map((t, i) => {
const p = document.createElement('p');
p.textContent = t;
return {
data: { index: i, number: i + 1 },
nodes: [p],
};
});
const App: React.FC<AppProps> = () => {
const [data, setData] = useState<MarkerData>(null!);
const [progress, setProgress] = useState<number>(null!);
const [counter, setCounter] = useState<number>(0);
return (
<>
{pars}
<Scrollyteller<MarkerData>
panels={panels}
onMarker={(data) => {
setData(data);
setCounter(counter + 1);
}}
onProgress={({ pctAboveFold }) => setProgress(pctAboveFold)}
>
<Graphic panel={data?.number} progress={progress} counter={counter} />
</Scrollyteller>
{pars}
</>
);
};
export default App;