File size: 2,017 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { Tooltip } from '@automattic/components';
import { localize } from 'i18n-calypso';
import { map } from 'lodash';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { CalendarEvent } from './event';

const noop = () => {};

class EventsTooltip extends Component {
	static propTypes = {
		title: PropTypes.string,
		events: PropTypes.array,
		maxEvents: PropTypes.number,
		moreEvents: PropTypes.string,
	};

	static defaultProps = {
		events: [],
		maxEvents: 8,
	};

	render() {
		const { events, isVisible, maxEvents } = this.props;

		let title = this.props.title;
		if ( ! title ) {
			title = this.props.translate( '%d post', '%d posts', {
				count: events.length,
				args: events.length,
			} );
		}

		const show = !! ( events && events.length && isVisible );
		const moreEvents = events.length - maxEvents;

		let moreEventsLabel = this.props.moreEventsLabel;

		if ( ! moreEventsLabel ) {
			moreEventsLabel = this.props.translate(
				'… and %(moreEvents)d more post',
				'… and %(moreEvents)d more posts',
				{
					count: moreEvents,
					args: {
						moreEvents,
					},
				}
			);
		}

		return (
			<Tooltip
				className="date-picker__events-tooltip"
				context={ this.props.context }
				isVisible={ show }
				onClose={ noop }
			>
				<span>{ title }</span>
				<hr className="date-picker__division" />
				<ul>
					{ map(
						events,
						( event, i ) =>
							i < maxEvents && (
								<li key={ event.id }>
									<CalendarEvent
										icon={ event.icon }
										socialIcon={ event.socialIcon }
										socialIconColor={ event.socialIconColor }
										title={
											event.title === ''
												? this.props.translate( '{{em}}(No title){{/em}}', {
														components: { em: <em /> },
												  } )
												: event.title
										}
									/>
								</li>
							)
					) }

					{ moreEvents > 0 && <li>{ moreEventsLabel }</li> }
				</ul>
			</Tooltip>
		);
	}
}

export default localize( EventsTooltip );