@comicrelief/component-library 7.12.2 → 7.13.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.
@@ -52,7 +52,8 @@ var Donate = function Donate(_ref) {
52
52
  noMoneyBuys = _ref.noMoneyBuys,
53
53
  PopUpText = _ref.PopUpText,
54
54
  chooseAmountText = _ref.chooseAmountText,
55
- isDesktopOverride = _ref.isDesktopOverride;
55
+ isDesktopOverride = _ref.isDesktopOverride,
56
+ otherAmountValue = _ref.otherAmountValue;
56
57
  var isDesktop = (0, _reactResponsive.useMediaQuery)({
57
58
  query: "(min-width: ".concat(_size.screen.medium, ")")
58
59
  }); // To let us store any updated override, and force a re-render
@@ -63,11 +64,10 @@ var Donate = function Donate(_ref) {
63
64
  setOverrideValue = _useState2[1]; // Store the updated override value
64
65
 
65
66
 
66
- _react.default.useEffect(function () {
67
+ (0, _react.useEffect)(function () {
67
68
  setOverrideValue(isDesktopOverride);
68
69
  }, [isDesktopOverride]); // If a boolean value has been passed, let it replace our 'internal' value
69
70
 
70
-
71
71
  isDesktop = overrideValue !== null ? overrideValue : isDesktop;
72
72
  return /*#__PURE__*/_react.default.createElement(_Donate.Container, {
73
73
  mobileBackgroundColor: mobileBackgroundColor,
@@ -119,7 +119,8 @@ var Donate = function Donate(_ref) {
119
119
  noMoneyBuys: noMoneyBuys,
120
120
  PopUpText: PopUpText,
121
121
  chooseAmountText: chooseAmountText,
122
- submitButtonColor: submitButtonColor
122
+ submitButtonColor: submitButtonColor,
123
+ otherAmountValue: otherAmountValue
123
124
  })));
124
125
  };
125
126
 
@@ -144,7 +145,8 @@ Donate.defaultProps = {
144
145
  noMoneyBuys: false,
145
146
  PopUpText: 'Help us deliver long-term impact by converting your single donation into a monthly gift.',
146
147
  chooseAmountText: '',
147
- isDesktopOverride: null
148
+ isDesktopOverride: null,
149
+ otherAmountValue: null
148
150
  };
149
151
  var _default = Donate;
150
152
  exports.default = _default;
@@ -103,6 +103,102 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
103
103
  />;
104
104
  ```
105
105
 
106
+ ## Single Giving "No Money Buys" with overridden manual input value
107
+
108
+ ```js
109
+ import data from './dev-data/data-single';
110
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
111
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
112
+ import { useState } from 'react';
113
+
114
+ // Simulating default state of a parent componenet
115
+ const [amountDonate, setAmountDonate] = useState(123.45);
116
+
117
+ // Simulating state update of a parent componenet
118
+ setTimeout(()=>{
119
+ setAmountDonate(567.89);
120
+ }, 3000);
121
+
122
+ <Donate
123
+ mobileBackgroundColor="blue_dark"
124
+ desktopOverlayColor="blue_dark"
125
+ formAlignRight={false}
126
+ imageLow={desktopPictures.imageLow}
127
+ images={desktopPictures.images}
128
+ mobileImageLow={mobilePictures.imageLow}
129
+ mobileImages={mobilePictures.images}
130
+ data={data}
131
+ mbshipID="mship-4"
132
+ donateLink="https://donation.comicrelief.com/"
133
+ clientID="donate"
134
+ cartID="default-comicrelief"
135
+ title="Donate Now"
136
+ noMoneyBuys
137
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
138
+ otherAmountValue={amountDonate}
139
+ />;
140
+ ```
141
+
142
+ ## Form align right, with red desktop overlay and purple mobile background colour, with a blue submit button, with overridden manual input value
143
+
144
+ ```js
145
+ import data from './dev-data/data';
146
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
147
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
148
+ import { useState } from 'react';
149
+
150
+ // Simulating default state of a parent componenet
151
+ const [amountDonate, setAmountDonate] = useState(111.22);
152
+
153
+ // Simulating state update of a parent componenet
154
+ setTimeout(()=>{
155
+ setAmountDonate(333.44);
156
+ }, 3000);
157
+
158
+ <Donate
159
+ alt="Background image"
160
+ formAlignRight={true}
161
+ imageLow={desktopPictures.imageLow}
162
+ images={desktopPictures.images}
163
+ mobileImageLow={mobilePictures.imageLow}
164
+ mobileImages={mobilePictures.images}
165
+ data={data}
166
+ mbshipID="mship-1"
167
+ donateLink="https://donation.comicrelief.com/"
168
+ clientID="donate"
169
+ cartID="default-comicrelief"
170
+ title="Donate Now"
171
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
172
+ otherAmountValue={amountDonate}
173
+ />;
174
+ ```
175
+
176
+ ## Form align left, with custom message after choosing an "Other amount" to donate, high value cart.
177
+ ```js
178
+ import data from './dev-data/data-high-value';
179
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
180
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
181
+
182
+ <Donate
183
+ mobileBackgroundColor="blue_dark"
184
+ desktopOverlayColor="blue_dark"
185
+ formAlignRight={false}
186
+ imageLow={desktopPictures.imageLow}
187
+ images={desktopPictures.images}
188
+ mobileImageLow={mobilePictures.imageLow}
189
+ mobileImages={mobilePictures.images}
190
+ data={data}
191
+ mbshipID="mship-2"
192
+ donateLink="https://donation.comicrelief.com/"
193
+ clientID="donate"
194
+ cartID="default-comicrelief"
195
+ title="Donate Now"
196
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
197
+ otherAmountText="Overridden via the 'Other amount text' prop"
198
+ />;
199
+ ```
200
+
201
+
106
202
  ## Form align right - no subtitle
107
203
 
108
204
  ```js
@@ -69,4 +69,23 @@ it('Single donation with no Money Buys renders correctly', function () {
69
69
  chooseAmountText: "Overridden via the 'choose amount text' props"
70
70
  })).toJSON();
71
71
  expect(tree).toMatchSnapshot();
72
+ });
73
+ it('"Single Giving, No Money Buys, with overridden manual input value" renders correctly', function () {
74
+ var tree = (0, _shallowWithTheme.default)( /*#__PURE__*/_react.default.createElement(_Donate.default, {
75
+ mobileBackgroundColor: "blue_dark",
76
+ desktopOverlayColor: "blue_dark",
77
+ formAlignRight: false,
78
+ imageLow: defaultData.pictures.imageLow,
79
+ images: defaultData.pictures.images,
80
+ data: _data.default,
81
+ mbshipID: "mship-4",
82
+ donateLink: "https://donation.comicrelief.com/",
83
+ clientID: "donate",
84
+ cartID: "default-comicrelief",
85
+ title: "Donate Now",
86
+ noMoneyBuys: true,
87
+ subtitle: "Please help us fund life-changing projects in the UK and around the world.",
88
+ otherAmountValue: 345.67
89
+ })).toJSON();
90
+ expect(tree).toMatchSnapshot();
72
91
  });
@@ -25,7 +25,7 @@ var _Donate = require("../Donate.style");
25
25
 
26
26
  var _GivingSelector = _interopRequireDefault(require("../GivingSelector/GivingSelector"));
27
27
 
28
- var _excluded = ["data", "donateLink", "otherAmountText", "clientID", "cartID", "mbshipID", "noMoneyBuys", "PopUpText", "chooseAmountText", "submitButtonColor"];
28
+ var _excluded = ["data", "donateLink", "otherAmountText", "clientID", "cartID", "mbshipID", "noMoneyBuys", "PopUpText", "chooseAmountText", "submitButtonColor", "otherAmountValue"];
29
29
 
30
30
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
31
 
@@ -44,6 +44,7 @@ var Signup = function Signup(_ref) {
44
44
  PopUpText = _ref.PopUpText,
45
45
  chooseAmountText = _ref.chooseAmountText,
46
46
  submitButtonColor = _ref.submitButtonColor,
47
+ otherAmountValue = _ref.otherAmountValue,
47
48
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
48
49
 
49
50
  var _useState = (0, _react.useState)('single'),
@@ -78,13 +79,20 @@ var Signup = function Signup(_ref) {
78
79
  setPopUpShown = _useState12[1];
79
80
 
80
81
  (0, _react.useEffect)(function () {
81
- var givingData = givingType === 'single' ? singleGiving : regularGiving; // Check the 2nd moneybuy exists before using it;
82
- // 'philantrophy' carts have been set up to use a single moneybuy.
83
- // See ENG-1685 for more details
82
+ // If a specific 'other amount' has been passed down, use it,
83
+ // otherwise assign based on the associated moneybuys:
84
+ if (otherAmountValue) {
85
+ setAmountDonate(parseFloat(otherAmountValue));
86
+ } else {
87
+ var _givingData = givingType === 'single' ? singleGiving : regularGiving; // Check the 2nd moneybuy exists before using it;
88
+ // 'philantrophy' carts have been set up to use a single moneybuy.
89
+ // See ENG-1685 for more details
90
+
84
91
 
85
- var thisAmount = givingData.moneybuys[1] ? givingData.moneybuys[1].value : givingData.moneybuys[0].value;
86
- setAmountDonate(parseFloat(thisAmount));
87
- }, [givingType, singleGiving, regularGiving]);
92
+ var thisAmount = _givingData.moneybuys[1] ? _givingData.moneybuys[1].value : _givingData.moneybuys[0].value;
93
+ setAmountDonate(parseFloat(thisAmount));
94
+ }
95
+ }, [givingType, singleGiving, regularGiving, otherAmountValue]);
88
96
  (0, _react.useEffect)(function () {
89
97
  var givingData = givingType === 'single' ? singleGiving : regularGiving;
90
98
  var moneyBuyNewDescription = otherAmountText;
@@ -119,9 +127,15 @@ var Signup = function Signup(_ref) {
119
127
  setErrorMsg(true);
120
128
  setMoneyBuyCopy(false);
121
129
  }
122
- }; // Create money buy boxes
130
+ }; // Update the local state if the prop has been set and changed
123
131
 
124
132
 
133
+ (0, _react.useEffect)(function () {
134
+ if (otherAmountValue) {
135
+ setAmountDonate(parseFloat(otherAmountValue));
136
+ }
137
+ }, [otherAmountValue, setAmountDonate]); // Create money buy boxes
138
+
125
139
  var givingData = givingType === 'single' ? singleGiving : regularGiving;
126
140
  var showGivingSelector = singleGiving !== null && regularGiving !== null;
127
141
  return /*#__PURE__*/_react.default.createElement(_Donate.FormWrapper, null, showGivingSelector && /*#__PURE__*/_react.default.createElement(_GivingSelector.default, {