-
-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathArticleGroup.js
More file actions
64 lines (58 loc) · 1.9 KB
/
ArticleGroup.js
File metadata and controls
64 lines (58 loc) · 1.9 KB
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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import OutboundLink from 'components/_common_/OutboundLink/OutboundLink';
import Button from 'components/_common_/Button/Button';
import styles from './ArticleGroup.css';
class ArticleGroup extends Component {
static propTypes = {
articles: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
}),
).isRequired,
numberOfInitiallyVisibleLinks: PropTypes.number.isRequired,
region: PropTypes.string.isRequired,
};
state = {
areAllLinksVisible: false,
};
clickHandler = () => {
this.setState(prevState => ({ areAllLinksVisible: !prevState.areAllLinksVisible }));
};
render() {
const { areAllLinksVisible } = this.state;
const { articles, region, numberOfInitiallyVisibleLinks } = this.props;
return (
<div className={styles.articlesGroup}>
<h2>{region}</h2>
<ul>
{articles.map((link, index) => {
const isArticleVisible = areAllLinksVisible || index < numberOfInitiallyVisibleLinks;
return isArticleVisible ? (
<li key={`GroupLink_${link.url}`}>
<OutboundLink
href={link.url}
analyticsEventLabel="Press Article"
>
{link.title}
</OutboundLink>
</li>
) : null;
})}
</ul>
{articles.length > numberOfInitiallyVisibleLinks && (
<Button
aria-pressed={areAllLinksVisible}
className={styles.areAllLinksVisibleButton}
theme={areAllLinksVisible ? 'slate' : 'primary'}
onClick={this.clickHandler}
>
{areAllLinksVisible ? 'Show Less' : 'Show All'}
</Button>
)}
</div>
);
}
}
export default ArticleGroup;