/
Example.tsx
73 lines (65 loc) · 1.85 KB
/
Example.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
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
import * as React from 'react';
import Gallery from 'react-photo-gallery';
import * as GooglePhoto from 'react-google-photo';
// https://unsplash.com/collections/589374/textures
const images = [
{
src:
'https://images.unsplash.com/photo-1509420316987-d27b02f81864?dpr=1&auto=format&fit=crop&w=1500&q=80&cs=tinysrgb&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D',
width: 1500,
height: 1000,
},
{
src:
'https://images.unsplash.com/photo-1509641498745-13c26fd1ed89?dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D',
width: 666,
height: 1000,
},
{
src:
'https://images.unsplash.com/photo-1491146179969-d674118945ff?dpr=1&auto=format&fit=crop&w=1500&q=80&cs=tinysrgb&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D',
width: 1500,
height: 844,
},
];
interface State {
index: number;
open: boolean;
}
export class Example extends React.Component<{}, State> {
state = {
index: 0,
open: false,
};
handleClickPrev = () => {
this.setState({ index: this.state.index - 1 });
};
handleClickNext = () => {
this.setState({ index: this.state.index + 1 });
};
handleClose = () => {
this.setState({ open: false });
};
handleClickGallery = (e: any, data: any) => {
this.setState({ open: true, index: data.index });
};
render() {
const { open, index } = this.state;
return (
<React.Fragment>
<Gallery photos={images} onClick={this.handleClickGallery} />
<GooglePhoto
open={open}
src={images}
srcIndex={index}
onClickPrev={this.handleClickPrev}
onClickNext={this.handleClickNext}
onClose={this.handleClose}
/>
<a href="https://github.com/pradel/react-google-photo/blob/master/docs/src/components/Example.tsx">
Source code
</a>
</React.Fragment>
);
}
}