@comicrelief/component-library 7.24.2 → 7.26.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.
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = exports.default = {
8
+ cartId: 'monthly-only',
9
+ singleGiving: null,
10
+ regularGiving: {
11
+ moneybuys: [{
12
+ description: 'a regular supply of toiletries for someone living in a refugee camp in Serbia.',
13
+ value: '5.50'
14
+ }, {
15
+ description: 'a potentially lifesaving call for a man at risk of suicide in the UK.',
16
+ value: '10'
17
+ }, {
18
+ description: 'the distribution of enough surplus food for a school breakfast club to feed 80 children.',
19
+ value: '20'
20
+ }]
21
+ }
22
+ };
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": "7.24.2",
4
+ "version": "7.26.0",
5
5
  "main": "dist/index.js",
6
6
  "license": "ISC",
7
7
  "jest": {
@@ -40,7 +40,10 @@ const Donate = ({
40
40
  PopUpText,
41
41
  chooseAmountText,
42
42
  isDesktopOverride,
43
- otherAmountValue
43
+ otherAmountValue,
44
+ additionalSingleCopy,
45
+ additionalMonthlyCopy,
46
+ defaultGivingType
44
47
  }) => {
45
48
  let isDesktop = useMediaQuery({ query: `(min-width: ${screen.medium})` });
46
49
 
@@ -127,6 +130,9 @@ const Donate = ({
127
130
  chooseAmountText={chooseAmountText}
128
131
  submitButtonColor={submitButtonColor}
129
132
  otherAmountValue={otherAmountValue}
133
+ additionalSingleCopy={additionalSingleCopy}
134
+ additionalMonthlyCopy={additionalMonthlyCopy}
135
+ defaultGivingType={defaultGivingType}
130
136
  />
131
137
  </Wrapper>
132
138
  </Container>
@@ -159,7 +165,10 @@ Donate.propTypes = {
159
165
  PopUpText: PropTypes.string,
160
166
  chooseAmountText: PropTypes.string,
161
167
  isDesktopOverride: PropTypes.bool,
162
- otherAmountValue: PropTypes.number
168
+ otherAmountValue: PropTypes.number,
169
+ additionalSingleCopy: PropTypes.string,
170
+ additionalMonthlyCopy: PropTypes.string,
171
+ defaultGivingType: PropTypes.string
163
172
  };
164
173
 
165
174
  Donate.defaultProps = {
@@ -186,7 +195,10 @@ Donate.defaultProps = {
186
195
  chooseAmountText: '',
187
196
  isDesktopOverride: null,
188
197
  otherAmountValue: null,
189
- title: null
198
+ title: null,
199
+ additionalSingleCopy: null,
200
+ additionalMonthlyCopy: null,
201
+ defaultGivingType: null
190
202
  };
191
203
 
192
204
  export default Donate;
@@ -354,3 +354,143 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
354
354
  isDesktopOverride={false}
355
355
  />;
356
356
  ```
357
+
358
+ ## Additional copy for BOTH giving types
359
+
360
+ ```js
361
+ import data from './dev-data/data';
362
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
363
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
364
+
365
+ <Donate
366
+ alt="Background image"
367
+ mobileBackgroundColor="deep_violet_dark"
368
+ desktopOverlayColor="red"
369
+ submitButtonColor="blue_dark"
370
+ formAlignRight={true}
371
+ imageLow={desktopPictures.imageLow}
372
+ images={desktopPictures.images}
373
+ mobileImageLow={mobilePictures.imageLow}
374
+ mobileImages={mobilePictures.images}
375
+ data={data}
376
+ mbshipID="mship-11"
377
+ donateLink="https://donation.comicrelief.com/"
378
+ clientID="donate"
379
+ cartID="default-comicrelief"
380
+ title="Donate Now"
381
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
382
+ additionalSingleCopy="Some additional single giving copy - Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa."
383
+ additionalMonthlyCopy="Some additional regular giving copy! - Quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos."
384
+ />;
385
+ ```
386
+
387
+ ## Additional copy for monthly only
388
+
389
+ ```js
390
+ import data from './dev-data/data';
391
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
392
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
393
+
394
+ <Donate
395
+ alt="Background image"
396
+ mobileBackgroundColor="deep_violet_dark"
397
+ desktopOverlayColor="red"
398
+ submitButtonColor="blue_dark"
399
+ formAlignRight={true}
400
+ imageLow={desktopPictures.imageLow}
401
+ images={desktopPictures.images}
402
+ mobileImageLow={mobilePictures.imageLow}
403
+ mobileImages={mobilePictures.images}
404
+ data={data}
405
+ mbshipID="mship-12"
406
+ donateLink="https://donation.comicrelief.com/"
407
+ clientID="donate"
408
+ cartID="default-comicrelief"
409
+ title="Donate Now"
410
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
411
+ additionalMonthlyCopy="Some additional regular giving copy! - Quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos."
412
+ />;
413
+ ```
414
+
415
+ ## Additional copy for single only
416
+
417
+ ```js
418
+ import data from './dev-data/data';
419
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
420
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
421
+
422
+ <Donate
423
+ alt="Background image"
424
+ mobileBackgroundColor="deep_violet_dark"
425
+ desktopOverlayColor="red"
426
+ submitButtonColor="blue_dark"
427
+ formAlignRight={true}
428
+ imageLow={desktopPictures.imageLow}
429
+ images={desktopPictures.images}
430
+ mobileImageLow={mobilePictures.imageLow}
431
+ mobileImages={mobilePictures.images}
432
+ data={data}
433
+ mbshipID="mship-13"
434
+ donateLink="https://donation.comicrelief.com/"
435
+ clientID="donate"
436
+ cartID="default-comicrelief"
437
+ title="Donate Now"
438
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
439
+ additionalSingleCopy="Some additional single giving copy - Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa."
440
+ />;
441
+ ```
442
+
443
+ ## Default monthly giving type
444
+
445
+ ```js
446
+ import data from './dev-data/data';
447
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
448
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
449
+
450
+ <Donate
451
+ alt="Background image"
452
+ mobileBackgroundColor="deep_violet_dark"
453
+ desktopOverlayColor="red"
454
+ submitButtonColor="blue_dark"
455
+ formAlignRight={true}
456
+ imageLow={desktopPictures.imageLow}
457
+ images={desktopPictures.images}
458
+ mobileImageLow={mobilePictures.imageLow}
459
+ mobileImages={mobilePictures.images}
460
+ data={data}
461
+ mbshipID="mship-14"
462
+ donateLink="https://donation.comicrelief.com/"
463
+ clientID="donate"
464
+ cartID="default-comicrelief"
465
+ title="Donate Now"
466
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
467
+ defaultGivingType="monthly"
468
+ />;
469
+ ```
470
+
471
+ ## Monthly ONLY
472
+
473
+ ```js
474
+ import data from './dev-data/data-monthly';
475
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
476
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
477
+
478
+ <Donate
479
+ alt="Background image"
480
+ mobileBackgroundColor="deep_violet_dark"
481
+ desktopOverlayColor="red"
482
+ submitButtonColor="blue_dark"
483
+ formAlignRight={true}
484
+ imageLow={desktopPictures.imageLow}
485
+ images={desktopPictures.images}
486
+ mobileImageLow={mobilePictures.imageLow}
487
+ mobileImages={mobilePictures.images}
488
+ data={data}
489
+ mbshipID="mship-15"
490
+ donateLink="https://donation.comicrelief.com/"
491
+ clientID="donate"
492
+ cartID="default-comicrelief"
493
+ title="Donate Now"
494
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
495
+ />;
496
+ ```
@@ -38,9 +38,12 @@ const Signup = ({
38
38
  chooseAmountText,
39
39
  submitButtonColor,
40
40
  otherAmountValue,
41
+ additionalSingleCopy,
42
+ additionalMonthlyCopy,
43
+ defaultGivingType,
41
44
  ...rest
42
45
  }) => {
43
- const [givingType, setGivingType] = useState('single');
46
+ const [givingType, setGivingType] = useState();
44
47
  const [errorMsg, setErrorMsg] = useState(false);
45
48
  const [amountDonate, setAmountDonate] = useState(10);
46
49
  const [moneyBuyCopy, setMoneyBuyCopy] = useState(true);
@@ -53,7 +56,7 @@ const Signup = ({
53
56
  // otherwise assign based on the associated moneybuys:
54
57
  if (otherAmountValue) {
55
58
  setAmountDonate(otherAmountValue);
56
- } else {
59
+ } else if (givingType) {
57
60
  const givingData = givingType === 'single' ? singleGiving : regularGiving;
58
61
 
59
62
  // Check the 2nd moneybuy exists before using it;
@@ -68,29 +71,31 @@ const Signup = ({
68
71
  }, [givingType, singleGiving, regularGiving, otherAmountValue]);
69
72
 
70
73
  useEffect(() => {
71
- const givingData = givingType === 'single' ? singleGiving : regularGiving;
74
+ if (givingType) {
75
+ const givingData = givingType === 'single' ? singleGiving : regularGiving;
72
76
 
73
- let moneyBuyNewDescription = otherAmountText;
77
+ let moneyBuyNewDescription = otherAmountText;
74
78
 
75
- givingData.moneybuys.map((moneyBuy, index) => {
76
- if (moneyBuy.value === amountDonate) {
77
- moneyBuyNewDescription = moneyBuy.description;
78
- }
79
+ givingData.moneybuys.map((moneyBuy, index) => {
80
+ if (moneyBuy.value === amountDonate) {
81
+ moneyBuyNewDescription = moneyBuy.description;
82
+ }
79
83
 
80
- return (
81
- index === 1
82
- && amountDonate === undefined
83
- && (setMoneyBuyCopy(moneyBuy.description),
84
- setAmountDonate(moneyBuy.value))
85
- );
86
- });
84
+ return (
85
+ index === 1
86
+ && amountDonate === undefined
87
+ && (setMoneyBuyCopy(moneyBuy.description),
88
+ setAmountDonate(moneyBuy.value))
89
+ );
90
+ });
87
91
 
88
- if (!isAmountValid(amountDonate)) {
89
- if (moneyBuyCopy) setMoneyBuyCopy(false);
90
- if (!errorMsg) setErrorMsg(true);
91
- } else {
92
- if (errorMsg) setErrorMsg(false);
93
- setMoneyBuyCopy(moneyBuyNewDescription);
92
+ if (!isAmountValid(amountDonate)) {
93
+ if (moneyBuyCopy) setMoneyBuyCopy(false);
94
+ if (!errorMsg) setErrorMsg(true);
95
+ } else {
96
+ if (errorMsg) setErrorMsg(false);
97
+ setMoneyBuyCopy(moneyBuyNewDescription);
98
+ }
94
99
  }
95
100
  }, [
96
101
  errorMsg,
@@ -108,6 +113,18 @@ const Signup = ({
108
113
  if (popOpen && !popUpShown) setPopUpShown(true);
109
114
  }, [popOpen, popUpShown]);
110
115
 
116
+ // On load, determine what should actually be the default giving type
117
+ useEffect(() => {
118
+ // Use any explicit setting
119
+ if (defaultGivingType) {
120
+ setGivingType(defaultGivingType);
121
+ } else {
122
+ // Else, use whatever's available
123
+ setGivingType(singleGiving !== null ? 'single' : 'monthly');
124
+ }
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps
126
+ }, []);
127
+
111
128
  const submitDonation = (
112
129
  event,
113
130
  amount,
@@ -168,7 +185,7 @@ const Signup = ({
168
185
 
169
186
  setAmountDonate(thisAmount);
170
187
  }
171
- }, [errorMsg, givingData.moneybuys]);
188
+ }, [errorMsg, givingData]);
172
189
 
173
190
  // Listen for click outside custom amount input if there is no value entered.
174
191
  useEffect(() => {
@@ -191,6 +208,10 @@ const Signup = ({
191
208
  return `Donate £${amountDonate} monthly`;
192
209
  };
193
210
 
211
+ const showAdditionalSingleCopy = givingType === 'single' && additionalSingleCopy;
212
+ const showAdditionalMonthlyCopy = givingType === 'monthly' && additionalMonthlyCopy;
213
+ const additionalCopy = showAdditionalSingleCopy || showAdditionalMonthlyCopy;
214
+
194
215
  return (
195
216
  <FormWrapper>
196
217
  {showGivingSelector && (
@@ -221,7 +242,7 @@ const Signup = ({
221
242
  {chooseAmountText || `${noMoneyBuys ? 'Enter' : 'Choose'} an amount to give`}
222
243
  </Text>
223
244
  </Legend>
224
- {!noMoneyBuys && (
245
+ {!noMoneyBuys && givingType && (
225
246
  <MoneyBuys>
226
247
  {givingData.moneybuys.map(({ value }, index) => (
227
248
  <MoneyBuy
@@ -276,6 +297,14 @@ const Signup = ({
276
297
  </Error>
277
298
  )}
278
299
 
300
+ {additionalCopy && (
301
+ <p className="additional-copy">
302
+ <strong>
303
+ {additionalCopy}
304
+ </strong>
305
+ </p>
306
+ )}
307
+
279
308
  {noMoneyBuys ? (
280
309
  <Button
281
310
  type="submit"
@@ -313,13 +342,19 @@ Signup.propTypes = {
313
342
  PopUpText: PropTypes.string.isRequired,
314
343
  chooseAmountText: PropTypes.string.isRequired,
315
344
  submitButtonColor: PropTypes.string.isRequired,
316
- otherAmountValue: PropTypes.number
345
+ otherAmountValue: PropTypes.number,
346
+ additionalSingleCopy: PropTypes.string,
347
+ additionalMonthlyCopy: PropTypes.string,
348
+ defaultGivingType: PropTypes.string
317
349
  };
318
350
 
319
351
  Signup.defaultProps = {
320
352
  noMoneyBuys: false,
321
353
  otherAmountValue: null,
322
- data: {}
354
+ data: {},
355
+ additionalSingleCopy: null,
356
+ additionalMonthlyCopy: null,
357
+ defaultGivingType: null
323
358
  };
324
359
 
325
360
  export default Signup;
@@ -51,8 +51,12 @@ const GivingSelector = ({
51
51
  );
52
52
  };
53
53
 
54
+ GivingSelector.defaultProps = {
55
+ givingType: null
56
+ };
57
+
54
58
  GivingSelector.propTypes = {
55
- givingType: PropTypes.string.isRequired,
59
+ givingType: PropTypes.string,
56
60
  changeGivingType: PropTypes.func.isRequired,
57
61
  setPopOpen: PropTypes.func.isRequired,
58
62
  mbshipID: PropTypes.string.isRequired