-
Notifications
You must be signed in to change notification settings - Fork 310
/
ExampleCustomComponentSelection.js
40 lines (35 loc) · 1.06 KB
/
ExampleCustomComponentSelection.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
import React, { useState, useCallback } from 'react';
import Gallery from 'react-photo-gallery';
import SelectedImage from './SelectedImage';
function ExampleCustomComponentSelection({ photos }) {
const [images, setImages] = useState(photos);
const [selectAll, setSelectAll] = useState(false);
const toggleSelectAll = () => {
setSelectAll(!selectAll);
};
const imageRenderer = useCallback(
({ index, left, top, key, containerHeight, photo }) => (
<SelectedImage
selected={selectAll ? true : false}
key={key}
margin={'2px'}
index={index}
photo={photo}
left={left}
top={top}
/>
),
[selectAll]
);
return (
<div>
<h2>Using the ImageComponent prop</h2>
<h3>Pass in a custom image component to create any visual representation such as selection</h3>
<p>
<button onClick={toggleSelectAll}>toggle select all</button>
</p>
<Gallery photos={images} renderImage={imageRenderer} />
</div>
);
}
export default ExampleCustomComponentSelection;