-
Notifications
You must be signed in to change notification settings - Fork 42
/
article-topic.js
51 lines (48 loc) · 1.42 KB
/
article-topic.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
41
42
43
44
45
46
47
48
49
50
51
import React from "react";
import Context from "@times-components/context";
import { Text, View } from "react-native";
import Link from "@times-components/link";
import { withTrackEvents } from "@times-components/tracking";
import styles from "./styles";
import topicPropTypes from "./article-topic-prop-types";
const ArticleTopic = ({ fontSize, lineHeight, name, onPress, slug }) => {
const fontSizeStyle = fontSize ? { fontSize } : null;
const lineHeightStyle = lineHeight ? { lineHeight } : null;
return (
<Context.Consumer>
{({ makeTopicUrl }) => (
<View style={styles.spacer}>
<Link
onPress={e => onPress(e, { name, slug })}
url={makeTopicUrl({ slug })}
>
<View style={styles.container}>
<Text
accessibilityComponentType="button"
accessibilityRole="button"
accessibilityTraits="button"
style={[styles.text, fontSizeStyle, lineHeightStyle]}
>
{name}
</Text>
</View>
</Link>
</View>
)}
</Context.Consumer>
);
};
ArticleTopic.propTypes = topicPropTypes;
export default withTrackEvents(ArticleTopic, {
analyticsEvents: [
{
actionName: "Pressed",
eventName: "onPress",
getAttrs: ({ name, slug }) => ({
name,
slug
}),
trackingName: "TopicLink"
}
]
});