@comicrelief/component-library 8.87.1 → 8.88.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@comicrelief/component-library",
3
3
  "author": "Comic Relief Engineering Team",
4
- "version": "8.87.1",
4
+ "version": "8.88.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
7
7
  "files": [
@@ -7,9 +7,9 @@ import { ButtonIconImgPath, ButtonIconSvgPath } from '../../../data/data';
7
7
 
8
8
  export default function ButtonExample() {
9
9
  // Covering all of the use cases:
10
- const blackCrossIcon = <Cross />;
11
- const whiteCrossIcon = <Cross colour="white" />;
12
- const redCrossIcon = <Cross colour="red" />;
10
+ const blackCrossIcon = <Cross size={20} />;
11
+ const whiteCrossIcon = <Cross colour="white" size={20} />;
12
+ const redCrossIcon = <Cross colour="red" size={20} />;
13
13
 
14
14
  const testImage = (
15
15
  <img
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
- import StyledLink, { HelperText, IconWrapper } from './Link.style';
4
+ import StyledLink, { HelperText, IconWrapper, Copywrapper } from './Link.style';
5
5
  import allowListed from '../../../utils/allowListed';
6
6
  import { getDomain } from '../../../utils/internalLinkHelper';
7
7
  import buttonTypes from '../../../theme/crTheme/buttonTypes';
@@ -67,8 +67,13 @@ const Link = ({
67
67
  $underline={underline}
68
68
  $fullWidth={fullWidth}
69
69
  $buttonType={buttonType}
70
+ $hasIcon={hasIcon}
70
71
  >
71
- {children}
72
+ {hasIcon
73
+ // Wrapping span to allow for grid positioning alongside icon
74
+ ? <Copywrapper>{children}</Copywrapper>
75
+ : children
76
+ }
72
77
  {window === '_blank' && <HelperText>(opens in new window)</HelperText>}
73
78
  {hasIcon && <IconWrapper type={type}>{icon}</IconWrapper>}
74
79
  </StyledLink>
@@ -3,6 +3,10 @@ import spacing from '../../../theme/shared/spacing';
3
3
  import hideVisually from '../../../theme/shared/hideVisually';
4
4
  import fontHelper from '../../../theme/crTheme/fontHelper';
5
5
 
6
+ export const Copywrapper = styled.span`
7
+ // Purely for some cleaner markup :)
8
+ `;
9
+
6
10
  const buttonStyle = () => css`
7
11
  display: inline-flex;
8
12
  position: relative;
@@ -68,6 +72,7 @@ export const IconWrapper = styled.span`
68
72
  width: auto;
69
73
  right: auto;
70
74
  position: relative;
75
+
71
76
  ${({ type }) => type === 'standard' && css`
72
77
  position: absolute;
73
78
  right: -2rem;
@@ -80,14 +85,62 @@ export const IconWrapper = styled.span`
80
85
  const StyledLink = styled.a`
81
86
  ${props => (props.type === 'button' ? buttonStyle : linkStyle)}
82
87
 
83
- ${({ $iconFirst }) => $iconFirst
88
+ ${props => props.$iconFirst && props.type === 'button'
84
89
  && css`
85
90
  flex-direction: row-reverse;
91
+
86
92
  span[type="button"] {
87
93
  margin-left: 0;
88
94
  margin-right: 1rem;
89
95
  }
90
96
  `};
97
+
98
+ // Icon-based tweaks, recreating updates to Button:
99
+ ${props => (props.$hasIcon && props.type === 'button') && css`
100
+ display: inline-grid;
101
+ grid-template-columns: 1fr repeat(1, auto) 1fr;
102
+ grid-column-gap: 0.6rem;
103
+ grid-template-rows: auto;
104
+ justify-items: center;
105
+
106
+ > ${Copywrapper} {
107
+ grid-column-start: 2;
108
+
109
+ // Request from Curtis to aesthetically rebalance these smaller buttons:
110
+ ${({ $fullWidth }) => (!$fullWidth && css`
111
+ padding-right: 1.5rem;
112
+ `)};
113
+ }
114
+
115
+ > ${IconWrapper} {
116
+ margin-left: auto;
117
+ // While Button heights now scale to fit content (important for lots
118
+ // of copy on a small breakpoint), we so still need to constrain the
119
+ // icon, to prevent silliness:
120
+ height: 1.25rem;
121
+ }
122
+
123
+ ${(props.$iconFirst && css`
124
+ > ${Copywrapper} {
125
+ order: 2;
126
+
127
+ ${({ $fullWidth }) => (!$fullWidth && css`
128
+ // Swap sides for the 'aesthetic rebalance' mentioned aobve:
129
+ padding-inline: 1.5rem 0;
130
+ `)};
131
+ }
132
+
133
+ > ${IconWrapper} {
134
+ // Place the icon before the copy in the Grid:
135
+ order: 1;
136
+
137
+ // Swap other alignment rule:
138
+ &[type="button"] {
139
+ margin-inline: 0 auto;
140
+ }
141
+ }
142
+ `)};
143
+ `};
91
144
  `;
92
145
 
93
146
  export const HelperText = styled.span`
@@ -101,7 +101,11 @@ it('renders a button with an icon', () => {
101
101
  target="_self"
102
102
  type="standard"
103
103
  >
104
- Internal link
104
+ <span
105
+ className=""
106
+ >
107
+ Internal link
108
+ </span>
105
109
  <span
106
110
  className="c1"
107
111
  type="standard"
@@ -99,6 +99,33 @@ export default function LinkExample() {
99
99
  </Link>
100
100
  </ExampleContainer>
101
101
 
102
+ <ExampleContainer>
103
+ <Link
104
+ color="red"
105
+ href="/test"
106
+ target="blank"
107
+ type="button"
108
+ fullWidth
109
+ icon={<Internal colour="white" size={20} />}
110
+ >
111
+ Link as full-width red button with an icon
112
+ </Link>
113
+ </ExampleContainer>
114
+
115
+ <ExampleContainer>
116
+ <Link
117
+ color="red"
118
+ href="/test"
119
+ target="blank"
120
+ type="button"
121
+ fullWidth
122
+ icon={<Internal colour="white" size={20} />}
123
+ iconFirst
124
+ >
125
+ Link as full-width red button with an icon first
126
+ </Link>
127
+ </ExampleContainer>
128
+
102
129
  <h3>Iconography</h3>
103
130
 
104
131
  <ExampleContainer>
@@ -108,9 +135,9 @@ export default function LinkExample() {
108
135
  href="#anchor"
109
136
  target="blank"
110
137
  type="button"
111
- icon={<Internal colour="white" mobileColour="red" />}
138
+ icon={<Internal colour="white" mobileColour="red" size={20} />}
112
139
  >
113
- Internal link, 'blue' with red icon on tablet and mobile
140
+ Internal link, &apos;blue&apos; with red icon on tablet and mobile
114
141
  </Link>
115
142
  </ExampleContainer>
116
143
 
@@ -121,7 +148,7 @@ export default function LinkExample() {
121
148
  href="#anchor"
122
149
  target="blank"
123
150
  type="button"
124
- icon={<External colour="white" mobileColour="blue" />}
151
+ icon={<External colour="white" mobileColour="blue" size={20} />}
125
152
  >
126
153
  External link (black on mobile, blue on desktop)
127
154
  </Link>
@@ -133,7 +160,7 @@ export default function LinkExample() {
133
160
  href="#anchor"
134
161
  target="blank"
135
162
  type="button"
136
- icon={<Download colour="white" mobileColour="blue" />}
163
+ icon={<Download colour="white" mobileColour="blue" size={20} />}
137
164
  >
138
165
  Download link (blue mobile-tablet icon, white desktop icon)
139
166
  </Link>
@@ -145,7 +172,7 @@ export default function LinkExample() {
145
172
  href="#anchor"
146
173
  target="blank"
147
174
  type="button"
148
- icon={<Favourite colour="white" mobileColour="blue" />}
175
+ icon={<Favourite colour="white" mobileColour="blue" size={20} />}
149
176
  >
150
177
  Favourite link (blue mobile-tablet icon, white desktop icon)
151
178
  </Link>
@@ -157,7 +184,7 @@ export default function LinkExample() {
157
184
  href="#anchor"
158
185
  target="blank"
159
186
  type="button"
160
- icon={<Chevron direction="up" colour="white" mobileColour="blue" />}
187
+ icon={<Chevron direction="up" colour="white" mobileColour="blue" size={20} />}
161
188
  >
162
189
  Chevron Up (blue mobile-tablet icon, white desktop icon)
163
190
  </Link>
@@ -169,7 +196,7 @@ export default function LinkExample() {
169
196
  href="#anchor"
170
197
  target="blank"
171
198
  type="button"
172
- icon={<Chevron direction="down" colour="white" mobileColour="blue" />}
199
+ icon={<Chevron direction="down" colour="white" mobileColour="blue" size={20} />}
173
200
  >
174
201
  Chevron Down (blue mobile-tablet icon, white desktop icon)
175
202
  </Link>
@@ -181,7 +208,7 @@ export default function LinkExample() {
181
208
  href="#anchor"
182
209
  target="blank"
183
210
  type="button"
184
- icon={<Chevron direction="left" colour="white" mobileColour="blue" />}
211
+ icon={<Chevron direction="left" colour="white" mobileColour="blue" size={20} />}
185
212
  >
186
213
  Chevron Left (blue mobile-tablet icon, white desktop icon)
187
214
  </Link>
@@ -193,7 +220,7 @@ export default function LinkExample() {
193
220
  href="#anchor"
194
221
  target="blank"
195
222
  type="button"
196
- icon={<Chevron direction="right" colour="white" mobileColour="blue" />}
223
+ icon={<Chevron direction="right" colour="white" mobileColour="blue" size={20} />}
197
224
  >
198
225
  Chevron Right (blue mobile-tablet icon, white desktop icon)
199
226
  </Link>
@@ -206,7 +233,7 @@ export default function LinkExample() {
206
233
  target="blank"
207
234
  type="button"
208
235
  iconFirst
209
- icon={<Arrow direction="left" colour="white" mobileColour="blue" />}
236
+ icon={<Arrow direction="left" colour="white" mobileColour="blue" size={20} />}
210
237
  >
211
238
  Arrow Left (blue mobile-tablet icon, white desktop icon)
212
239
  </Link>
@@ -218,7 +245,7 @@ export default function LinkExample() {
218
245
  href="#anchor"
219
246
  target="blank"
220
247
  type="button"
221
- icon={<AtSign colour="white" mobileColour="blue" />}
248
+ icon={<AtSign colour="white" mobileColour="blue" size={20} />}
222
249
  >
223
250
  At Sign (blue mobile-tablet icon, white desktop icon)
224
251
  </Link>
@@ -15,11 +15,11 @@ exports[`renders Column view correctly 1`] = `
15
15
  object-fit: cover;
16
16
  }
17
17
 
18
- .c9 {
18
+ .c10 {
19
19
  fill: #FFFFFF;
20
20
  }
21
21
 
22
- .c8 {
22
+ .c9 {
23
23
  display: inline-flex;
24
24
  margin-left: 1rem;
25
25
  align-self: center;
@@ -48,6 +48,11 @@ exports[`renders Column view correctly 1`] = `
48
48
  letter-spacing: 0;
49
49
  font-size: 1rem;
50
50
  line-height: 1.25rem;
51
+ display: inline-grid;
52
+ grid-template-columns: 1fr repeat(1,auto) 1fr;
53
+ grid-column-gap: 0.6rem;
54
+ grid-template-rows: auto;
55
+ justify-items: center;
51
56
  }
52
57
 
53
58
  .c7:hover,
@@ -64,6 +69,16 @@ exports[`renders Column view correctly 1`] = `
64
69
  opacity: 0.35;
65
70
  }
66
71
 
72
+ .c7 >.{
73
+ grid-column-start: 2;
74
+ padding-right: 1.5rem;
75
+ }
76
+
77
+ .c7 >.c8 {
78
+ margin-left: auto;
79
+ height: 1.25rem;
80
+ }
81
+
67
82
  .c0 {
68
83
  display: flex;
69
84
  position: relative;
@@ -109,13 +124,13 @@ exports[`renders Column view correctly 1`] = `
109
124
  }
110
125
 
111
126
  @media (min-width: 1024px) {
112
- .c9 {
127
+ .c10 {
113
128
  fill: #FFFFFF;
114
129
  }
115
130
  }
116
131
 
117
132
  @media (min-width: 740px) {
118
- .c8 {
133
+ .c9 {
119
134
  width: auto;
120
135
  right: auto;
121
136
  position: relative;
@@ -227,13 +242,17 @@ exports[`renders Column view correctly 1`] = `
227
242
  target="_self"
228
243
  type="button"
229
244
  >
230
- Find out more
231
245
  <span
232
- className="c8"
246
+ className=""
247
+ >
248
+ Find out more
249
+ </span>
250
+ <span
251
+ className="c8 c9"
233
252
  type="button"
234
253
  >
235
254
  <svg
236
- className="c9"
255
+ className="c10"
237
256
  colour="white"
238
257
  fill="#FFFFFF"
239
258
  height={20}
@@ -267,11 +286,11 @@ exports[`renders correctly 1`] = `
267
286
  object-fit: cover;
268
287
  }
269
288
 
270
- .c9 {
289
+ .c10 {
271
290
  fill: #FFFFFF;
272
291
  }
273
292
 
274
- .c8 {
293
+ .c9 {
275
294
  display: inline-flex;
276
295
  margin-left: 1rem;
277
296
  align-self: center;
@@ -300,6 +319,11 @@ exports[`renders correctly 1`] = `
300
319
  letter-spacing: 0;
301
320
  font-size: 1rem;
302
321
  line-height: 1.25rem;
322
+ display: inline-grid;
323
+ grid-template-columns: 1fr repeat(1,auto) 1fr;
324
+ grid-column-gap: 0.6rem;
325
+ grid-template-rows: auto;
326
+ justify-items: center;
303
327
  }
304
328
 
305
329
  .c7:hover,
@@ -316,6 +340,16 @@ exports[`renders correctly 1`] = `
316
340
  opacity: 0.35;
317
341
  }
318
342
 
343
+ .c7 >.{
344
+ grid-column-start: 2;
345
+ padding-right: 1.5rem;
346
+ }
347
+
348
+ .c7 >.c8 {
349
+ margin-left: auto;
350
+ height: 1.25rem;
351
+ }
352
+
319
353
  .c0 {
320
354
  display: flex;
321
355
  position: relative;
@@ -361,13 +395,13 @@ exports[`renders correctly 1`] = `
361
395
  }
362
396
 
363
397
  @media (min-width: 1024px) {
364
- .c9 {
398
+ .c10 {
365
399
  fill: #FFFFFF;
366
400
  }
367
401
  }
368
402
 
369
403
  @media (min-width: 740px) {
370
- .c8 {
404
+ .c9 {
371
405
  width: auto;
372
406
  right: auto;
373
407
  position: relative;
@@ -510,13 +544,17 @@ exports[`renders correctly 1`] = `
510
544
  target="_self"
511
545
  type="button"
512
546
  >
513
- Find out more
514
547
  <span
515
- className="c8"
548
+ className=""
549
+ >
550
+ Find out more
551
+ </span>
552
+ <span
553
+ className="c8 c9"
516
554
  type="button"
517
555
  >
518
556
  <svg
519
- className="c9"
557
+ className="c10"
520
558
  colour="white"
521
559
  fill="#FFFFFF"
522
560
  height={20}
@@ -56,7 +56,7 @@ exports[`renders correctly 1`] = `
56
56
  line-height: inherit;
57
57
  }
58
58
 
59
- .c12 {
59
+ .c13 {
60
60
  display: inline-flex;
61
61
  margin-left: 1rem;
62
62
  align-self: center;
@@ -85,6 +85,11 @@ exports[`renders correctly 1`] = `
85
85
  letter-spacing: 0;
86
86
  font-size: 1rem;
87
87
  line-height: 1.25rem;
88
+ display: inline-grid;
89
+ grid-template-columns: 1fr repeat(1,auto) 1fr;
90
+ grid-column-gap: 0.6rem;
91
+ grid-template-rows: auto;
92
+ justify-items: center;
88
93
  }
89
94
 
90
95
  .c11:hover,
@@ -101,7 +106,17 @@ exports[`renders correctly 1`] = `
101
106
  opacity: 0.35;
102
107
  }
103
108
 
104
- .c13 {
109
+ .c11 >.{
110
+ grid-column-start: 2;
111
+ padding-right: 1.5rem;
112
+ }
113
+
114
+ .c11 >.c12 {
115
+ margin-left: auto;
116
+ height: 1.25rem;
117
+ }
118
+
119
+ .c14 {
105
120
  fill: #FFFFFF;
106
121
  }
107
122
 
@@ -187,7 +202,7 @@ exports[`renders correctly 1`] = `
187
202
  }
188
203
 
189
204
  @media (min-width: 740px) {
190
- .c12 {
205
+ .c13 {
191
206
  width: auto;
192
207
  right: auto;
193
208
  position: relative;
@@ -221,7 +236,7 @@ exports[`renders correctly 1`] = `
221
236
  }
222
237
 
223
238
  @media (min-width: 1024px) {
224
- .c13 {
239
+ .c14 {
225
240
  fill: #FFFFFF;
226
241
  }
227
242
  }
@@ -330,13 +345,17 @@ exports[`renders correctly 1`] = `
330
345
  target="_self"
331
346
  type="button"
332
347
  >
333
- Check out the shop
334
348
  <span
335
- className="c12"
349
+ className=""
350
+ >
351
+ Check out the shop
352
+ </span>
353
+ <span
354
+ className="c12 c13"
336
355
  type="button"
337
356
  >
338
357
  <svg
339
- className="c13"
358
+ className="c14"
340
359
  fill="#FFFFFF"
341
360
  height={24}
342
361
  viewBox="0 0 96 96"