@ebay/ui-core-react 3.11.2 → 3.12.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/README.md +1 -1
- package/ebay-carousel/README.md +34 -0
- package/ebay-carousel/carousel-control-button.d.ts +14 -0
- package/ebay-carousel/carousel-control-button.d.ts.map +1 -0
- package/ebay-carousel/carousel-control-button.js +25 -0
- package/ebay-carousel/carousel-item.d.ts +12 -0
- package/ebay-carousel/carousel-item.d.ts.map +1 -0
- package/ebay-carousel/carousel-item.js +66 -0
- package/ebay-carousel/carousel-list.d.ts +20 -0
- package/ebay-carousel/carousel-list.d.ts.map +1 -0
- package/ebay-carousel/carousel-list.js +78 -0
- package/ebay-carousel/carousel.d.ts +23 -0
- package/ebay-carousel/carousel.d.ts.map +1 -0
- package/ebay-carousel/carousel.js +117 -0
- package/ebay-carousel/helpers.d.ts +15 -0
- package/ebay-carousel/helpers.d.ts.map +1 -0
- package/ebay-carousel/helpers.js +129 -0
- package/ebay-carousel/index.d.ts +3 -0
- package/ebay-carousel/index.d.ts.map +1 -0
- package/ebay-carousel/index.js +6 -0
- package/ebay-carousel/scroll-to-transition.d.ts +21 -0
- package/ebay-carousel/scroll-to-transition.d.ts.map +1 -0
- package/ebay-carousel/scroll-to-transition.js +102 -0
- package/ebay-carousel/types.d.ts +9 -0
- package/ebay-carousel/types.d.ts.map +1 -0
- package/ebay-carousel/types.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ eBayUI React components
|
|
|
17
17
|
* [x] [ebay-badge](src/ebay-badge)
|
|
18
18
|
* [x] [ebay-breadcrumbs](src/ebay-breadcrumbs)
|
|
19
19
|
* [x] [ebay-button](src/ebay-button)
|
|
20
|
-
* [
|
|
20
|
+
* [x] [ebay-carouse](src/ebay-carousel)
|
|
21
21
|
* [x] [ebay-checkbox](src/ebay-checkbox)
|
|
22
22
|
* [ ] `ebay-combobox`
|
|
23
23
|
* [ ] `ebay-confirm-dialog`
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# EbayCarousel
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
```react
|
|
6
|
+
<EbayCarousel>
|
|
7
|
+
<CarouselItem>
|
|
8
|
+
Item 1
|
|
9
|
+
</CarouselItem>
|
|
10
|
+
</EbayCarousel>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Attributes
|
|
14
|
+
|
|
15
|
+
Name | Type | Stateful | Required | Description
|
|
16
|
+
--- |---------|----------| --- | ---
|
|
17
|
+
`gap` | Number | Yes | No | margin between carousel items in pixels.
|
|
18
|
+
`index` | Number | Yes | No | 0 - based index position. It sets the current slide to be displayed
|
|
19
|
+
`itemsPerSlide` | Number | Yes | No | number of items for each carousel slide and enable slide controls. If set to a whole number, will default to x.1 where x is the whole number set.
|
|
20
|
+
`a11yPreviousText` | String | No | Yes | A11y text for previous button and mask.
|
|
21
|
+
`a11yNextText` | String | No | Yes | A11y text for next button and mask.
|
|
22
|
+
|
|
23
|
+
## Events
|
|
24
|
+
|
|
25
|
+
Event | Data | Description
|
|
26
|
+
--- |-------| ---
|
|
27
|
+
`onNext` | Event | Trigggered when next slide button is clicked
|
|
28
|
+
`onPrevious` | Event | Triggered when previous slide button is clicked
|
|
29
|
+
`onScroll` | Event | Triggered when scrolling slides
|
|
30
|
+
`onSlide` | Event | new slide is navigated to (by controls or API)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## CarouselItem
|
|
34
|
+
Will render slides content
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FC, SyntheticEvent } from 'react';
|
|
2
|
+
import { CarouselControlType } from './types';
|
|
3
|
+
declare type CarouselControlProps = {
|
|
4
|
+
label?: string;
|
|
5
|
+
hidden?: boolean;
|
|
6
|
+
type: CarouselControlType;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
onClick: (event: SyntheticEvent<HTMLButtonElement>, { direction }: {
|
|
9
|
+
direction: any;
|
|
10
|
+
}) => void;
|
|
11
|
+
};
|
|
12
|
+
declare const CarouselControlButton: FC<CarouselControlProps>;
|
|
13
|
+
export default CarouselControlButton;
|
|
14
|
+
//# sourceMappingURL=carousel-control-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carousel-control-button.d.ts","sourceRoot":"","sources":["../../src/ebay-carousel/carousel-control-button.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAGjD,OAAO,EAAE,mBAAmB,EAAqB,MAAM,SAAS,CAAA;AAEhE,aAAK,oBAAoB,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,iBAAiB,CAAC,EAAE,EAAE,SAAS,EAAE;;KAAA,KAAK,IAAI,CAAC;CAC9E,CAAA;AAYD,QAAA,MAAM,qBAAqB,EAAE,EAAE,CAAC,oBAAoB,CAmBnD,CAAA;AAED,eAAe,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var react_1 = __importDefault(require("react"));
|
|
7
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
8
|
+
var ebay_icon_1 = require("../ebay-icon");
|
|
9
|
+
var icon = {
|
|
10
|
+
prev: 'carouselPrev',
|
|
11
|
+
next: 'carouselNext'
|
|
12
|
+
};
|
|
13
|
+
var typeToDirection = {
|
|
14
|
+
prev: 'LEFT',
|
|
15
|
+
next: 'RIGHT'
|
|
16
|
+
};
|
|
17
|
+
var CarouselControlButton = function (_a) {
|
|
18
|
+
var type = _a.type, label = _a.label, hidden = _a.hidden, disabled = _a.disabled, onClick = _a.onClick;
|
|
19
|
+
var handleOnClick = function (event) {
|
|
20
|
+
onClick(event, { direction: typeToDirection[type] });
|
|
21
|
+
};
|
|
22
|
+
return (react_1.default.createElement("button", { className: classnames_1.default('carousel__control', "carousel__control--" + type), "aria-label": label, "aria-disabled": disabled, disabled: disabled, onClick: handleOnClick },
|
|
23
|
+
react_1.default.createElement(ebay_icon_1.EbayIcon, { className: classnames_1.default('icon', "icon--carousel-" + type), focusable: false, name: icon[type], "aria-hidden": hidden })));
|
|
24
|
+
};
|
|
25
|
+
exports.default = CarouselControlButton;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { ComponentProps, RefObject } from 'react';
|
|
2
|
+
import { ListItemRef } from './types';
|
|
3
|
+
declare type ListProps = ComponentProps<'li'>;
|
|
4
|
+
declare type CarouselItemProps = ListProps & {
|
|
5
|
+
slideWidth?: number;
|
|
6
|
+
offset?: number;
|
|
7
|
+
className?: string;
|
|
8
|
+
forwardedRef?: RefObject<ListItemRef>;
|
|
9
|
+
};
|
|
10
|
+
declare const _default: React.ForwardRefExoticComponent<Pick<CarouselItemProps, "slot" | "style" | "title" | "key" | "className" | "forwardedRef" | "color" | "id" | "lang" | "role" | "tabIndex" | "offset" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "placeholder" | "spellCheck" | "translate" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "value" | "slideWidth"> & React.RefAttributes<React.FC<CarouselItemProps>>>;
|
|
11
|
+
export default _default;
|
|
12
|
+
//# sourceMappingURL=carousel-item.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carousel-item.d.ts","sourceRoot":"","sources":["../../src/ebay-carousel/carousel-item.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACV,cAAc,EAEd,SAAS,EAIZ,MAAM,OAAO,CAAA;AAGd,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC,aAAK,SAAS,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;AACrC,aAAK,iBAAiB,GAAG,SAAS,GAAG;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,CAAA;CACxC,CAAC;;AAiCF,wBAA+C"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
33
|
+
var t = {};
|
|
34
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
35
|
+
t[p] = s[p];
|
|
36
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
37
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
38
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
39
|
+
t[p[i]] = s[p[i]];
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
var react_1 = __importStar(require("react"));
|
|
45
|
+
var component_utils_1 = require("../common/component-utils");
|
|
46
|
+
var helpers_1 = require("./helpers");
|
|
47
|
+
var EbayCarouselItem = function (_a) {
|
|
48
|
+
var slideWidth = _a.slideWidth, offset = _a.offset, forwardedRef = _a.forwardedRef, children = _a.children, rest = __rest(_a, ["slideWidth", "offset", "forwardedRef", "children"]);
|
|
49
|
+
var itemRef = react_1.useRef();
|
|
50
|
+
var _b = react_1.useState(false), isVisible = _b[0], setIsVisible = _b[1];
|
|
51
|
+
react_1.useImperativeHandle(forwardedRef, function () {
|
|
52
|
+
if (!itemRef.current)
|
|
53
|
+
return;
|
|
54
|
+
var _a = helpers_1.getRelativeRects(itemRef.current), left = _a.left, right = _a.right;
|
|
55
|
+
var fullyVisible = left === undefined ||
|
|
56
|
+
(left - offset >= -0.01 && right - offset <= slideWidth + 0.01);
|
|
57
|
+
setIsVisible(fullyVisible);
|
|
58
|
+
return {
|
|
59
|
+
left: left,
|
|
60
|
+
right: right,
|
|
61
|
+
fullyVisible: fullyVisible
|
|
62
|
+
};
|
|
63
|
+
}, [slideWidth, offset]);
|
|
64
|
+
return (react_1.default.createElement("li", __assign({ ref: itemRef, "aria-hidden": !isVisible }, rest), children));
|
|
65
|
+
};
|
|
66
|
+
exports.default = component_utils_1.withForwardRef(EbayCarouselItem);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FC, ReactNode, RefObject } from 'react';
|
|
2
|
+
import { ListItemRef } from './types';
|
|
3
|
+
declare type CarouselListProps = {
|
|
4
|
+
gap?: number;
|
|
5
|
+
itemsPerSlide: number;
|
|
6
|
+
slideWidth: number;
|
|
7
|
+
offset: number;
|
|
8
|
+
activeIndex: number;
|
|
9
|
+
nextControlDisabled?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
itemsRef?: RefObject<Array<ListItemRef | null>>;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
onSetActiveIndex: (index: number) => void;
|
|
14
|
+
onScroll?: ({ index }: {
|
|
15
|
+
index: any;
|
|
16
|
+
}) => void;
|
|
17
|
+
};
|
|
18
|
+
declare const CarouselList: FC<CarouselListProps>;
|
|
19
|
+
export default CarouselList;
|
|
20
|
+
//# sourceMappingURL=carousel-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carousel-list.d.ts","sourceRoot":"","sources":["../../src/ebay-carousel/carousel-list.tsx"],"names":[],"mappings":"AAAA,OAAc,EACV,EAAE,EAAE,SAAS,EAEL,SAAS,EACpB,MAAM,OAAO,CAAA;AAId,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC,aAAK,iBAAiB,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC;IAChD,QAAQ,EAAE,SAAS,CAAC;IACpB,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,QAAQ,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE;;KAAA,KAAK,IAAI,CAAC;CAClC,CAAC;AAEF,QAAA,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CA2EvC,CAAA;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
var react_1 = __importStar(require("react"));
|
|
26
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
27
|
+
var helpers_1 = require("./helpers");
|
|
28
|
+
var scroll_to_transition_1 = require("./scroll-to-transition");
|
|
29
|
+
var CarouselList = function (_a) {
|
|
30
|
+
var _b = _a.gap, gap = _b === void 0 ? 16 : _b, itemsPerSlide = _a.itemsPerSlide, slideWidth = _a.slideWidth, offset = _a.offset, activeIndex = _a.activeIndex, nextControlDisabled = _a.nextControlDisabled, className = _a.className, itemsRef = _a.itemsRef, children = _a.children, onSetActiveIndex = _a.onSetActiveIndex, onScroll = _a.onScroll;
|
|
31
|
+
var _c = react_1.useState(0), translateLeft = _c[0], setTranslateLeft = _c[1];
|
|
32
|
+
var _d = react_1.useState(false), skipScrolling = _d[0], setSkipScrolling = _d[1];
|
|
33
|
+
var _e = react_1.useState(false), scrollTransitioning = _e[0], setScrollTransitioning = _e[1];
|
|
34
|
+
var listRef = react_1.useRef(null);
|
|
35
|
+
var scrollTimeout = react_1.useRef(null);
|
|
36
|
+
react_1.useEffect(function () {
|
|
37
|
+
var size = react_1.Children.count(children);
|
|
38
|
+
if (!size || !listRef.current)
|
|
39
|
+
return;
|
|
40
|
+
if (skipScrolling) {
|
|
41
|
+
setSkipScrolling(false);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
var list = listRef.current;
|
|
45
|
+
var isNativeScroll = helpers_1.isNativeScrolling(list);
|
|
46
|
+
if (isNativeScroll) {
|
|
47
|
+
setScrollTransitioning(true);
|
|
48
|
+
scroll_to_transition_1.scrollTransition(list, offset, function () { return setScrollTransitioning(false); });
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
setTranslateLeft(offset);
|
|
52
|
+
}
|
|
53
|
+
}, [offset]);
|
|
54
|
+
var handleFinishScrolling = react_1.useCallback(function () {
|
|
55
|
+
var scrollLeft = listRef.current.scrollLeft;
|
|
56
|
+
var closest = helpers_1.getClosestIndex(scrollLeft, itemsRef.current, slideWidth, itemsPerSlide, gap);
|
|
57
|
+
if (closest !== activeIndex) {
|
|
58
|
+
setSkipScrolling(true);
|
|
59
|
+
onSetActiveIndex(closest);
|
|
60
|
+
onScroll({ index: closest });
|
|
61
|
+
}
|
|
62
|
+
}, [listRef.current, itemsRef.current, slideWidth, activeIndex, onSetActiveIndex]);
|
|
63
|
+
var handleScroll = function () {
|
|
64
|
+
if (scrollTimeout.current) {
|
|
65
|
+
clearTimeout(scrollTimeout.current);
|
|
66
|
+
}
|
|
67
|
+
scrollTimeout.current = setTimeout(function () {
|
|
68
|
+
if (!scrollTransitioning) {
|
|
69
|
+
handleFinishScrolling();
|
|
70
|
+
}
|
|
71
|
+
}, 640);
|
|
72
|
+
};
|
|
73
|
+
return (react_1.default.createElement("div", { className: classnames_1.default('carousel__viewport', {
|
|
74
|
+
'carousel__viewport--mask': !nextControlDisabled
|
|
75
|
+
}, className) },
|
|
76
|
+
react_1.default.createElement("ul", { className: "carousel__list", ref: listRef, onScroll: handleScroll, style: { transform: "translate3d(" + -translateLeft + "px, 0, 0)" } }, helpers_1.alterChildren(children, itemsRef, itemsPerSlide, slideWidth, offset, gap))));
|
|
77
|
+
};
|
|
78
|
+
exports.default = CarouselList;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { ComponentProps, FC } from 'react';
|
|
2
|
+
declare type CarouselProps = ComponentProps<'div'> & {
|
|
3
|
+
className?: string;
|
|
4
|
+
gap?: number;
|
|
5
|
+
index?: number;
|
|
6
|
+
imageTreatment?: boolean;
|
|
7
|
+
itemsPerSlide?: number;
|
|
8
|
+
a11yPreviousText?: string;
|
|
9
|
+
a11yNextText?: string;
|
|
10
|
+
onNext?: (event: React.SyntheticEvent) => void;
|
|
11
|
+
onPrevious?: (event: React.SyntheticEvent) => void;
|
|
12
|
+
onScroll?: ({ index }: {
|
|
13
|
+
index: any;
|
|
14
|
+
}) => void;
|
|
15
|
+
onSlide?: ({ slide }: {
|
|
16
|
+
slide: any;
|
|
17
|
+
}) => void;
|
|
18
|
+
onPlay?: (event: React.SyntheticEvent) => void;
|
|
19
|
+
onPause?: (event: React.SyntheticEvent) => void;
|
|
20
|
+
};
|
|
21
|
+
declare const EbayCarousel: FC<CarouselProps>;
|
|
22
|
+
export default EbayCarousel;
|
|
23
|
+
//# sourceMappingURL=carousel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carousel.d.ts","sourceRoot":"","sources":["../../src/ebay-carousel/carousel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAY,cAAc,EAAE,EAAE,EAA+C,MAAM,OAAO,CAAA;AAQxG,aAAK,aAAa,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,KAAK,IAAI,CAAC;IAC/C,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,KAAK,IAAI,CAAC;IACnD,QAAQ,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE;;KAAA,KAAK,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE;;KAAA,KAAK,IAAI,CAAC;IAC9B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,KAAK,IAAI,CAAA;IAC9C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,KAAK,IAAI,CAAA;CAClD,CAAC;AAMF,QAAA,MAAM,YAAY,EAAE,EAAE,CAAC,aAAa,CA0GnC,CAAA;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
33
|
+
var t = {};
|
|
34
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
35
|
+
t[p] = s[p];
|
|
36
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
37
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
38
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
39
|
+
t[p[i]] = s[p[i]];
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
};
|
|
43
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
44
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
var react_1 = __importStar(require("react"));
|
|
48
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
49
|
+
var carousel_control_button_1 = __importDefault(require("./carousel-control-button"));
|
|
50
|
+
var carousel_list_1 = __importDefault(require("./carousel-list"));
|
|
51
|
+
var helpers_1 = require("./helpers");
|
|
52
|
+
var debounce_1 = require("../common/debounce");
|
|
53
|
+
// TO-DO:
|
|
54
|
+
// Image slides
|
|
55
|
+
// Auto play
|
|
56
|
+
var EbayCarousel = function (_a) {
|
|
57
|
+
var _b = _a.gap, gap = _b === void 0 ? 16 : _b, _c = _a.index, index = _c === void 0 ? 0 : _c, _itemsPerSlide = _a.itemsPerSlide, a11yPreviousText = _a.a11yPreviousText, a11yNextText = _a.a11yNextText, _d = _a.onScroll, onScroll = _d === void 0 ? function () { } : _d, _e = _a.onNext, onNext = _e === void 0 ? function () { } : _e, _f = _a.onPrevious, onPrevious = _f === void 0 ? function () { } : _f, _g = _a.onSlide, onSlide = _g === void 0 ? function () { } : _g, className = _a.className, children = _a.children, rest = __rest(_a, ["gap", "index", "itemsPerSlide", "a11yPreviousText", "a11yNextText", "onScroll", "onNext", "onPrevious", "onSlide", "className", "children"]);
|
|
58
|
+
var _h = react_1.useState(index), activeIndex = _h[0], setActiveIndex = _h[1];
|
|
59
|
+
var _j = react_1.useState(0), slideWidth = _j[0], setSlideWidth = _j[1];
|
|
60
|
+
var _k = react_1.useState(0), offset = _k[0], setOffset = _k[1];
|
|
61
|
+
var containerRef = react_1.useRef(null);
|
|
62
|
+
var itemsRef = react_1.useRef([]);
|
|
63
|
+
var itemCount = react_1.Children.count(children);
|
|
64
|
+
var itemsPerSlide = Math.floor(_itemsPerSlide) || undefined;
|
|
65
|
+
var isSingleSlide = itemCount <= itemsPerSlide;
|
|
66
|
+
var prevControlDisabled = isSingleSlide || offset === 0;
|
|
67
|
+
var nextControlDisabled = isSingleSlide || (offset === helpers_1.getMaxOffset(itemsRef.current, slideWidth));
|
|
68
|
+
var handleResize = function () {
|
|
69
|
+
if (!containerRef.current)
|
|
70
|
+
return;
|
|
71
|
+
var containerWidth = containerRef.current.getBoundingClientRect().width;
|
|
72
|
+
setSlideWidth(containerWidth);
|
|
73
|
+
};
|
|
74
|
+
react_1.useEffect(function () {
|
|
75
|
+
window.addEventListener('resize', debounce_1.debounce(handleResize, 16));
|
|
76
|
+
return function () {
|
|
77
|
+
window.removeEventListener('resize', debounce_1.debounce(handleResize, 16));
|
|
78
|
+
};
|
|
79
|
+
}, []);
|
|
80
|
+
react_1.useEffect(function () {
|
|
81
|
+
setOffset(helpers_1.getOffset(itemsRef.current, activeIndex, slideWidth));
|
|
82
|
+
}, [activeIndex, slideWidth]);
|
|
83
|
+
react_1.useEffect(function () {
|
|
84
|
+
if (index >= 0 && index <= itemCount - 1) {
|
|
85
|
+
setActiveIndex(index);
|
|
86
|
+
}
|
|
87
|
+
}, [index]);
|
|
88
|
+
react_1.useEffect(function () {
|
|
89
|
+
itemsRef.current = itemsRef.current.splice(0, itemCount);
|
|
90
|
+
}, [children]);
|
|
91
|
+
react_1.useEffect(function () {
|
|
92
|
+
var containerWidth = containerRef.current.getBoundingClientRect().width;
|
|
93
|
+
setSlideWidth(containerWidth);
|
|
94
|
+
}, [containerRef.current]);
|
|
95
|
+
var handleControlClick = function (event, _a) {
|
|
96
|
+
var direction = _a.direction;
|
|
97
|
+
var nextIndex = helpers_1.getNextIndex(direction, activeIndex, itemsRef.current, slideWidth, itemsPerSlide);
|
|
98
|
+
var slide = helpers_1.getSlide(activeIndex, itemsPerSlide, nextIndex);
|
|
99
|
+
setActiveIndex(nextIndex);
|
|
100
|
+
if (direction === 'LEFT') {
|
|
101
|
+
onPrevious(event);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
onNext(event);
|
|
105
|
+
}
|
|
106
|
+
onSlide({ slide: slide });
|
|
107
|
+
};
|
|
108
|
+
return (react_1.default.createElement("div", __assign({ className: classnames_1.default('carousel', className, {
|
|
109
|
+
'carousel--slides': itemsPerSlide,
|
|
110
|
+
'carousel--peek': itemsPerSlide % 1 === 0
|
|
111
|
+
}) }, rest),
|
|
112
|
+
react_1.default.createElement("div", { ref: containerRef, className: "carousel__container" },
|
|
113
|
+
react_1.default.createElement(carousel_control_button_1.default, { label: a11yPreviousText, type: "prev", disabled: prevControlDisabled, onClick: handleControlClick }),
|
|
114
|
+
react_1.default.createElement(carousel_list_1.default, { itemsRef: itemsRef, offset: offset, gap: gap, itemsPerSlide: itemsPerSlide, nextControlDisabled: nextControlDisabled, activeIndex: activeIndex, onScroll: onScroll, onSetActiveIndex: setActiveIndex, slideWidth: slideWidth }, children),
|
|
115
|
+
react_1.default.createElement(carousel_control_button_1.default, { type: "next", label: a11yNextText, disabled: nextControlDisabled, onClick: handleControlClick }))));
|
|
116
|
+
};
|
|
117
|
+
exports.default = EbayCarousel;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactElement, ReactNode, RefObject } from 'react';
|
|
2
|
+
import { ListItemRef, MovementDirection, RelativeRect } from './types';
|
|
3
|
+
export declare function getRelativeRects(el: Element): RelativeRect;
|
|
4
|
+
export declare const isNativeScrolling: (el: Element) => boolean;
|
|
5
|
+
export declare const getMaxOffset: (items: ListItemRef[], slideWidth: number) => number;
|
|
6
|
+
export declare const getOffset: (items: ListItemRef[], index: number, slideWidth: number) => number;
|
|
7
|
+
export declare const alterChildren: (children: ReactNode, itemsRef: RefObject<Array<ListItemRef | null>>, itemsPerSlide?: number, slideWidth?: number, offset?: number, gap?: number) => ReactElement[];
|
|
8
|
+
/**
|
|
9
|
+
* Gets the slide for a given index.
|
|
10
|
+
* Defaults to the current index if none provided.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getSlide: (activeIndex: number, itemsPerSlide?: number, nextIndex?: number) => undefined | number;
|
|
13
|
+
export declare const getNextIndex: (direction: MovementDirection, activeIndex: number, items?: ListItemRef[], slideWidth?: number, itemsPerSlide?: number) => number;
|
|
14
|
+
export declare const getClosestIndex: (scrollLeft: number, items: ListItemRef[], slideWidth: number, itemsPerSlide?: number, gap?: number) => number;
|
|
15
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/ebay-carousel/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAClF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtE,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO,GAAG,YAAY,CAW1D;AAED,eAAO,MAAM,iBAAiB,OAAQ,OAAO,KAAG,OAAuD,CAAA;AAEvG,eAAO,MAAM,YAAY,UAAW,WAAW,EAAE,cAAc,MAAM,KAAG,MAOvE,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,WAAW,EAAE,SAAS,MAAM,cAAc,MAAM,KAAG,MAMnF,CAAA;AAED,eAAO,MAAM,aAAa,aACZ,SAAS,YACT,SAAS,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,kBAC9B,MAAM,eACT,MAAM,WACV,MAAM,QACT,MAAM,KAAG,YAAY,EAwB7B,CAAA;AAgBF;;;GAGG;AACH,eAAO,MAAM,QAAQ,gBAAiB,MAAM,kBAAkB,MAAM,yBAA4B,SAAS,GAAG,MAM3G,CAAA;AAID,eAAO,MAAM,YAAY,cACV,iBAAiB,eACf,MAAM,UACX,WAAW,EAAE,eACR,MAAM,kBACH,MAAM,KAAG,MAyB5B,CAAA;AAED,eAAO,MAAM,eAAe,eACZ,MAAM,SACX,WAAW,EAAE,cACR,MAAM,gCAEZ,MAAM,KAAG,MA0BlB,CAAA"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getClosestIndex = exports.getNextIndex = exports.getSlide = exports.alterChildren = exports.getOffset = exports.getMaxOffset = exports.isNativeScrolling = exports.getRelativeRects = void 0;
|
|
15
|
+
var react_1 = require("react");
|
|
16
|
+
function getRelativeRects(el) {
|
|
17
|
+
var parent = el.parentElement;
|
|
18
|
+
var currentLeft = parent
|
|
19
|
+
? parent.firstElementChild.getBoundingClientRect().left
|
|
20
|
+
: 0;
|
|
21
|
+
var _a = el.getBoundingClientRect(), left = _a.left, right = _a.right;
|
|
22
|
+
return {
|
|
23
|
+
left: left - currentLeft,
|
|
24
|
+
right: right - currentLeft
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.getRelativeRects = getRelativeRects;
|
|
28
|
+
exports.isNativeScrolling = function (el) { return getComputedStyle(el).overflowX !== 'visible'; };
|
|
29
|
+
exports.getMaxOffset = function (items, slideWidth) {
|
|
30
|
+
if (!items.length) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
var lastEl = items[items.length - 1];
|
|
34
|
+
return Math.max(lastEl.right - slideWidth, 0) || 0;
|
|
35
|
+
};
|
|
36
|
+
exports.getOffset = function (items, index, slideWidth) {
|
|
37
|
+
if (!items.length) {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
return Math.min(items[index].left, exports.getMaxOffset(items, slideWidth)) || 0;
|
|
41
|
+
};
|
|
42
|
+
exports.alterChildren = function (children, itemsRef, itemsPerSlide, slideWidth, offset, gap) { return react_1.Children.map(children, function (item, index) {
|
|
43
|
+
var _a = item.props.style, style = _a === void 0 ? {} : _a;
|
|
44
|
+
var itemWidth;
|
|
45
|
+
if (itemsPerSlide) {
|
|
46
|
+
var itemsInSlide = itemsPerSlide + (itemsPerSlide % 1);
|
|
47
|
+
itemWidth = "calc(" + 100 / itemsInSlide + "% - " + ((itemsInSlide - 1) * gap) / itemsInSlide + "px)";
|
|
48
|
+
}
|
|
49
|
+
var isStartOfSlide = itemsPerSlide ? index % itemsPerSlide === 0 : true;
|
|
50
|
+
return react_1.cloneElement(item, __assign(__assign({}, item.props), { slideWidth: slideWidth,
|
|
51
|
+
offset: offset, ref: function (el) {
|
|
52
|
+
itemsRef.current[index] = el;
|
|
53
|
+
}, className: isStartOfSlide ? 'carousel__snap-point' : item.props.className, style: __assign(__assign({}, style), { width: itemWidth || style.width, marginRight: gap && index !== react_1.Children.count(children) - 1 ? gap + "px" : style.marginRight }) }));
|
|
54
|
+
}); };
|
|
55
|
+
/**
|
|
56
|
+
* Ensures that an index is valid.
|
|
57
|
+
*/
|
|
58
|
+
var normalizeIndex = function (index, items, itemsPerSlide) {
|
|
59
|
+
if (index > 0) {
|
|
60
|
+
var result = index;
|
|
61
|
+
result %= items.length || 1; // Ensure index is within bounds.
|
|
62
|
+
result -= result % (itemsPerSlide || 1); // Round index to the nearest valid slide index.
|
|
63
|
+
result = Math.abs(result); // Ensure positive value.
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
return 0;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Gets the slide for a given index.
|
|
70
|
+
* Defaults to the current index if none provided.
|
|
71
|
+
*/
|
|
72
|
+
exports.getSlide = function (activeIndex, itemsPerSlide, nextIndex) {
|
|
73
|
+
if (nextIndex === void 0) { nextIndex = activeIndex; }
|
|
74
|
+
if (!itemsPerSlide) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return Math.ceil(nextIndex / itemsPerSlide);
|
|
78
|
+
};
|
|
79
|
+
var getDelta = function (direction) { return direction === 'LEFT' ? -1 : 1; };
|
|
80
|
+
exports.getNextIndex = function (direction, activeIndex, items, slideWidth, itemsPerSlide) {
|
|
81
|
+
var i = activeIndex;
|
|
82
|
+
var item;
|
|
83
|
+
// If going backward from 0, we go to the end.
|
|
84
|
+
if (direction === 'LEFT' && i === 0) {
|
|
85
|
+
i = items.length - 1;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Find the index of the next item that is not fully in view.
|
|
89
|
+
do {
|
|
90
|
+
var delta = getDelta(direction);
|
|
91
|
+
item = items[i += delta];
|
|
92
|
+
} while (item && item.fullyVisible);
|
|
93
|
+
if (direction === 'LEFT' && !itemsPerSlide) {
|
|
94
|
+
// If going left without items per slide, go as far left as possible while keeping this item fully in view.
|
|
95
|
+
var targetOffset = item.right - slideWidth;
|
|
96
|
+
do {
|
|
97
|
+
item = items[--i];
|
|
98
|
+
} while (item && item.left >= targetOffset);
|
|
99
|
+
i += 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return normalizeIndex(i, items, itemsPerSlide);
|
|
103
|
+
};
|
|
104
|
+
exports.getClosestIndex = function (scrollLeft, items, slideWidth, itemsPerSlide, gap) {
|
|
105
|
+
if (itemsPerSlide === void 0) { itemsPerSlide = 1; }
|
|
106
|
+
var closest;
|
|
107
|
+
if (scrollLeft >= exports.getMaxOffset(items, slideWidth) - gap) {
|
|
108
|
+
closest = items.length - 1;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// Find the closest item using a binary search on each carousel slide.
|
|
112
|
+
var totalItems = items.length;
|
|
113
|
+
var low = 0;
|
|
114
|
+
var high = Math.ceil(totalItems / itemsPerSlide) - 1;
|
|
115
|
+
while (high - low > 1) {
|
|
116
|
+
var mid = Math.floor((low + high) / 2);
|
|
117
|
+
if (scrollLeft > items[mid * itemsPerSlide].left) {
|
|
118
|
+
low = mid;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
high = mid;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
var deltaLow = Math.abs(scrollLeft - items[low * itemsPerSlide].left);
|
|
125
|
+
var deltaHigh = Math.abs(scrollLeft - items[high * itemsPerSlide].left);
|
|
126
|
+
closest = normalizeIndex((deltaLow > deltaHigh ? high : low) * itemsPerSlide, items, itemsPerSlide);
|
|
127
|
+
}
|
|
128
|
+
return closest;
|
|
129
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ebay-carousel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var carousel_1 = require("./carousel");
|
|
4
|
+
Object.defineProperty(exports, "EbayCarousel", { enumerable: true, get: function () { return carousel_1.default; } });
|
|
5
|
+
var carousel_item_1 = require("./carousel-item");
|
|
6
|
+
Object.defineProperty(exports, "EbayCarouselItem", { enumerable: true, get: function () { return carousel_item_1.default; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks on an interval to see if the element is scrolling.
|
|
3
|
+
* When the scrolling has finished it then calls the function.
|
|
4
|
+
*
|
|
5
|
+
* @param {HTMLElement} el The element which scrolls.
|
|
6
|
+
* @param {(offset: number)=>{}} fn The function to call after scrolling completes.
|
|
7
|
+
* @return {function} A function to cancel the scroll listener.
|
|
8
|
+
*/
|
|
9
|
+
declare type ReturnFunctionType = () => void;
|
|
10
|
+
/**
|
|
11
|
+
* Utility to animate scroll position of an element using an `ease-out` curve over 250ms.
|
|
12
|
+
* Cancels the animation if the user touches back down.
|
|
13
|
+
*
|
|
14
|
+
* @param {HTMLElement} el The element to scroll.
|
|
15
|
+
* @param {number} to The offset to animate to.
|
|
16
|
+
* @param {function} fn A function that will be called after the transition completes.
|
|
17
|
+
* @return {function} A function that cancels the transition.
|
|
18
|
+
*/
|
|
19
|
+
export declare function scrollTransition(el: HTMLElement, to: number, fn: () => void): ReturnFunctionType;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=scroll-to-transition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-to-transition.d.ts","sourceRoot":"","sources":["../../src/ebay-carousel/scroll-to-transition.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,aAAK,kBAAkB,GAAG,MAAM,IAAI,CAAA;AA2BpC;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,kBAAkB,CAgEhG"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// copy-pasted from @ebay/ebayui-core/dist/components/ebay-carousel/utils/scroll-transition
|
|
3
|
+
// todo: replace with ebayui-core-react/ebay-carousel when it's ready
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.scrollTransition = void 0;
|
|
6
|
+
var onScrollEnd = function (el, fn) {
|
|
7
|
+
var timeout;
|
|
8
|
+
var frame;
|
|
9
|
+
var lastPos;
|
|
10
|
+
(function checkMoved() {
|
|
11
|
+
var scrollLeft = el.scrollLeft;
|
|
12
|
+
if (lastPos !== scrollLeft) {
|
|
13
|
+
lastPos = scrollLeft;
|
|
14
|
+
timeout = setTimeout(function () {
|
|
15
|
+
frame = requestAnimationFrame(checkMoved);
|
|
16
|
+
}, 90);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
fn(lastPos);
|
|
20
|
+
}());
|
|
21
|
+
return function () {
|
|
22
|
+
clearTimeout(timeout);
|
|
23
|
+
cancelAnimationFrame(frame);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var supportsScrollBehavior = typeof window !== 'undefined' && 'scrollBehavior' in document.body.style;
|
|
27
|
+
/**
|
|
28
|
+
* Utility to animate scroll position of an element using an `ease-out` curve over 250ms.
|
|
29
|
+
* Cancels the animation if the user touches back down.
|
|
30
|
+
*
|
|
31
|
+
* @param {HTMLElement} el The element to scroll.
|
|
32
|
+
* @param {number} to The offset to animate to.
|
|
33
|
+
* @param {function} fn A function that will be called after the transition completes.
|
|
34
|
+
* @return {function} A function that cancels the transition.
|
|
35
|
+
*/
|
|
36
|
+
function scrollTransition(el, to, fn) {
|
|
37
|
+
if (supportsScrollBehavior) {
|
|
38
|
+
el.scrollTo({ left: to });
|
|
39
|
+
return onScrollEnd(el, fn);
|
|
40
|
+
}
|
|
41
|
+
var lastPosition;
|
|
42
|
+
var cancelInterruptTransition;
|
|
43
|
+
var frame = requestAnimationFrame(function (startTime) {
|
|
44
|
+
var scrollLeft = el.scrollLeft;
|
|
45
|
+
var distance = to - scrollLeft;
|
|
46
|
+
var duration = 450;
|
|
47
|
+
(function animate(curTime) {
|
|
48
|
+
var delta = curTime - startTime;
|
|
49
|
+
if (delta > duration) {
|
|
50
|
+
el.scrollLeft = to;
|
|
51
|
+
cancel();
|
|
52
|
+
return fn();
|
|
53
|
+
}
|
|
54
|
+
el.scrollLeft = easeInOut(delta / duration) * distance + scrollLeft;
|
|
55
|
+
frame = requestAnimationFrame(animate);
|
|
56
|
+
}(startTime));
|
|
57
|
+
});
|
|
58
|
+
// The animation can be interrupted by new touch events.
|
|
59
|
+
el.addEventListener('touchstart', handleTouchStart);
|
|
60
|
+
return cancel;
|
|
61
|
+
function cancel() {
|
|
62
|
+
cancelAnimationFrame(frame);
|
|
63
|
+
if (lastPosition === undefined) {
|
|
64
|
+
cancelTouchStart();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (cancelInterruptTransition)
|
|
68
|
+
cancelInterruptTransition();
|
|
69
|
+
cancelTouchEnd();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function handleTouchStart() {
|
|
73
|
+
cancel();
|
|
74
|
+
lastPosition = el.scrollLeft;
|
|
75
|
+
// If we were interrupted by a touch start we wait for a touch end to see if we moved.
|
|
76
|
+
el.addEventListener('touchend', handleTouchEnd);
|
|
77
|
+
}
|
|
78
|
+
function handleTouchEnd() {
|
|
79
|
+
cancelTouchEnd();
|
|
80
|
+
// If we haven't moved because of the interrupt we continue to transition.
|
|
81
|
+
if (lastPosition === el.scrollLeft) {
|
|
82
|
+
cancelInterruptTransition = scrollTransition(el, to, fn);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function cancelTouchStart() {
|
|
86
|
+
el.removeEventListener('touchstart', handleTouchStart);
|
|
87
|
+
}
|
|
88
|
+
function cancelTouchEnd() {
|
|
89
|
+
el.removeEventListener('touchend', handleTouchEnd);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.scrollTransition = scrollTransition;
|
|
93
|
+
/**
|
|
94
|
+
* Ease out timing function.
|
|
95
|
+
* Based on https://gist.github.com/gre/1650294.
|
|
96
|
+
*
|
|
97
|
+
* @param {number} val - A number between 0 and 1.
|
|
98
|
+
* @return {number}
|
|
99
|
+
*/
|
|
100
|
+
function easeInOut(val) {
|
|
101
|
+
return val < 0.5 ? 2 * val * val : -1 + (4 - 2 * val) * val;
|
|
102
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare type CarouselControlType = 'prev' | 'next';
|
|
2
|
+
export declare type MovementDirection = 'LEFT' | 'RIGHT' | 'NONE';
|
|
3
|
+
export declare type RelativeRect = Pick<ClientRect, 'left' | 'right'>;
|
|
4
|
+
export declare type ListItemRef = {
|
|
5
|
+
left: number;
|
|
6
|
+
right: number;
|
|
7
|
+
fullyVisible: boolean;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ebay-carousel/types.ts"],"names":[],"mappings":"AAAA,oBAAY,mBAAmB,GAAG,MAAM,GAAG,MAAM,CAAA;AAEjD,oBAAY,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAEzD,oBAAY,YAAY,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAC,OAAO,CAAC,CAAA;AAE3D,oBAAY,WAAW,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,OAAO,CAAC;CACzB,CAAA"}
|