sfc-utils 1.4.56 → 1.4.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/datawrapper.mjs +31 -0
- package/components/helpers/utilfunctions.mjs +23 -2
- package/components/slideshow/imageslideshow.mjs +16 -0
- package/components/topper2.mjs +42 -10
- package/package.json +2 -2
- package/styles/modules/imageslideshow.module.less +9 -2
- package/styles/modules/topper2.module.less +42 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Helmet } from "react-helmet"
|
|
3
|
+
import { getFigureWidth } from './helpers/utilfunctions.mjs'
|
|
4
|
+
|
|
5
|
+
const Datawrapper = ({ altText, id, height, figureWidth = 'text-width' }) => {
|
|
6
|
+
|
|
7
|
+
const url = `https://datawrapper.dwcdn.net/${id}`
|
|
8
|
+
const nu_id = `datawrapper-chart-${id}`
|
|
9
|
+
|
|
10
|
+
// width options: float-left, float-right, text-width, large, wide, full
|
|
11
|
+
const width = getFigureWidth(figureWidth);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
{/* responsive DW script */}
|
|
16
|
+
<Helmet>
|
|
17
|
+
<script
|
|
18
|
+
type="text/javascript"
|
|
19
|
+
src="https://datawrapper.dwcdn.net/lib/embed.min.js"
|
|
20
|
+
></script>
|
|
21
|
+
</Helmet>
|
|
22
|
+
<div className={`iframe_Container graphic-wrapper inline-figure ${width}`}>
|
|
23
|
+
<figure>
|
|
24
|
+
<iframe title={altText} aria-label={altText} id={nu_id} src={url} scrolling="no" frameborder="0" style={{ width: 0, minWidth: "100%", border: "none" }} height={height}></iframe>
|
|
25
|
+
</figure>
|
|
26
|
+
</div>
|
|
27
|
+
</>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default Datawrapper
|
|
@@ -50,7 +50,7 @@ function appendLayoutScripts(isEmbedded, isAdRemoved, marketKey) {
|
|
|
50
50
|
document.body.appendChild(script)
|
|
51
51
|
|
|
52
52
|
// Init sailthru
|
|
53
|
-
if (window && window.Sailthru && marketKey){
|
|
53
|
+
if (window && window.Sailthru && marketKey) {
|
|
54
54
|
window.Sailthru.init({ customerId: getBrands2(marketKey).attributes.sailCustomer })
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -81,4 +81,25 @@ function formatHDN(isEmbedded, url_add, meta) {
|
|
|
81
81
|
return stringHDN;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
function getFigureWidth(maxWidth) {
|
|
85
|
+
switch (maxWidth) {
|
|
86
|
+
case "text-width":
|
|
87
|
+
return "text-width";
|
|
88
|
+
case "large":
|
|
89
|
+
return "large mw-lg mt-md mb-md ml-auto mr-auto";
|
|
90
|
+
case "wide":
|
|
91
|
+
return "wide mw-xl mt-md mb-md ml-auto mr-auto";
|
|
92
|
+
case "full":
|
|
93
|
+
return "full mw-100 mt-md mb-md ml-auto mr-auto";
|
|
94
|
+
case "embed":
|
|
95
|
+
return "mw-xl ml-auto mr-auto";
|
|
96
|
+
case "float-right":
|
|
97
|
+
return "float-right";
|
|
98
|
+
case "float-left":
|
|
99
|
+
return "float-left";
|
|
100
|
+
default:
|
|
101
|
+
return "text-width";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { debounce, appendLayoutScripts, formatHDN, getFigureWidth }
|
|
@@ -28,6 +28,22 @@ const ImageSlideshow = ({ wcmData, imageList, altList, topperStyle, isLayoutInve
|
|
|
28
28
|
};
|
|
29
29
|
}, [index]);
|
|
30
30
|
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
// Find the max height ratio within an wcm image list, this is only used for the small visual slideshow
|
|
33
|
+
if (wcmData.nodes) {
|
|
34
|
+
let ratioList = wcmData.nodes.map((d) => d.photo.ratio)
|
|
35
|
+
console.log(ratioList)
|
|
36
|
+
let minRatio = Math.max(...ratioList)
|
|
37
|
+
|
|
38
|
+
// During server-side rendering, access to ":root" is unavailable. This is okay; we just need
|
|
39
|
+
// to make sure that the site does not crash during SSR
|
|
40
|
+
let r = (typeof window != "undefined") ? document.querySelector(':root') : null;
|
|
41
|
+
if (r) {
|
|
42
|
+
r.style.setProperty('--small-visual-height-ratio', minRatio);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}, [])
|
|
46
|
+
|
|
31
47
|
const getContainerClass = () => {
|
|
32
48
|
switch (topperStyle) {
|
|
33
49
|
case "stacked":
|
package/components/topper2.mjs
CHANGED
|
@@ -6,13 +6,14 @@ import CaptionCreditSlideshow from "./slideshow/captioncreditslideshow.mjs"
|
|
|
6
6
|
import ImageSlideshow from "./slideshow/imageslideshow.mjs"
|
|
7
7
|
import * as topperStyles from "../styles/modules/topper2.module.less"
|
|
8
8
|
import * as imageStyles from "../styles/modules/topperimage.module.less"
|
|
9
|
+
import Datawrapper from "./datawrapper.mjs"
|
|
9
10
|
|
|
10
11
|
const Topper2 = ({ settings, wcmData, mods }) => {
|
|
11
12
|
let {
|
|
12
|
-
Topper_Style, Title, Title_Style, Deck, Image, Image_Alt, Kicker, Video_Mp4,
|
|
13
|
-
HeaderDek_Vertical_Position, HeaderDek_Vertical_Offset,
|
|
14
|
-
HeaderDek_Horizontal_Position, Inverted_Colors, Inverted_Layout,
|
|
15
|
-
Topper_Background_Color, Small_Visual_Max_Width, Small_Visual_Topper_Url
|
|
13
|
+
Topper_Style, Title, Title_Style, Deck, Image, Image_Alt, Kicker, Video_Mp4, Datawrapper_Id,
|
|
14
|
+
Image_Caption, Image_Credits, HeaderDek_Vertical_Position, HeaderDek_Vertical_Offset,
|
|
15
|
+
HeaderDek_Horizontal_Offset, HeaderDek_Horizontal_Position, Inverted_Colors, Inverted_Layout,
|
|
16
|
+
Inverted_Text_Color, Topper_Background_Color, Small_Visual_Max_Width, Small_Visual_Topper_Url
|
|
16
17
|
} = settings
|
|
17
18
|
|
|
18
19
|
// During server-side rendering, access to ":root" is unavailable. This is okay; we just need
|
|
@@ -216,6 +217,11 @@ const Topper2 = ({ settings, wcmData, mods }) => {
|
|
|
216
217
|
return (wcmIdList.length > 1);
|
|
217
218
|
}
|
|
218
219
|
|
|
220
|
+
/** Checks if the media type is a datawrapper chart */
|
|
221
|
+
const isDatawrapper = () => {
|
|
222
|
+
return Datawrapper_Id && Datawrapper_Id !== 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
219
225
|
/** Converts string from spreadsheet into a list and pads the list if the length is incorrect */
|
|
220
226
|
const convertStringToList = (str, size) => {
|
|
221
227
|
// If the string is empty (ie caption/credit is not filled out), return early
|
|
@@ -262,8 +268,18 @@ const Topper2 = ({ settings, wcmData, mods }) => {
|
|
|
262
268
|
)
|
|
263
269
|
}
|
|
264
270
|
|
|
271
|
+
const getDatawrapperHtml = () => {
|
|
272
|
+
let datawrapperCss = ""
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<Datawrapper altText={Image_Alt} id={Datawrapper_Id} />
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
|
|
265
279
|
/* Returns the corresponding image HTML for each topper style and slideshow status */
|
|
266
280
|
const getMediaHTML = (isSlideshow) => {
|
|
281
|
+
if (isDatawrapper()) return getDatawrapperHtml();
|
|
282
|
+
|
|
267
283
|
if (Video_Mp4) return getVideoHtml();
|
|
268
284
|
|
|
269
285
|
if (isSlideshow) return (
|
|
@@ -426,17 +442,18 @@ const Topper2 = ({ settings, wcmData, mods }) => {
|
|
|
426
442
|
extraStyles={[topperStyles.smallPaddingLeftWhenTablet]}
|
|
427
443
|
/>
|
|
428
444
|
}
|
|
429
|
-
{!isSlideshow(wcmIdList) && <CaptionCredit caption={Image_Caption} credit={Image_Credits} extraStyles={[topperStyles.smallPaddingLeftWhenTablet]} />}
|
|
445
|
+
{!isSlideshow(wcmIdList) && (!isDatawrapper()) && <CaptionCredit caption={Image_Caption} credit={Image_Credits} extraStyles={[topperStyles.smallPaddingLeftWhenTablet]} />}
|
|
430
446
|
</figure>
|
|
431
447
|
</div>
|
|
432
448
|
</>
|
|
433
449
|
);
|
|
434
450
|
|
|
435
451
|
case "small-visual":
|
|
452
|
+
let smallVisualCss = (isDatawrapper()) ? `${topperStyles.imageSmallVisualDatawrapper}` : `${topperStyles.imageSmallVisual}`;
|
|
436
453
|
return (
|
|
437
454
|
<>
|
|
438
455
|
<div>
|
|
439
|
-
<figure className={`mw-xl ml-auto mr-auto ${
|
|
456
|
+
<figure className={`mw-xl ml-auto mr-auto ${smallVisualCss}`}>
|
|
440
457
|
{getMediaHTML(isSlideshow(wcmIdList))}
|
|
441
458
|
</figure>
|
|
442
459
|
{Kicker && <Heading level={6} text={Kicker} className={kickerStyleList().join(' ')} />}
|
|
@@ -478,7 +495,15 @@ const Topper2 = ({ settings, wcmData, mods }) => {
|
|
|
478
495
|
);
|
|
479
496
|
|
|
480
497
|
case "side-by-side":
|
|
481
|
-
let figureCss =
|
|
498
|
+
let figureCss = "";
|
|
499
|
+
if (isSlideshow(wcmIdList)) {
|
|
500
|
+
figureCss = `${topperStyles.imageSideBySideSlideshow}`
|
|
501
|
+
} else if (isDatawrapper()) {
|
|
502
|
+
figureCss = `${topperStyles.imageSideBySideDatawrapper}`
|
|
503
|
+
} else {
|
|
504
|
+
figureCss = `${topperStyles.imageSideBySide}`
|
|
505
|
+
}
|
|
506
|
+
|
|
482
507
|
let sideBySideContainerCss = (Inverted_Layout === "headerdek-right-image-left") ? `${topperStyles.topperContainerSideBySide} ${topperStyles.reverseFlexbox}` : `${topperStyles.topperContainerSideBySide}`;
|
|
483
508
|
setBackgroundAndTextColor();
|
|
484
509
|
return (
|
|
@@ -508,13 +533,20 @@ const Topper2 = ({ settings, wcmData, mods }) => {
|
|
|
508
533
|
creditStyles={[sideBySideCapCredColorCss()]}
|
|
509
534
|
/>
|
|
510
535
|
}
|
|
511
|
-
{!isSlideshow(wcmIdList) && <CaptionCredit caption={Image_Caption} credit={Image_Credits} extraStyles={[topperStyles.captionSideBySide, sideBySideCapCredColorCss()]} creditStyles={[sideBySideCapCredColorCss()]} />}
|
|
536
|
+
{!isSlideshow(wcmIdList) && (!isDatawrapper()) && <CaptionCredit caption={Image_Caption} credit={Image_Credits} extraStyles={[topperStyles.captionSideBySide, sideBySideCapCredColorCss()]} creditStyles={[sideBySideCapCredColorCss()]} />}
|
|
512
537
|
</figure>
|
|
513
538
|
</div>
|
|
514
539
|
);
|
|
515
540
|
|
|
516
541
|
case "side-by-side-portrait":
|
|
517
|
-
let portraitFigureCss =
|
|
542
|
+
let portraitFigureCss = "";
|
|
543
|
+
if (isSlideshow(wcmIdList)) {
|
|
544
|
+
portraitFigureCss = `${topperStyles.imageSideBySidePortraitSlideshow}`
|
|
545
|
+
} else if (isDatawrapper()) {
|
|
546
|
+
portraitFigureCss = `${topperStyles.imageSideBySidePortraitDatawrapper}`
|
|
547
|
+
} else {
|
|
548
|
+
portraitFigureCss = `${topperStyles.imageSideBySidePortrait}`
|
|
549
|
+
}
|
|
518
550
|
let sideBySidePortraitContainerCss = (Inverted_Layout === "headerdek-right-image-left") ? `${topperStyles.topperContainerSideBySidePortrait} ${topperStyles.reverseFlexbox}` : `${topperStyles.topperContainerSideBySidePortrait}`;
|
|
519
551
|
setBackgroundAndTextColor();
|
|
520
552
|
return (
|
|
@@ -546,7 +578,7 @@ const Topper2 = ({ settings, wcmData, mods }) => {
|
|
|
546
578
|
creditStyles={[sideBySideCapCredColorCss()]}
|
|
547
579
|
/>
|
|
548
580
|
}
|
|
549
|
-
{!isSlideshow(wcmIdList) && <CaptionCredit caption={Image_Caption} credit={Image_Credits} extraStyles={[topperStyles.captionSideBySidePortrait, sideBySideCapCredColorCss(), sideBySidePortraitFloatCss()]} creditStyles={[sideBySideCapCredColorCss()]} />}
|
|
581
|
+
{!isSlideshow(wcmIdList) && (!isDatawrapper()) && <CaptionCredit caption={Image_Caption} credit={Image_Credits} extraStyles={[topperStyles.captionSideBySidePortrait, sideBySideCapCredColorCss(), sideBySidePortraitFloatCss()]} creditStyles={[sideBySideCapCredColorCss()]} />}
|
|
550
582
|
</figure>
|
|
551
583
|
</div>
|
|
552
584
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sfc-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.57",
|
|
4
4
|
"author": "ewagstaff <evanjwagstaff@gmail.com>",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"archieml": "^0.4.2",
|
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
"react-transition-group": "^4.4.5",
|
|
15
15
|
"write": "^2.0.0"
|
|
16
16
|
}
|
|
17
|
-
}
|
|
17
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
@import (less) '../values';
|
|
2
2
|
|
|
3
|
+
:root {
|
|
4
|
+
--small-visual-height-ratio: 2/3;
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
.container-stacked {
|
|
4
8
|
margin: 0 auto;
|
|
5
9
|
white-space: nowrap;
|
|
@@ -36,7 +40,7 @@
|
|
|
36
40
|
|
|
37
41
|
.container-small-visual {
|
|
38
42
|
width: 150px;
|
|
39
|
-
height: calc(150px*
|
|
43
|
+
height: calc(150px*var(--small-visual-height-ratio))
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
.image-wrapper-stacked {
|
|
@@ -69,7 +73,10 @@
|
|
|
69
73
|
.image-wrapper-small-visual {
|
|
70
74
|
position: absolute;
|
|
71
75
|
width: 150px;
|
|
72
|
-
|
|
76
|
+
right: 0;
|
|
77
|
+
left: 0;
|
|
78
|
+
bottom: 0;
|
|
79
|
+
margin: auto;
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
.image-wrapper-side-by-side-portrait {
|
|
@@ -98,6 +98,20 @@
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
.imageSmallVisualDatawrapper {
|
|
102
|
+
position: relative;
|
|
103
|
+
height: auto;
|
|
104
|
+
width: 100%;
|
|
105
|
+
margin: @s24 auto 0 auto;
|
|
106
|
+
|
|
107
|
+
@media (max-width: 960px) {
|
|
108
|
+
margin-left: @s16;
|
|
109
|
+
margin-right: @s16;
|
|
110
|
+
width: auto;
|
|
111
|
+
height: auto;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
101
115
|
.imageSideBySide {
|
|
102
116
|
width: 50%;
|
|
103
117
|
float: left;
|
|
@@ -110,6 +124,18 @@
|
|
|
110
124
|
}
|
|
111
125
|
}
|
|
112
126
|
|
|
127
|
+
.imageSideBySideDatawrapper {
|
|
128
|
+
width: 50%;
|
|
129
|
+
float: left;
|
|
130
|
+
padding: @s16;
|
|
131
|
+
|
|
132
|
+
@media (max-width: @lg) {
|
|
133
|
+
width: 100%;
|
|
134
|
+
float: none;
|
|
135
|
+
padding-bottom: 0;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
113
139
|
.imageSideBySideSlideshow {
|
|
114
140
|
width: 50%;
|
|
115
141
|
height: calc(50vw*2/3 + 10px);
|
|
@@ -136,6 +162,22 @@
|
|
|
136
162
|
}
|
|
137
163
|
}
|
|
138
164
|
|
|
165
|
+
.imageSideBySidePortraitDatawrapper {
|
|
166
|
+
width: 50%;
|
|
167
|
+
height: 90vh;
|
|
168
|
+
min-height: calc(600px + 32px);
|
|
169
|
+
float: left;
|
|
170
|
+
padding: @s16;
|
|
171
|
+
|
|
172
|
+
@media (max-width: @lg) {
|
|
173
|
+
width: 100%;
|
|
174
|
+
float: none;
|
|
175
|
+
height: auto;
|
|
176
|
+
padding-bottom: 0;
|
|
177
|
+
min-height: unset;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
139
181
|
.imageSideBySidePortraitSlideshow {
|
|
140
182
|
width: 50%;
|
|
141
183
|
height: 90vh;
|