-
Notifications
You must be signed in to change notification settings - Fork 42
/
article-body-row.web.js
171 lines (166 loc) · 4.47 KB
/
article-body-row.web.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React from "react";
import PropTypes from "prop-types";
import Ad from "@times-components/ad";
import ArticleImage from "@times-components/article-image";
import InteractiveWrapper from "@times-components/interactive-wrapper";
import KeyFacts from "@times-components/key-facts";
import { renderTree } from "@times-components/markup-forest";
import coreRenderers from "@times-components/markup";
import PullQuote from "@times-components/pull-quote";
import Video from "@times-components/video";
import BodyParagraph from "./article-body-paragraph";
import ArticleLink from "./article-link";
import AspectRatioContainer from "../media-aspect-ratio";
import InsetCaption from "./inset-caption";
import {
PrimaryImg,
SecondaryImg,
InlineImg,
InteractiveContainer,
PullQuoteContainer,
PullQuoteResp
} from "../styles/article-body/responsive";
import styles from "../styles/article-body";
export const responsiveDisplayWrapper = displayType => {
switch (displayType) {
case "secondary":
return SecondaryImg;
case "inline":
return InlineImg;
default:
return PrimaryImg;
}
};
const ArticleRow = ({ content: { data, index } }) =>
renderTree(data, {
...coreRenderers,
ad(key, attributes) {
return {
element: (
<Ad
key={key}
slotName="inline-ad"
style={styles.ad}
{...attributes}
/>
)
};
},
paragraph(key, attributes, children) {
return {
element: (
<BodyParagraph key={key} uid={index}>
{children}
</BodyParagraph>
)
};
},
image(key, { display, ratio, url, caption, credits }) {
const MediaWrapper = responsiveDisplayWrapper(display);
return {
element: (
<MediaWrapper key={key}>
<ArticleImage
captionOptions={{
caption,
credits
}}
imageOptions={{
display,
ratio,
uri: url
}}
/>
</MediaWrapper>
)
};
},
video(
key,
{
brightcovePolicyKey,
brightcoveVideoId,
brightcoveAccountId,
posterImageUrl,
caption,
skySports
}
) {
const MediaWrapper = responsiveDisplayWrapper("primary");
return {
element: (
<MediaWrapper key={key}>
<figure style={{ margin: 0 }}>
<AspectRatioContainer aspectRatio="16:9">
<Video
accountId={brightcoveAccountId}
height="100%"
policyKey={brightcovePolicyKey}
poster={{ uri: posterImageUrl }}
skySports={skySports}
videoId={brightcoveVideoId}
width="100%"
/>
</AspectRatioContainer>
<figcaption>
<InsetCaption caption={caption} />
</figcaption>
</figure>
</MediaWrapper>
)
};
},
pullQuote(key, { content, caption: { name, twitter } }) {
return {
element: (
<PullQuoteContainer key={key}>
<PullQuoteResp>
<PullQuote caption={name} content={content} twitter={twitter} />
</PullQuoteResp>
</PullQuoteContainer>
)
};
},
keyFacts(key, attributes, renderedChildren, indx, node) {
return {
element: <KeyFacts ast={node} key={key} />,
shouldRenderChildren: false
};
},
link(key, attributes, children) {
const { href, target } = attributes;
return {
element: (
<ArticleLink key={key} target={target} url={href} uuid={index}>
{children}
</ArticleLink>
)
};
},
interactive(key, { url, element }) {
const { attributes, value } = element;
return {
element: (
<InteractiveContainer>
<InteractiveWrapper
attributes={attributes}
element={value}
key={key}
source={url}
/>
</InteractiveContainer>
)
};
}
});
ArticleRow.propTypes = {
content: PropTypes.shape({
data: PropTypes.shape({
attributes: PropTypes.object,
children: PropTypes.arrayOf(PropTypes.object),
name: PropTypes.string
}),
index: PropTypes.number
}).isRequired
};
export default ArticleRow;