@comicrelief/component-library 6.6.3 → 6.6.4

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.
@@ -7,7 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
- var _react = _interopRequireDefault(require("react"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
11
13
 
12
14
  var _reactResponsive = require("react-responsive");
13
15
 
@@ -21,6 +23,10 @@ var _Form = _interopRequireDefault(require("./Form/Form"));
21
23
 
22
24
  var _Donate = require("./Donate.style");
23
25
 
26
+ 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); }
27
+
28
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+
24
30
  var Donate = function Donate(_ref) {
25
31
  var alt = _ref.alt,
26
32
  cartID = _ref.cartID,
@@ -44,15 +50,26 @@ var Donate = function Donate(_ref) {
44
50
  PopUpText = _ref.PopUpText,
45
51
  chooseAmountText = _ref.chooseAmountText,
46
52
  isDesktopOverride = _ref.isDesktopOverride;
47
- // Can't assign this conditionally due to Hook rules..
48
53
  var isDesktop = (0, _reactResponsive.useMediaQuery)({
49
54
  query: "(min-width: ".concat(_size.screen.medium, ")")
50
- }); // ... but we can just do this, allowing the parent to control that if IT re-renders
55
+ }); // To let us store any updated override, and force a re-render
56
+
57
+ var _useState = (0, _react.useState)(null),
58
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
59
+ overrideValue = _useState2[0],
60
+ setOverrideValue = _useState2[1]; // Store the updated override value
61
+
62
+
63
+ _react.default.useEffect(function () {
64
+ setOverrideValue(isDesktopOverride);
65
+ }, [isDesktopOverride]); // If a boolean value has been passed, let it replace our 'internal' value
66
+
51
67
 
52
- if (isDesktopOverride !== null) isDesktop = isDesktopOverride;
68
+ isDesktop = overrideValue !== null ? overrideValue : isDesktop;
53
69
  return /*#__PURE__*/_react.default.createElement(_Donate.Container, {
54
70
  backgroundColor: backgroundColor,
55
- id: mbshipID
71
+ id: mbshipID,
72
+ key: overrideValue
56
73
  }, !isDesktop && mobileImages ? /*#__PURE__*/_react.default.createElement(_Picture.default, {
57
74
  backgroundColor: backgroundColor,
58
75
  image: mobileImage,
@@ -224,3 +224,30 @@ import data from './dev-data/data-single';
224
224
  chooseAmountText="Overridden via the 'choose amount text' props"
225
225
  />;
226
226
  ```
227
+
228
+ ## Forcing mobile layout via isDesktop override; needed to pass parent prop for external media queries
229
+
230
+ ```js
231
+ import data from './dev-data/data';
232
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
233
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
234
+
235
+ <Donate
236
+ alt="Background image"
237
+ backgroundColor="red"
238
+ formAlignRight={true}
239
+ imageLow={desktopPictures.imageLow}
240
+ images={desktopPictures.images}
241
+ mobileImageLow={mobilePictures.imageLow}
242
+ mobileImages={mobilePictures.images}
243
+ data={data}
244
+ mbshipID="mship-1"
245
+ donateLink="https://donation.comicrelief.com/"
246
+ clientID="donate"
247
+ cartID="default-comicrelief"
248
+ title="Donate Now"
249
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
250
+ otherDescription="will help us fund amazing projects in the UK and around the world."
251
+ isDesktopOverride={false}
252
+ />;
253
+ ```
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": "6.6.3",
4
+ "version": "6.6.4",
5
5
  "main": "dist/index.js",
6
6
  "license": "ISC",
7
7
  "jest": {
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { useMediaQuery } from 'react-responsive';
3
3
  import PropTypes from 'prop-types';
4
4
 
@@ -38,14 +38,21 @@ const Donate = ({
38
38
  chooseAmountText,
39
39
  isDesktopOverride
40
40
  }) => {
41
- // Can't assign this conditionally due to Hook rules..
42
41
  let isDesktop = useMediaQuery({ query: `(min-width: ${screen.medium})` });
43
42
 
44
- // ... but we can just do this, allowing the parent to control that if IT re-renders
45
- if (isDesktopOverride !== null) isDesktop = isDesktopOverride;
43
+ // To let us store any updated override, and force a re-render
44
+ const [overrideValue, setOverrideValue] = useState(null);
45
+
46
+ // Store the updated override value
47
+ React.useEffect(() => {
48
+ setOverrideValue(isDesktopOverride);
49
+ }, [isDesktopOverride]);
50
+
51
+ // If a boolean value has been passed, let it replace our 'internal' value
52
+ isDesktop = overrideValue !== null ? overrideValue : isDesktop;
46
53
 
47
54
  return (
48
- <Container backgroundColor={backgroundColor} id={mbshipID}>
55
+ <Container backgroundColor={backgroundColor} id={mbshipID} key={overrideValue}>
49
56
  {!isDesktop && mobileImages ? (
50
57
  <Picture
51
58
  backgroundColor={backgroundColor}
@@ -224,3 +224,30 @@ import data from './dev-data/data-single';
224
224
  chooseAmountText="Overridden via the 'choose amount text' props"
225
225
  />;
226
226
  ```
227
+
228
+ ## Forcing mobile layout via isDesktop override; needed to pass parent prop for external media queries
229
+
230
+ ```js
231
+ import data from './dev-data/data';
232
+ const mobilePictures = require('../../../styleguide/data/data').mobileImages;
233
+ const desktopPictures = require('../../../styleguide/data/data').defaultData;
234
+
235
+ <Donate
236
+ alt="Background image"
237
+ backgroundColor="red"
238
+ formAlignRight={true}
239
+ imageLow={desktopPictures.imageLow}
240
+ images={desktopPictures.images}
241
+ mobileImageLow={mobilePictures.imageLow}
242
+ mobileImages={mobilePictures.images}
243
+ data={data}
244
+ mbshipID="mship-1"
245
+ donateLink="https://donation.comicrelief.com/"
246
+ clientID="donate"
247
+ cartID="default-comicrelief"
248
+ title="Donate Now"
249
+ subtitle="Please help us fund life-changing projects in the UK and around the world."
250
+ otherDescription="will help us fund amazing projects in the UK and around the world."
251
+ isDesktopOverride={false}
252
+ />;
253
+ ```