@ebay/ui-core-react 7.4.0-alpha.8 → 7.4.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 +2 -2
- package/array.polyfill.flat-5BAolFdk.js +1 -0
- package/badge-CoHKfiPt.js +1 -0
- package/button-DGuEBUDJ.js +1 -0
- package/calendar-lAu6VfAb.js +1 -0
- package/common/component-utils/forwardRef/index.js +1 -10
- package/common/component-utils/index.js +1 -9
- package/common/component-utils/utils/index.js +1 -25
- package/common/event-utils/index.js +1 -113
- package/common/floating-label-utils/hooks/index.js +1 -106
- package/common/notice-utils/notice-cta/index.js +1 -5
- package/common/random-id/index.js +1 -13
- package/common/tooltip-utils/constants/index.js +1 -97
- package/common/tooltip-utils/index.js +1 -11
- package/debounce-BQsYxxOL.js +1 -0
- package/dialog-previous-button-CpuFLkQp.js +1 -0
- package/drawer-rqXAEeqd.js +1 -0
- package/ebay-alert-dialog/index.js +1 -26
- package/ebay-badge/index.js +1 -4
- package/ebay-breadcrumbs/index.js +1 -47
- package/ebay-button/index.js +1 -5
- package/ebay-calendar/index.js +1 -4
- package/ebay-carousel/index.js +1 -345
- package/ebay-checkbox/index.js +1 -52
- package/ebay-confirm-dialog/index.js +1 -28
- package/ebay-cta-button/index.js +1 -22
- package/ebay-date-textbox/index.js +1 -140
- package/ebay-dialog-base/components/animation/index.js +1 -92
- package/ebay-dialog-base/components/dialog-footer/index.js +1 -4
- package/ebay-dialog-base/components/dialog-header/index.js +1 -4
- package/ebay-dialog-base/index.js +1 -13
- package/ebay-drawer-dialog/index.js +1 -4
- package/ebay-eek/index.js +1 -54
- package/ebay-fake-menu/index.js +1 -10
- package/ebay-fake-menu/menu-item/index.js +1 -49
- package/ebay-fake-menu-button/index.js +1 -7
- package/ebay-fake-menu-button/menu-button/index.js +1 -12
- package/ebay-fake-tabs/index.js +1 -30
- package/ebay-field/index.js +1 -21
- package/ebay-fullscreen-dialog/index.js +1 -10
- package/ebay-icon/index.js +1 -4
- package/ebay-icon/types.d.ts +1 -1
- package/ebay-icon/types.d.ts.map +1 -1
- package/ebay-icon-button/index.js +1 -4
- package/ebay-infotip/index.js +1 -76
- package/ebay-inline-notice/index.js +1 -36
- package/ebay-lightbox-dialog/index.js +1 -12
- package/ebay-listbox-button/index.d.ts +2 -1
- package/ebay-listbox-button/index.d.ts.map +1 -1
- package/ebay-listbox-button/index.js +2 -151
- package/ebay-listbox-button/listbox-button-option.d.ts +10 -0
- package/ebay-listbox-button/listbox-button-option.d.ts.map +1 -0
- package/ebay-listbox-button/listbox-button.d.ts +5 -15
- package/ebay-listbox-button/listbox-button.d.ts.map +1 -1
- package/ebay-menu/index.js +1 -9
- package/ebay-menu-button/index.js +1 -113
- package/ebay-notice-base/index.js +1 -7
- package/ebay-page-notice/index.js +1 -50
- package/ebay-pagination/index.js +1 -244
- package/ebay-panel-dialog/index.js +1 -12
- package/ebay-progress-bar/index.js +1 -6
- package/ebay-progress-spinner/index.js +1 -4
- package/ebay-progress-stepper/index.js +1 -72
- package/ebay-radio/index.js +1 -4
- package/ebay-radio/radio/index.js +1 -48
- package/ebay-section-notice/index.js +1 -69
- package/ebay-section-title/index.js +1 -38
- package/ebay-segmented-buttons/index.js +1 -46
- package/ebay-select/index.js +1 -98
- package/ebay-signal/index.js +1 -9
- package/ebay-snackbar-dialog/index.js +1 -81
- package/ebay-split-button/index.js +1 -22
- package/ebay-star-rating/index.js +1 -9
- package/ebay-star-rating-select/index.js +1 -55
- package/ebay-svg/index.js +1 -5189
- package/ebay-svg/symbols.d.ts.map +1 -1
- package/ebay-switch/index.js +1 -27
- package/ebay-tabs/index.js +1 -88
- package/ebay-textbox/index.js +1 -10
- package/ebay-toast-dialog/index.js +1 -9
- package/ebay-toggle-button/README.md +39 -0
- package/ebay-toggle-button/index.d.ts +3 -0
- package/ebay-toggle-button/index.d.ts.map +1 -0
- package/ebay-toggle-button/index.js +1 -0
- package/ebay-toggle-button/toggle-button.d.ts +5 -0
- package/ebay-toggle-button/toggle-button.d.ts.map +1 -0
- package/ebay-toggle-button/types.d.ts +23 -0
- package/ebay-toggle-button/types.d.ts.map +1 -0
- package/ebay-toggle-button-group/README.md +56 -0
- package/ebay-toggle-button-group/index.d.ts +3 -0
- package/ebay-toggle-button-group/index.d.ts.map +1 -0
- package/ebay-toggle-button-group/index.js +1 -0
- package/ebay-toggle-button-group/toggle-button-group.d.ts +5 -0
- package/ebay-toggle-button-group/toggle-button-group.d.ts.map +1 -0
- package/ebay-toggle-button-group/types.d.ts +20 -0
- package/ebay-toggle-button-group/types.d.ts.map +1 -0
- package/ebay-tooltip/index.js +1 -64
- package/ebay-tourtip/index.js +1 -54
- package/ebay-video/index.js +1 -229
- package/events/index.js +1 -18
- package/icon-TuxfQndO.js +1 -0
- package/icon-button-Cwaj-eT9.js +1 -0
- package/label-CnrpYJ-g.js +1 -0
- package/menu-CV-INYLM.js +1 -0
- package/menu-_LzP6yje.js +1 -0
- package/menu-button-BZ66jxvI.js +1 -0
- package/notice-content-9iF4T8uB.js +1 -0
- package/notice-content-C0ZStfuX.js +1 -0
- package/notice-footer-Cw1DMzoB.js +1 -0
- package/package.json +2 -5
- package/progress-spinner-U2qOANON.js +1 -0
- package/range-DOsPN0h5.js +1 -0
- package/textbox-dUhinDwj.js +1 -0
- package/toggle-button-D8l0YB43.js +1 -0
- package/use-roving-index-DoAVBgsp.js +1 -0
- package/use-tooltip-CL3_zAeg.js +1 -0
- package/utils/index.js +1 -13
- package/array.polyfill.flat-DyxysTxZ.js +0 -21
- package/badge-CR5t7-2L.js +0 -8
- package/button-B4bZIgwB.js +0 -83
- package/calendar-D-DWjrMU.js +0 -333
- package/debounce-v8bWAUnY.js +0 -9
- package/dialog-previous-button-EC_Y6KaT.js +0 -370
- package/drawer-DBDktEBZ.js +0 -69
- package/ebay-listbox/README.md +0 -100
- package/ebay-listbox/index.d.ts +0 -4
- package/ebay-listbox/index.d.ts.map +0 -1
- package/ebay-listbox/index.js +0 -6
- package/ebay-listbox/listbox-option-description.d.ts +0 -4
- package/ebay-listbox/listbox-option-description.d.ts.map +0 -1
- package/ebay-listbox/listbox-option.d.ts +0 -10
- package/ebay-listbox/listbox-option.d.ts.map +0 -1
- package/ebay-listbox/listbox.d.ts +0 -21
- package/ebay-listbox/listbox.d.ts.map +0 -1
- package/icon-B17Di3YL.js +0 -56
- package/icon-button-BQWoMgX1.js +0 -31
- package/index-BXizW4ue.js +0 -89
- package/index-DcH7Tjjd.js +0 -272
- package/label-C0AS4fnO.js +0 -19
- package/listbox-DGbY99kq.js +0 -674
- package/menu-Bsy48CE1.js +0 -163
- package/menu-button-CKGsgg6G.js +0 -89
- package/menu-fCOy6wBS.js +0 -29
- package/notice-content-BTXVxttv.js +0 -8
- package/notice-content-BhUeK1pd.js +0 -3
- package/notice-footer-CIQ8SM6N.js +0 -10
- package/progress-spinner-DOFKRtuu.js +0 -20
- package/range-C5qzyhg4.js +0 -3
- package/textbox-J291yCpJ.js +0 -136
- package/use-roving-index-CEM_UsCH.js +0 -58
- package/use-tooltip-7JxcZHJn.js +0 -92
- package/utils/scroll.d.ts +0 -2
- package/utils/scroll.d.ts.map +0 -1
package/ebay-carousel/index.js
CHANGED
|
@@ -1,345 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const classNames = require("classnames");
|
|
5
|
-
const icon$1 = require("../icon-B17Di3YL.js");
|
|
6
|
-
const debounce = require("../debounce-v8bWAUnY.js");
|
|
7
|
-
const common_componentUtils_forwardRef = require("../common/component-utils/forwardRef/index.js");
|
|
8
|
-
require("../array.polyfill.flat-DyxysTxZ.js");
|
|
9
|
-
const icon = {
|
|
10
|
-
prev: "chevronLeft12",
|
|
11
|
-
next: "chevronRight12"
|
|
12
|
-
};
|
|
13
|
-
const typeToDirection = {
|
|
14
|
-
prev: "LEFT",
|
|
15
|
-
next: "RIGHT"
|
|
16
|
-
};
|
|
17
|
-
const CarouselControlButton = ({ type, label, hidden, disabled, onClick }) => {
|
|
18
|
-
const handleOnClick = (event) => {
|
|
19
|
-
onClick(event, { direction: typeToDirection[type] });
|
|
20
|
-
};
|
|
21
|
-
return React.createElement(
|
|
22
|
-
"button",
|
|
23
|
-
{ className: classNames("carousel__control", `carousel__control--${type}`), "aria-label": label, "aria-disabled": disabled, disabled, onClick: handleOnClick },
|
|
24
|
-
React.createElement(icon$1.EbayIcon, { className: classNames("icon", `icon--carousel-${type}`), focusable: false, name: icon[type], "aria-hidden": hidden })
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
function getRelativeRects(el) {
|
|
28
|
-
const parent = el.parentElement;
|
|
29
|
-
const currentLeft = parent ? parent.firstElementChild.getBoundingClientRect().left : 0;
|
|
30
|
-
const { left, right } = el.getBoundingClientRect();
|
|
31
|
-
return {
|
|
32
|
-
left: left - currentLeft,
|
|
33
|
-
right: right - currentLeft
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
const isNativeScrolling = (el) => getComputedStyle(el).overflowX !== "visible";
|
|
37
|
-
const getMaxOffset = (items, slideWidth) => {
|
|
38
|
-
if (!items.length) {
|
|
39
|
-
return 0;
|
|
40
|
-
}
|
|
41
|
-
const lastEl = items[items.length - 1];
|
|
42
|
-
return Math.max(lastEl.right - slideWidth, 0) || 0;
|
|
43
|
-
};
|
|
44
|
-
const getOffset = (items, index, slideWidth) => {
|
|
45
|
-
if (!items.length) {
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
return Math.min(items[index].left, getMaxOffset(items, slideWidth)) || 0;
|
|
49
|
-
};
|
|
50
|
-
const alterChildren = (children, itemsRef, itemsPerSlide, slideWidth, offset, gap) => React.Children.map(children, (item, index) => {
|
|
51
|
-
const { style = {} } = item.props;
|
|
52
|
-
let itemWidth;
|
|
53
|
-
if (itemsPerSlide) {
|
|
54
|
-
const itemsInSlide = itemsPerSlide + itemsPerSlide % 1;
|
|
55
|
-
itemWidth = `calc(${100 / itemsInSlide}% - ${(itemsInSlide - 1) * gap / itemsInSlide}px)`;
|
|
56
|
-
}
|
|
57
|
-
const isStartOfSlide = itemsPerSlide ? index % itemsPerSlide === 0 : true;
|
|
58
|
-
return React.cloneElement(item, {
|
|
59
|
-
...item.props,
|
|
60
|
-
slideWidth,
|
|
61
|
-
offset,
|
|
62
|
-
ref: (el) => {
|
|
63
|
-
itemsRef.current[index] = el;
|
|
64
|
-
},
|
|
65
|
-
className: isStartOfSlide ? "carousel__snap-point" : item.props.className,
|
|
66
|
-
style: {
|
|
67
|
-
...style,
|
|
68
|
-
width: itemWidth || style.width,
|
|
69
|
-
marginRight: gap && index !== React.Children.count(children) - 1 ? `${gap}px` : style.marginRight
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
const normalizeIndex = (index, items, itemsPerSlide) => {
|
|
74
|
-
if (index > 0) {
|
|
75
|
-
let result = index;
|
|
76
|
-
result %= items.length || 1;
|
|
77
|
-
result -= result % (itemsPerSlide || 1);
|
|
78
|
-
result = Math.abs(result);
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
return 0;
|
|
82
|
-
};
|
|
83
|
-
const getSlide = (activeIndex, itemsPerSlide, nextIndex = activeIndex) => {
|
|
84
|
-
if (!itemsPerSlide) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
return Math.ceil(nextIndex / itemsPerSlide);
|
|
88
|
-
};
|
|
89
|
-
const getDelta = (direction) => direction === "LEFT" ? -1 : 1;
|
|
90
|
-
const getNextIndex = (direction, activeIndex, items, slideWidth, itemsPerSlide) => {
|
|
91
|
-
let i = activeIndex;
|
|
92
|
-
let item;
|
|
93
|
-
if (direction === "LEFT" && i === 0) {
|
|
94
|
-
i = items.length - 1;
|
|
95
|
-
} else {
|
|
96
|
-
do {
|
|
97
|
-
const delta = getDelta(direction);
|
|
98
|
-
item = items[i += delta];
|
|
99
|
-
} while (item && item.fullyVisible);
|
|
100
|
-
if (direction === "LEFT" && !itemsPerSlide) {
|
|
101
|
-
const targetOffset = item.right - slideWidth;
|
|
102
|
-
do {
|
|
103
|
-
item = items[--i];
|
|
104
|
-
} while (item && item.left >= targetOffset);
|
|
105
|
-
i += 1;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return normalizeIndex(i, items, itemsPerSlide);
|
|
109
|
-
};
|
|
110
|
-
const getClosestIndex = (scrollLeft, items, slideWidth, itemsPerSlide = 1, gap) => {
|
|
111
|
-
let closest;
|
|
112
|
-
if (scrollLeft >= getMaxOffset(items, slideWidth) - gap) {
|
|
113
|
-
closest = items.length - 1;
|
|
114
|
-
} else {
|
|
115
|
-
const totalItems = items.length;
|
|
116
|
-
let low = 0;
|
|
117
|
-
let high = Math.ceil(totalItems / itemsPerSlide) - 1;
|
|
118
|
-
while (high - low > 1) {
|
|
119
|
-
const mid = Math.floor((low + high) / 2);
|
|
120
|
-
if (scrollLeft > items[mid * itemsPerSlide].left) {
|
|
121
|
-
low = mid;
|
|
122
|
-
} else {
|
|
123
|
-
high = mid;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const deltaLow = Math.abs(scrollLeft - items[low * itemsPerSlide].left);
|
|
127
|
-
const deltaHigh = Math.abs(scrollLeft - items[high * itemsPerSlide].left);
|
|
128
|
-
closest = normalizeIndex((deltaLow > deltaHigh ? high : low) * itemsPerSlide, items, itemsPerSlide);
|
|
129
|
-
}
|
|
130
|
-
return closest;
|
|
131
|
-
};
|
|
132
|
-
const onScrollEnd = (el, fn) => {
|
|
133
|
-
let timeout;
|
|
134
|
-
let frame;
|
|
135
|
-
let lastPos;
|
|
136
|
-
(function checkMoved() {
|
|
137
|
-
const { scrollLeft } = el;
|
|
138
|
-
if (lastPos !== scrollLeft) {
|
|
139
|
-
lastPos = scrollLeft;
|
|
140
|
-
timeout = setTimeout(() => {
|
|
141
|
-
frame = requestAnimationFrame(checkMoved);
|
|
142
|
-
}, 90);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
fn(lastPos);
|
|
146
|
-
})();
|
|
147
|
-
return () => {
|
|
148
|
-
clearTimeout(timeout);
|
|
149
|
-
cancelAnimationFrame(frame);
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
const supportsScrollBehavior = typeof window !== "undefined" && "scrollBehavior" in document.body.style;
|
|
153
|
-
function scrollTransition(el, to, fn) {
|
|
154
|
-
if (supportsScrollBehavior) {
|
|
155
|
-
el.scrollTo({ left: to });
|
|
156
|
-
return onScrollEnd(el, fn);
|
|
157
|
-
}
|
|
158
|
-
let lastPosition;
|
|
159
|
-
let cancelInterruptTransition;
|
|
160
|
-
let frame = requestAnimationFrame((startTime) => {
|
|
161
|
-
const { scrollLeft } = el;
|
|
162
|
-
const distance = to - scrollLeft;
|
|
163
|
-
const duration = 450;
|
|
164
|
-
(function animate(curTime) {
|
|
165
|
-
const delta = curTime - startTime;
|
|
166
|
-
if (delta > duration) {
|
|
167
|
-
el.scrollLeft = to;
|
|
168
|
-
cancel();
|
|
169
|
-
return fn();
|
|
170
|
-
}
|
|
171
|
-
el.scrollLeft = easeInOut(delta / duration) * distance + scrollLeft;
|
|
172
|
-
frame = requestAnimationFrame(animate);
|
|
173
|
-
})(startTime);
|
|
174
|
-
});
|
|
175
|
-
el.addEventListener("touchstart", handleTouchStart);
|
|
176
|
-
return cancel;
|
|
177
|
-
function cancel() {
|
|
178
|
-
cancelAnimationFrame(frame);
|
|
179
|
-
if (lastPosition === void 0) {
|
|
180
|
-
cancelTouchStart();
|
|
181
|
-
} else {
|
|
182
|
-
if (cancelInterruptTransition)
|
|
183
|
-
cancelInterruptTransition();
|
|
184
|
-
cancelTouchEnd();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function handleTouchStart() {
|
|
188
|
-
cancel();
|
|
189
|
-
lastPosition = el.scrollLeft;
|
|
190
|
-
el.addEventListener("touchend", handleTouchEnd);
|
|
191
|
-
}
|
|
192
|
-
function handleTouchEnd() {
|
|
193
|
-
cancelTouchEnd();
|
|
194
|
-
if (lastPosition === el.scrollLeft) {
|
|
195
|
-
cancelInterruptTransition = scrollTransition(el, to, fn);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function cancelTouchStart() {
|
|
199
|
-
el.removeEventListener("touchstart", handleTouchStart);
|
|
200
|
-
}
|
|
201
|
-
function cancelTouchEnd() {
|
|
202
|
-
el.removeEventListener("touchend", handleTouchEnd);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
function easeInOut(val) {
|
|
206
|
-
return val < 0.5 ? 2 * val * val : -1 + (4 - 2 * val) * val;
|
|
207
|
-
}
|
|
208
|
-
const CarouselList = ({ gap = 16, itemsPerSlide, slideWidth, offset, activeIndex, nextControlDisabled, className, itemsRef, children, onSetActiveIndex, onScroll }) => {
|
|
209
|
-
const [translateLeft, setTranslateLeft] = React.useState(0);
|
|
210
|
-
const [skipScrolling, setSkipScrolling] = React.useState(false);
|
|
211
|
-
const [scrollTransitioning, setScrollTransitioning] = React.useState(false);
|
|
212
|
-
const listRef = React.useRef(null);
|
|
213
|
-
const scrollTimeout = React.useRef(null);
|
|
214
|
-
React.useEffect(() => {
|
|
215
|
-
const size = React.Children.count(children);
|
|
216
|
-
if (!size || !listRef.current)
|
|
217
|
-
return;
|
|
218
|
-
if (skipScrolling) {
|
|
219
|
-
setSkipScrolling(false);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const list = listRef.current;
|
|
223
|
-
const isNativeScroll = isNativeScrolling(list);
|
|
224
|
-
if (isNativeScroll) {
|
|
225
|
-
setScrollTransitioning(true);
|
|
226
|
-
scrollTransition(list, offset, () => setScrollTransitioning(false));
|
|
227
|
-
} else {
|
|
228
|
-
setTranslateLeft(offset);
|
|
229
|
-
}
|
|
230
|
-
}, [offset]);
|
|
231
|
-
const handleFinishScrolling = React.useCallback(() => {
|
|
232
|
-
const scrollLeft = listRef.current.scrollLeft;
|
|
233
|
-
const closest = getClosestIndex(scrollLeft, itemsRef.current, slideWidth, itemsPerSlide, gap);
|
|
234
|
-
if (closest !== activeIndex) {
|
|
235
|
-
setSkipScrolling(true);
|
|
236
|
-
onSetActiveIndex(closest);
|
|
237
|
-
onScroll({ index: closest });
|
|
238
|
-
}
|
|
239
|
-
}, [listRef.current, itemsRef.current, slideWidth, activeIndex, onSetActiveIndex]);
|
|
240
|
-
const handleScroll = () => {
|
|
241
|
-
if (scrollTimeout.current) {
|
|
242
|
-
clearTimeout(scrollTimeout.current);
|
|
243
|
-
}
|
|
244
|
-
scrollTimeout.current = setTimeout(() => {
|
|
245
|
-
if (!scrollTransitioning) {
|
|
246
|
-
handleFinishScrolling();
|
|
247
|
-
}
|
|
248
|
-
}, 640);
|
|
249
|
-
};
|
|
250
|
-
return React.createElement(
|
|
251
|
-
"div",
|
|
252
|
-
{ className: classNames("carousel__viewport", {
|
|
253
|
-
"carousel__viewport--mask": !nextControlDisabled
|
|
254
|
-
}, className) },
|
|
255
|
-
React.createElement("ul", { className: "carousel__list", ref: listRef, onScroll: handleScroll, style: { transform: `translate3d(${-translateLeft}px, 0, 0)` } }, alterChildren(children, itemsRef, itemsPerSlide, slideWidth, offset, gap))
|
|
256
|
-
);
|
|
257
|
-
};
|
|
258
|
-
const EbayCarousel = ({ gap = 16, index = 0, itemsPerSlide: _itemsPerSlide, a11yPreviousText, a11yNextText, onScroll = () => {
|
|
259
|
-
}, onNext = () => {
|
|
260
|
-
}, onPrevious = () => {
|
|
261
|
-
}, onSlide = () => {
|
|
262
|
-
}, className, children, ...rest }) => {
|
|
263
|
-
const [activeIndex, setActiveIndex] = React.useState(index);
|
|
264
|
-
const [slideWidth, setSlideWidth] = React.useState(0);
|
|
265
|
-
const [offset, setOffset] = React.useState(0);
|
|
266
|
-
const containerRef = React.useRef(null);
|
|
267
|
-
const itemsRef = React.useRef([]);
|
|
268
|
-
const itemCount = React.Children.count(children);
|
|
269
|
-
const itemsPerSlide = Math.floor(_itemsPerSlide) || void 0;
|
|
270
|
-
const isSingleSlide = itemCount <= itemsPerSlide;
|
|
271
|
-
const prevControlDisabled = isSingleSlide || offset === 0;
|
|
272
|
-
const nextControlDisabled = isSingleSlide || offset === getMaxOffset(itemsRef.current, slideWidth);
|
|
273
|
-
const handleResize = () => {
|
|
274
|
-
if (!containerRef.current)
|
|
275
|
-
return;
|
|
276
|
-
const { width: containerWidth } = containerRef.current.getBoundingClientRect();
|
|
277
|
-
setSlideWidth(containerWidth);
|
|
278
|
-
};
|
|
279
|
-
React.useEffect(() => {
|
|
280
|
-
window.addEventListener("resize", debounce.debounce(handleResize, 16));
|
|
281
|
-
return () => {
|
|
282
|
-
window.removeEventListener("resize", debounce.debounce(handleResize, 16));
|
|
283
|
-
};
|
|
284
|
-
}, []);
|
|
285
|
-
React.useEffect(() => {
|
|
286
|
-
setOffset(getOffset(itemsRef.current, activeIndex, slideWidth));
|
|
287
|
-
}, [activeIndex, slideWidth]);
|
|
288
|
-
React.useEffect(() => {
|
|
289
|
-
if (index >= 0 && index <= itemCount - 1) {
|
|
290
|
-
setActiveIndex(index);
|
|
291
|
-
}
|
|
292
|
-
}, [index]);
|
|
293
|
-
React.useEffect(() => {
|
|
294
|
-
itemsRef.current = itemsRef.current.splice(0, itemCount);
|
|
295
|
-
}, [children]);
|
|
296
|
-
React.useEffect(() => {
|
|
297
|
-
const { width: containerWidth } = containerRef.current.getBoundingClientRect();
|
|
298
|
-
setSlideWidth(containerWidth);
|
|
299
|
-
}, [containerRef.current]);
|
|
300
|
-
const handleControlClick = (event, { direction }) => {
|
|
301
|
-
const nextIndex = getNextIndex(direction, activeIndex, itemsRef.current, slideWidth, itemsPerSlide);
|
|
302
|
-
const slide = getSlide(activeIndex, itemsPerSlide, nextIndex);
|
|
303
|
-
setActiveIndex(nextIndex);
|
|
304
|
-
if (direction === "LEFT") {
|
|
305
|
-
onPrevious(event);
|
|
306
|
-
} else {
|
|
307
|
-
onNext(event);
|
|
308
|
-
}
|
|
309
|
-
onSlide({ slide });
|
|
310
|
-
};
|
|
311
|
-
return React.createElement(
|
|
312
|
-
"div",
|
|
313
|
-
{ className: classNames("carousel", className, {
|
|
314
|
-
"carousel--slides": itemsPerSlide,
|
|
315
|
-
"carousel--peek": itemsPerSlide % 1 === 0
|
|
316
|
-
}), ...rest },
|
|
317
|
-
React.createElement(
|
|
318
|
-
"div",
|
|
319
|
-
{ ref: containerRef, className: "carousel__container" },
|
|
320
|
-
React.createElement(CarouselControlButton, { label: a11yPreviousText, type: "prev", disabled: prevControlDisabled, onClick: handleControlClick }),
|
|
321
|
-
React.createElement(CarouselList, { itemsRef, offset, gap, itemsPerSlide, nextControlDisabled, activeIndex, onScroll, onSetActiveIndex: setActiveIndex, slideWidth }, children),
|
|
322
|
-
React.createElement(CarouselControlButton, { type: "next", label: a11yNextText, disabled: nextControlDisabled, onClick: handleControlClick })
|
|
323
|
-
)
|
|
324
|
-
);
|
|
325
|
-
};
|
|
326
|
-
const EbayCarouselItem = ({ slideWidth, offset, forwardedRef, children, ...rest }) => {
|
|
327
|
-
const itemRef = React.useRef();
|
|
328
|
-
const [isVisible, setIsVisible] = React.useState(false);
|
|
329
|
-
React.useImperativeHandle(forwardedRef, () => {
|
|
330
|
-
if (!itemRef.current)
|
|
331
|
-
return;
|
|
332
|
-
const { left, right } = getRelativeRects(itemRef.current);
|
|
333
|
-
const fullyVisible = left === void 0 || left - offset >= -0.01 && right - offset <= slideWidth + 0.01;
|
|
334
|
-
setIsVisible(fullyVisible);
|
|
335
|
-
return {
|
|
336
|
-
left,
|
|
337
|
-
right,
|
|
338
|
-
fullyVisible
|
|
339
|
-
};
|
|
340
|
-
}, [slideWidth, offset]);
|
|
341
|
-
return React.createElement("li", { ref: itemRef, "aria-hidden": !isVisible, ...rest }, children);
|
|
342
|
-
};
|
|
343
|
-
const carouselItem = common_componentUtils_forwardRef.withForwardRef(EbayCarouselItem);
|
|
344
|
-
exports.EbayCarousel = EbayCarousel;
|
|
345
|
-
exports.EbayCarouselItem = carouselItem;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),S=require("classnames"),z=require("../icon-TuxfQndO.js"),x=require("../debounce-BQsYxxOL.js"),A=require("../common/component-utils/forwardRef/index.js");require("../array.polyfill.flat-5BAolFdk.js");const D={prev:"chevronLeft12",next:"chevronRight12"},V={prev:"LEFT",next:"RIGHT"},q=({type:e,label:t,hidden:n,disabled:r,onClick:l})=>{const c=s=>{l(s,{direction:V[e]})};return o.createElement("button",{className:S("carousel__control",`carousel__control--${e}`),"aria-label":t,"aria-disabled":r,disabled:r,onClick:c},o.createElement(z.EbayIcon,{className:S("icon",`icon--carousel-${e}`),focusable:!1,name:D[e],"aria-hidden":n}))};function H(e){const t=e.parentElement,n=t?t.firstElementChild.getBoundingClientRect().left:0,{left:r,right:l}=e.getBoundingClientRect();return{left:r-n,right:l-n}}const W=e=>getComputedStyle(e).overflowX!=="visible",y=(e,t)=>{if(!e.length)return 0;const n=e[e.length-1];return Math.max(n.right-t,0)||0},j=(e,t,n)=>e.length&&Math.min(e[t].left,y(e,n))||0,G=(e,t,n,r,l,c)=>o.Children.map(e,(s,a)=>{const{style:i={}}=s.props;let d;if(n){const u=n+n%1;d=`calc(${100/u}% - ${(u-1)*c/u}px)`}const f=n?a%n===0:!0;return o.cloneElement(s,{...s.props,slideWidth:r,offset:l,ref:u=>{t.current[a]=u},className:f?"carousel__snap-point":s.props.className,style:{...i,width:d||i.width,marginRight:c&&a!==o.Children.count(e)-1?`${c}px`:i.marginRight}})}),O=(e,t,n)=>{if(e>0){let r=e;return r%=t.length||1,r-=r%(n||1),r=Math.abs(r),r}return 0},U=(e,t,n=e)=>{if(t)return Math.ceil(n/t)},X=e=>e==="LEFT"?-1:1,J=(e,t,n,r,l)=>{let c=t,s;if(e==="LEFT"&&c===0)c=n.length-1;else{do{const a=X(e);s=n[c+=a]}while(s&&s.fullyVisible);if(e==="LEFT"&&!l){const a=s.right-r;do s=n[--c];while(s&&s.left>=a);c+=1}}return O(c,n,l)},K=(e,t,n,r=1,l)=>{let c;if(e>=y(t,n)-l)c=t.length-1;else{const s=t.length;let a=0,i=Math.ceil(s/r)-1;for(;i-a>1;){const u=Math.floor((a+i)/2);e>t[u*r].left?a=u:i=u}const d=Math.abs(e-t[a*r].left),f=Math.abs(e-t[i*r].left);c=O((d>f?i:a)*r,t,r)}return c},Q=(e,t)=>{let n,r,l;return function c(){const{scrollLeft:s}=e;if(l!==s){l=s,n=setTimeout(()=>{r=requestAnimationFrame(c)},90);return}t(l)}(),()=>{clearTimeout(n),cancelAnimationFrame(r)}},Y=typeof window<"u"&&"scrollBehavior"in document.body.style;function B(e,t,n){if(Y)return e.scrollTo({left:t}),Q(e,n);let r,l,c=requestAnimationFrame(u=>{const{scrollLeft:g}=e,L=t-g,h=450;(function T(p){const m=p-u;if(m>h)return e.scrollLeft=t,s(),n();e.scrollLeft=Z(m/h)*L+g,c=requestAnimationFrame(T)})(u)});return e.addEventListener("touchstart",a),s;function s(){cancelAnimationFrame(c),r===void 0?d():(l&&l(),f())}function a(){s(),r=e.scrollLeft,e.addEventListener("touchend",i)}function i(){f(),r===e.scrollLeft&&(l=B(e,t,n))}function d(){e.removeEventListener("touchstart",a)}function f(){e.removeEventListener("touchend",i)}}function Z(e){return e<.5?2*e*e:-1+(4-2*e)*e}const P=({gap:e=16,itemsPerSlide:t,slideWidth:n,offset:r,activeIndex:l,nextControlDisabled:c,className:s,itemsRef:a,children:i,onSetActiveIndex:d,onScroll:f})=>{const[u,g]=o.useState(0),[L,h]=o.useState(!1),[T,p]=o.useState(!1),m=o.useRef(null),E=o.useRef(null);o.useEffect(()=>{if(!o.Children.count(i)||!m.current)return;if(L){h(!1);return}const b=m.current;W(b)?(p(!0),B(b,r,()=>p(!1))):g(r)},[r]);const C=o.useCallback(()=>{const v=m.current.scrollLeft,b=K(v,a.current,n,t,e);b!==l&&(h(!0),d(b),f({index:b}))},[m.current,a.current,n,l,d]),R=()=>{E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{T||C()},640)};return o.createElement("div",{className:S("carousel__viewport",{"carousel__viewport--mask":!c},s)},o.createElement("ul",{className:"carousel__list",ref:m,onScroll:R,style:{transform:`translate3d(${-u}px, 0, 0)`}},G(i,a,t,n,r,e)))},ee=({gap:e=16,index:t=0,itemsPerSlide:n,a11yPreviousText:r,a11yNextText:l,onScroll:c=()=>{},onNext:s=()=>{},onPrevious:a=()=>{},onSlide:i=()=>{},className:d,children:f,...u})=>{const[g,L]=o.useState(t),[h,T]=o.useState(0),[p,m]=o.useState(0),E=o.useRef(null),C=o.useRef([]),R=o.Children.count(f),v=Math.floor(n)||void 0,b=R<=v,I=b||p===0,_=b||p===y(C.current,h),N=()=>{if(!E.current)return;const{width:w}=E.current.getBoundingClientRect();T(w)};o.useEffect(()=>(window.addEventListener("resize",x.debounce(N,16)),()=>{window.removeEventListener("resize",x.debounce(N,16))}),[]),o.useEffect(()=>{m(j(C.current,g,h))},[g,h]),o.useEffect(()=>{t>=0&&t<=R-1&&L(t)},[t]),o.useEffect(()=>{C.current=C.current.splice(0,R)},[f]),o.useEffect(()=>{const{width:w}=E.current.getBoundingClientRect();T(w)},[E.current]);const F=(w,{direction:M})=>{const k=J(M,g,C.current,h,v),$=U(g,v,k);L(k),M==="LEFT"?a(w):s(w),i({slide:$})};return o.createElement("div",{className:S("carousel",d,{"carousel--slides":v,"carousel--peek":v%1===0}),...u},o.createElement("div",{ref:E,className:"carousel__container"},o.createElement(q,{label:r,type:"prev",disabled:I,onClick:F}),o.createElement(P,{itemsRef:C,offset:p,gap:e,itemsPerSlide:v,nextControlDisabled:_,activeIndex:g,onScroll:c,onSetActiveIndex:L,slideWidth:h},f),o.createElement(q,{type:"next",label:l,disabled:_,onClick:F})))},te=({slideWidth:e,offset:t,forwardedRef:n,children:r,...l})=>{const c=o.useRef(),[s,a]=o.useState(!1);return o.useImperativeHandle(n,()=>{if(!c.current)return;const{left:i,right:d}=H(c.current),f=i===void 0||i-t>=-.01&&d-t<=e+.01;return a(f),{left:i,right:d,fullyVisible:f}},[e,t]),o.createElement("li",{ref:c,"aria-hidden":!s,...l},r)},ne=A.withForwardRef(te);exports.EbayCarousel=ee;exports.EbayCarouselItem=ne;
|
package/ebay-checkbox/index.js
CHANGED
|
@@ -1,52 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const classNames = require("classnames");
|
|
5
|
-
const icon = require("../icon-B17Di3YL.js");
|
|
6
|
-
const label = require("../label-C0AS4fnO.js");
|
|
7
|
-
const common_componentUtils_utils = require("../common/component-utils/utils/index.js");
|
|
8
|
-
const isControlled = (checked) => typeof checked !== "undefined";
|
|
9
|
-
const EbayCheckbox = ({ id, size = "default", className, style, checked, defaultChecked = false, onChange = () => {
|
|
10
|
-
}, onFocus = () => {
|
|
11
|
-
}, onKeyDown = () => {
|
|
12
|
-
}, children, inputRef, ...rest }) => {
|
|
13
|
-
const [isChecked, setChecked] = React.useState(defaultChecked);
|
|
14
|
-
const handleChange = (e) => {
|
|
15
|
-
const input = e.target;
|
|
16
|
-
onChange(e, { value: input == null ? void 0 : input.value, checked: Boolean(input == null ? void 0 : input.checked) });
|
|
17
|
-
setChecked(input == null ? void 0 : input.checked);
|
|
18
|
-
};
|
|
19
|
-
const handleFocus = (e) => {
|
|
20
|
-
var _a, _b;
|
|
21
|
-
return onFocus(e, { value: (_a = e.target) == null ? void 0 : _a.value, checked: Boolean((_b = e.target) == null ? void 0 : _b.checked) });
|
|
22
|
-
};
|
|
23
|
-
const handleKeyDown = (e) => {
|
|
24
|
-
const input = e.target;
|
|
25
|
-
onKeyDown(e, { value: input.value, checked: Boolean(input.checked) });
|
|
26
|
-
};
|
|
27
|
-
const containerClass = classNames("checkbox", className, { "checkbox--large": size === "large" });
|
|
28
|
-
const iconChecked = size === "large" ? React.createElement(icon.EbayIcon, { name: "checkboxChecked24", className: "checkbox__checked" }) : React.createElement(icon.EbayIcon, { name: "checkboxChecked18", className: "checkbox__checked" });
|
|
29
|
-
const iconUnChecked = size === "large" ? React.createElement(icon.EbayIcon, { name: "checkboxUnchecked24", className: "checkbox__unchecked" }) : React.createElement(icon.EbayIcon, { name: "checkboxUnchecked18", className: "checkbox__unchecked" });
|
|
30
|
-
const ebayLabel = common_componentUtils_utils.findComponent(children, label.Label);
|
|
31
|
-
return React.createElement(
|
|
32
|
-
React.Fragment,
|
|
33
|
-
null,
|
|
34
|
-
React.createElement(
|
|
35
|
-
"span",
|
|
36
|
-
{ className: containerClass, style: { ...style, alignItems: "center" } },
|
|
37
|
-
React.createElement("input", { ...rest, id, className: "checkbox__control", type: "checkbox", checked: isControlled(checked) ? checked : isChecked, onChange: handleChange, onFocus: handleFocus, onKeyDown: handleKeyDown, ref: inputRef }),
|
|
38
|
-
React.createElement(
|
|
39
|
-
"span",
|
|
40
|
-
{ className: "checkbox__icon", hidden: true },
|
|
41
|
-
iconChecked,
|
|
42
|
-
iconUnChecked
|
|
43
|
-
)
|
|
44
|
-
),
|
|
45
|
-
ebayLabel ? React.cloneElement(ebayLabel, {
|
|
46
|
-
...ebayLabel.props,
|
|
47
|
-
position: "end",
|
|
48
|
-
htmlFor: id
|
|
49
|
-
}) : children
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
exports.EbayCheckbox = EbayCheckbox;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),q=require("classnames"),a=require("../icon-TuxfQndO.js"),I=require("../label-CnrpYJ-g.js"),F=require("../common/component-utils/utils/index.js"),U=o=>typeof o<"u",B=({id:o,size:t="default",className:k,style:d,checked:s,defaultChecked:m=!1,onChange:b=()=>{},onFocus:u=()=>{},onKeyDown:i=()=>{},children:h,inputRef:x,...E})=>{const[g,y]=c.useState(m),_=n=>{const e=n.target;b(n,{value:e==null?void 0:e.value,checked:!!(e!=null&&e.checked)}),y(e==null?void 0:e.checked)},C=n=>{var e,r;return u(n,{value:(e=n.target)==null?void 0:e.value,checked:!!((r=n.target)!=null&&r.checked)})},N=n=>{const e=n.target;i(n,{value:e.value,checked:!!e.checked})},f=q("checkbox",k,{"checkbox--large":t==="large"}),p=t==="large"?c.createElement(a.EbayIcon,{name:"checkboxChecked24",className:"checkbox__checked"}):c.createElement(a.EbayIcon,{name:"checkboxChecked18",className:"checkbox__checked"}),v=t==="large"?c.createElement(a.EbayIcon,{name:"checkboxUnchecked24",className:"checkbox__unchecked"}):c.createElement(a.EbayIcon,{name:"checkboxUnchecked18",className:"checkbox__unchecked"}),l=F.findComponent(h,I.Label);return c.createElement(c.Fragment,null,c.createElement("span",{className:f,style:{...d,alignItems:"center"}},c.createElement("input",{...E,id:o,className:"checkbox__control",type:"checkbox",checked:U(s)?s:g,onChange:_,onFocus:C,onKeyDown:N,ref:x}),c.createElement("span",{className:"checkbox__icon",hidden:!0},p,v)),l?c.cloneElement(l,{...l.props,position:"end",htmlFor:o}):h)};exports.EbayCheckbox=B;
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const classNames = require("classnames");
|
|
5
|
-
const ebayDialogBase_components_dialogFooter = require("../ebay-dialog-base/components/dialog-footer/index.js");
|
|
6
|
-
const dialogPreviousButton = require("../dialog-previous-button-EC_Y6KaT.js");
|
|
7
|
-
require("../icon-button-BQWoMgX1.js");
|
|
8
|
-
const button = require("../button-B4bZIgwB.js");
|
|
9
|
-
const classPrefix = "confirm-dialog";
|
|
10
|
-
const EbayConfirmDialog = ({ a11yCloseText = "Close Dialog", confirmText, rejectText, onReject = () => {
|
|
11
|
-
}, onConfirm = () => {
|
|
12
|
-
}, ...rest }) => {
|
|
13
|
-
const confirmBtnRef = React.useRef(null);
|
|
14
|
-
const confirmId = "confirm-dialog-confirm";
|
|
15
|
-
const mainId = "confirm-dialog-main";
|
|
16
|
-
return React.createElement(
|
|
17
|
-
dialogPreviousButton.DialogBaseWithState,
|
|
18
|
-
{ focus: confirmBtnRef, ...rest, a11yCloseText, role: "dialog", mainId, classPrefix, className: classNames(rest.className, `${classPrefix}--mask-fade`), windowClass: `${classPrefix}__window ${classPrefix}__window--fade`, buttonPosition: "hidden", onCloseBtnClick: onReject },
|
|
19
|
-
rest.children,
|
|
20
|
-
React.createElement(
|
|
21
|
-
ebayDialogBase_components_dialogFooter,
|
|
22
|
-
null,
|
|
23
|
-
React.createElement(button.EbayButton, { onClick: onReject, className: "confirm-dialog__reject" }, rejectText),
|
|
24
|
-
React.createElement(button.EbayButton, { ref: confirmBtnRef, priority: "primary", onClick: onConfirm, id: confirmId, "aria-describedby": mainId, className: "confirm-dialog__confirm" }, confirmText)
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
exports.EbayConfirmDialog = EbayConfirmDialog;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),u=require("classnames"),f=require("../ebay-dialog-base/components/dialog-footer/index.js"),g=require("../dialog-previous-button-CpuFLkQp.js");require("../icon-button-Cwaj-eT9.js");const t=require("../button-DGuEBUDJ.js"),o="confirm-dialog",b=({a11yCloseText:c="Close Dialog",confirmText:l,rejectText:s,onReject:n=()=>{},onConfirm:m=()=>{},...i})=>{const a=e.useRef(null),d="confirm-dialog-confirm",r="confirm-dialog-main";return e.createElement(g.DialogBaseWithState,{focus:a,...i,a11yCloseText:c,role:"dialog",mainId:r,classPrefix:o,className:u(i.className,`${o}--mask-fade`),windowClass:`${o}__window ${o}__window--fade`,buttonPosition:"hidden",onCloseBtnClick:n},i.children,e.createElement(f,null,e.createElement(t.EbayButton,{onClick:n,className:"confirm-dialog__reject"},s),e.createElement(t.EbayButton,{ref:a,priority:"primary",onClick:m,id:d,"aria-describedby":r,className:"confirm-dialog__confirm"},l)))};exports.EbayConfirmDialog=b;
|
package/ebay-cta-button/index.js
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const classNames = require("classnames");
|
|
5
|
-
const common_componentUtils_forwardRef = require("../common/component-utils/forwardRef/index.js");
|
|
6
|
-
const icon = require("../icon-B17Di3YL.js");
|
|
7
|
-
const button = require("../button-B4bZIgwB.js");
|
|
8
|
-
const EbayCtaButton = ({ size, children, fluid, truncate, forwardedRef, className: extraClasses, ...rest }) => {
|
|
9
|
-
const className = classNames(extraClasses, "cta-btn", { "cta-btn--large": size === "large" }, { "cta-btn--fluid": fluid }, { "cta-btn--truncated": truncate });
|
|
10
|
-
return React.createElement(
|
|
11
|
-
"a",
|
|
12
|
-
{ ...rest, className, ref: forwardedRef },
|
|
13
|
-
React.createElement(
|
|
14
|
-
button.EbayButtonCell,
|
|
15
|
-
{ type: "cta" },
|
|
16
|
-
React.createElement("span", null, children),
|
|
17
|
-
React.createElement(icon.EbayIcon, { name: "arrowRight24" })
|
|
18
|
-
)
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
const ctaButton = common_componentUtils_forwardRef.withForwardRef(EbayCtaButton);
|
|
22
|
-
exports.EbayCtaButton = ctaButton;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),u=require("classnames"),i=require("../common/component-utils/forwardRef/index.js"),m=require("../icon-TuxfQndO.js"),b=require("../button-DGuEBUDJ.js"),E=({size:e,children:a,fluid:n,truncate:r,forwardedRef:c,className:o,...s})=>{const l=u(o,"cta-btn",{"cta-btn--large":e==="large"},{"cta-btn--fluid":n},{"cta-btn--truncated":r});return t.createElement("a",{...s,className:l,ref:c},t.createElement(b.EbayButtonCell,{type:"cta"},t.createElement("span",null,a),t.createElement(m.EbayIcon,{name:"arrowRight24"})))},y=i.withForwardRef(E);exports.EbayCtaButton=y;
|
|
@@ -1,140 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const index = require("../index-DcH7Tjjd.js");
|
|
5
|
-
const calendar = require("../calendar-D-DWjrMU.js");
|
|
6
|
-
const textbox = require("../textbox-J291yCpJ.js");
|
|
7
|
-
require("../icon-B17Di3YL.js");
|
|
8
|
-
const classNames = require("classnames");
|
|
9
|
-
const MIN_WIDTH_FOR_DOUBLE_PANE = 600;
|
|
10
|
-
const EbayDateTextbox = ({ className, inputPlaceholderText = "YYYY-MM-DD", a11yOpenPopoverText = "open calendar", range, value: controlledValue, rangeEnd: controlledRangeEnd, defaultValue, defaultRangeEnd, collapseOnSelect, onChange = () => {
|
|
11
|
-
}, onInputChange = () => {
|
|
12
|
-
}, onInputRangeEndChange = () => {
|
|
13
|
-
}, ...rest }) => {
|
|
14
|
-
const expander = React.useRef();
|
|
15
|
-
const containerRef = React.useRef(null);
|
|
16
|
-
const [internalValue, setInternalValue] = React.useState(defaultValue || "");
|
|
17
|
-
const [internalRangeEnd, setInternalRangeEnd] = React.useState(defaultRangeEnd || "");
|
|
18
|
-
const valueToRender = textbox.isControlled(controlledValue) ? controlledValue : internalValue;
|
|
19
|
-
const rangeEndToRender = textbox.isControlled(controlledRangeEnd) ? controlledRangeEnd : internalRangeEnd;
|
|
20
|
-
const [firstSelected, setFirstSelected] = React.useState(() => calendar.dateArgToISO(valueToRender));
|
|
21
|
-
const [secondSelected, setSecondSelected] = React.useState(() => calendar.dateArgToISO(rangeEndToRender));
|
|
22
|
-
const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);
|
|
23
|
-
const [numMonths, setNumMonths] = React.useState(1);
|
|
24
|
-
const openPopover = () => {
|
|
25
|
-
setIsPopoverOpen(true);
|
|
26
|
-
};
|
|
27
|
-
const closePopover = () => {
|
|
28
|
-
setIsPopoverOpen(false);
|
|
29
|
-
};
|
|
30
|
-
React.useEffect(() => {
|
|
31
|
-
if (!containerRef.current) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
expander.current = new index.src_default(containerRef.current, {
|
|
35
|
-
hostSelector: ".ebay-date-textbox--main > .icon-btn",
|
|
36
|
-
contentSelector: ".date-textbox__popover",
|
|
37
|
-
expandOnClick: true,
|
|
38
|
-
autoCollapse: true
|
|
39
|
-
});
|
|
40
|
-
containerRef.current.addEventListener("expander-expand", openPopover);
|
|
41
|
-
containerRef.current.addEventListener("expander-collapse", closePopover);
|
|
42
|
-
const calculateNumMonths = () => {
|
|
43
|
-
setNumMonths(document.documentElement.clientWidth < MIN_WIDTH_FOR_DOUBLE_PANE ? 1 : 2);
|
|
44
|
-
};
|
|
45
|
-
calculateNumMonths();
|
|
46
|
-
window.addEventListener("resize", calculateNumMonths);
|
|
47
|
-
return () => {
|
|
48
|
-
var _a;
|
|
49
|
-
(_a = expander.current) == null ? void 0 : _a.destroy();
|
|
50
|
-
window.removeEventListener("resize", calculateNumMonths);
|
|
51
|
-
};
|
|
52
|
-
}, []);
|
|
53
|
-
const handleInputChange = (event, index2) => {
|
|
54
|
-
const date = new Date(event.target.value);
|
|
55
|
-
const iso = isNaN(date.getTime()) ? null : calendar.toISO(date);
|
|
56
|
-
if (index2 === 0) {
|
|
57
|
-
setFirstSelected(iso);
|
|
58
|
-
setInternalValue(iso || "");
|
|
59
|
-
} else {
|
|
60
|
-
setSecondSelected(iso);
|
|
61
|
-
setInternalRangeEnd(iso || "");
|
|
62
|
-
}
|
|
63
|
-
if (range) {
|
|
64
|
-
onChange(event, {
|
|
65
|
-
rangeStart: index2 === 0 ? iso : firstSelected,
|
|
66
|
-
rangeEnd: index2 === 1 ? iso : secondSelected
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
onChange(event, {
|
|
70
|
-
selected: iso
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const handlePopoverSelect = (event, { iso }) => {
|
|
75
|
-
setFirstSelected(iso);
|
|
76
|
-
setInternalValue(iso);
|
|
77
|
-
if (range) {
|
|
78
|
-
const selected = firstSelected || secondSelected;
|
|
79
|
-
const eventData = {
|
|
80
|
-
rangeStart: iso,
|
|
81
|
-
rangeEnd: selected
|
|
82
|
-
};
|
|
83
|
-
if (firstSelected && secondSelected) {
|
|
84
|
-
setInternalRangeEnd("");
|
|
85
|
-
setSecondSelected(null);
|
|
86
|
-
eventData.rangeEnd = null;
|
|
87
|
-
} else if (selected) {
|
|
88
|
-
if (selected < iso) {
|
|
89
|
-
setFirstSelected(selected);
|
|
90
|
-
setInternalValue(selected);
|
|
91
|
-
setInternalRangeEnd(iso);
|
|
92
|
-
setSecondSelected(iso);
|
|
93
|
-
eventData.rangeStart = selected;
|
|
94
|
-
eventData.rangeEnd = iso;
|
|
95
|
-
} else {
|
|
96
|
-
setFirstSelected(iso);
|
|
97
|
-
setInternalValue(iso);
|
|
98
|
-
setInternalRangeEnd(selected);
|
|
99
|
-
setSecondSelected(selected);
|
|
100
|
-
eventData.rangeStart = iso;
|
|
101
|
-
eventData.rangeEnd = selected;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
onChange(event, eventData);
|
|
105
|
-
} else {
|
|
106
|
-
onChange(event, {
|
|
107
|
-
selected: iso
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (collapseOnSelect) {
|
|
111
|
-
expander.current.expanded = false;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const handleInternalChange = (event, index2) => {
|
|
115
|
-
if (index2 === 0) {
|
|
116
|
-
setInternalValue(event.target.value);
|
|
117
|
-
onInputChange(event);
|
|
118
|
-
} else {
|
|
119
|
-
setInternalRangeEnd(event.target.value);
|
|
120
|
-
onInputRangeEndChange(event);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const [rangeStartPlaceholder, mainPlaceholder] = Array.isArray(inputPlaceholderText) ? inputPlaceholderText : [inputPlaceholderText, inputPlaceholderText];
|
|
124
|
-
return React.createElement(
|
|
125
|
-
"span",
|
|
126
|
-
{ className: classNames("date-textbox", className), ref: containerRef },
|
|
127
|
-
range && React.createElement(textbox.EbayTextbox, { value: valueToRender, placeholder: rangeStartPlaceholder, onInputChange: (event) => handleInternalChange(event, 0), onBlur: (event) => handleInputChange(event, 0) }),
|
|
128
|
-
React.createElement(
|
|
129
|
-
textbox.EbayTextbox,
|
|
130
|
-
{ className: "ebay-date-textbox--main", placeholder: mainPlaceholder, value: range ? rangeEndToRender : valueToRender, onInputChange: (event) => handleInternalChange(event, range ? 1 : 0), onBlur: (event) => handleInputChange(event, range ? 1 : 0) },
|
|
131
|
-
React.createElement(textbox.EbayTextboxPostfixIcon, { name: "calendar24", buttonAriaLabel: a11yOpenPopoverText })
|
|
132
|
-
),
|
|
133
|
-
React.createElement(
|
|
134
|
-
"div",
|
|
135
|
-
{ hidden: !isPopoverOpen, className: "date-textbox__popover" },
|
|
136
|
-
React.createElement(calendar.EbayCalendar, { ...rest, range, interactive: true, navigable: true, numMonths, selected: firstSelected && secondSelected ? [firstSelected, secondSelected] : firstSelected || secondSelected || void 0, onSelect: handlePopoverSelect })
|
|
137
|
-
)
|
|
138
|
-
);
|
|
139
|
-
};
|
|
140
|
-
exports.EbayDateTextbox = EbayDateTextbox;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),k=require("makeup-expander"),S=require("../calendar-lAu6VfAb.js"),i=require("../textbox-dUhinDwj.js");require("../icon-TuxfQndO.js");const H=require("classnames"),U=600,V=({className:O,inputPlaceholderText:E="YYYY-MM-DD",a11yOpenPopoverText:T="open calendar",range:o,value:v,rangeEnd:g,defaultValue:D,defaultRangeEnd:R,collapseOnSelect:_,onChange:p=()=>{},onInputChange:M=()=>{},onInputRangeEndChange:P=()=>{},...q})=>{const m=n.useRef(),l=n.useRef(null),[w,d]=n.useState(D||""),[A,u]=n.useState(R||""),f=i.isControlled(v)?v:w,y=i.isControlled(g)?g:A,[s,b]=n.useState(()=>S.dateArgToISO(f)),[c,x]=n.useState(()=>S.dateArgToISO(y)),[C,I]=n.useState(!1),[L,Y]=n.useState(1),B=()=>{I(!0)},z=()=>{I(!1)};n.useEffect(()=>{if(!l.current)return;m.current=new k(l.current,{hostSelector:".ebay-date-textbox--main > .icon-btn",contentSelector:".date-textbox__popover",expandOnClick:!0,autoCollapse:!0}),l.current.addEventListener("expander-expand",B),l.current.addEventListener("expander-collapse",z);const e=()=>{Y(document.documentElement.clientWidth<U?1:2)};return e(),window.addEventListener("resize",e),()=>{var t;(t=m.current)==null||t.destroy(),window.removeEventListener("resize",e)}},[]);const h=(e,t)=>{const r=new Date(e.target.value),a=isNaN(r.getTime())?null:S.toISO(r);t===0?(b(a),d(a||"")):(x(a),u(a||"")),o?p(e,{rangeStart:t===0?a:s,rangeEnd:t===1?a:c}):p(e,{selected:a})},F=(e,{iso:t})=>{if(b(t),d(t),o){const r=s||c,a={rangeStart:t,rangeEnd:r};s&&c?(u(""),x(null),a.rangeEnd=null):r&&(r<t?(b(r),d(r),u(t),x(t),a.rangeStart=r,a.rangeEnd=t):(b(t),d(t),u(r),x(r),a.rangeStart=t,a.rangeEnd=r)),p(e,a)}else p(e,{selected:t});_&&(m.current.expanded=!1)},N=(e,t)=>{t===0?(d(e.target.value),M(e)):(u(e.target.value),P(e))},[W,j]=Array.isArray(E)?E:[E,E];return n.createElement("span",{className:H("date-textbox",O),ref:l},o&&n.createElement(i.EbayTextbox,{value:f,placeholder:W,onInputChange:e=>N(e,0),onBlur:e=>h(e,0)}),n.createElement(i.EbayTextbox,{className:"ebay-date-textbox--main",placeholder:j,value:o?y:f,onInputChange:e=>N(e,o?1:0),onBlur:e=>h(e,o?1:0)},n.createElement(i.EbayTextboxPostfixIcon,{name:"calendar24",buttonAriaLabel:T})),n.createElement("div",{hidden:!C,className:"date-textbox__popover"},n.createElement(S.EbayCalendar,{...q,range:o,interactive:!0,navigable:!0,numMonths:L,selected:s&&c?[s,c]:s||c||void 0,onSelect:F})))};exports.EbayDateTextbox=V;
|