File size: 1,516 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { Button, FormLabel } from '@automattic/components';
import { createRef, PureComponent } from 'react';
import FormCheckbox from 'calypso/components/forms/form-checkbox';
import PostLikes from '../';
import PostLikesPopover from '../popover';

class PostLikesExample extends PureComponent {
	popoverContext = createRef();

	state = {
		showDisplayNames: false,
		showPopover: false,
	};

	toggleDisplayNames = () => {
		this.setState( {
			showDisplayNames: ! this.state.showDisplayNames,
		} );
	};

	togglePopover = () => {
		this.setState( {
			showPopover: ! this.state.showPopover,
		} );
	};

	closePopover = () => {
		this.setState( {
			showPopover: false,
		} );
	};

	render() {
		return (
			<div>
				<FormLabel>
					<FormCheckbox
						onChange={ this.toggleDisplayNames }
						checked={ this.state.showDisplayNames }
					/>
					<span>Show display names</span>
				</FormLabel>
				<PostLikes
					siteId={ 3584907 }
					postId={ 37769 }
					showDisplayNames={ this.state.showDisplayNames }
				/>
				<Button ref={ this.popoverContext } onClick={ this.togglePopover }>
					Toggle likes popover
				</Button>
				{ this.state.showPopover && (
					<PostLikesPopover
						siteId={ 3584907 }
						postId={ 39717 }
						showDisplayNames={ this.state.showDisplayNames }
						context={ this.popoverContext.current }
						position="bottom"
						onClose={ this.closePopover }
					/>
				) }
			</div>
		);
	}
}

PostLikesExample.displayName = 'PostLikes';

export default PostLikesExample;