sfc-utils 1.4.56 → 1.4.58

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.
@@ -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
- export { debounce, appendLayoutScripts, formatHDN }
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":
@@ -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, Image_Caption, Image_Credits,
13
- HeaderDek_Vertical_Position, HeaderDek_Vertical_Offset, HeaderDek_Horizontal_Offset,
14
- HeaderDek_Horizontal_Position, Inverted_Colors, Inverted_Layout, Inverted_Text_Color,
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 ${topperStyles.imageSmallVisual}`}>
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 = isSlideshow(wcmIdList) ? `${topperStyles.imageSideBySideSlideshow}` : `${topperStyles.imageSideBySide}`;
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 = isSlideshow(wcmIdList) ? `${topperStyles.imageSideBySidePortraitSlideshow}` : `${topperStyles.imageSideBySidePortrait}`;
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.56",
3
+ "version": "1.4.58",
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,9 +1,12 @@
1
- .hed, .deck{
1
+ .hed,
2
+ .deck {
2
3
  text-align: center;
3
4
  margin: @s16 0;
5
+
4
6
  &.left {
5
7
  text-align: left;
6
8
  }
9
+
7
10
  @media (max-width: 960px) {
8
11
  text-align: left;
9
12
  padding: 0 @s16;
@@ -14,28 +17,41 @@ h1 {
14
17
  font-size: 4rem;
15
18
  font-family: @hed;
16
19
  }
20
+
17
21
  //could the next three classes be moved into byline module?
18
22
  .byline-wrapper {
19
23
  max-width: @lg;
20
24
  border-bottom: 1px solid @grey-75;
21
25
  margin: @s16 auto @s24;
22
26
  padding-bottom: @s8;
27
+ display: flex;
28
+ flex-direction: row;
29
+ justify-content: space-between;
30
+ align-items: flex-end;
31
+
23
32
  @media (max-width: 960px) {
24
33
  margin: @s16 @s16 @s24;
25
34
  }
35
+
26
36
  @media (max-width: @md) {
27
- border-bottom: none; }
37
+ border-bottom: none;
38
+ display: block;
39
+ }
28
40
  }
41
+
29
42
  .byline-name {
30
- font-weight: 700;
43
+ font-weight: 700;
31
44
  }
32
45
 
33
46
  .byline {
34
47
  text-align: left;
35
48
  display: inline-block;
36
- a, a:visited {
49
+
50
+ a,
51
+ a:visited {
37
52
  text-decoration: none;
38
53
  color: @black;
54
+
39
55
  &:hover {
40
56
  color: @brand;
41
57
  }
@@ -48,23 +64,29 @@ h1 {
48
64
 
49
65
  // Handle basic embed classes
50
66
  .inline-figure {
51
- &.float-left, &.float-right {
67
+
68
+ &.float-left,
69
+ &.float-right {
52
70
  max-width: @xl;
53
71
  margin: 0 auto;
54
- @media (max-width: @xl){
72
+
73
+ @media (max-width: @xl) {
55
74
  max-width: @md;
56
75
  padding: 0 @s16;
57
76
  }
77
+
58
78
  figure {
59
79
  max-width: @xs;
60
80
  width: 100%;
61
- @media (max-width: @xl){
81
+
82
+ @media (max-width: @xl) {
62
83
  max-width: @md;
63
84
  float: none;
64
85
  margin: @s24 auto;
65
86
  }
66
87
  }
67
88
  }
89
+
68
90
  &.float-left {
69
91
  figure {
70
92
  float: left;
@@ -72,25 +94,31 @@ h1 {
72
94
  }
73
95
 
74
96
  }
97
+
75
98
  &.float-right {
76
99
  figure {
77
100
  float: right;
78
101
  margin-left: @s16;
79
102
  }
80
103
  }
104
+
81
105
  &.full {
82
106
  max-width: 100%;
83
107
  }
84
108
  }
85
109
 
86
- .inline-figure.wide, .inline-figure.full, .inline-figure.large {
110
+ .inline-figure.wide,
111
+ .inline-figure.full,
112
+ .inline-figure.large {
87
113
  &.graphic-wrapper {
88
114
  @media @max-desktop {
89
115
  padding: 0 @s16;
90
116
  }
91
117
  }
92
- .caption {
118
+
119
+ .caption {
93
120
  max-width: @w-text-width;
121
+
94
122
  @media @max-text-width {
95
123
  padding: 0 @s16;
96
124
  }
@@ -100,8 +128,8 @@ h1 {
100
128
  //side-by-side photos
101
129
  .side-by-side-wrapper {
102
130
  @media (max-width: 1200px) {
103
- padding-left: @s16;
104
- padding-right: @s16;
131
+ padding-left: @s16;
132
+ padding-right: @s16;
105
133
  }
106
134
  }
107
135
 
@@ -110,92 +138,109 @@ h1 {
110
138
  width: 100%;
111
139
  display: inline-block;
112
140
  vertical-align: top;
113
- @media (max-width: 1200px){
114
- width: calc(50% - 4px);
115
- // max-width: 640px;
141
+
142
+ @media (max-width: 1200px) {
143
+ width: calc(50% - 4px);
144
+ // max-width: 640px;
116
145
  }
146
+
117
147
  @media @tablet {
118
- width: 100%;
119
- max-width: 640px;
148
+ width: 100%;
149
+ max-width: 640px;
120
150
  }
121
151
  }
152
+
122
153
  .side-by-side-left {
123
154
  margin-right: @s4;
155
+
124
156
  @media @tablet {
125
- margin-bottom: @s8;
157
+ margin-bottom: @s8;
126
158
  }
127
159
  }
160
+
128
161
  .side-by-side-right {
129
162
  margin-left: @s4;
130
163
  }
131
164
 
132
- .side-by-side-left, .side-by-side-right{
165
+ .side-by-side-left,
166
+ .side-by-side-right {
133
167
  @media @tablet {
134
- margin-right: auto;
135
- margin-left: auto;
136
- display: block;
168
+ margin-right: auto;
169
+ margin-left: auto;
170
+ display: block;
137
171
  }
138
172
  }
173
+
139
174
  .side-by-side-caption-wrapper {
140
175
  margin-bottom: @s24;
141
176
  margin-top: @s4;
142
177
  line-height: 1.3;
178
+
143
179
  .caption {
144
- margin-bottom: 0;
145
- margin-top: 0;
146
- display: inline;
147
- padding: 0 !important;
180
+ margin-bottom: 0;
181
+ margin-top: 0;
182
+ display: inline;
183
+ padding: 0 !important;
148
184
  }
185
+
149
186
  @media @max-text-width {
150
- padding: 0;
187
+ padding: 0;
151
188
  }
152
189
  }
190
+
153
191
  .side-by-side-caption-left {
154
- &::before{
155
- content: "LEFT: ";
192
+ &::before {
193
+ content: "LEFT: ";
194
+ font-family: @sans;
195
+ font-size: @s14;
196
+ font-weight: 700;
197
+ color: @grey-75;
198
+ }
199
+
200
+ @media @tablet {
201
+ &::before {
202
+ content: "TOP: ";
156
203
  font-family: @sans;
157
204
  font-size: @s14;
158
205
  font-weight: 700;
159
206
  color: @grey-75;
160
- }
161
- @media @tablet{
162
- &::before{
163
- content: "TOP: ";
164
- font-family: @sans;
165
- font-size: @s14;
166
- font-weight: 700;
167
- color: @grey-75;
168
- }
207
+ }
169
208
  }
170
209
  }
210
+
171
211
  .side-by-side-caption-right {
172
- &::before{
173
- content: " RIGHT: ";
212
+ &::before {
213
+ content: " RIGHT: ";
214
+ font-family: @sans;
215
+ font-size: @s14;
216
+ font-weight: 700;
217
+ color: @grey-50;
218
+ }
219
+
220
+ @media @tablet {
221
+ &::before {
222
+ content: " BOTTOM: ";
174
223
  font-family: @sans;
175
224
  font-size: @s14;
176
225
  font-weight: 700;
177
226
  color: @grey-50;
178
- }
179
- @media @tablet{
180
- &::before{
181
- content: " BOTTOM: ";
182
- font-family: @sans;
183
- font-size: @s14;
184
- font-weight: 700;
185
- color: @grey-50;
186
- }
227
+ }
187
228
  }
188
229
  }
189
230
 
190
231
  //custom graphic
191
232
  .graphic-wrapper {
192
- &.inline-figure.wide, &.inline-figure.full, &.inline-figure.large {
233
+
234
+ &.inline-figure.wide,
235
+ &.inline-figure.full,
236
+ &.inline-figure.large {
193
237
  .caption {
194
- max-width: 100%;
195
- @media @max-text-width {
196
- padding: 0;
197
- }
198
- }
238
+ max-width: 100%;
239
+
240
+ @media @max-text-width {
241
+ padding: 0;
242
+ }
243
+ }
199
244
  }
200
245
  }
201
246
 
@@ -212,6 +257,7 @@ h1 {
212
257
  .caption {
213
258
  max-width: @lg;
214
259
  margin-bottom: @s8;
260
+
215
261
  @media (max-width: 960px) {
216
262
  padding: 0 @s16;
217
263
  }
@@ -242,6 +288,7 @@ a {
242
288
  a {
243
289
  text-decoration-color: @grey-75;
244
290
  }
291
+
245
292
  svg {
246
293
  height: 0.75rem;
247
294
  margin-left: @s4;
@@ -253,6 +300,7 @@ ul {
253
300
  padding-left: 2.2rem;
254
301
  &:extend(.text-width);
255
302
  }
303
+
256
304
  body ul {
257
305
  margin-bottom: @s24;
258
306
  }
@@ -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*2/3);
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
- height: calc(150px*2/3)
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;