@royaloperahouse/chord 1.18.3 → 1.19.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ ## [1.19.0]
2
+ - Add timer to navigation basket
1
3
  ## [1.18.3]
2
4
  - iOS devices show image instead of video for Compact PageHeading
3
5
 
@@ -3677,12 +3677,12 @@ var _templateObject$t;
3677
3677
  var NavTopContainer$1 = /*#__PURE__*/styled__default.div(_templateObject$t || (_templateObject$t = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n flex-direction: row;\n column-gap: 16px;\n justify-content: flex-end;\n height: 26px;\n\n @media ", " {\n column-gap: 8px;\n }\n"])), devices.mobile);
3678
3678
 
3679
3679
  var _templateObject$u, _templateObject2$f, _templateObject3$9, _templateObject4$5;
3680
- var BasketContainer = /*#__PURE__*/styled__default.div(_templateObject$u || (_templateObject$u = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: inline-flex;\n flex-direction: row;\n justify-content: flex-start;\n align-items: center;\n cursor: pointer;\n border-bottom: 1px solid var(--base-color-transparent);\n\n ", "\n\n :hover {\n border-bottom: 1px solid var(--base-color-", ");\n && a {\n color: var(--base-color-", ");\n }\n && svg path {\n fill: var(--base-color-", ");\n }\n }\n"])), function (_ref) {
3680
+ var BasketContainer = /*#__PURE__*/styled__default.div(_templateObject$u || (_templateObject$u = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: inline-flex;\n flex-direction: row;\n justify-content: flex-start;\n align-items: center;\n cursor: pointer;\n border-bottom: 1px solid var(--base-color-transparent);\n\n ", "\n\n :hover {\n border-bottom: 1px solid var(--base-color-", ");\n && a {\n color: var(--base-color-", ");\n }\n && svg path {\n fill: var(--base-color-", ");\n }\n }\n\n ", "\n"])), function (_ref) {
3681
3681
  var selected = _ref.selected,
3682
3682
  colorPrimary = _ref.colorPrimary;
3683
3683
 
3684
3684
  if (selected) {
3685
- return "\n border-bottom: 1px solid var(--base-color-" + colorPrimary + ");\n && a {\n color: var(--base-color-" + colorPrimary + ");\n } \n && svg path {\n fill: var(--base-color-" + colorPrimary + ");\n }\n ";
3685
+ return "\n border-bottom: 1px solid var(--base-color-" + colorPrimary + ");\n && a {\n color: var(--base-color-" + colorPrimary + ");\n }\n && svg path {\n fill: var(--base-color-" + colorPrimary + ");\n }\n ";
3686
3686
  }
3687
3687
 
3688
3688
  return '';
@@ -3695,18 +3695,136 @@ var BasketContainer = /*#__PURE__*/styled__default.div(_templateObject$u || (_te
3695
3695
  }, function (_ref4) {
3696
3696
  var colorPrimary = _ref4.colorPrimary;
3697
3697
  return colorPrimary;
3698
+ }, function (_ref5) {
3699
+ var isActive = _ref5.isActive,
3700
+ colorPrimary = _ref5.colorPrimary;
3701
+
3702
+ if (isActive) {
3703
+ return "\n && a {\n color: var(--base-color-" + colorPrimary + ");\n }\n && svg path {\n fill: var(--base-color-" + colorPrimary + ");\n }\n ";
3704
+ }
3705
+
3706
+ return '';
3698
3707
  });
3699
3708
  var SvgContainer = /*#__PURE__*/styled__default.div(_templateObject2$f || (_templateObject2$f = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n\n svg {\n width: var(--navigation-large-gap);\n height: var(--navigation-large-gap);\n }\n"])));
3700
3709
  var NumContainer = /*#__PURE__*/styled__default.div(_templateObject3$9 || (_templateObject3$9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n justify-content: center;\n width: 12px;\n height: 12px;\n position: absolute;\n top: 8px;\n margin-left: 6px;\n\n & .basket-num {\n color: white;\n font-size: 10px;\n font-family: var(--font-family-navigation);\n }\n"])));
3701
- var BasketText = /*#__PURE__*/styled__default.a(_templateObject4$5 || (_templateObject4$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: var(--font-size-navigation);\n font-family: var(--font-family-navigation);\n color: var(--base-color-black);\n margin-left: 6px;\n text-decoration: none;\n\n @media ", " {\n display: none;\n }\n"])), devices.mobile);
3710
+ var BasketText = /*#__PURE__*/styled__default.a(_templateObject4$5 || (_templateObject4$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: var(--font-size-navigation);\n font-family: var(--font-family-navigation);\n color: var(--base-color-black);\n margin-left: 6px;\n text-decoration: none;\n"])));
3711
+
3712
+ var getSecondsUntil = function getSecondsUntil(expiryUnixTimestamp) {
3713
+ if (!expiryUnixTimestamp) return 0;
3714
+ var now = Date.now();
3715
+ var expiry = new Date(expiryUnixTimestamp * 1000);
3716
+ var diff = Math.round((expiry.getTime() - now) / 1000);
3717
+ return diff > 0 ? diff : 0;
3718
+ };
3719
+ var formatTime = function formatTime(seconds) {
3720
+ if (seconds > 60) {
3721
+ return Math.ceil(seconds / 60) + " mins";
3722
+ }
3723
+
3724
+ return seconds + " sec" + (seconds === 1 ? '' : 's');
3725
+ };
3726
+ var checkTimeRed = function checkTimeRed(seconds) {
3727
+ if (seconds <= 0) {
3728
+ return false;
3729
+ }
3730
+
3731
+ return seconds / 60 <= 5;
3732
+ };
3733
+
3734
+ var useBasket = function useBasket(expiryUnixTimestamp, numItems, numVirtualItems) {
3735
+ if (numItems === void 0) {
3736
+ numItems = 0;
3737
+ }
3738
+
3739
+ if (numVirtualItems === void 0) {
3740
+ numVirtualItems = 0;
3741
+ }
3742
+
3743
+ var _useState = React.useState(),
3744
+ basketText = _useState[0],
3745
+ setBasketText = _useState[1];
3746
+
3747
+ var _useState2 = React.useState(),
3748
+ basketIsActive = _useState2[0],
3749
+ setBasketIsActive = _useState2[1];
3750
+
3751
+ var _useState3 = React.useState(0),
3752
+ basketTotalNumItems = _useState3[0],
3753
+ setBasketTotalNumItems = _useState3[1];
3754
+
3755
+ var _useState4 = React.useState(getSecondsUntil(expiryUnixTimestamp)),
3756
+ seconds = _useState4[0],
3757
+ setSeconds = _useState4[1];
3758
+
3759
+ var _useState5 = React.useState(),
3760
+ timer = _useState5[0],
3761
+ setTimer = _useState5[1];
3762
+
3763
+ var _useState6 = React.useState(true),
3764
+ basketIsEmpty = _useState6[0],
3765
+ setBasketIsEmpty = _useState6[1];
3766
+
3767
+ React.useEffect(function () {
3768
+ if (numItems > 0 || numVirtualItems > 0) {
3769
+ setBasketIsEmpty(false);
3770
+ } else {
3771
+ setBasketIsEmpty(true);
3772
+ }
3773
+
3774
+ setBasketTotalNumItems(numItems + numVirtualItems);
3775
+ }, [numItems, numVirtualItems]);
3776
+ React.useEffect(function () {
3777
+ if (!expiryUnixTimestamp) return;
3778
+ setSeconds(getSecondsUntil(expiryUnixTimestamp));
3779
+ }, [expiryUnixTimestamp]);
3780
+ React.useEffect(function () {
3781
+ if (timer) {
3782
+ clearInterval(timer); // clears the old timer before setting a new one
3783
+ }
3784
+
3785
+ if (!expiryUnixTimestamp || numItems === 0) return function () {
3786
+ return undefined;
3787
+ };
3788
+ var interval = setInterval(function () {
3789
+ setSeconds(getSecondsUntil(expiryUnixTimestamp));
3790
+ }, 1000);
3791
+ setTimer(interval);
3792
+ return function () {
3793
+ return clearInterval(interval);
3794
+ };
3795
+ }, [expiryUnixTimestamp]);
3796
+ React.useEffect(function () {
3797
+ if (!timer) return;
3798
+
3799
+ if (seconds > 0) {
3800
+ setBasketText(formatTime(seconds));
3801
+ setBasketIsActive(checkTimeRed(seconds));
3802
+ } else {
3803
+ clearInterval(timer);
3804
+ setBasketTotalNumItems(numVirtualItems);
3805
+ setBasketText('');
3806
+ setBasketIsActive(false);
3807
+ setBasketIsEmpty(true);
3808
+ }
3809
+ }, [seconds, timer]);
3810
+ return {
3811
+ basketText: basketText,
3812
+ basketTotalNumItems: basketTotalNumItems,
3813
+ basketIsActive: basketIsActive,
3814
+ basketIsEmpty: basketIsEmpty
3815
+ };
3816
+ };
3702
3817
 
3703
3818
  var Basket$1 = function Basket(_ref) {
3704
3819
  var text = _ref.text,
3820
+ expiryTime = _ref.expiryTime,
3705
3821
  link = _ref.link,
3706
3822
  _ref$selected = _ref.selected,
3707
3823
  selected = _ref$selected === void 0 ? false : _ref$selected,
3708
3824
  _ref$numItems = _ref.numItems,
3709
3825
  numItems = _ref$numItems === void 0 ? 0 : _ref$numItems,
3826
+ _ref$numVirtualItems = _ref.numVirtualItems,
3827
+ numVirtualItems = _ref$numVirtualItems === void 0 ? 0 : _ref$numVirtualItems,
3710
3828
  onClick = _ref.onClick,
3711
3829
  _ref$colorPrimary = _ref.colorPrimary,
3712
3830
  colorPrimary = _ref$colorPrimary === void 0 ? 'primary' : _ref$colorPrimary;
@@ -3717,28 +3835,34 @@ var Basket$1 = function Basket(_ref) {
3717
3835
  }
3718
3836
  };
3719
3837
 
3838
+ var _useBasket = useBasket(expiryTime, numItems, numVirtualItems),
3839
+ basketText = _useBasket.basketText,
3840
+ basketTotalNumItems = _useBasket.basketTotalNumItems,
3841
+ basketIsActive = _useBasket.basketIsActive,
3842
+ basketIsEmpty = _useBasket.basketIsEmpty;
3843
+
3720
3844
  var onKeyDownHandler = function onKeyDownHandler(e) {
3721
3845
  if (e.key === 'Enter') {
3722
3846
  onClickHandler();
3723
3847
  }
3724
3848
  };
3725
3849
 
3726
- var empty = numItems <= 0;
3727
3850
  return /*#__PURE__*/React__default.createElement(BasketContainer, {
3728
3851
  selected: selected,
3729
3852
  onClick: onClickHandler,
3730
3853
  onKeyDown: onKeyDownHandler,
3731
3854
  colorPrimary: colorPrimary,
3855
+ isActive: basketIsActive,
3732
3856
  tabIndex: 0
3733
- }, /*#__PURE__*/React__default.createElement(SvgContainer, null, empty ? /*#__PURE__*/React__default.createElement(Icon, {
3857
+ }, /*#__PURE__*/React__default.createElement(SvgContainer, null, basketIsEmpty ? /*#__PURE__*/React__default.createElement(Icon, {
3734
3858
  iconName: "Basket"
3735
3859
  }) : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, {
3736
3860
  iconName: "BasketFull"
3737
3861
  }), /*#__PURE__*/React__default.createElement(NumContainer, null, /*#__PURE__*/React__default.createElement("span", {
3738
3862
  className: "basket-num"
3739
- }, numItems)))), /*#__PURE__*/React__default.createElement("div", null, !empty ? /*#__PURE__*/React__default.createElement(BasketText, {
3863
+ }, basketTotalNumItems)))), /*#__PURE__*/React__default.createElement("div", null, !basketIsEmpty ? /*#__PURE__*/React__default.createElement(BasketText, {
3740
3864
  "data-testid": "baskettext"
3741
- }, text) : ''));
3865
+ }, expiryTime ? basketText : text) : ''));
3742
3866
  };
3743
3867
 
3744
3868
  var _templateObject$v, _templateObject2$g;
@@ -4002,8 +4126,10 @@ var NavTop = function NavTop(_ref) {
4002
4126
  accountOptions = _ref.accountOptions,
4003
4127
  onLink = _ref.onLink,
4004
4128
  basketText = _ref.basketText,
4129
+ basketExpiryUnixTimestamp = _ref.basketExpiryUnixTimestamp,
4005
4130
  basketLink = _ref.basketLink,
4006
4131
  basketNumItems = _ref.basketNumItems,
4132
+ basketNumVirtualItems = _ref.basketNumVirtualItems,
4007
4133
  onClickSearch = _ref.onClickSearch,
4008
4134
  _ref$isShowSearch = _ref.isShowSearch,
4009
4135
  isShowSearch = _ref$isShowSearch === void 0 ? false : _ref$isShowSearch,
@@ -4016,7 +4142,9 @@ var NavTop = function NavTop(_ref) {
4016
4142
  }), /*#__PURE__*/React__default.createElement(Basket$1, {
4017
4143
  link: basketLink,
4018
4144
  text: basketText,
4145
+ expiryTime: basketExpiryUnixTimestamp,
4019
4146
  numItems: basketNumItems,
4147
+ numVirtualItems: basketNumVirtualItems,
4020
4148
  onClick: onLink,
4021
4149
  colorPrimary: colorPrimary
4022
4150
  }), /*#__PURE__*/React__default.createElement(Account, {
@@ -4372,8 +4500,10 @@ var Navigation = function Navigation(_ref) {
4372
4500
  accountText: navTopData.accountText,
4373
4501
  accountLink: navTopData.accountLink,
4374
4502
  basketText: navTopData.basketText,
4503
+ basketExpiryUnixTimestamp: navTopData.basketExpiryUnixTimestamp,
4375
4504
  basketLink: navTopData.basketLink,
4376
4505
  basketNumItems: navTopData.basketNumItems,
4506
+ basketNumVirtualItems: navTopData.basketNumVirtualItems,
4377
4507
  onClickSearch: onClickSearchHandler,
4378
4508
  onLink: onLinkHandler,
4379
4509
  isShowSearch: showSearch,