@comicrelief/component-library 8.52.0 → 8.52.2

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.
@@ -15,25 +15,25 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
15
15
  object-fit: cover;
16
16
  }
17
17
 
18
- .c23 {
18
+ .c21 {
19
19
  -webkit-transform: rotate(0);
20
20
  -ms-transform: rotate(0);
21
21
  transform: rotate(0);
22
22
  fill: #000000;
23
23
  }
24
24
 
25
- .c25 {
25
+ .c23 {
26
26
  -webkit-transform: rotate(180deg);
27
27
  -ms-transform: rotate(180deg);
28
28
  transform: rotate(180deg);
29
29
  fill: #000000;
30
30
  }
31
31
 
32
- .c21 {
32
+ .c19 {
33
33
  fill: #000000;
34
34
  }
35
35
 
36
- .c11 {
36
+ .c9 {
37
37
  position: fixed;
38
38
  top: 0;
39
39
  left: 0;
@@ -55,7 +55,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
55
55
  visibility: hidden;
56
56
  }
57
57
 
58
- .c12 {
58
+ .c10 {
59
59
  position: absolute;
60
60
  top: 0;
61
61
  left: 0;
@@ -65,7 +65,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
65
65
  z-index: 0;
66
66
  }
67
67
 
68
- .c13 {
68
+ .c11 {
69
69
  display: block;
70
70
  padding: 0.5rem;
71
71
  background: transparent;
@@ -74,7 +74,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
74
74
  margin-top: 72px;
75
75
  }
76
76
 
77
- .c14 {
77
+ .c12 {
78
78
  display: -webkit-box;
79
79
  display: -webkit-flex;
80
80
  display: -ms-flexbox;
@@ -93,7 +93,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
93
93
  border-radius: 1rem;
94
94
  }
95
95
 
96
- .c15 {
96
+ .c13 {
97
97
  position: relative;
98
98
  display: -webkit-box;
99
99
  display: -webkit-flex;
@@ -113,7 +113,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
113
113
  overflow: hidden;
114
114
  }
115
115
 
116
- .c15 > div {
116
+ .c13 > div {
117
117
  display: -webkit-box;
118
118
  display: -webkit-flex;
119
119
  display: -ms-flexbox;
@@ -130,13 +130,13 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
130
130
  transition: width 0.3s ease-in-out,height 0.3s ease-in-out;
131
131
  }
132
132
 
133
- .c15 img {
133
+ .c13 img {
134
134
  opacity: 0;
135
135
  -webkit-transition: opacity 0.1s ease-out 0.3s;
136
136
  transition: opacity 0.1s ease-out 0.3s;
137
137
  }
138
138
 
139
- .c16 {
139
+ .c14 {
140
140
  position: absolute;
141
141
  top: 50%;
142
142
  left: 50%;
@@ -145,7 +145,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
145
145
  transform: translate(-50%,-50%);
146
146
  }
147
147
 
148
- .c17 {
148
+ .c15 {
149
149
  display: -webkit-box;
150
150
  display: -webkit-flex;
151
151
  display: -ms-flexbox;
@@ -162,7 +162,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
162
162
  padding: 0 1rem;
163
163
  }
164
164
 
165
- .c18 {
165
+ .c16 {
166
166
  position: absolute;
167
167
  display: -webkit-box;
168
168
  display: -webkit-flex;
@@ -185,25 +185,25 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
185
185
  z-index: 10;
186
186
  }
187
187
 
188
- .c18 svg {
188
+ .c16 svg {
189
189
  -webkit-transition: all 0.1s ease-out;
190
190
  transition: all 0.1s ease-out;
191
191
  }
192
192
 
193
- .c18:hover svg {
193
+ .c16:hover svg {
194
194
  fill: #E52630;
195
195
  }
196
196
 
197
- .c18:focus-visible {
197
+ .c16:focus-visible {
198
198
  outline: 2px solid #E52630;
199
199
  }
200
200
 
201
- .c19 {
201
+ .c17 {
202
202
  top: 0;
203
203
  right: 0;
204
204
  }
205
205
 
206
- .c22 {
206
+ .c20 {
207
207
  top: 30%;
208
208
  left: 0;
209
209
  -webkit-transform: translate(0,-50%);
@@ -213,7 +213,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
213
213
  border-bottom-left-radius: 0;
214
214
  }
215
215
 
216
- .c24 {
216
+ .c22 {
217
217
  top: 30%;
218
218
  right: 0;
219
219
  -webkit-transform: translate(0,-50%);
@@ -223,7 +223,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
223
223
  border-bottom-right-radius: 0;
224
224
  }
225
225
 
226
- .c20 {
226
+ .c18 {
227
227
  position: absolute;
228
228
  width: 1px;
229
229
  height: 1px;
@@ -280,7 +280,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
280
280
  gap: 1.1rem;
281
281
  }
282
282
 
283
- .c10 {
283
+ .c8 {
284
284
  display: none;
285
285
  }
286
286
 
@@ -292,7 +292,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
292
292
  -webkit-flex-direction: column;
293
293
  -ms-flex-direction: column;
294
294
  flex-direction: column;
295
- gap: 0.8rem;
295
+ gap: 0.9rem;
296
296
  padding: 0;
297
297
  margin: 0;
298
298
  background: none;
@@ -302,15 +302,17 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
302
302
  color: inherit;
303
303
  }
304
304
 
305
+ .c3:focus-visible {
306
+ outline: 2px solid black;
307
+ outline-offset: 0.5rem;
308
+ border-radius: 1rem;
309
+ }
310
+
305
311
  .c3 div:first-child {
306
312
  -webkit-transition: all 0.1s ease-out;
307
313
  transition: all 0.1s ease-out;
308
314
  }
309
315
 
310
- .c3:focus-visible {
311
- outline: 2px solid #000000;
312
- }
313
-
314
316
  .c3 > div:first-child:hover {
315
317
  box-shadow: 0px 3px 10px 0px rgba(0,0,0,0.4);
316
318
  }
@@ -349,41 +351,33 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
349
351
  padding: 0 1rem;
350
352
  }
351
353
 
352
- .c8:first-child {
353
- margin-bottom: 0;
354
- }
355
-
356
- .c9 {
357
- line-height: 1;
358
- }
359
-
360
354
  @media (min-width:1024px) {
361
- .c23 {
355
+ .c21 {
362
356
  fill: #000000;
363
357
  }
364
358
  }
365
359
 
366
360
  @media (min-width:1024px) {
367
- .c25 {
361
+ .c23 {
368
362
  fill: #000000;
369
363
  }
370
364
  }
371
365
 
372
366
  @media (min-width:1024px) {
373
- .c13 {
367
+ .c11 {
374
368
  margin-top: 84px;
375
369
  }
376
370
  }
377
371
 
378
372
  @media (min-width:1024px) {
379
- .c22 {
373
+ .c20 {
380
374
  position: fixed;
381
375
  top: 50%;
382
376
  }
383
377
  }
384
378
 
385
379
  @media (min-width:1024px) {
386
- .c24 {
380
+ .c22 {
387
381
  position: fixed;
388
382
  top: 50%;
389
383
  }
@@ -412,12 +406,12 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
412
406
  className="c2 gallery-column"
413
407
  >
414
408
  <button
415
- aria-label="Image 1"
409
+ aria-label=""
416
410
  className="c3 gallery-node"
417
411
  data-node-index={0}
418
412
  onPointerUp={[Function]}
419
413
  tabIndex={0}
420
- title="Image 1"
414
+ title=""
421
415
  >
422
416
  <div
423
417
  className="c4 gallery-node-image"
@@ -428,7 +422,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
428
422
  width="100%"
429
423
  >
430
424
  <img
431
- alt="Image 1"
425
+ alt=""
432
426
  className="c6 lazyload"
433
427
  data-src="image1.jpg"
434
428
  height="auto"
@@ -439,30 +433,19 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
439
433
  </div>
440
434
  <div
441
435
  className="c7"
442
- >
443
- <div
444
- className="c8"
445
- >
446
- Image 1
447
- </div>
448
- <div
449
- className="c9"
450
- >
451
- Caption 1
452
- </div>
453
- </div>
436
+ />
454
437
  </button>
455
438
  </div>
456
439
  <div
457
440
  className="c2 gallery-column"
458
441
  >
459
442
  <button
460
- aria-label="Image 2"
443
+ aria-label=""
461
444
  className="c3 gallery-node"
462
445
  data-node-index={0}
463
446
  onPointerUp={[Function]}
464
447
  tabIndex={0}
465
- title="Image 2"
448
+ title=""
466
449
  >
467
450
  <div
468
451
  className="c4 gallery-node-image"
@@ -473,7 +456,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
473
456
  width="100%"
474
457
  >
475
458
  <img
476
- alt="Image 2"
459
+ alt=""
477
460
  className="c6 lazyload"
478
461
  data-src="image2.jpg"
479
462
  height="auto"
@@ -484,30 +467,19 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
484
467
  </div>
485
468
  <div
486
469
  className="c7"
487
- >
488
- <div
489
- className="c8"
490
- >
491
- Image 2
492
- </div>
493
- <div
494
- className="c9"
495
- >
496
- Caption 2
497
- </div>
498
- </div>
470
+ />
499
471
  </button>
500
472
  </div>
501
473
  <div
502
474
  className="c2 gallery-column"
503
475
  >
504
476
  <button
505
- aria-label="Image 3"
477
+ aria-label=""
506
478
  className="c3 gallery-node"
507
479
  data-node-index={0}
508
480
  onPointerUp={[Function]}
509
481
  tabIndex={0}
510
- title="Image 3"
482
+ title=""
511
483
  >
512
484
  <div
513
485
  className="c4 gallery-node-image"
@@ -518,7 +490,7 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
518
490
  width="100%"
519
491
  >
520
492
  <img
521
- alt="Image 3"
493
+ alt=""
522
494
  className="c6 lazyload"
523
495
  data-src="image3.jpg"
524
496
  height="auto"
@@ -529,46 +501,35 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
529
501
  </div>
530
502
  <div
531
503
  className="c7"
532
- >
533
- <div
534
- className="c8"
535
- >
536
- Image 3
537
- </div>
538
- <div
539
- className="c9"
540
- >
541
- Caption 3
542
- </div>
543
- </div>
504
+ />
544
505
  </button>
545
506
  </div>
546
507
  <div
547
- className="c10"
508
+ className="c8"
548
509
  >
549
510
  No images to display
550
511
  </div>
551
512
  </div>
552
513
  <div
553
- className="c11"
514
+ className="c9"
554
515
  >
555
516
  <div
556
- className="c12"
517
+ className="c10"
557
518
  onPointerUp={[Function]}
558
519
  />
559
520
  <dialog
560
521
  aria-describedby="lightboxDescription"
561
522
  aria-labelledby="lightboxTitle"
562
- className="c13"
523
+ className="c11"
563
524
  >
564
525
  <div
565
- className="c14"
526
+ className="c12"
566
527
  >
567
528
  <div
568
- className="c15 lightbox-image"
529
+ className="c13 lightbox-image"
569
530
  >
570
531
  <div
571
- className="c16"
532
+ className="c14"
572
533
  >
573
534
  <span
574
535
  className="css-1xdhyk6"
@@ -588,25 +549,21 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
588
549
  <div
589
550
  aria-atomic="true"
590
551
  aria-live="polite"
591
- className="c17"
552
+ className="c15"
592
553
  id="lightboxDescription"
593
- >
594
- <div
595
- id="lightboxTitle"
596
- />
597
- </div>
554
+ />
598
555
  <button
599
- className="c18 c19"
556
+ className="c16 c17"
600
557
  onClick={[Function]}
601
558
  type="button"
602
559
  >
603
560
  <span
604
- className="c20"
561
+ className="c18"
605
562
  >
606
563
  Close
607
564
  </span>
608
565
  <svg
609
- className="c21"
566
+ className="c19"
610
567
  height={16}
611
568
  viewBox="0 0 96 96"
612
569
  width={16}
@@ -618,17 +575,17 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
618
575
  </svg>
619
576
  </button>
620
577
  <button
621
- className="c18 c22"
578
+ className="c16 c20"
622
579
  onClick={[Function]}
623
580
  type="button"
624
581
  >
625
582
  <span
626
- className="c20"
583
+ className="c18"
627
584
  >
628
585
  Previous
629
586
  </span>
630
587
  <svg
631
- className="c23"
588
+ className="c21"
632
589
  direction="left"
633
590
  height={16}
634
591
  viewBox="0 0 96 96"
@@ -643,17 +600,17 @@ exports[`handle a Dynamic Gallery with mocked gallery nodes 1`] = `
643
600
  </svg>
644
601
  </button>
645
602
  <button
646
- className="c18 c24"
603
+ className="c16 c22"
647
604
  onClick={[Function]}
648
605
  type="button"
649
606
  >
650
607
  <span
651
- className="c20"
608
+ className="c18"
652
609
  >
653
610
  Next
654
611
  </span>
655
612
  <svg
656
- className="c25"
613
+ className="c23"
657
614
  direction="right"
658
615
  height={16}
659
616
  viewBox="0 0 96 96"
@@ -1025,11 +982,7 @@ exports[`renders an empty Dynamic Gallery with no options set 1`] = `
1025
982
  aria-live="polite"
1026
983
  className="c9"
1027
984
  id="lightboxDescription"
1028
- >
1029
- <div
1030
- id="lightboxTitle"
1031
- />
1032
- </div>
985
+ />
1033
986
  <button
1034
987
  className="c10 c11"
1035
988
  onClick={[Function]}
@@ -5,8 +5,9 @@ import PropTypes from 'prop-types';
5
5
  // so lives here to avoid circular dependencies
6
6
  // eslint-disable-next-line import/prefer-default-export
7
7
  export const GalleryNodeType = PropTypes.shape({
8
- title: PropTypes.string,
9
8
  image: PropTypes.string.isRequired,
10
- body: PropTypes.node,
11
- caption: PropTypes.node
9
+ gridBody: PropTypes.node,
10
+ gridCaption: PropTypes.node,
11
+ lightboxBody: PropTypes.node,
12
+ lightboxCaption: PropTypes.node
12
13
  });
@@ -1,3 +1,4 @@
1
+ import React, { isValidElement } from 'react';
1
2
  import { defaultData } from '../../../styleguide/data/data';
2
3
 
3
4
  /**
@@ -19,10 +20,46 @@ export default function createMockGalleryNodes(nodeCount = 10) {
19
20
  for (let i = 0; i < nodeCount; i += 1) {
20
21
  nodes.push({
21
22
  image: images[Math.floor(Math.random() * images.length)],
22
- title: `image ${i}`,
23
- caption: 'Age group: 0-10',
24
- body: `This is the body for image ${i}. It can be used to display additional information about the image.`
23
+ title: (
24
+ <p>
25
+ {`image ${i}`}
26
+ </p>),
27
+ gridCaption: <p>Grid: Group age: 0-10</p>,
28
+ lightboxCaption: <p>Lightbox: Group age: 0-10</p>,
29
+ gridBody: (
30
+ <p>
31
+ {/* eslint-disable-next-line */}
32
+ Grid: This is the body for image {i}. It can be used to display additional information about the image.
33
+ </p>
34
+ ),
35
+ lightboxBody: (
36
+ <p>
37
+ {/* eslint-disable-next-line */}
38
+ Lightbox: This is the body for image {i}. It can be used to display additional information about the image.
39
+ </p>
40
+ )
25
41
  });
26
42
  }
27
43
  return nodes;
28
44
  }
45
+
46
+ /**
47
+ * extract text from a react node;
48
+ * this is used to get usable strings from a styled text node from the CMS,
49
+ * if we need the plain string for eg alt text
50
+ */
51
+ export function extractNodeText(reactNode) {
52
+ let text = '';
53
+ if (typeof reactNode === 'string') {
54
+ text = reactNode;
55
+ } else if (typeof reactNode === 'number') {
56
+ text = reactNode.toString();
57
+ } else if (reactNode instanceof Array) {
58
+ reactNode.forEach(child => {
59
+ text += extractNodeText(child);
60
+ });
61
+ } else if (isValidElement(reactNode)) {
62
+ text += extractNodeText(reactNode.props.children);
63
+ }
64
+ return text;
65
+ }