@comicrelief/component-library 7.13.0 → 7.15.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.
@@ -76,8 +76,12 @@ describe('Donate component', () => {
76
76
  .find('p.error--amount')
77
77
  .contains('Please enter an amount between £1 and £25000 and up to 2 decimal places');
78
78
  cy.get('@container')
79
- .find('form > fieldset > input')
80
- .contains('Donate monthly');
79
+ .find('[id="mship-1--MoneyBuy-userInput"]')
80
+ .clear()
81
+ .type('16');
82
+ cy.get('@container')
83
+ .find('form > fieldset > button')
84
+ .contains('Donate £16 monthly');
81
85
  cy.get('@container')
82
86
  .find('h2')
83
87
  .should('exist');
@@ -138,8 +142,12 @@ describe('Donate component', () => {
138
142
  .find('p.error--amount')
139
143
  .should('contain', 'Please enter an amount between £1 and £25000 and up to 2 decimal places');
140
144
  cy.get('@container')
141
- .find('form > fieldset > input')
142
- .contains('Donate now');
145
+ .find('[id="mship-2--MoneyBuy-userInput"]')
146
+ .clear()
147
+ .type('179');
148
+ cy.get('@container')
149
+ .find('form > fieldset > button')
150
+ .contains('Donate £179 now');
143
151
  cy.get('@container')
144
152
  .find('h2')
145
153
  .should('exist');
@@ -199,8 +207,12 @@ describe('Donate component', () => {
199
207
  .find('p.error--amount')
200
208
  .contains('Please enter an amount between £1 and £25000 and up to 2 decimal places');
201
209
  cy.get('@container')
202
- .find('form > fieldset > input')
203
- .contains('Donate now');
210
+ .find('[id="mship-3--MoneyBuy-userInput"]')
211
+ .clear()
212
+ .type('898');
213
+ cy.get('@container')
214
+ .find('form > fieldset > button')
215
+ .contains('Donate £898 now');
204
216
  cy.get('@container')
205
217
  .find('h2')
206
218
  .should('exist');
@@ -258,7 +270,7 @@ describe('Donate component', () => {
258
270
  .type('5')
259
271
  .should('not.have', 'Please enter an amount between £1 and £250000 and up to 2 decimal places');
260
272
  cy.get('@container')
261
- .find('form > fieldset > input')
273
+ .find('form > fieldset > button')
262
274
  .contains('Donate');
263
275
  cy.get('@container')
264
276
  .find('h2')
@@ -92,13 +92,13 @@ exports[`renders correctly 1`] = `
92
92
  aria-describedby="school-lookup"
93
93
  autoComplete="off"
94
94
  className="c5"
95
+ defaultValue=""
95
96
  id="school-lookup"
96
97
  name="school-lookup"
97
98
  onChange={[Function]}
98
99
  placeholder="Type to start search"
99
100
  required={false}
100
101
  type="text"
101
- value=""
102
102
  />
103
103
  </div>
104
104
 
@@ -43,20 +43,15 @@ var Typeahead = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
43
43
  fetchErrorHandler = _ref.fetchErrorHandler,
44
44
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
45
45
 
46
- var _useState = (0, _react.useState)(''),
46
+ var _useState = (0, _react.useState)([]),
47
47
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
48
- value = _useState2[0],
49
- setValue = _useState2[1];
48
+ options = _useState2[0],
49
+ setOptions = _useState2[1];
50
50
 
51
- var _useState3 = (0, _react.useState)([]),
51
+ var _useState3 = (0, _react.useState)(''),
52
52
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
53
- options = _useState4[0],
54
- setOptions = _useState4[1];
55
-
56
- var _useState5 = (0, _react.useState)(''),
57
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
58
- errorMsg = _useState6[0],
59
- setErrorMsg = _useState6[1];
53
+ errorMsg = _useState4[0],
54
+ setErrorMsg = _useState4[1];
60
55
 
61
56
  var handleChange = /*#__PURE__*/function () {
62
57
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(query) {
@@ -119,12 +114,11 @@ var Typeahead = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
119
114
 
120
115
  var debouncedHandleChange = (0, _react.useCallback)((0, _lodash.debounce)(handleChange, DELAY_DURATION), []);
121
116
  return /*#__PURE__*/_react.default.createElement(_TextInputWithDropdown.default, Object.assign({
122
- value: value,
117
+ defaultValue: "",
123
118
  options: optionParser ? options.map(optionParser) : options,
124
119
  errorMsg: errorMsg,
125
120
  onChange: function onChange(e) {
126
121
  var newValue = e.currentTarget.value;
127
- setValue(newValue);
128
122
  debouncedHandleChange(newValue);
129
123
  },
130
124
  onSelect: function onSelect(parsedOption, optionIndex) {
@@ -136,7 +130,6 @@ var Typeahead = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
136
130
 
137
131
  setOptions([]);
138
132
  setErrorMsg('');
139
- setValue('');
140
133
  },
141
134
  id: id,
142
135
  label: label,
@@ -92,13 +92,13 @@ exports[`renders correctly 1`] = `
92
92
  aria-describedby="typeahead-test"
93
93
  autoComplete="off"
94
94
  className="c5"
95
+ defaultValue=""
95
96
  id="typeahead-test"
96
97
  name="q"
97
98
  onChange={[Function]}
98
99
  placeholder="Type to start searching..."
99
100
  required={false}
100
101
  type="text"
101
- value=""
102
102
  />
103
103
  </div>
104
104
 
@@ -11,7 +11,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
11
11
  alt="Background image"
12
12
  mobileBackgroundColor="deep_violet_dark"
13
13
  desktopOverlayColor="red"
14
- submitButtonColor="blue_dark"
14
+ submitButtonColor="blue_dark"
15
15
  formAlignRight={true}
16
16
  imageLow={desktopPictures.imageLow}
17
17
  images={desktopPictures.images}
@@ -35,6 +35,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
35
35
 
36
36
  <Donate
37
37
  mobileBackgroundColor="blue_dark"
38
+ submitButtonColor="blue_dark"
38
39
  desktopOverlayColor="blue_dark"
39
40
  formAlignRight={false}
40
41
  imageLow={desktopPictures.imageLow}
@@ -61,6 +62,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
61
62
 
62
63
  <Donate
63
64
  mobileBackgroundColor="blue_dark"
65
+ submitButtonColor="blue_dark"
64
66
  desktopOverlayColor="blue_dark"
65
67
  formAlignRight={false}
66
68
  imageLow={desktopPictures.imageLow}
@@ -86,6 +88,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
86
88
 
87
89
  <Donate
88
90
  mobileBackgroundColor="blue_dark"
91
+ submitButtonColor="blue_dark"
89
92
  desktopOverlayColor="blue_dark"
90
93
  formAlignRight={false}
91
94
  imageLow={desktopPictures.imageLow}
@@ -209,6 +212,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
209
212
  <Donate
210
213
  alt="Background image"
211
214
  mobileBackgroundColor="transparent"
215
+ submitButtonColor="blue_dark"
212
216
  desktopOverlayColor="transparent"
213
217
  formAlignRight={true}
214
218
  imageLow={desktopPictures.imageLow}
@@ -234,6 +238,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
234
238
 
235
239
  <Donate
236
240
  mobileBackgroundColor="transparent"
241
+ submitButtonColor="blue_dark"
237
242
  formAlignRight={false}
238
243
  imageLow={desktopPictures.imageLow}
239
244
  images={desktopPictures.images}
@@ -258,6 +263,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
258
263
 
259
264
  <Donate
260
265
  mobileBackgroundColor="blue_dark"
266
+ submitButtonColor="blue_dark"
261
267
  formAlignRight={false}
262
268
  imageLow={desktopPictures.imageLow}
263
269
  images={desktopPictures.images}
@@ -282,6 +288,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
282
288
 
283
289
  <Donate
284
290
  mobileBackgroundColor="blue_dark"
291
+ submitButtonColor="blue_dark"
285
292
  formAlignRight={false}
286
293
  imageLow={desktopPictures.imageLow}
287
294
  images={desktopPictures.images}
@@ -305,6 +312,7 @@ import data from './dev-data/data-single';
305
312
 
306
313
  <Donate
307
314
  desktopOverlayColor="blue_dark"
315
+ submitButtonColor="blue_dark"
308
316
  mobileBackgroundColor="blue_dark"
309
317
  formAlignRight={false}
310
318
  data={data}
@@ -329,6 +337,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
329
337
  <Donate
330
338
  alt="Background image"
331
339
  mobileBackgroundColor="red"
340
+ submitButtonColor="blue_dark"
332
341
  desktopOverlayColor="red"
333
342
  formAlignRight={true}
334
343
  imageLow={desktopPictures.imageLow}
@@ -57,7 +57,7 @@ var Signup = function Signup(_ref) {
57
57
  errorMsg = _useState4[0],
58
58
  setErrorMsg = _useState4[1];
59
59
 
60
- var _useState5 = (0, _react.useState)(null),
60
+ var _useState5 = (0, _react.useState)(10),
61
61
  _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
62
62
  amountDonate = _useState6[0],
63
63
  setAmountDonate = _useState6[1];
@@ -137,7 +137,50 @@ var Signup = function Signup(_ref) {
137
137
  }, [otherAmountValue, setAmountDonate]); // Create money buy boxes
138
138
 
139
139
  var givingData = givingType === 'single' ? singleGiving : regularGiving;
140
- var showGivingSelector = singleGiving !== null && regularGiving !== null;
140
+ var showGivingSelector = singleGiving !== null && regularGiving !== null; // Create ref for amount input
141
+
142
+ var amountRef = (0, _react.useRef)(null); // Create ref for amount button
143
+
144
+ var buttonRef = (0, _react.useRef)(null);
145
+ var handleClickOutside = (0, _react.useCallback)(function (event) {
146
+ if (!errorMsg) {
147
+ return;
148
+ }
149
+
150
+ if (buttonRef.current && event.target === buttonRef.current) {
151
+ return;
152
+ }
153
+
154
+ if (amountRef.current && !amountRef.current.contains(event.target)) {
155
+ // Check the 2nd moneybuy exists before using it;
156
+ // 'philantrophy' carts have been set up to use a single moneybuy.
157
+ // See ENG-1685 for more details
158
+ var thisAmount = givingData.moneybuys[1] ? givingData.moneybuys[1].value : givingData.moneybuys[0].value;
159
+ setAmountDonate(parseFloat(thisAmount));
160
+ }
161
+ }, [errorMsg, givingData.moneybuys]); // Listen for click outside custom amount input if there is no value entered.
162
+
163
+ (0, _react.useEffect)(function () {
164
+ // Bind the event listener
165
+ document.addEventListener('mousedown', handleClickOutside);
166
+ return function () {
167
+ // Unbind the event listener on clean up
168
+ document.removeEventListener('mousedown', handleClickOutside);
169
+ };
170
+ }, [errorMsg, handleClickOutside]); // Create function to conditionally render button text
171
+
172
+ var renderButtonText = function renderButtonText() {
173
+ if (errorMsg) {
174
+ return 'Donate';
175
+ }
176
+
177
+ if (givingType === 'single') {
178
+ return "Donate \xA3".concat((0, _Membership.amountFormatter)(amountDonate), " now");
179
+ }
180
+
181
+ return "Donate \xA3".concat((0, _Membership.amountFormatter)(amountDonate), " monthly");
182
+ };
183
+
141
184
  return /*#__PURE__*/_react.default.createElement(_Donate.FormWrapper, null, showGivingSelector && /*#__PURE__*/_react.default.createElement(_GivingSelector.default, {
142
185
  givingType: givingType,
143
186
  changeGivingType: function changeGivingType(data) {
@@ -190,7 +233,8 @@ var Signup = function Signup(_ref) {
190
233
  onChange: function onChange(e) {
191
234
  return setAmountDonate(parseFloat(e.target.value));
192
235
  },
193
- "aria-label": "Input a different amount"
236
+ "aria-label": "Input a different amount",
237
+ ref: amountRef
194
238
  }))), amountDonate >= 1 && !noMoneyBuys && moneyBuyCopy && /*#__PURE__*/_react.default.createElement(_Donate.Copy, {
195
239
  as: "p"
196
240
  }, /*#__PURE__*/_react.default.createElement("strong", null, "\xA3".concat(amountDonate.toFixed(2), " ")), moneyBuyCopy), errorMsg && /*#__PURE__*/_react.default.createElement(_Donate.Error, {
@@ -198,15 +242,12 @@ var Signup = function Signup(_ref) {
198
242
  tag: "p"
199
243
  }, "Please enter an amount between \xA31 and \xA325000 and up to 2 decimal places"), noMoneyBuys ? /*#__PURE__*/_react.default.createElement(_Donate.Button, {
200
244
  type: "submit",
201
- as: "input",
202
- value: "Donate",
203
245
  color: submitButtonColor
204
- }) : /*#__PURE__*/_react.default.createElement(_Donate.Button, {
246
+ }, errorMsg ? 'Donate' : "Donate \xA3".concat((0, _Membership.amountFormatter)(amountDonate))) : /*#__PURE__*/_react.default.createElement(_Donate.Button, {
205
247
  type: "submit",
206
- as: "input",
207
- value: givingType === 'single' ? 'Donate now' : 'Donate monthly',
208
- color: submitButtonColor
209
- }))));
248
+ color: submitButtonColor,
249
+ ref: buttonRef
250
+ }, renderButtonText()))));
210
251
  };
211
252
 
212
253
  Signup.defaultProps = {
@@ -637,12 +637,13 @@ exports[`"Single Giving, No Money Buys, with overridden manual input value" rend
637
637
 
638
638
  </label>
639
639
  </div>
640
- <input
640
+ <button
641
641
  className="c24"
642
642
  color="red"
643
643
  type="submit"
644
- value="Donate"
645
- />
644
+ >
645
+ Donate £345.67
646
+ </button>
646
647
  </fieldset>
647
648
  </form>
648
649
  </div>
@@ -955,6 +956,11 @@ exports[`Monthly donation renders correctly 1`] = `
955
956
  }
956
957
 
957
958
  .c28 {
959
+ line-height: 1.5;
960
+ margin-top: 2rem;
961
+ }
962
+
963
+ .c29 {
958
964
  width: 100%;
959
965
  margin: 2rem 0 2rem;
960
966
  color: #FFFFFF;
@@ -973,9 +979,9 @@ exports[`Monthly donation renders correctly 1`] = `
973
979
  appearance: none;
974
980
  }
975
981
 
976
- .c28:active,
977
- .c28:focus,
978
- .c28:hover {
982
+ .c29:active,
983
+ .c29:focus,
984
+ .c29:hover {
979
985
  outline: none;
980
986
  background-color: #961D35;
981
987
  }
@@ -1225,7 +1231,7 @@ exports[`Monthly donation renders correctly 1`] = `
1225
1231
  }
1226
1232
 
1227
1233
  @media (min-width:740px) {
1228
- .c28 {
1234
+ .c29 {
1229
1235
  padding: 1rem 2rem;
1230
1236
  }
1231
1237
  }
@@ -1478,18 +1484,26 @@ exports[`Monthly donation renders correctly 1`] = `
1478
1484
  required={false}
1479
1485
  step="0.01"
1480
1486
  type="number"
1481
- value=" "
1487
+ value="10"
1482
1488
  />
1483
1489
  </div>
1484
1490
 
1485
1491
  </label>
1486
1492
  </div>
1487
- <input
1493
+ <p
1488
1494
  className="c28"
1495
+ >
1496
+ <strong>
1497
+ £10.00
1498
+ </strong>
1499
+ </p>
1500
+ <button
1501
+ className="c29"
1489
1502
  color="red"
1490
1503
  type="submit"
1491
- value="Donate now"
1492
- />
1504
+ >
1505
+ Donate £10 now
1506
+ </button>
1493
1507
  </fieldset>
1494
1508
  </form>
1495
1509
  </div>
@@ -1594,11 +1608,11 @@ exports[`Single donation renders correctly 1`] = `
1594
1608
  font-size: 1.25rem;
1595
1609
  }
1596
1610
 
1597
- .c13 {
1611
+ .c18 {
1598
1612
  display: block;
1599
1613
  }
1600
1614
 
1601
- .c13 input {
1615
+ .c18 input {
1602
1616
  border: none;
1603
1617
  background-color: #BECCF9;
1604
1618
  color: #000000;
@@ -1608,23 +1622,30 @@ exports[`Single donation renders correctly 1`] = `
1608
1622
  border-radius: 10px;
1609
1623
  box-shadow: 0px 0px 16px rgba(0,0,0,0.15);
1610
1624
  height: auto;
1625
+ background-color: #0565D1;
1626
+ box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1627
+ color: #FFFFFF;
1611
1628
  }
1612
1629
 
1613
- .c13 input:focus {
1630
+ .c18 input:focus {
1614
1631
  border: none;
1615
1632
  outline: none;
1616
1633
  box-shadow: inset 0 0 0 4px #0565D1;
1617
1634
  }
1618
1635
 
1619
- .c13 input:active:focus {
1636
+ .c18 input:active:focus {
1620
1637
  box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1621
1638
  }
1622
1639
 
1623
- .c18 {
1640
+ .c18 input:focus {
1641
+ box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1642
+ }
1643
+
1644
+ .c13 {
1624
1645
  display: block;
1625
1646
  }
1626
1647
 
1627
- .c18 input {
1648
+ .c13 input {
1628
1649
  border: none;
1629
1650
  background-color: #BECCF9;
1630
1651
  color: #000000;
@@ -1634,22 +1655,15 @@ exports[`Single donation renders correctly 1`] = `
1634
1655
  border-radius: 10px;
1635
1656
  box-shadow: 0px 0px 16px rgba(0,0,0,0.15);
1636
1657
  height: auto;
1637
- background-color: #0565D1;
1638
- box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1639
- color: #FFFFFF;
1640
1658
  }
1641
1659
 
1642
- .c18 input:focus {
1660
+ .c13 input:focus {
1643
1661
  border: none;
1644
1662
  outline: none;
1645
1663
  box-shadow: inset 0 0 0 4px #0565D1;
1646
1664
  }
1647
1665
 
1648
- .c18 input:active:focus {
1649
- box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1650
- }
1651
-
1652
- .c18 input:focus {
1666
+ .c13 input:active:focus {
1653
1667
  box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1654
1668
  }
1655
1669
 
@@ -1878,14 +1892,14 @@ exports[`Single donation renders correctly 1`] = `
1878
1892
  }
1879
1893
 
1880
1894
  @media (min-width:740px) {
1881
- .c13 input {
1895
+ .c18 input {
1882
1896
  font-size: 2rem;
1883
1897
  padding: 1.5rem;
1884
1898
  }
1885
1899
  }
1886
1900
 
1887
1901
  @media (min-width:740px) {
1888
- .c18 input {
1902
+ .c13 input {
1889
1903
  font-size: 2rem;
1890
1904
  padding: 1.5rem;
1891
1905
  }
@@ -2197,12 +2211,13 @@ exports[`Single donation renders correctly 1`] = `
2197
2211
  </strong>
2198
2212
  a support worker to visit 10 isolated young mums with postnatal depression in the UK.
2199
2213
  </p>
2200
- <input
2214
+ <button
2201
2215
  className="c24"
2202
2216
  color="red"
2203
2217
  type="submit"
2204
- value="Donate now"
2205
- />
2218
+ >
2219
+ Donate £20 now
2220
+ </button>
2206
2221
  </fieldset>
2207
2222
  </form>
2208
2223
  </div>
@@ -2650,18 +2665,19 @@ exports[`Single donation with no Money Buys renders correctly 1`] = `
2650
2665
  required={false}
2651
2666
  step="0.01"
2652
2667
  type="number"
2653
- value=" "
2668
+ value="10"
2654
2669
  />
2655
2670
  </div>
2656
2671
 
2657
2672
  </label>
2658
2673
  </div>
2659
- <input
2674
+ <button
2660
2675
  className="c18"
2661
2676
  color="red"
2662
2677
  type="submit"
2663
- value="Donate"
2664
- />
2678
+ >
2679
+ Donate £10
2680
+ </button>
2665
2681
  </fieldset>
2666
2682
  </form>
2667
2683
  </div>
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.13.0",
4
+ "version": "7.15.0",
5
5
  "main": "dist/index.js",
6
6
  "license": "ISC",
7
7
  "jest": {
@@ -92,13 +92,13 @@ exports[`renders correctly 1`] = `
92
92
  aria-describedby="school-lookup"
93
93
  autoComplete="off"
94
94
  className="c5"
95
+ defaultValue=""
95
96
  id="school-lookup"
96
97
  name="school-lookup"
97
98
  onChange={[Function]}
98
99
  placeholder="Type to start search"
99
100
  required={false}
100
101
  type="text"
101
- value=""
102
102
  />
103
103
  </div>
104
104
 
@@ -24,7 +24,6 @@ const Typeahead = React.forwardRef(
24
24
  },
25
25
  ref
26
26
  ) => {
27
- const [value, setValue] = useState('');
28
27
  const [options, setOptions] = useState([]);
29
28
  const [errorMsg, setErrorMsg] = useState('');
30
29
 
@@ -62,13 +61,11 @@ const Typeahead = React.forwardRef(
62
61
 
63
62
  return (
64
63
  <TextInputWithDropdown
65
- value={value}
64
+ defaultValue=""
66
65
  options={optionParser ? options.map(optionParser) : options}
67
66
  errorMsg={errorMsg}
68
67
  onChange={e => {
69
68
  const newValue = e.currentTarget.value;
70
- setValue(newValue);
71
-
72
69
  debouncedHandleChange(newValue);
73
70
  }}
74
71
  onSelect={(parsedOption, optionIndex) => {
@@ -81,7 +78,6 @@ const Typeahead = React.forwardRef(
81
78
  // reset
82
79
  setOptions([]);
83
80
  setErrorMsg('');
84
- setValue('');
85
81
  }}
86
82
  id={id}
87
83
  label={label}
@@ -92,13 +92,13 @@ exports[`renders correctly 1`] = `
92
92
  aria-describedby="typeahead-test"
93
93
  autoComplete="off"
94
94
  className="c5"
95
+ defaultValue=""
95
96
  id="typeahead-test"
96
97
  name="q"
97
98
  onChange={[Function]}
98
99
  placeholder="Type to start searching..."
99
100
  required={false}
100
101
  type="text"
101
- value=""
102
102
  />
103
103
  </div>
104
104
 
@@ -11,7 +11,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
11
11
  alt="Background image"
12
12
  mobileBackgroundColor="deep_violet_dark"
13
13
  desktopOverlayColor="red"
14
- submitButtonColor="blue_dark"
14
+ submitButtonColor="blue_dark"
15
15
  formAlignRight={true}
16
16
  imageLow={desktopPictures.imageLow}
17
17
  images={desktopPictures.images}
@@ -35,6 +35,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
35
35
 
36
36
  <Donate
37
37
  mobileBackgroundColor="blue_dark"
38
+ submitButtonColor="blue_dark"
38
39
  desktopOverlayColor="blue_dark"
39
40
  formAlignRight={false}
40
41
  imageLow={desktopPictures.imageLow}
@@ -61,6 +62,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
61
62
 
62
63
  <Donate
63
64
  mobileBackgroundColor="blue_dark"
65
+ submitButtonColor="blue_dark"
64
66
  desktopOverlayColor="blue_dark"
65
67
  formAlignRight={false}
66
68
  imageLow={desktopPictures.imageLow}
@@ -86,6 +88,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
86
88
 
87
89
  <Donate
88
90
  mobileBackgroundColor="blue_dark"
91
+ submitButtonColor="blue_dark"
89
92
  desktopOverlayColor="blue_dark"
90
93
  formAlignRight={false}
91
94
  imageLow={desktopPictures.imageLow}
@@ -209,6 +212,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
209
212
  <Donate
210
213
  alt="Background image"
211
214
  mobileBackgroundColor="transparent"
215
+ submitButtonColor="blue_dark"
212
216
  desktopOverlayColor="transparent"
213
217
  formAlignRight={true}
214
218
  imageLow={desktopPictures.imageLow}
@@ -234,6 +238,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
234
238
 
235
239
  <Donate
236
240
  mobileBackgroundColor="transparent"
241
+ submitButtonColor="blue_dark"
237
242
  formAlignRight={false}
238
243
  imageLow={desktopPictures.imageLow}
239
244
  images={desktopPictures.images}
@@ -258,6 +263,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
258
263
 
259
264
  <Donate
260
265
  mobileBackgroundColor="blue_dark"
266
+ submitButtonColor="blue_dark"
261
267
  formAlignRight={false}
262
268
  imageLow={desktopPictures.imageLow}
263
269
  images={desktopPictures.images}
@@ -282,6 +288,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
282
288
 
283
289
  <Donate
284
290
  mobileBackgroundColor="blue_dark"
291
+ submitButtonColor="blue_dark"
285
292
  formAlignRight={false}
286
293
  imageLow={desktopPictures.imageLow}
287
294
  images={desktopPictures.images}
@@ -305,6 +312,7 @@ import data from './dev-data/data-single';
305
312
 
306
313
  <Donate
307
314
  desktopOverlayColor="blue_dark"
315
+ submitButtonColor="blue_dark"
308
316
  mobileBackgroundColor="blue_dark"
309
317
  formAlignRight={false}
310
318
  data={data}
@@ -329,6 +337,7 @@ const desktopPictures = require('../../../styleguide/data/data').defaultData;
329
337
  <Donate
330
338
  alt="Background image"
331
339
  mobileBackgroundColor="red"
340
+ submitButtonColor="blue_dark"
332
341
  desktopOverlayColor="red"
333
342
  formAlignRight={true}
334
343
  imageLow={desktopPictures.imageLow}
@@ -1,4 +1,6 @@
1
- import React, { useState, useEffect } from 'react';
1
+ import React, {
2
+ useState, useRef, useEffect, useCallback
3
+ } from 'react';
2
4
  import PropTypes from 'prop-types';
3
5
 
4
6
  import PopUpComponent from './PopUpComponent';
@@ -40,7 +42,7 @@ const Signup = ({
40
42
  }) => {
41
43
  const [givingType, setGivingType] = useState('single');
42
44
  const [errorMsg, setErrorMsg] = useState(false);
43
- const [amountDonate, setAmountDonate] = useState(null);
45
+ const [amountDonate, setAmountDonate] = useState(10);
44
46
  const [moneyBuyCopy, setMoneyBuyCopy] = useState(true);
45
47
  const [popOpen, setPopOpen] = useState(false);
46
48
  // In order to keep track of whether the user has ever been shown the popup
@@ -142,6 +144,53 @@ const Signup = ({
142
144
  const givingData = givingType === 'single' ? singleGiving : regularGiving;
143
145
  const showGivingSelector = singleGiving !== null && regularGiving !== null;
144
146
 
147
+ // Create ref for amount input
148
+ const amountRef = useRef(null);
149
+ // Create ref for amount button
150
+ const buttonRef = useRef(null);
151
+
152
+ const handleClickOutside = useCallback(event => {
153
+ if (!errorMsg) {
154
+ return;
155
+ }
156
+
157
+ if (buttonRef.current && event.target === buttonRef.current) {
158
+ return;
159
+ }
160
+
161
+ if (amountRef.current && !amountRef.current.contains(event.target)) {
162
+ // Check the 2nd moneybuy exists before using it;
163
+ // 'philantrophy' carts have been set up to use a single moneybuy.
164
+ // See ENG-1685 for more details
165
+ const thisAmount = givingData.moneybuys[1]
166
+ ? givingData.moneybuys[1].value
167
+ : givingData.moneybuys[0].value;
168
+
169
+ setAmountDonate(parseFloat(thisAmount));
170
+ }
171
+ }, [errorMsg, givingData.moneybuys]);
172
+
173
+ // Listen for click outside custom amount input if there is no value entered.
174
+ useEffect(() => {
175
+ // Bind the event listener
176
+ document.addEventListener('mousedown', handleClickOutside);
177
+ return () => {
178
+ // Unbind the event listener on clean up
179
+ document.removeEventListener('mousedown', handleClickOutside);
180
+ };
181
+ }, [errorMsg, handleClickOutside]);
182
+
183
+ // Create function to conditionally render button text
184
+ const renderButtonText = () => {
185
+ if (errorMsg) {
186
+ return 'Donate';
187
+ }
188
+ if (givingType === 'single') {
189
+ return `Donate £${amountFormatter(amountDonate)} now`;
190
+ }
191
+ return `Donate £${amountFormatter(amountDonate)} monthly`;
192
+ };
193
+
145
194
  return (
146
195
  <FormWrapper>
147
196
  {showGivingSelector && (
@@ -210,6 +259,7 @@ const Signup = ({
210
259
  placeholder="0.00"
211
260
  onChange={e => setAmountDonate(parseFloat(e.target.value))}
212
261
  aria-label="Input a different amount"
262
+ ref={amountRef}
213
263
  />
214
264
  </FormFieldset>
215
265
  {amountDonate >= 1 && !noMoneyBuys && moneyBuyCopy && (
@@ -227,14 +277,23 @@ const Signup = ({
227
277
  )}
228
278
 
229
279
  {noMoneyBuys ? (
230
- <Button type="submit" as="input" value="Donate" color={submitButtonColor} />
280
+ <Button
281
+ type="submit"
282
+ color={submitButtonColor}
283
+ >
284
+ {errorMsg
285
+ ? 'Donate'
286
+ : `Donate £${amountFormatter(amountDonate)}`}
287
+ </Button>
231
288
  ) : (
232
289
  <Button
233
290
  type="submit"
234
- as="input"
235
- value={givingType === 'single' ? 'Donate now' : 'Donate monthly'}
236
291
  color={submitButtonColor}
237
- />
292
+ ref={buttonRef}
293
+ >
294
+ {renderButtonText()}
295
+ </Button>
296
+
238
297
  )}
239
298
 
240
299
  </OuterFieldset>
@@ -637,12 +637,13 @@ exports[`"Single Giving, No Money Buys, with overridden manual input value" rend
637
637
 
638
638
  </label>
639
639
  </div>
640
- <input
640
+ <button
641
641
  className="c24"
642
642
  color="red"
643
643
  type="submit"
644
- value="Donate"
645
- />
644
+ >
645
+ Donate £345.67
646
+ </button>
646
647
  </fieldset>
647
648
  </form>
648
649
  </div>
@@ -955,6 +956,11 @@ exports[`Monthly donation renders correctly 1`] = `
955
956
  }
956
957
 
957
958
  .c28 {
959
+ line-height: 1.5;
960
+ margin-top: 2rem;
961
+ }
962
+
963
+ .c29 {
958
964
  width: 100%;
959
965
  margin: 2rem 0 2rem;
960
966
  color: #FFFFFF;
@@ -973,9 +979,9 @@ exports[`Monthly donation renders correctly 1`] = `
973
979
  appearance: none;
974
980
  }
975
981
 
976
- .c28:active,
977
- .c28:focus,
978
- .c28:hover {
982
+ .c29:active,
983
+ .c29:focus,
984
+ .c29:hover {
979
985
  outline: none;
980
986
  background-color: #961D35;
981
987
  }
@@ -1225,7 +1231,7 @@ exports[`Monthly donation renders correctly 1`] = `
1225
1231
  }
1226
1232
 
1227
1233
  @media (min-width:740px) {
1228
- .c28 {
1234
+ .c29 {
1229
1235
  padding: 1rem 2rem;
1230
1236
  }
1231
1237
  }
@@ -1478,18 +1484,26 @@ exports[`Monthly donation renders correctly 1`] = `
1478
1484
  required={false}
1479
1485
  step="0.01"
1480
1486
  type="number"
1481
- value=" "
1487
+ value="10"
1482
1488
  />
1483
1489
  </div>
1484
1490
 
1485
1491
  </label>
1486
1492
  </div>
1487
- <input
1493
+ <p
1488
1494
  className="c28"
1495
+ >
1496
+ <strong>
1497
+ £10.00
1498
+ </strong>
1499
+ </p>
1500
+ <button
1501
+ className="c29"
1489
1502
  color="red"
1490
1503
  type="submit"
1491
- value="Donate now"
1492
- />
1504
+ >
1505
+ Donate £10 now
1506
+ </button>
1493
1507
  </fieldset>
1494
1508
  </form>
1495
1509
  </div>
@@ -1594,11 +1608,11 @@ exports[`Single donation renders correctly 1`] = `
1594
1608
  font-size: 1.25rem;
1595
1609
  }
1596
1610
 
1597
- .c13 {
1611
+ .c18 {
1598
1612
  display: block;
1599
1613
  }
1600
1614
 
1601
- .c13 input {
1615
+ .c18 input {
1602
1616
  border: none;
1603
1617
  background-color: #BECCF9;
1604
1618
  color: #000000;
@@ -1608,23 +1622,30 @@ exports[`Single donation renders correctly 1`] = `
1608
1622
  border-radius: 10px;
1609
1623
  box-shadow: 0px 0px 16px rgba(0,0,0,0.15);
1610
1624
  height: auto;
1625
+ background-color: #0565D1;
1626
+ box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1627
+ color: #FFFFFF;
1611
1628
  }
1612
1629
 
1613
- .c13 input:focus {
1630
+ .c18 input:focus {
1614
1631
  border: none;
1615
1632
  outline: none;
1616
1633
  box-shadow: inset 0 0 0 4px #0565D1;
1617
1634
  }
1618
1635
 
1619
- .c13 input:active:focus {
1636
+ .c18 input:active:focus {
1620
1637
  box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1621
1638
  }
1622
1639
 
1623
- .c18 {
1640
+ .c18 input:focus {
1641
+ box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1642
+ }
1643
+
1644
+ .c13 {
1624
1645
  display: block;
1625
1646
  }
1626
1647
 
1627
- .c18 input {
1648
+ .c13 input {
1628
1649
  border: none;
1629
1650
  background-color: #BECCF9;
1630
1651
  color: #000000;
@@ -1634,22 +1655,15 @@ exports[`Single donation renders correctly 1`] = `
1634
1655
  border-radius: 10px;
1635
1656
  box-shadow: 0px 0px 16px rgba(0,0,0,0.15);
1636
1657
  height: auto;
1637
- background-color: #0565D1;
1638
- box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1639
- color: #FFFFFF;
1640
1658
  }
1641
1659
 
1642
- .c18 input:focus {
1660
+ .c13 input:focus {
1643
1661
  border: none;
1644
1662
  outline: none;
1645
1663
  box-shadow: inset 0 0 0 4px #0565D1;
1646
1664
  }
1647
1665
 
1648
- .c18 input:active:focus {
1649
- box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1650
- }
1651
-
1652
- .c18 input:focus {
1666
+ .c13 input:active:focus {
1653
1667
  box-shadow: 0px 0px 16px rgba(0,0,0,0.3);
1654
1668
  }
1655
1669
 
@@ -1878,14 +1892,14 @@ exports[`Single donation renders correctly 1`] = `
1878
1892
  }
1879
1893
 
1880
1894
  @media (min-width:740px) {
1881
- .c13 input {
1895
+ .c18 input {
1882
1896
  font-size: 2rem;
1883
1897
  padding: 1.5rem;
1884
1898
  }
1885
1899
  }
1886
1900
 
1887
1901
  @media (min-width:740px) {
1888
- .c18 input {
1902
+ .c13 input {
1889
1903
  font-size: 2rem;
1890
1904
  padding: 1.5rem;
1891
1905
  }
@@ -2197,12 +2211,13 @@ exports[`Single donation renders correctly 1`] = `
2197
2211
  </strong>
2198
2212
  a support worker to visit 10 isolated young mums with postnatal depression in the UK.
2199
2213
  </p>
2200
- <input
2214
+ <button
2201
2215
  className="c24"
2202
2216
  color="red"
2203
2217
  type="submit"
2204
- value="Donate now"
2205
- />
2218
+ >
2219
+ Donate £20 now
2220
+ </button>
2206
2221
  </fieldset>
2207
2222
  </form>
2208
2223
  </div>
@@ -2650,18 +2665,19 @@ exports[`Single donation with no Money Buys renders correctly 1`] = `
2650
2665
  required={false}
2651
2666
  step="0.01"
2652
2667
  type="number"
2653
- value=" "
2668
+ value="10"
2654
2669
  />
2655
2670
  </div>
2656
2671
 
2657
2672
  </label>
2658
2673
  </div>
2659
- <input
2674
+ <button
2660
2675
  className="c18"
2661
2676
  color="red"
2662
2677
  type="submit"
2663
- value="Donate"
2664
- />
2678
+ >
2679
+ Donate £10
2680
+ </button>
2665
2681
  </fieldset>
2666
2682
  </form>
2667
2683
  </div>