summaryrefslogtreecommitdiff
blob: c0df631a7521f71af28e6cbcdbcecb637498ec76 (plain)
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
/**
 * External Dependencies
 */
import React from 'react';

/**
 * Internal Dependencies
 */
import SimpleNotice from 'components/notice/index.jsx';
import NoticeAction from 'components/notice/notice-action';

import './style.scss';

/**
 * NoticesList component
 *
 * @param {*} props - Props
 * @returns {React.Component}	- NoticesList component
 */
export default function NoticesList(
	props = { handleLocalNoticeDismissClick: null, notices: Object.freeze( [] ) }
) {
	const noticesList = props.notices.map( function ( notice ) {
		const onDismissClick = theNotice => () => {
			theNotice && props.handleLocalNoticeDismissClick( theNotice.id );
		};
		return (
			<SimpleNotice
				key={ 'notice-' + notice.id }
				status={ notice.status }
				duration={ notice.duration || null }
				text={ notice.text }
				isCompact={ notice.isCompact }
				onDismissClick={ onDismissClick( notice ) }
				showDismiss={ notice.showDismiss }
			>
				{ notice.button && (
					<NoticeAction href={ notice.href } onClick={ onDismissClick( notice ) }>
						{ notice.button }
					</NoticeAction>
				) }
			</SimpleNotice>
		);
	} );

	if ( ! noticesList.length ) {
		return null;
	}

	return (
		<div id={ props.id } className="global-notices">
			{ noticesList }
		</div>
	);
}