@skyscanner/backpack-web 23.2.1 → 23.3.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.
Files changed (111) hide show
  1. package/bpk-component-aria-live/src/BpkAriaLive.js +0 -1
  2. package/bpk-component-badge/src/BpkBadge.js +0 -1
  3. package/{bpk-scrim-utils/src/customPropTypes.js → bpk-component-banner-alert/index.d.ts} +16 -14
  4. package/bpk-component-banner-alert/src/AnimateAndFade.d.ts +61 -0
  5. package/bpk-component-banner-alert/src/AnimateAndFade.js +3 -9
  6. package/bpk-component-banner-alert/src/BpkBannerAlert.d.ts +29 -0
  7. package/bpk-component-banner-alert/src/BpkBannerAlert.js +42 -21
  8. package/bpk-component-banner-alert/src/BpkBannerAlertDismissable.d.ts +30 -0
  9. package/bpk-component-banner-alert/src/BpkBannerAlertDismissable.js +31 -33
  10. package/bpk-component-banner-alert/src/BpkBannerAlertExpandable.d.ts +35 -0
  11. package/bpk-component-banner-alert/src/BpkBannerAlertExpandable.js +15 -28
  12. package/bpk-component-banner-alert/src/BpkBannerAlertInner.d.ts +58 -0
  13. package/bpk-component-banner-alert/src/BpkBannerAlertInner.js +65 -87
  14. package/bpk-component-banner-alert/src/common-types.d.ts +44 -0
  15. package/bpk-component-banner-alert/src/common-types.js +5 -23
  16. package/bpk-component-banner-alert/src/themeAttributes.d.ts +20 -0
  17. package/bpk-component-banner-alert/src/withBannerAlertState.d.ts +169 -0
  18. package/bpk-component-banner-alert/src/withBannerAlertState.js +10 -29
  19. package/bpk-component-boilerplate/src/BpkBoilerplate.js +0 -1
  20. package/bpk-component-button/index.js +13 -0
  21. package/bpk-component-button/src/BpkButtonV2/BpkButton.js +0 -1
  22. package/bpk-component-calendar/index.d.ts +30 -0
  23. package/bpk-component-calendar/index.js +5 -4
  24. package/bpk-component-calendar/src/BpkCalendarContainer.d.ts +429 -0
  25. package/bpk-component-calendar/src/BpkCalendarContainer.js +19 -29
  26. package/bpk-component-calendar/src/BpkCalendarDate.d.ts +62 -0
  27. package/bpk-component-calendar/src/BpkCalendarDate.js +15 -39
  28. package/bpk-component-calendar/src/BpkCalendarGrid.d.ts +68 -0
  29. package/bpk-component-calendar/src/BpkCalendarGrid.js +9 -40
  30. package/bpk-component-calendar/src/BpkCalendarGridHeader.d.ts +36 -0
  31. package/bpk-component-calendar/src/BpkCalendarGridHeader.js +33 -52
  32. package/bpk-component-calendar/src/BpkCalendarGridTransition.d.ts +56 -0
  33. package/bpk-component-calendar/src/BpkCalendarGridTransition.js +43 -42
  34. package/bpk-component-calendar/src/BpkCalendarNav.d.ts +37 -0
  35. package/bpk-component-calendar/src/BpkCalendarNav.js +18 -32
  36. package/bpk-component-calendar/src/Week.d.ts +51 -0
  37. package/bpk-component-calendar/src/Week.js +48 -70
  38. package/bpk-component-calendar/src/composeCalendar.d.ts +52 -0
  39. package/bpk-component-calendar/src/composeCalendar.js +34 -95
  40. package/bpk-component-calendar/src/custom-proptypes-legacy.js +140 -0
  41. package/bpk-component-calendar/src/custom-proptypes.d.ts +46 -0
  42. package/bpk-component-calendar/src/custom-proptypes.js +2 -61
  43. package/bpk-component-calendar/src/date-utils.d.ts +54 -0
  44. package/bpk-component-calendar/src/utils.d.ts +26 -0
  45. package/bpk-component-calendar/src/utils.js +1 -0
  46. package/bpk-component-calendar/test-utils.d.ts +56 -0
  47. package/bpk-component-calendar/test-utils.js +2 -2
  48. package/bpk-component-card/index.d.ts +24 -0
  49. package/bpk-component-card/src/BpkCard.d.ts +39 -0
  50. package/bpk-component-card/src/BpkCard.js +9 -25
  51. package/bpk-component-card/src/BpkCardWrapper.d.ts +33 -0
  52. package/bpk-component-card/src/BpkCardWrapper.js +10 -18
  53. package/bpk-component-card/src/BpkDividedCard.d.ts +43 -0
  54. package/bpk-component-card/src/BpkDividedCard.js +9 -24
  55. package/bpk-component-chip/index.d.ts +32 -0
  56. package/bpk-component-chip/src/BpkDismissibleChip.d.ts +28 -0
  57. package/bpk-component-chip/src/BpkDismissibleChip.js +9 -8
  58. package/bpk-component-chip/src/BpkDropdownChip.d.ts +29 -0
  59. package/bpk-component-chip/src/BpkDropdownChip.js +39 -25
  60. package/bpk-component-chip/src/BpkSelectableChip.d.ts +39 -0
  61. package/bpk-component-chip/src/BpkSelectableChip.js +34 -48
  62. package/bpk-component-chip/src/commonTypes.d.ts +56 -0
  63. package/bpk-component-chip/src/commonTypes.js +8 -2
  64. package/bpk-component-dialog/src/BpkDialog.js +0 -1
  65. package/bpk-component-dialog/src/BpkDialogInner.js +0 -2
  66. package/bpk-component-graphic-promotion/src/BpkGraphicPromo.js +0 -2
  67. package/bpk-component-icon/src/classNameModifierHOCFactory.js +0 -1
  68. package/bpk-component-icon/src/withAlignment.js +1 -1
  69. package/bpk-component-icon/src/withDescription.js +1 -1
  70. package/bpk-component-icon/src/withRtlSupport.js +0 -2
  71. package/bpk-component-input/index.d.ts +39 -0
  72. package/bpk-component-input/src/BpkClearButton.d.ts +28 -0
  73. package/bpk-component-input/src/BpkClearButton.js +6 -14
  74. package/bpk-component-input/src/BpkInput.d.ts +46 -0
  75. package/bpk-component-input/src/BpkInput.js +7 -3
  76. package/bpk-component-input/src/common-types.d.ts +91 -0
  77. package/bpk-component-input/src/common-types.js +4 -1
  78. package/bpk-component-input/src/withOpenEvents.d.ts +121 -0
  79. package/bpk-component-input/src/withOpenEvents.js +14 -25
  80. package/bpk-component-modal/index.js +11 -4
  81. package/bpk-component-modal/src/BpkModalV2/BpKModal.module.css +18 -0
  82. package/bpk-component-modal/src/BpkModalV2/BpkModal.d.ts +35 -0
  83. package/bpk-component-modal/src/BpkModalV2/BpkModal.js +133 -0
  84. package/bpk-component-rtl-toggle/index.d.ts +23 -0
  85. package/bpk-component-rtl-toggle/src/BpkRtlToggle.d.ts +41 -0
  86. package/bpk-component-rtl-toggle/src/BpkRtlToggle.js +9 -12
  87. package/bpk-component-rtl-toggle/src/updateOnDirectionChange.d.ts +151 -0
  88. package/bpk-component-rtl-toggle/src/updateOnDirectionChange.js +9 -2
  89. package/bpk-component-rtl-toggle/src/utils.d.ts +25 -0
  90. package/bpk-react-utils/index.d.ts +58 -0
  91. package/bpk-react-utils/index.js +1 -0
  92. package/bpk-react-utils/src/Portal.d.ts +76 -0
  93. package/bpk-react-utils/src/Portal.js +33 -43
  94. package/bpk-react-utils/src/TransitionInitialMount.d.ts +27 -0
  95. package/bpk-react-utils/src/TransitionInitialMount.js +7 -8
  96. package/bpk-react-utils/src/cssModules.d.ts +22 -0
  97. package/bpk-react-utils/src/deprecated.js +2 -1
  98. package/bpk-react-utils/src/deviceDetection.d.ts +22 -0
  99. package/bpk-react-utils/src/deviceDetection.js +3 -1
  100. package/bpk-react-utils/src/isRTL.d.ts +20 -0
  101. package/bpk-react-utils/src/isRTL.js +3 -1
  102. package/bpk-react-utils/src/withDefaultProps.d.ts +33 -0
  103. package/bpk-react-utils/src/withDefaultProps.js +11 -24
  104. package/bpk-react-utils/src/wrapDisplayName.d.ts +21 -0
  105. package/bpk-scrim-utils/src/BpkScrim.d.ts +24 -0
  106. package/bpk-scrim-utils/src/BpkScrim.js +5 -10
  107. package/bpk-scrim-utils/src/scroll-utils.d.ts +24 -0
  108. package/bpk-scrim-utils/src/scroll-utils.js +1 -1
  109. package/bpk-scrim-utils/src/withScrim.d.ts +95 -0
  110. package/bpk-scrim-utils/src/withScrim.js +5 -12
  111. package/package.json +1 -1
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.addCalendarGridTransition = void 0;
7
- var _propTypes = _interopRequireDefault(require("prop-types"));
8
7
  var _react = require("react");
9
8
  var _bpkReactUtils = require("../../bpk-react-utils");
10
9
  var _utils = require("./utils");
@@ -12,31 +11,30 @@ var _dateUtils = require("./date-utils");
12
11
  var _BpkCalendarGridTransitionModule = _interopRequireDefault(require("./BpkCalendarGridTransition.module.css"));
13
12
  var _jsxRuntime = require("react/jsx-runtime");
14
13
  const _excluded = ["TransitionComponent", "className", "focusedDate"];
15
- /*
16
- * Backpack - Skyscanner's Design System
17
- *
18
- * Copyright 2016 Skyscanner Ltd
19
- *
20
- * Licensed under the Apache License, Version 2.0 (the "License");
21
- * you may not use this file except in compliance with the License.
22
- * You may obtain a copy of the License at
23
- *
24
- * http://www.apache.org/licenses/LICENSE-2.0
25
- *
26
- * Unless required by applicable law or agreed to in writing, software
27
- * distributed under the License is distributed on an "AS IS" BASIS,
28
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
- * See the License for the specific language governing permissions and
30
- * limitations under the License.
31
- */
32
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
15
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
34
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
35
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
36
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
37
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
38
17
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
39
18
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
19
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
21
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
22
+ * Backpack - Skyscanner's Design System
23
+ *
24
+ * Copyright 2016 Skyscanner Ltd
25
+ *
26
+ * Licensed under the Apache License, Version 2.0 (the "License");
27
+ * you may not use this file except in compliance with the License.
28
+ * You may obtain a copy of the License at
29
+ *
30
+ * http://www.apache.org/licenses/LICENSE-2.0
31
+ *
32
+ * Unless required by applicable law or agreed to in writing, software
33
+ * distributed under the License is distributed on an "AS IS" BASIS,
34
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35
+ * See the License for the specific language governing permissions and
36
+ * limitations under the License.
37
+ */
40
38
  const getClassName = (0, _bpkReactUtils.cssModules)(_BpkCalendarGridTransitionModule.default);
41
39
  const transitionValues = {
42
40
  previous: '0px',
@@ -47,6 +45,10 @@ const getFocusedDateForMonth = (month, currentFocusedDate, minDate, maxDate) =>
47
45
  class BpkCalendarGridTransition extends _react.Component {
48
46
  constructor(props) {
49
47
  super(props);
48
+ _defineProperty(this, "isTransitionEndSupported", void 0);
49
+ const {
50
+ month = new Date()
51
+ } = props;
50
52
  this.onMonthTransitionEnd = this.onMonthTransitionEnd.bind(this);
51
53
  this.state = {
52
54
  isTransitioning: false,
@@ -54,15 +56,20 @@ class BpkCalendarGridTransition extends _react.Component {
54
56
  // Used in a test so this is valid usage.
55
57
  // eslint-disable-next-line react/no-unused-state
56
58
  currentMonth: props.month,
57
- months: [(0, _dateUtils.addMonths)(props.month, -1), props.month, (0, _dateUtils.addMonths)(props.month, 1)]
59
+ months: [(0, _dateUtils.addMonths)(month, -1), month, (0, _dateUtils.addMonths)(month, 1)]
58
60
  };
59
61
  this.isTransitionEndSupported = (0, _utils.isTransitionEndSupported)();
60
62
  }
61
- UNSAFE_componentWillReceiveProps(nextProps) {
62
- const hasMonthChanged = !(0, _dateUtils.isSameMonth)(this.props.month, nextProps.month);
63
+ UNSAFE_componentWillReceiveProps({
64
+ month: nextMonth = new Date()
65
+ }) {
66
+ const {
67
+ month = new Date()
68
+ } = this.props;
69
+ const hasMonthChanged = !(0, _dateUtils.isSameMonth)(month, nextMonth);
63
70
  if (hasMonthChanged) {
64
71
  const reverse = (0, _bpkReactUtils.isRTL)();
65
- if ((0, _dateUtils.differenceInCalendarMonths)(nextProps.month, this.props.month) === 1) {
72
+ if ((0, _dateUtils.differenceInCalendarMonths)(nextMonth, month) === 1) {
66
73
  // Transition to next month
67
74
  this.setState({
68
75
  transitionValue: reverse ? transitionValues.previous : transitionValues.next,
@@ -70,7 +77,7 @@ class BpkCalendarGridTransition extends _react.Component {
70
77
  });
71
78
  return;
72
79
  }
73
- if ((0, _dateUtils.differenceInCalendarMonths)(nextProps.month, this.props.month) === -1) {
80
+ if ((0, _dateUtils.differenceInCalendarMonths)(nextMonth, month) === -1) {
74
81
  // Transition to previous month
75
82
  this.setState({
76
83
  transitionValue: reverse ? transitionValues.next : transitionValues.previous,
@@ -81,8 +88,8 @@ class BpkCalendarGridTransition extends _react.Component {
81
88
  this.setState({
82
89
  // Used in a test so this is valid usage.
83
90
  // eslint-disable-next-line react/no-unused-state
84
- currentMonth: nextProps.month,
85
- months: [(0, _dateUtils.addMonths)(nextProps.month, -1), nextProps.month, (0, _dateUtils.addMonths)(nextProps.month, 1)]
91
+ currentMonth: nextMonth,
92
+ months: [(0, _dateUtils.addMonths)(nextMonth, -1), nextMonth, (0, _dateUtils.addMonths)(nextMonth, 1)]
86
93
  });
87
94
  }
88
95
  }
@@ -96,7 +103,7 @@ class BpkCalendarGridTransition extends _react.Component {
96
103
  }
97
104
  onMonthTransitionEnd() {
98
105
  const {
99
- month
106
+ month = new Date()
100
107
  } = this.props;
101
108
  this.setState({
102
109
  transitionValue: transitionValues.current,
@@ -111,8 +118,8 @@ class BpkCalendarGridTransition extends _react.Component {
111
118
  const _this$props = this.props,
112
119
  {
113
120
  TransitionComponent,
114
- className,
115
- focusedDate
121
+ className = null,
122
+ focusedDate = null
116
123
  } = _this$props,
117
124
  rest = _objectWithoutProperties(_this$props, _excluded);
118
125
  const {
@@ -152,20 +159,14 @@ class BpkCalendarGridTransition extends _react.Component {
152
159
  });
153
160
  }
154
161
  }
155
- BpkCalendarGridTransition.propTypes = {
156
- TransitionComponent: _propTypes.default.elementType.isRequired,
157
- className: _propTypes.default.string,
158
- month: _propTypes.default.instanceOf(Date),
159
- focusedDate: _propTypes.default.instanceOf(Date)
160
- };
161
- BpkCalendarGridTransition.defaultProps = {
162
+ _defineProperty(BpkCalendarGridTransition, "defaultProps", {
162
163
  className: null,
163
- month: null,
164
+ month: new Date(),
164
165
  focusedDate: null
165
- };
166
- const addCalendarGridTransition = TransitionComponent => props => /*#__PURE__*/(0, _jsxRuntime.jsx)(BpkCalendarGridTransition, _objectSpread({
166
+ });
167
+ const addCalendarGridTransition = TransitionComponent => props => /*#__PURE__*/(0, _jsxRuntime.jsx)(BpkCalendarGridTransition, _objectSpread(_objectSpread({}, props), {}, {
167
168
  TransitionComponent: TransitionComponent
168
- }, props));
169
+ }));
169
170
  exports.addCalendarGridTransition = addCalendarGridTransition;
170
171
  var _default = BpkCalendarGridTransition;
171
172
  exports.default = _default;
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2016 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import type { ChangeEvent, MouseEvent } from 'react';
20
+ type MonthChangeEvent = ChangeEvent<HTMLInputElement> | MouseEvent<HTMLButtonElement>;
21
+ type Props = {
22
+ changeMonthLabel: string;
23
+ formatMonth: (month: Date) => string;
24
+ id: string;
25
+ maxDate: Date;
26
+ minDate: Date;
27
+ month: Date;
28
+ nextMonthLabel: string;
29
+ previousMonthLabel: string;
30
+ onMonthChange?: (event: MonthChangeEvent, options: {
31
+ month: Date;
32
+ source: string;
33
+ }) => void;
34
+ disabled?: boolean;
35
+ };
36
+ declare const BpkCalendarNav: ({ changeMonthLabel, disabled, formatMonth, id, maxDate, minDate, month, nextMonthLabel, onMonthChange, previousMonthLabel, }: Props) => JSX.Element;
37
+ export default BpkCalendarNav;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _propTypes = _interopRequireDefault(require("prop-types"));
8
7
  var _arrowLeft = _interopRequireDefault(require("../../bpk-component-icon/lg/arrow-left"));
9
8
  var _arrowRight = _interopRequireDefault(require("../../bpk-component-icon/lg/arrow-right"));
10
9
  var _bpkComponentSelect = _interopRequireDefault(require("../../bpk-component-select"));
@@ -32,6 +31,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
32
31
  * limitations under the License.
33
32
  */
34
33
 
34
+ // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
35
+
36
+ // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
37
+
38
+ // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
39
+
35
40
  const getClassName = (0, _bpkReactUtils.cssModules)(_BpkCalendarNavModule.default);
36
41
  const changeMonth = ({
37
42
  callback,
@@ -53,19 +58,18 @@ const changeMonth = ({
53
58
  });
54
59
  }
55
60
  };
56
- const BpkCalendarNav = props => {
57
- const {
58
- changeMonthLabel,
59
- disabled,
60
- formatMonth,
61
- id,
62
- maxDate,
63
- minDate,
64
- month,
65
- nextMonthLabel,
66
- onMonthChange,
67
- previousMonthLabel
68
- } = props;
61
+ const BpkCalendarNav = ({
62
+ changeMonthLabel,
63
+ disabled = false,
64
+ formatMonth,
65
+ id,
66
+ maxDate,
67
+ minDate,
68
+ month,
69
+ nextMonthLabel,
70
+ onMonthChange = () => {},
71
+ previousMonthLabel
72
+ }) => {
69
73
  const baseMonth = (0, _dateUtils.startOfMonth)(month);
70
74
  const {
71
75
  max,
@@ -157,23 +161,5 @@ const BpkCalendarNav = props => {
157
161
  })
158
162
  });
159
163
  };
160
- BpkCalendarNav.propTypes = {
161
- // Required
162
- changeMonthLabel: _propTypes.default.string.isRequired,
163
- formatMonth: _propTypes.default.func.isRequired,
164
- id: _propTypes.default.string.isRequired,
165
- maxDate: _propTypes.default.instanceOf(Date).isRequired,
166
- minDate: _propTypes.default.instanceOf(Date).isRequired,
167
- month: _propTypes.default.instanceOf(Date).isRequired,
168
- nextMonthLabel: _propTypes.default.string.isRequired,
169
- previousMonthLabel: _propTypes.default.string.isRequired,
170
- // Optional
171
- onMonthChange: _propTypes.default.func,
172
- disabled: _propTypes.default.bool
173
- };
174
- BpkCalendarNav.defaultProps = {
175
- onMonthChange: null,
176
- disabled: false
177
- };
178
164
  var _default = BpkCalendarNav;
179
165
  exports.default = _default;
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2016 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import type { ElementType } from 'react';
20
+ import { Component } from 'react';
21
+ import type { DateModifiers, SelectionConfiguration } from './custom-proptypes';
22
+ export type Props = DefaultProps & {
23
+ DateComponent: ElementType;
24
+ dateModifiers: DateModifiers;
25
+ dates: Date[];
26
+ formatDateFull: (date: Date) => Date | string;
27
+ preventKeyboardFocus: boolean;
28
+ markToday: boolean;
29
+ markOutsideDays: boolean;
30
+ isKeyboardFocusable: boolean;
31
+ month: Date;
32
+ weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6;
33
+ [rest: string]: any;
34
+ };
35
+ type DefaultProps = {
36
+ dateProps: {};
37
+ focusedDate: Date | number | null;
38
+ ignoreOutsideDate: boolean;
39
+ maxDate: Date | null;
40
+ minDate: Date | null;
41
+ onDateClick: () => void;
42
+ onDateKeyDown: () => void;
43
+ cellClassName: string | null;
44
+ selectionConfiguration: SelectionConfiguration;
45
+ };
46
+ declare class Week extends Component<Props> {
47
+ static defaultProps: DefaultProps;
48
+ shouldComponentUpdate(nextProps: Props): boolean;
49
+ render(): JSX.Element | null;
50
+ }
51
+ export default Week;
@@ -4,16 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _propTypes = _interopRequireDefault(require("prop-types"));
8
7
  var _react = require("react");
9
8
  var _bpkReactUtils = require("../../bpk-react-utils");
10
9
  var _dateUtils = require("./date-utils");
11
- var _customProptypes = _interopRequireWildcard(require("./custom-proptypes"));
10
+ var _customProptypes = require("./custom-proptypes");
12
11
  var _BpkCalendarGridModule = _interopRequireDefault(require("./BpkCalendarGrid.module.css"));
13
12
  var _BpkCalendarDate = require("./BpkCalendarDate");
14
13
  var _jsxRuntime = require("react/jsx-runtime");
15
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
- 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; }
17
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
15
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -59,12 +56,16 @@ function or(total, bool) {
59
56
  * @returns {Boolean} true is selected and false if not
60
57
  */
61
58
  function getSelectedDate(date, selectionConfiguration) {
62
- const startDate = selectionConfiguration.date || selectionConfiguration.startDate;
63
- const {
64
- endDate
65
- } = selectionConfiguration;
66
- const sameStartDay = (0, _dateUtils.isSameDay)(date, startDate);
67
- const sameEndDay = (0, _dateUtils.isSameDay)(date, endDate);
59
+ let startDate;
60
+ let endDate;
61
+ if (selectionConfiguration.type === _customProptypes.CALENDAR_SELECTION_TYPE.single) {
62
+ startDate = selectionConfiguration.date;
63
+ } else {
64
+ startDate = selectionConfiguration.startDate;
65
+ endDate = selectionConfiguration.endDate;
66
+ }
67
+ const sameStartDay = startDate && (0, _dateUtils.isSameDay)(date, startDate);
68
+ const sameEndDay = endDate && (0, _dateUtils.isSameDay)(date, endDate);
68
69
  if (startDate && endDate && (sameStartDay || sameEndDay || (0, _dateUtils.isWithinRange)(date, {
69
70
  start: startDate,
70
71
  end: endDate
@@ -88,9 +89,12 @@ function getSelectionType(date, selectionConfiguration, formatDateFull, month, w
88
89
  const {
89
90
  endDate,
90
91
  startDate
91
- } = selectionConfiguration;
92
- const sameStartDay = (0, _dateUtils.isSameDay)(date, startDate);
93
- const sameEndDay = (0, _dateUtils.isSameDay)(date, endDate);
92
+ } = selectionConfiguration.type === _customProptypes.CALENDAR_SELECTION_TYPE.range ? selectionConfiguration : {
93
+ startDate: null,
94
+ endDate: null
95
+ };
96
+ const sameStartDay = startDate && (0, _dateUtils.isSameDay)(date, startDate);
97
+ const sameEndDay = endDate && (0, _dateUtils.isSameDay)(date, endDate);
94
98
  const rangeDates = startDate && endDate;
95
99
  const isEmptyCell = !(0, _dateUtils.isSameMonth)(date, month) && ignoreOutsideDate;
96
100
  if (selectionConfiguration.type === _customProptypes.CALENDAR_SELECTION_TYPE.single && selectionConfiguration.date && (selectionConfiguration.date === formatDateFull(date) || formatDateFull(selectionConfiguration.date) === formatDateFull(date))) {
@@ -147,9 +151,9 @@ function getSelectionType(date, selectionConfiguration, formatDateFull, month, w
147
151
  const singleDateHandler = (props, nextProps) => {
148
152
  const currentSelectConfig = props.selectionConfiguration;
149
153
  const nextSelectConfig = nextProps.selectionConfiguration;
150
- if (((0, _dateUtils.isSameWeek)(nextSelectConfig.date, nextProps.dates[0], {
154
+ if ((nextSelectConfig.date && (0, _dateUtils.isSameWeek)(nextSelectConfig.date, nextProps.dates[0], {
151
155
  weekStartsOn: nextProps.weekStartsOn
152
- }) || (0, _dateUtils.isSameWeek)(currentSelectConfig.date, props.dates[0], {
156
+ }) || currentSelectConfig.date && (0, _dateUtils.isSameWeek)(currentSelectConfig.date, props.dates[0], {
153
157
  weekStartsOn: props.weekStartsOn
154
158
  })) && currentSelectConfig.date !== nextSelectConfig.date) {
155
159
  return true;
@@ -164,14 +168,21 @@ const singleDateHandler = (props, nextProps) => {
164
168
  * @returns {Boolean} based on if the date has changed
165
169
  */
166
170
  const rangeDateHandler = (props, nextProps) => {
167
- const startDateChanged = !(0, _dateUtils.isSameDay)(props.selectionConfiguration.startDate, nextProps.selectionConfiguration.startDate);
168
- const endDateChanged = !(0, _dateUtils.isSameDay)(props.selectionConfiguration.endDate, nextProps.selectionConfiguration.endDate);
171
+ const {
172
+ endDate,
173
+ startDate
174
+ } = props.selectionConfiguration;
175
+ const {
176
+ endDate: nextEndDate,
177
+ startDate: nextStartDate
178
+ } = nextProps.selectionConfiguration;
179
+ const startDateChanged = startDate && nextStartDate && !(0, _dateUtils.isSameDay)(startDate, nextStartDate);
180
+ const endDateChanged = endDate && nextEndDate && !(0, _dateUtils.isSameDay)(endDate, nextEndDate);
169
181
  if (startDateChanged || endDateChanged) {
170
182
  return true;
171
183
  }
172
184
  return false;
173
185
  };
174
-
175
186
  /*
176
187
  Week - table row containing a week full of DateContainer components
177
188
  */
@@ -187,9 +198,9 @@ class Week extends _react.Component {
187
198
  // If focusedDate is changing, and it'll be included as part
188
199
  // of either the week we're rendering now or the next week
189
200
  // we'll render, component should update.
190
- if (((0, _dateUtils.isSameWeek)(nextProps.focusedDate, nextProps.dates[0], {
201
+ if ((nextProps.focusedDate && (0, _dateUtils.isSameWeek)(nextProps.focusedDate, nextProps.dates[0], {
191
202
  weekStartsOn: nextProps.weekStartsOn
192
- }) || (0, _dateUtils.isSameWeek)(this.props.focusedDate, this.props.dates[0], {
203
+ }) || this.props.focusedDate && (0, _dateUtils.isSameWeek)(this.props.focusedDate, this.props.dates[0], {
193
204
  weekStartsOn: this.props.weekStartsOn
194
205
  })) && this.props.focusedDate !== nextProps.focusedDate) {
195
206
  return true;
@@ -229,6 +240,7 @@ class Week extends _react.Component {
229
240
  render() {
230
241
  const {
231
242
  DateComponent,
243
+ cellClassName,
232
244
  dateModifiers,
233
245
  dateProps,
234
246
  focusedDate,
@@ -262,7 +274,7 @@ class Week extends _react.Component {
262
274
  }) : false;
263
275
  const dateSelectionType = getSelectionType(date, selectionConfiguration, formatDateFull, month, weekStartsOn, ignoreOutsideDate);
264
276
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(DateContainer, {
265
- className: this.props.cellClassName,
277
+ className: cellClassName,
266
278
  isEmptyCell: !(0, _dateUtils.isSameMonth)(date, month) && ignoreOutsideDate,
267
279
  isBlocked: isBlocked,
268
280
  selectionType: dateSelectionType,
@@ -274,7 +286,7 @@ class Week extends _react.Component {
274
286
  onDateKeyDown: onDateKeyDown,
275
287
  preventKeyboardFocus: preventKeyboardFocus,
276
288
  isKeyboardFocusable: isKeyboardFocusable,
277
- isFocused: (0, _dateUtils.isSameDay)(date, focusedDate),
289
+ isFocused: focusedDate && (0, _dateUtils.isSameDay)(date, focusedDate),
278
290
  isSelected: getSelectedDate(date, selectionConfiguration),
279
291
  isBlocked: isBlocked,
280
292
  isOutside: markOutsideDays && !(0, _dateUtils.isSameMonth)(date, month),
@@ -286,54 +298,30 @@ class Week extends _react.Component {
286
298
  });
287
299
  }
288
300
  }
289
- Week.propTypes = {
290
- DateComponent: _propTypes.default.elementType.isRequired,
291
- dateModifiers: _customProptypes.default.DateModifiers.isRequired,
292
- dates: _propTypes.default.arrayOf(Date).isRequired,
293
- formatDateFull: _propTypes.default.func.isRequired,
294
- preventKeyboardFocus: _propTypes.default.bool.isRequired,
295
- markToday: _propTypes.default.bool.isRequired,
296
- markOutsideDays: _propTypes.default.bool.isRequired,
297
- isKeyboardFocusable: _propTypes.default.bool.isRequired,
298
- month: _propTypes.default.instanceOf(Date).isRequired,
299
- weekStartsOn: _propTypes.default.number.isRequired,
300
- focusedDate: _propTypes.default.instanceOf(Date),
301
- maxDate: _propTypes.default.instanceOf(Date),
302
- minDate: _propTypes.default.instanceOf(Date),
303
- cellClassName: _propTypes.default.string,
304
- onDateClick: _propTypes.default.func,
305
- onDateKeyDown: _propTypes.default.func,
306
- selectionConfiguration: _customProptypes.default.SelectionConfiguration,
307
- ignoreOutsideDate: _propTypes.default.bool,
308
- dateProps: _propTypes.default.object // eslint-disable-line react/forbid-prop-types
309
- };
310
-
311
- Week.defaultProps = {
312
- cellClassName: null,
301
+ _defineProperty(Week, "defaultProps", {
302
+ dateProps: {},
313
303
  focusedDate: null,
304
+ ignoreOutsideDate: false,
314
305
  maxDate: null,
315
306
  minDate: null,
316
- onDateClick: null,
317
- onDateKeyDown: null,
307
+ onDateClick: () => {},
308
+ onDateKeyDown: () => {},
318
309
  selectionConfiguration: {
319
310
  type: _customProptypes.CALENDAR_SELECTION_TYPE.single,
320
311
  date: null
321
312
  },
322
- ignoreOutsideDate: false,
323
- dateProps: null
324
- };
325
-
313
+ cellClassName: null
314
+ });
326
315
  /*
327
316
  DateContainer - one for each date in the grid; wraps the actual BpkCalendarDate (or custom) component
328
317
  */
329
- const DateContainer = props => {
330
- const {
331
- children,
332
- className,
333
- isBlocked,
334
- isEmptyCell,
335
- selectionType
336
- } = props;
318
+ const DateContainer = ({
319
+ children,
320
+ className = null,
321
+ isBlocked,
322
+ isEmptyCell,
323
+ selectionType
324
+ }) => {
337
325
  const classNames = getClassName('bpk-calendar-grid__date', `bpk-calendar-grid__date--${selectionType}`, className);
338
326
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
339
327
  "aria-hidden": isEmptyCell || isBlocked,
@@ -341,15 +329,5 @@ const DateContainer = props => {
341
329
  children: children
342
330
  });
343
331
  };
344
- DateContainer.propTypes = {
345
- children: _propTypes.default.element.isRequired,
346
- selectionType: _propTypes.default.string.isRequired,
347
- isEmptyCell: _propTypes.default.bool.isRequired,
348
- isBlocked: _propTypes.default.bool.isRequired,
349
- className: _propTypes.default.string
350
- };
351
- DateContainer.defaultProps = {
352
- className: null
353
- };
354
332
  var _default = Week;
355
333
  exports.default = _default;
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2016 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import type { ComponentType } from 'react';
20
+ import type { DaysOfWeek, SelectionConfiguration, DateModifiers } from './custom-proptypes';
21
+ type Props = {
22
+ changeMonthLabel?: string | null;
23
+ daysOfWeek: DaysOfWeek;
24
+ formatDateFull: (date: Date) => Date | string;
25
+ formatMonth: (date: Date) => Date | string;
26
+ id: string;
27
+ maxDate: Date;
28
+ minDate: Date;
29
+ month: Date;
30
+ nextMonthLabel?: string | null;
31
+ previousMonthLabel?: string | null;
32
+ weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6;
33
+ className?: string | null;
34
+ dateModifiers?: DateModifiers;
35
+ fixedWidth?: boolean;
36
+ focusedDate?: Date | null;
37
+ markOutsideDays?: boolean;
38
+ markToday?: boolean;
39
+ onMonthChange?: () => void;
40
+ onDateClick?: () => void;
41
+ onDateKeyDown?: () => void;
42
+ preventKeyboardFocus?: boolean;
43
+ selectionConfiguration?: SelectionConfiguration;
44
+ gridClassName?: string | null;
45
+ weekDayKey?: string;
46
+ navProps?: {} | null;
47
+ headerProps?: {} | null;
48
+ gridProps?: {} | null;
49
+ dateProps?: {} | null;
50
+ };
51
+ declare const composeCalendar: (Nav: ComponentType<any> | string | null, GridHeader: ComponentType<any> | string | null, Grid: ComponentType<any> | string, CalendarDate: ComponentType<any> | string | null) => ({ changeMonthLabel, className, dateModifiers, dateProps, daysOfWeek, fixedWidth, focusedDate, formatDateFull, formatMonth, gridClassName, gridProps, headerProps, id, markOutsideDays, markToday, maxDate, minDate, month, navProps, nextMonthLabel, onDateClick, onDateKeyDown, onMonthChange, preventKeyboardFocus, previousMonthLabel, selectionConfiguration, weekDayKey, weekStartsOn, }: Props) => JSX.Element;
52
+ export default composeCalendar;