@skyscanner/backpack-web 0.0.3 → 0.0.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.
- package/bpk-component-accordion/src/BpkAccordion.js +1 -1
- package/bpk-component-accordion/src/BpkAccordionItem.js +2 -2
- package/bpk-component-accordion/src/withAccordionItemState.js +2 -2
- package/bpk-component-accordion/src/withSingleItemAccordionState.js +1 -1
- package/bpk-component-aria-live/examples.js +1 -1
- package/bpk-component-aria-live/src/BpkAriaLive.js +1 -1
- package/bpk-component-autosuggest/src/BpkAutosuggest.js +1 -1
- package/bpk-component-autosuggest/src/BpkAutosuggestSuggestion.js +1 -1
- package/bpk-component-badge/BadgeLayout.js +1 -1
- package/bpk-component-badge/src/BpkBadge.js +1 -1
- package/bpk-component-banner-alert/examples.js +1 -1
- package/bpk-component-banner-alert/src/AnimateAndFade.js +2 -2
- package/bpk-component-banner-alert/src/BpkBannerAlertInner.js +2 -2
- package/bpk-component-banner-alert/src/withBannerAlertState.js +1 -1
- package/bpk-component-barchart/examples.js +1 -1
- package/bpk-component-barchart/hocs.js +1 -1
- package/bpk-component-barchart/src/BpkBarchart.js +1 -1
- package/bpk-component-barchart/src/BpkBarchartBar.js +1 -1
- package/bpk-component-barchart/src/BpkChartAxis.js +1 -1
- package/bpk-component-barchart/src/BpkChartDataTable.js +1 -1
- package/bpk-component-barchart/src/BpkChartGridLines.js +9 -9
- package/bpk-component-barchart/src/RTLtransforms.js +1 -1
- package/bpk-component-blockquote/src/BpkBlockquote.js +1 -1
- package/bpk-component-breadcrumb/src/BpkBreadcrumb.js +1 -1
- package/bpk-component-breadcrumb/src/BpkBreadcrumbItem.js +1 -1
- package/bpk-component-breakpoint/examples.js +1 -1
- package/bpk-component-calendar/src/BpkCalendarContainer.js +1 -1
- package/bpk-component-calendar/src/BpkCalendarDate.js +1 -1
- package/bpk-component-calendar/src/BpkCalendarGrid.js +1 -1
- package/bpk-component-calendar/src/BpkCalendarGridHeader.js +1 -1
- package/bpk-component-calendar/src/BpkCalendarGridTransition.js +12 -12
- package/bpk-component-calendar/src/BpkCalendarNav.js +1 -1
- package/bpk-component-calendar/src/Week.js +2 -2
- package/bpk-component-calendar/src/composeCalendar.js +1 -1
- package/bpk-component-card/src/BpkCard.js +1 -1
- package/bpk-component-checkbox/src/BpkCheckbox.js +1 -1
- package/bpk-component-chip/examples.js +1 -1
- package/bpk-component-chip/src/BpkSelectableChip.js +1 -1
- package/bpk-component-close-button/src/BpkCloseButton.js +1 -1
- package/bpk-component-code/src/BpkCode.js +1 -1
- package/bpk-component-code/src/BpkCodeBlock.js +1 -1
- package/bpk-component-content-container/src/BpkContentContainer.js +1 -1
- package/bpk-component-datatable/src/BpkDataTable.js +1 -1
- package/bpk-component-datatable/src/BpkDataTableColumn.js +1 -1
- package/bpk-component-datatable/src/bpkHeaderRenderer.js +1 -1
- package/bpk-component-datepicker/src/BpkDatepicker.js +1 -1
- package/bpk-component-description-list/src/ComponentFactory.js +1 -1
- package/bpk-component-dialog/examples.js +1 -1
- package/bpk-component-dialog/src/BpkDialog.js +1 -1
- package/bpk-component-dialog/src/BpkDialogInner.js +2 -2
- package/bpk-component-drawer/examples.js +1 -1
- package/bpk-component-drawer/src/BpkDrawer.js +2 -2
- package/bpk-component-drawer/src/BpkDrawerContent.js +1 -1
- package/bpk-component-fieldset/examples.js +1 -1
- package/bpk-component-fieldset/src/BpkFieldset.js +1 -1
- package/bpk-component-flare/examples.js +1 -1
- package/bpk-component-flare/src/BpkContentBubble.js +1 -1
- package/bpk-component-flare/src/BpkFlareBar.js +1 -1
- package/bpk-component-form-validation/examples.js +1 -1
- package/bpk-component-form-validation/src/BpkFormValidation.js +2 -2
- package/bpk-component-grid/src/BpkGridColumn.js +1 -1
- package/bpk-component-grid/src/BpkGridContainer.js +1 -1
- package/bpk-component-grid/src/BpkGridRow.js +1 -1
- package/bpk-component-grid-toggle/src/BpkGridToggle.js +1 -1
- package/bpk-component-horizontal-nav/examples.js +1 -1
- package/bpk-component-horizontal-nav/src/BpkHorizontalNav.js +1 -1
- package/bpk-component-horizontal-nav/src/BpkHorizontalNavItem.js +1 -1
- package/bpk-component-icon/src/classNameModifierHOCFactory.js +1 -1
- package/bpk-component-icon/src/withAlignment.js +3 -4
- package/bpk-component-icon/src/withDescription.js +1 -1
- package/bpk-component-icon/src/withRtlSupport.js +1 -1
- package/bpk-component-image/src/BpkBackgroundImage.js +1 -1
- package/bpk-component-image/src/BpkImage.js +1 -1
- package/bpk-component-image/src/withLazyLoading.js +1 -1
- package/bpk-component-image/src/withLoadingBehavior.js +28 -28
- package/bpk-component-infinite-scroll/examples.js +1 -1
- package/bpk-component-infinite-scroll/src/withInfiniteScroll.js +106 -106
- package/bpk-component-input/examples.js +1 -1
- package/bpk-component-input/src/BpkClearButton.js +1 -1
- package/bpk-component-input/src/BpkInput.js +1 -1
- package/bpk-component-input/src/withOpenEvents.js +1 -1
- package/bpk-component-label/src/BpkLabel.js +1 -1
- package/bpk-component-link/src/BpkButtonLink.js +1 -1
- package/bpk-component-link/src/BpkLink.js +1 -1
- package/bpk-component-list/src/BpkList.js +1 -1
- package/bpk-component-list/src/BpkListItem.js +1 -1
- package/bpk-component-map/src/BpkIconMarker.js +1 -1
- package/bpk-component-map/src/BpkIconMarkerBackground.js +1 -1
- package/bpk-component-map/src/BpkPriceMarker.js +1 -1
- package/bpk-component-map/src/DefaultLoadingElement.js +1 -1
- package/bpk-component-mobile-scroll-container/examples.js +1 -1
- package/bpk-component-mobile-scroll-container/src/BpkMobileScrollContainer.js +1 -1
- package/bpk-component-modal/examples.js +1 -1
- package/bpk-component-modal/src/BpkModal.js +8 -8
- package/bpk-component-modal/src/BpkModalInner.js +1 -1
- package/bpk-component-navigation-bar/AirlineLogo.js +1 -1
- package/bpk-component-navigation-bar/examples.js +1 -1
- package/bpk-component-navigation-bar/src/BpkNavigationBar.js +1 -1
- package/bpk-component-navigation-bar/src/BpkNavigationBarButtonLink.js +1 -1
- package/bpk-component-navigation-bar/src/BpkNavigationBarIconButton.js +1 -1
- package/bpk-component-navigation-stack/examples.js +1 -1
- package/bpk-component-navigation-stack/src/BpkNavigationStack.js +4 -5
- package/bpk-component-navigation-stack/stories-components.js +1 -1
- package/bpk-component-nudger/examples.js +1 -1
- package/bpk-component-nudger/src/BpkConfigurableNudger.js +1 -1
- package/bpk-component-nudger/src/BpkNudger.js +1 -1
- package/bpk-component-overlay/examples.js +1 -1
- package/bpk-component-overlay/src/BpkOverlay.js +2 -2
- package/bpk-component-pagination/src/BpkPagination.js +1 -1
- package/bpk-component-pagination/src/BpkPaginationList.js +1 -1
- package/bpk-component-pagination/src/BpkPaginationNudger.js +1 -1
- package/bpk-component-pagination/src/BpkPaginationPage.js +1 -1
- package/bpk-component-panel/src/BpkPanel.js +1 -1
- package/bpk-component-phone-input/src/BpkPhoneInput.js +1 -1
- package/bpk-component-popover/examples.js +1 -1
- package/bpk-component-popover/src/BpkPopover.js +1 -1
- package/bpk-component-popover/src/BpkPopoverPortal.js +1 -1
- package/bpk-component-progress/examples.js +1 -1
- package/bpk-component-progress/src/BpkProgress.js +1 -1
- package/bpk-component-radio/src/BpkRadio.js +1 -1
- package/bpk-component-rating/examples.js +1 -1
- package/bpk-component-rating/src/BpkRating.js +1 -1
- package/bpk-component-rtl-toggle/src/updateOnDirectionChange.js +1 -1
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGrid.js +1 -1
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGridList.js +1 -1
- package/bpk-component-section-list/src/BpkSectionListItem.js +1 -1
- package/bpk-component-section-list/src/BpkSectionListSection.js +1 -1
- package/bpk-component-select/src/BpkSelect.js +1 -1
- package/bpk-component-skip-link/src/BpkSkipLink.js +1 -1
- package/bpk-component-slider/src/BpkSlider.js +1 -1
- package/bpk-component-spinner/SpinnerLayout.js +1 -1
- package/bpk-component-spinner/src/BpkExtraLargeSpinner.js +1 -1
- package/bpk-component-spinner/src/BpkLargeSpinner.js +1 -1
- package/bpk-component-spinner/src/BpkSpinner.js +1 -1
- package/bpk-component-star-rating/src/BpkInteractiveStar.js +1 -1
- package/bpk-component-star-rating/src/BpkInteractiveStarRating.js +1 -1
- package/bpk-component-star-rating/src/BpkStar.js +1 -1
- package/bpk-component-star-rating/src/BpkStarRating.js +4 -4
- package/bpk-component-star-rating/src/withInteractiveStarRatingState.js +1 -1
- package/bpk-component-switch/src/BpkSwitch.js +1 -1
- package/bpk-component-table/src/BpkTable.js +1 -1
- package/bpk-component-table/src/BpkTableCell.js +1 -1
- package/bpk-component-table/src/BpkTableHeadCell.js +1 -1
- package/bpk-component-text/examples.js +1 -1
- package/bpk-component-text/src/BpkText.js +1 -1
- package/bpk-component-textarea/src/BpkTextarea.js +1 -1
- package/bpk-component-theme-toggle/src/BpkThemeToggle.js +1 -1
- package/bpk-component-theme-toggle/src/updateOnThemeChange.js +1 -1
- package/bpk-component-ticket/examples.js +1 -1
- package/bpk-component-ticket/src/BpkTicket.js +7 -7
- package/bpk-component-tooltip/examples.js +1 -1
- package/bpk-component-tooltip/src/BpkTooltip.js +1 -1
- package/bpk-component-tooltip/src/BpkTooltipPortal.js +1 -1
- package/bpk-scrim-utils/src/BpkScrim.js +1 -1
- package/bpk-scrim-utils/src/withScrim.js +1 -1
- package/package.json +1 -1
|
@@ -22,7 +22,7 @@ import PropTypes from 'prop-types';
|
|
|
22
22
|
import React, { type Node } from 'react';
|
|
23
23
|
import Transition from 'react-transition-group/Transition';
|
|
24
24
|
import { animations } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
|
|
25
|
-
import { cssModules } from 'bpk-react-utils';
|
|
25
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
26
26
|
import { BpkButtonLink } from '../../bpk-component-link';
|
|
27
27
|
import BpkCloseButton from '../../bpk-component-close-button';
|
|
28
28
|
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
formatDateFull,
|
|
35
35
|
} from '../../bpk-component-calendar/test-utils';
|
|
36
36
|
import { format } from '../../bpk-component-calendar/src/date-utils';
|
|
37
|
-
import { cssModules } from 'bpk-react-utils';
|
|
37
|
+
import { cssModules } from '../bpk-react-utils';
|
|
38
38
|
|
|
39
39
|
import STYLES from './examples.module.scss';
|
|
40
40
|
|
|
@@ -21,7 +21,7 @@ import PropTypes from 'prop-types';
|
|
|
21
21
|
import React, { cloneElement, type Element } from 'react';
|
|
22
22
|
import BpkLabel from '../../bpk-component-label';
|
|
23
23
|
import BpkFormValidation from '../../bpk-component-form-validation';
|
|
24
|
-
import { cssModules } from 'bpk-react-utils';
|
|
24
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
25
25
|
|
|
26
26
|
import STYLES from './BpkFieldset.module.scss';
|
|
27
27
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import React from 'react';
|
|
22
22
|
import BpkText, { TEXT_STYLES } from '../../bpk-component-text';
|
|
23
|
-
import { cssModules } from 'bpk-react-utils';
|
|
23
|
+
import { cssModules } from '../bpk-react-utils';
|
|
24
24
|
|
|
25
25
|
import { BpkFlareBar, BpkContentBubble } from './index';
|
|
26
26
|
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import React from 'react';
|
|
20
20
|
import PropTypes from 'prop-types';
|
|
21
|
-
import { cssModules } from 'bpk-react-utils';
|
|
21
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
22
22
|
|
|
23
23
|
import BpkFlareBar from './BpkFlareBar';
|
|
24
24
|
import STYLES from './bpk-content-bubble.module.scss';
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import React from 'react';
|
|
20
20
|
import PropTypes from 'prop-types';
|
|
21
|
-
import { cssModules } from 'bpk-react-utils';
|
|
21
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
22
22
|
|
|
23
23
|
import STYLES from './bpk-flare-bar.module.scss';
|
|
24
24
|
import Pointer from './__generated__/js/pointer';
|
|
@@ -23,7 +23,7 @@ import BpkSelect from '../../bpk-component-select';
|
|
|
23
23
|
import BpkCheckbox from '../../bpk-component-checkbox';
|
|
24
24
|
import BpkTextarea from '../../bpk-component-textarea';
|
|
25
25
|
import BpkInput from '../../bpk-component-input';
|
|
26
|
-
import { cssModules } from 'bpk-react-utils';
|
|
26
|
+
import { cssModules } from '../bpk-react-utils';
|
|
27
27
|
|
|
28
28
|
import STYLES from './examples.module.scss';
|
|
29
29
|
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
|
|
19
19
|
import PropTypes from 'prop-types';
|
|
20
20
|
import React from 'react';
|
|
21
|
-
import AnimateHeight from 'bpk-animate-height';
|
|
22
|
-
import { cssModules } from 'bpk-react-utils';
|
|
21
|
+
import AnimateHeight from '../../bpk-animate-height';
|
|
22
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
23
23
|
import BpkSmallExclamationIcon from '../../bpk-component-icon/sm/exclamation-circle';
|
|
24
24
|
import { withAlignment } from '../../bpk-component-icon';
|
|
25
25
|
import {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import PropTypes from 'prop-types';
|
|
20
20
|
import React from 'react';
|
|
21
|
-
import { cssModules } from 'bpk-react-utils';
|
|
21
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
22
22
|
import { BpkButtonLink } from '../../bpk-component-link';
|
|
23
23
|
|
|
24
24
|
import STYLES from './BpkGridToggle.module.scss';
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import PropTypes from 'prop-types';
|
|
21
21
|
import ReactDOM from 'react-dom';
|
|
22
|
-
import { cssModules } from 'bpk-react-utils';
|
|
22
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
23
23
|
import React, { Component, type Node } from 'react';
|
|
24
24
|
import BpkMobileScrollContainer from '../../bpk-component-mobile-scroll-container';
|
|
25
25
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import React, { Component, type Node } from 'react';
|
|
21
21
|
import PropTypes from 'prop-types';
|
|
22
|
-
import { cssModules } from 'bpk-react-utils';
|
|
22
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
23
23
|
|
|
24
24
|
import { HORIZONTAL_NAV_TYPES } from './BpkHorizontalNav';
|
|
25
25
|
import STYLES from './BpkHorizontalNavItem.module.scss';
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import PropTypes from 'prop-types';
|
|
20
20
|
import React from 'react';
|
|
21
|
-
import { wrapDisplayName } from 'bpk-react-utils';
|
|
21
|
+
import { wrapDisplayName } from '../../bpk-react-utils';
|
|
22
22
|
|
|
23
23
|
export default (displayName, classNamesToAdd = []) =>
|
|
24
24
|
(ComposedComponent) => {
|
|
@@ -17,15 +17,14 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import React from 'react';
|
|
20
|
-
import { wrapDisplayName } from 'bpk-react-utils';
|
|
20
|
+
import { wrapDisplayName } from '../../bpk-react-utils';
|
|
21
21
|
|
|
22
22
|
export default function withAlignment(Component, objectHeight, subjectHeight) {
|
|
23
23
|
const WithAlignment = (props) => {
|
|
24
24
|
const objectHeightDecimal = `${objectHeight}`.replace('rem', '');
|
|
25
25
|
const subjectHeightDecimal = `${subjectHeight}`.replace('rem', '');
|
|
26
|
-
const marginTopCalculated = `${
|
|
27
|
-
|
|
28
|
-
}rem`;
|
|
26
|
+
const marginTopCalculated = `${Math.max(0, objectHeightDecimal - subjectHeightDecimal) / 2
|
|
27
|
+
}rem`;
|
|
29
28
|
|
|
30
29
|
return (
|
|
31
30
|
<span
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
/* @flow strict */
|
|
19
19
|
|
|
20
20
|
import React, { type AbstractComponent } from 'react';
|
|
21
|
-
import { cssModules, wrapDisplayName } from 'bpk-react-utils';
|
|
21
|
+
import { cssModules, wrapDisplayName } from '../../bpk-react-utils';
|
|
22
22
|
|
|
23
23
|
import STYLES from './withDescription.module.scss';
|
|
24
24
|
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { cssModules } from 'bpk-react-utils';
|
|
19
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
20
20
|
|
|
21
21
|
import STYLES from './BpkIcon.module.scss';
|
|
22
22
|
import classNameModifierHOCFactory from './classNameModifierHOCFactory';
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import React, { type Node, Component } from 'react';
|
|
21
21
|
import PropTypes from 'prop-types';
|
|
22
|
-
import { cssModules, deprecated } from 'bpk-react-utils';
|
|
22
|
+
import { cssModules, deprecated } from '../../bpk-react-utils';
|
|
23
23
|
import { BpkSpinner } from '../../bpk-component-spinner';
|
|
24
24
|
import CSSTransition from 'react-transition-group/CSSTransition';
|
|
25
25
|
import { animations } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import React, { type Node, Component } from 'react';
|
|
21
21
|
import PropTypes from 'prop-types';
|
|
22
|
-
import { cssModules, deprecated } from 'bpk-react-utils';
|
|
22
|
+
import { cssModules, deprecated } from '../../bpk-react-utils';
|
|
23
23
|
import { BpkSpinner } from '../../bpk-component-spinner';
|
|
24
24
|
import CSSTransition from 'react-transition-group/CSSTransition';
|
|
25
25
|
import { animations } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import React, { type Node, type ComponentType } from 'react';
|
|
21
21
|
import PropTypes from 'prop-types';
|
|
22
|
-
import { wrapDisplayName } from 'bpk-react-utils';
|
|
22
|
+
import { wrapDisplayName } from '../../bpk-react-utils';
|
|
23
23
|
import throttle from 'lodash/throttle';
|
|
24
24
|
|
|
25
25
|
type WithLazyLoadingProps = {
|
|
@@ -18,48 +18,48 @@
|
|
|
18
18
|
/* @flow */
|
|
19
19
|
|
|
20
20
|
import React, { type AbstractComponent } from 'react';
|
|
21
|
-
import { wrapDisplayName } from 'bpk-react-utils';
|
|
21
|
+
import { wrapDisplayName } from '../../bpk-react-utils';
|
|
22
22
|
|
|
23
23
|
type InjectedProps = {|
|
|
24
24
|
onLoad: () => mixed,
|
|
25
|
-
|
|
25
|
+
loading: boolean,
|
|
26
26
|
|};
|
|
27
27
|
|
|
28
28
|
export default function withLoadingBehavior<Config>(
|
|
29
29
|
Component: AbstractComponent<{| ...Config, ...InjectedProps |}>,
|
|
30
|
-
): AbstractComponent<Config> {
|
|
31
|
-
class WithLoadingBehavior<C: Config> extends React.Component<
|
|
30
|
+
): AbstractComponent < Config > {
|
|
31
|
+
class WithLoadingBehavior < C: Config> extends React.Component <
|
|
32
32
|
C,
|
|
33
33
|
{| loading: boolean |},
|
|
34
34
|
> {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
constructor() {
|
|
36
|
+
super();
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
this.state = {
|
|
39
|
+
loading: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
42
|
|
|
43
43
|
onLoad = () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
this.setState(() => ({
|
|
45
|
+
loading: false,
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
49
|
+
render() {
|
|
50
|
+
return (
|
|
51
|
+
<Component
|
|
52
|
+
onLoad={this.onLoad}
|
|
53
|
+
loading={this.state.loading}
|
|
54
|
+
{...this.props}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
}
|
|
59
|
+
WithLoadingBehavior.displayName = wrapDisplayName(
|
|
60
|
+
Component,
|
|
61
|
+
'withLoadingBehavior',
|
|
62
|
+
);
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
return WithLoadingBehavior;
|
|
65
65
|
}
|
|
@@ -24,7 +24,7 @@ import { action } from 'bpk-storybook-utils';
|
|
|
24
24
|
import BpkButton from '../../bpk-component-button';
|
|
25
25
|
import { BpkList, BpkListItem } from '../../bpk-component-list';
|
|
26
26
|
import { BpkSpinner, SPINNER_TYPES } from '../../bpk-component-spinner';
|
|
27
|
-
import { cssModules } from 'bpk-react-utils';
|
|
27
|
+
import { cssModules } from '../bpk-react-utils';
|
|
28
28
|
|
|
29
29
|
import STYLES from './examples.module.scss';
|
|
30
30
|
|
|
@@ -25,7 +25,7 @@ import React, {
|
|
|
25
25
|
type AbstractComponent,
|
|
26
26
|
} from 'react';
|
|
27
27
|
import PropTypes from 'prop-types';
|
|
28
|
-
import { cssModules } from 'bpk-react-utils';
|
|
28
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
29
29
|
import omit from 'lodash/omit';
|
|
30
30
|
import extend from 'lodash/extend';
|
|
31
31
|
|
|
@@ -95,133 +95,133 @@ type PropsWithDefault = Config<Props, typeof defaultProps>;
|
|
|
95
95
|
|
|
96
96
|
const withInfiniteScroll = <T: ExtendedProps>(
|
|
97
97
|
ComponentToExtend: AbstractComponent<T>,
|
|
98
|
-
): AbstractComponent<PropsWithDefault & $Diff<T, ExtendedProps>> =>
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
): AbstractComponent<PropsWithDefault & $Diff<T, ExtendedProps>> =>
|
|
99
|
+
class WithInfiniteScroll extends Component<Props, State> {
|
|
100
|
+
handleIntersection: IntersectionObserverCallback;
|
|
101
101
|
|
|
102
102
|
handleKeyPress: (e: SyntheticKeyboardEvent<HTMLButtonElement>) => void;
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
handleSeeMoreClick: (e: SyntheticEvent<HTMLButtonElement>) => void;
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
observer: IntersectionObserver;
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
sentinel: ?HTMLElement;
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
static propTypes = {...propTypes};
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
static defaultProps = {...defaultProps};
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
constructor(props: Props) {
|
|
115
|
+
super(props);
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
this.state = {
|
|
118
|
+
index: 0,
|
|
119
119
|
elementsToRender: [],
|
|
120
120
|
isListFinished: false,
|
|
121
121
|
showSeeMore: false,
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
this.props.dataSource.onDataChange(this.updateData);
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
const thresholds = {
|
|
127
|
+
small: 0.01,
|
|
128
128
|
half: 0.5,
|
|
129
129
|
full: 0.99, // using 0.99 instead of 1 to avoid problems with float precision in IE11
|
|
130
130
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const displaySize = this.props.loaderIntersectionTrigger || 'full';
|
|
132
|
+
this.observer = new IntersectionObserver(this.handleIntersection, {
|
|
133
|
+
threshold: thresholds[displaySize] || thresholds.full,
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
componentDidMount() {
|
|
138
|
+
this.fetchItems({
|
|
139
|
+
elementsPerScroll: this.props.initiallyLoadedElements,
|
|
140
|
+
}).then((newState) => {
|
|
141
|
+
this.setState(newState);
|
|
142
|
+
});
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
componentDidUpdate(prevProps) {
|
|
146
146
|
if (this.sentinel && this.state.index > 0) {
|
|
147
|
-
|
|
147
|
+
this.observer.observe(this.sentinel);
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
if (this.props.dataSource !== prevProps.dataSource) {
|
|
151
|
+
prevProps.dataSource.removeListener(this.updateData);
|
|
152
152
|
this.props.dataSource.onDataChange(this.updateData);
|
|
153
153
|
this.fetchItems({
|
|
154
154
|
index: 0,
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
elementsPerScroll: this.props.elementsPerScroll,
|
|
156
|
+
elementsToRender: [],
|
|
157
157
|
}).then((newState) => this.setStateAfterDsUpdate(newState));
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
componentWillUnmount() {
|
|
162
|
+
this.props.dataSource.removeListener(this.updateData);
|
|
163
|
+
if (this.sentinel) {
|
|
164
|
+
this.observer.unobserve(this.sentinel);
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
setStateAfterDsUpdate(newState: State) {
|
|
169
169
|
// After a data source update (calling updateData in the data source or changing the dataSource prop)
|
|
170
170
|
// all visible data is fetched again (from 0 to current index) to update the list with the new data.
|
|
171
171
|
// If after this call there is no elementsToRender or index present in state
|
|
172
172
|
// it means the new data source has no items and we need to
|
|
173
173
|
// reset the list, which we do by setting `elementsToRender` to `[]` and `index` to `0`
|
|
174
|
-
const {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
const {elementsToRender, index} = newState;
|
|
175
|
+
this.setState({
|
|
176
|
+
...newState,
|
|
177
|
+
elementsToRender: elementsToRender || [],
|
|
178
178
|
index: index || 0,
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
updateData = () => {
|
|
183
|
-
const {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
183
|
+
const {index} = this.state;
|
|
184
|
+
// This means updateData was called before any data was loaded, e.g.
|
|
185
|
+
// An ArrayDataSource initialized empty and then changed latter on via `updateData`
|
|
186
|
+
// In this case we want to load new data and not just replace the old one.
|
|
187
|
+
// "See More After" should also be computed again in this case.
|
|
188
|
+
const isFirstLoad = index < this.props.elementsPerScroll;
|
|
189
|
+
this.fetchItems({
|
|
190
|
+
index: 0,
|
|
191
191
|
elementsPerScroll: isFirstLoad ? this.props.elementsPerScroll : index,
|
|
192
192
|
elementsToRender: [],
|
|
193
193
|
computeShowSeeMore: isFirstLoad,
|
|
194
194
|
}).then((newState) => this.setStateAfterDsUpdate(newState));
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
const {
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
fetchItems(config): Promise<$Shape<State>> {
|
|
198
|
+
const {onScrollFinished, seeMoreAfter} = this.props;
|
|
199
|
+
const {computeShowSeeMore, elementsPerScroll, elementsToRender, index} =
|
|
200
|
+
extend(
|
|
201
201
|
{
|
|
202
202
|
index: this.state.index,
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
elementsPerScroll: this.props.elementsPerScroll,
|
|
204
|
+
elementsToRender: this.state.elementsToRender,
|
|
205
|
+
computeShowSeeMore: true,
|
|
206
206
|
},
|
|
207
207
|
config,
|
|
208
|
-
|
|
208
|
+
);
|
|
209
209
|
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
return this.props.dataSource
|
|
211
|
+
.fetchItems(index, elementsPerScroll)
|
|
212
212
|
.then((nextElements) => {
|
|
213
|
-
|
|
213
|
+
let result = {
|
|
214
214
|
isListFinished: true,
|
|
215
215
|
};
|
|
216
216
|
if (nextElements && nextElements.length > 0) {
|
|
217
217
|
const nextIndex = index + elementsPerScroll;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
218
|
+
result = {
|
|
219
|
+
index: nextIndex,
|
|
220
|
+
elementsToRender: (elementsToRender || []).concat(nextElements),
|
|
221
|
+
showSeeMore: computeShowSeeMore
|
|
222
|
+
? seeMoreAfter === index / elementsPerScroll
|
|
223
|
+
: this.state.showSeeMore,
|
|
224
|
+
isListFinished: nextElements.length < elementsPerScroll,
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
227
|
if (onScrollFinished && result.isListFinished) {
|
|
@@ -233,65 +233,65 @@ const withInfiniteScroll = <T: ExtendedProps>(
|
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
const {
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
handleIntersection = (entries: Array<IntersectionObserverEntry>) => {
|
|
237
|
+
const {onScroll} = this.props;
|
|
238
|
+
const entry = entries[0];
|
|
239
|
+
if (entry.isIntersecting) {
|
|
240
240
|
if (this.sentinel) {
|
|
241
|
-
|
|
241
|
+
this.observer.unobserve(this.sentinel);
|
|
242
242
|
}
|
|
243
|
-
|
|
244
|
-
|
|
243
|
+
if (onScroll) {
|
|
244
|
+
onScroll({ currentIndex: this.state.index });
|
|
245
245
|
}
|
|
246
246
|
return this.fetchItems().then((newState) => {
|
|
247
|
-
|
|
247
|
+
this.setState(newState);
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
|
-
|
|
250
|
+
return Promise.resolve();
|
|
251
251
|
};
|
|
252
252
|
|
|
253
253
|
handleSeeMoreClick = () => {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
this.fetchItems().then((newState) => {
|
|
255
|
+
this.setState(newState);
|
|
256
|
+
});
|
|
257
257
|
};
|
|
258
258
|
|
|
259
|
-
|
|
260
|
-
const {
|
|
261
|
-
|
|
259
|
+
render() {
|
|
260
|
+
const {elementsToRender, isListFinished, showSeeMore} = this.state;
|
|
261
|
+
const {renderLoadingComponent, renderSeeMoreComponent} = this.props;
|
|
262
262
|
|
|
263
|
-
|
|
263
|
+
const rest = omit(this.props, Object.keys(propTypes));
|
|
264
264
|
|
|
265
|
-
|
|
265
|
+
let loadingOrButton = null;
|
|
266
266
|
|
|
267
|
-
|
|
267
|
+
if (!isListFinished) {
|
|
268
268
|
if (showSeeMore && renderSeeMoreComponent) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
269
|
+
loadingOrButton = renderSeeMoreComponent({
|
|
270
|
+
onSeeMoreClick: this.handleSeeMoreClick,
|
|
271
|
+
});
|
|
272
272
|
} else {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
273
|
+
loadingOrButton = (
|
|
274
|
+
<div
|
|
275
|
+
ref={(spinner) => {
|
|
276
|
+
this.sentinel = spinner;
|
|
277
|
+
}}
|
|
278
|
+
className={
|
|
279
|
+
renderLoadingComponent ? null : getClassNames('bpk-sentinel')
|
|
280
|
+
}
|
|
281
|
+
>
|
|
282
|
+
{renderLoadingComponent && renderLoadingComponent()}
|
|
283
|
+
</div>
|
|
284
|
+
);
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
288
|
+
return (
|
|
289
|
+
<div>
|
|
290
|
+
<ComponentToExtend {...rest} elements={elementsToRender} />
|
|
291
|
+
{loadingOrButton}
|
|
292
|
+
</div>
|
|
293
|
+
);
|
|
294
294
|
}
|
|
295
295
|
};
|
|
296
296
|
|
|
297
|
-
export default withInfiniteScroll;
|
|
297
|
+
export default withInfiniteScroll;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import React, { Component } from 'react';
|
|
21
21
|
import PropTypes from 'prop-types';
|
|
22
|
-
import { cssModules } from 'bpk-react-utils';
|
|
22
|
+
import { cssModules } from '../bpk-react-utils';
|
|
23
23
|
import { action } from 'bpk-storybook-utils';
|
|
24
24
|
import BpkLabel from '../../bpk-component-label';
|
|
25
25
|
import BpkBannerAlert, { ALERT_TYPES } from '../../bpk-component-banner-alert';
|