@comicrelief/component-library 7.10.0 → 7.11.1

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.
@@ -17,7 +17,7 @@ var _PopUpComponent = _interopRequireDefault(require("./PopUpComponent"));
17
17
 
18
18
  var _Text = _interopRequireDefault(require("../../../Atoms/Text/Text"));
19
19
 
20
- var _MoneyBox = _interopRequireDefault(require("../MoneyBox/MoneyBox"));
20
+ var _MoneyBuy = _interopRequireDefault(require("../MoneyBuy/MoneyBuy"));
21
21
 
22
22
  var _Membership = require("../../../../utils/Membership");
23
23
 
@@ -56,7 +56,7 @@ var Signup = function Signup(_ref) {
56
56
  errorMsg = _useState4[0],
57
57
  setErrorMsg = _useState4[1];
58
58
 
59
- var _useState5 = (0, _react.useState)(' '),
59
+ var _useState5 = (0, _react.useState)(null),
60
60
  _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
61
61
  amountDonate = _useState6[0],
62
62
  setAmountDonate = _useState6[1];
@@ -144,10 +144,10 @@ var Signup = function Signup(_ref) {
144
144
  weight: "bold"
145
145
  }, chooseAmountText || "".concat(noMoneyBuys ? 'Enter' : 'Choose', " an amount to give"))), !noMoneyBuys && /*#__PURE__*/_react.default.createElement(_Donate.MoneyBuys, null, givingData.moneybuys.map(function (_ref2, index) {
146
146
  var value = _ref2.value;
147
- return /*#__PURE__*/_react.default.createElement(_MoneyBox.default, {
147
+ return /*#__PURE__*/_react.default.createElement(_MoneyBuy.default, {
148
148
  isSelected: amountDonate === value,
149
- amount: value,
150
- description: "\xA3".concat(value),
149
+ amount: (0, _Membership.amountFormatter)(value),
150
+ description: "\xA3".concat((0, _Membership.amountFormatter)(value)),
151
151
  setOtherAmount: function setOtherAmount() {
152
152
  return setAmountDonate(parseFloat(value));
153
153
  },
@@ -170,7 +170,7 @@ var Signup = function Signup(_ref) {
170
170
  }, rest, {
171
171
  max: "25000",
172
172
  min: "1",
173
- value: amountDonate,
173
+ value: (0, _Membership.amountFormatter)(amountDonate),
174
174
  pattern: "[^[0-9]+([,.][0-9]+)?$]",
175
175
  placeholder: "0.00",
176
176
  onChange: function onChange(e) {
@@ -25,9 +25,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
25
25
 
26
26
  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; }
27
27
 
28
- var MoneyBox = (0, _styledComponents.default)(_Input.default).withConfig({
29
- displayName: "MoneyBox",
30
- componentId: "sc-1d9rl92-0"
28
+ var MoneyBuyButton = (0, _styledComponents.default)(_Input.default).withConfig({
29
+ displayName: "MoneyBuy__MoneyBuyButton",
30
+ componentId: "sc-38g5hn-0"
31
31
  })(["display:block;input{border:none;background-color:", ";color:", ";font-size:", ";font-family:", ";font-weight:normal;border-radius:10px;padding:", ";box-shadow:0px 0px 16px rgba(0,0,0,0.15);height:auto;", "{font-size:", ";padding:", ";}&:focus{border:none;outline:none;box-shadow:inset 0 0 0 4px ", ";}&:active:focus{box-shadow:0px 0px 16px rgba(0,0,0,0.3);}", "}"], function (_ref) {
32
32
  var theme = _ref.theme;
33
33
  return theme.color('blue_light');
@@ -63,7 +63,7 @@ var MoneyBuy = function MoneyBuy(_ref10) {
63
63
  currency = _ref10.currency,
64
64
  description = _ref10.description,
65
65
  rest = (0, _objectWithoutProperties2.default)(_ref10, _excluded);
66
- return /*#__PURE__*/_react.default.createElement(MoneyBox, Object.assign({}, rest, {
66
+ return /*#__PURE__*/_react.default.createElement(MoneyBuyButton, Object.assign({}, rest, {
67
67
  "aria-label": description,
68
68
  value: "".concat(currency, " ").concat(amount),
69
69
  type: "button",
@@ -705,7 +705,7 @@ exports[`Monthly donation renders correctly 1`] = `
705
705
 
706
706
  <input
707
707
  aria-describedby="mship-1--moneyBuy-box1"
708
- aria-label="£10"
708
+ aria-label="£10.10"
709
709
  className="c23"
710
710
  id="mship-1--moneyBuy-box1"
711
711
  name="mship-1--moneyBuy1"
@@ -713,7 +713,7 @@ exports[`Monthly donation renders correctly 1`] = `
713
713
  placeholder=""
714
714
  required={false}
715
715
  type="button"
716
- value="£ 10"
716
+ value="£ 10.10"
717
717
  />
718
718
  </div>
719
719
 
@@ -1531,7 +1531,7 @@ exports[`Single donation renders correctly 1`] = `
1531
1531
  required={false}
1532
1532
  step="0.01"
1533
1533
  type="number"
1534
- value={20}
1534
+ value="20"
1535
1535
  />
1536
1536
  </div>
1537
1537
 
@@ -9,7 +9,7 @@ var _default = {
9
9
  singleGiving: {
10
10
  moneybuys: [{
11
11
  description: 'a pregnant woman in Uganda to have access to a birth kit so she can have a clean, safe delivery.',
12
- value: 10
12
+ value: 10.1
13
13
  }, {
14
14
  description: 'a support worker to visit 10 isolated young mums with postnatal depression in the UK.',
15
15
  value: 20
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.handleDonateSubmission = exports.isInputMatchBoxValue = exports.isAmountValid = exports.onKeyPress = void 0;
6
+ exports.amountFormatter = exports.handleDonateSubmission = exports.isInputMatchBoxValue = exports.isAmountValid = exports.onKeyPress = void 0;
7
7
 
8
8
  // this function prevent keyboard characters like e, + , - to be passed on the input
9
9
  var onKeyPress = function onKeyPress(event) {
@@ -14,6 +14,15 @@ var onKeyPress = function onKeyPress(event) {
14
14
 
15
15
  exports.onKeyPress = onKeyPress;
16
16
 
17
+ var amountFormatter = function amountFormatter(amount) {
18
+ if (!amount) return ' '; // Determine how many places to fix the number to before passing
19
+
20
+ var decPoint = !Number.isInteger(amount) ? 2 : 0;
21
+ return parseFloat(amount).toFixed(decPoint);
22
+ };
23
+
24
+ exports.amountFormatter = amountFormatter;
25
+
17
26
  var isAmountValid = function isAmountValid(input) {
18
27
  var reg = /^\s*(?=.*[1-9])\d*(?:\.\d{1,2})?\s*$/g;
19
28
  var isValid = input * 1 >= 1 && input * 1 <= 25000 && reg.test(input);
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var whiteList = ['https://giftaid.comicrelief.com', 'https://donation.comicrelief.com', 'https://www.comicrelief.com', 'https://www.sportrelief.com', 'https://app.beapplied.com/org/comic-relief', 'http://stories.comicrelief.com'];
7
+ var whiteList = ['https://giftaid.comicrelief.com', 'https://donation.comicrelief.com', 'https://www.comicrelief.com', 'https://www.sportrelief.com', 'https://app.beapplied.com/org/comic-relief', 'stories.comicrelief.com'];
8
8
 
9
9
  var whiteListed = function whiteListed(url) {
10
10
  if (url !== undefined && url !== null && whiteList.some(function (v) {
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.10.0",
4
+ "version": "7.11.1",
5
5
  "main": "dist/index.js",
6
6
  "license": "ISC",
7
7
  "jest": {
@@ -3,10 +3,11 @@ import PropTypes from 'prop-types';
3
3
 
4
4
  import PopUpComponent from './PopUpComponent';
5
5
  import Text from '../../../Atoms/Text/Text';
6
- import MoneyBox from '../MoneyBox/MoneyBox';
6
+ import MoneyBuy from '../MoneyBuy/MoneyBuy';
7
7
  import {
8
8
  handleDonateSubmission,
9
- isAmountValid
9
+ isAmountValid,
10
+ amountFormatter
10
11
  } from '../../../../utils/Membership';
11
12
  import {
12
13
  Button,
@@ -38,7 +39,7 @@ const Signup = ({
38
39
  }) => {
39
40
  const [givingType, setGivingType] = useState('single');
40
41
  const [errorMsg, setErrorMsg] = useState(false);
41
- const [amountDonate, setAmountDonate] = useState(' ');
42
+ const [amountDonate, setAmountDonate] = useState(null);
42
43
  const [moneyBuyCopy, setMoneyBuyCopy] = useState(true);
43
44
  const [popOpen, setPopOpen] = useState(false);
44
45
  // In order to keep track of whether the user has ever been shown the popup
@@ -160,10 +161,10 @@ const Signup = ({
160
161
  {!noMoneyBuys && (
161
162
  <MoneyBuys>
162
163
  {givingData.moneybuys.map(({ value }, index) => (
163
- <MoneyBox
164
+ <MoneyBuy
164
165
  isSelected={amountDonate === value}
165
- amount={value}
166
- description={`£${value}`}
166
+ amount={amountFormatter(value)}
167
+ description={`£${amountFormatter(value)}`}
167
168
  setOtherAmount={() => setAmountDonate(parseFloat(value))}
168
169
  key={value}
169
170
  name={`${mbshipID}--moneyBuy${index + 1}`}
@@ -190,7 +191,7 @@ const Signup = ({
190
191
  {...rest}
191
192
  max="25000"
192
193
  min="1"
193
- value={amountDonate}
194
+ value={amountFormatter(amountDonate)}
194
195
  pattern="[^[0-9]+([,.][0-9]+)?$]"
195
196
  placeholder="0.00"
196
197
  onChange={e => setAmountDonate(parseFloat(e.target.value))}
@@ -6,7 +6,7 @@ import Input from '../../../Atoms/Input/Input';
6
6
  import spacing from '../../../../theme/shared/spacing';
7
7
  import { media } from '../../../../theme/shared/size';
8
8
 
9
- const MoneyBox = styled(Input)`
9
+ const MoneyBuyButton = styled(Input)`
10
10
  display: block;
11
11
  input {
12
12
  border: none;
@@ -51,7 +51,7 @@ const MoneyBuy = ({
51
51
  description,
52
52
  ...rest
53
53
  }) => (
54
- <MoneyBox
54
+ <MoneyBuyButton
55
55
  {...rest}
56
56
  aria-label={description}
57
57
  value={`${currency} ${amount}`}
@@ -63,10 +63,10 @@ const MoneyBuy = ({
63
63
  );
64
64
 
65
65
  MoneyBuy.propTypes = {
66
- amount: PropTypes.number,
66
+ amount: PropTypes.string,
67
67
  currency: PropTypes.string,
68
68
  description: PropTypes.string,
69
- // Function already set does'nt need to be passed as props
69
+ // Function already set doesn't need to be passed as props
70
70
  setOtherAmount: PropTypes.func.isRequired
71
71
  };
72
72
 
@@ -705,7 +705,7 @@ exports[`Monthly donation renders correctly 1`] = `
705
705
 
706
706
  <input
707
707
  aria-describedby="mship-1--moneyBuy-box1"
708
- aria-label="£10"
708
+ aria-label="£10.10"
709
709
  className="c23"
710
710
  id="mship-1--moneyBuy-box1"
711
711
  name="mship-1--moneyBuy1"
@@ -713,7 +713,7 @@ exports[`Monthly donation renders correctly 1`] = `
713
713
  placeholder=""
714
714
  required={false}
715
715
  type="button"
716
- value="£ 10"
716
+ value="£ 10.10"
717
717
  />
718
718
  </div>
719
719
 
@@ -1531,7 +1531,7 @@ exports[`Single donation renders correctly 1`] = `
1531
1531
  required={false}
1532
1532
  step="0.01"
1533
1533
  type="number"
1534
- value={20}
1534
+ value="20"
1535
1535
  />
1536
1536
  </div>
1537
1537
 
@@ -5,7 +5,7 @@ export default {
5
5
  {
6
6
  description:
7
7
  'a pregnant woman in Uganda to have access to a birth kit so she can have a clean, safe delivery.',
8
- value: 10
8
+ value: 10.1
9
9
  },
10
10
  {
11
11
  description:
@@ -5,6 +5,13 @@ const onKeyPress = event => {
5
5
  if (/\+|-|e/.test(keyValue)) event.preventDefault();
6
6
  };
7
7
 
8
+ const amountFormatter = amount => {
9
+ if (!amount) return ' ';
10
+ // Determine how many places to fix the number to before passing
11
+ const decPoint = (!Number.isInteger(amount)) ? 2 : 0;
12
+ return parseFloat(amount).toFixed(decPoint);
13
+ };
14
+
8
15
  const isAmountValid = input => {
9
16
  const reg = /^\s*(?=.*[1-9])\d*(?:\.\d{1,2})?\s*$/g;
10
17
  const isValid = input * 1 >= 1 && input * 1 <= 25000 && reg.test(input);
@@ -64,5 +71,6 @@ export {
64
71
  onKeyPress,
65
72
  isAmountValid,
66
73
  isInputMatchBoxValue,
67
- handleDonateSubmission
74
+ handleDonateSubmission,
75
+ amountFormatter
68
76
  };
@@ -4,7 +4,7 @@ const whiteList = [
4
4
  'https://www.comicrelief.com',
5
5
  'https://www.sportrelief.com',
6
6
  'https://app.beapplied.com/org/comic-relief',
7
- 'http://stories.comicrelief.com'
7
+ 'stories.comicrelief.com'
8
8
  ];
9
9
 
10
10
  const whiteListed = url => {