@expofp/ui 3.21.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 +30 -0
- package/dist/Alert/Alert.d.ts +20 -0
- package/dist/Alert/Alert.js +23 -0
- package/dist/Alert/index.d.ts +3 -0
- package/dist/Alert/index.js +1 -0
- package/dist/Autocomplete/Autocomplete.d.ts +21 -0
- package/dist/Autocomplete/Autocomplete.js +183 -0
- package/dist/Autocomplete/index.d.ts +3 -0
- package/dist/Autocomplete/index.js +1 -0
- package/dist/Badge/Badge.d.ts +14 -0
- package/dist/Badge/Badge.js +15 -0
- package/dist/Badge/index.d.ts +3 -0
- package/dist/Badge/index.js +1 -0
- package/dist/Button/Button.d.ts +30 -0
- package/dist/Button/Button.js +41 -0
- package/dist/Button/index.d.ts +3 -0
- package/dist/Button/index.js +1 -0
- package/dist/Checkbox/Checkbox.d.ts +19 -0
- package/dist/Checkbox/Checkbox.js +19 -0
- package/dist/Checkbox/index.d.ts +3 -0
- package/dist/Checkbox/index.js +1 -0
- package/dist/CheckboxButton/CheckboxButton.d.ts +12 -0
- package/dist/CheckboxButton/CheckboxButton.js +19 -0
- package/dist/CheckboxButton/index.d.ts +3 -0
- package/dist/CheckboxButton/index.js +1 -0
- package/dist/DownloadList/DownloadList.d.ts +15 -0
- package/dist/DownloadList/DownloadList.js +9 -0
- package/dist/DownloadList/index.d.ts +3 -0
- package/dist/DownloadList/index.js +2 -0
- package/dist/Draggable/Draggable.d.ts +9 -0
- package/dist/Draggable/Draggable.js +92 -0
- package/dist/Draggable/index.d.ts +3 -0
- package/dist/Draggable/index.js +2 -0
- package/dist/EntityItem/EntityItem.d.ts +46 -0
- package/dist/EntityItem/EntityItem.js +29 -0
- package/dist/EntityItem/index.d.ts +3 -0
- package/dist/EntityItem/index.js +1 -0
- package/dist/EventBadge/EventBadge.d.ts +13 -0
- package/dist/EventBadge/EventBadge.js +10 -0
- package/dist/EventBadge/index.d.ts +3 -0
- package/dist/EventBadge/index.js +1 -0
- package/dist/HeatmapLegend/HeatmapLegend.d.ts +15 -0
- package/dist/HeatmapLegend/HeatmapLegend.js +11 -0
- package/dist/HeatmapLegend/index.d.ts +3 -0
- package/dist/HeatmapLegend/index.js +2 -0
- package/dist/HighlightText/HighlightText.d.ts +7 -0
- package/dist/HighlightText/HighlightText.js +14 -0
- package/dist/HighlightText/index.d.ts +2 -0
- package/dist/HighlightText/index.js +1 -0
- package/dist/LevelBadge/LevelBadge.d.ts +9 -0
- package/dist/LevelBadge/LevelBadge.js +10 -0
- package/dist/LevelBadge/index.d.ts +3 -0
- package/dist/LevelBadge/index.js +2 -0
- package/dist/LevelSelector/LevelSelector.d.ts +19 -0
- package/dist/LevelSelector/LevelSelector.js +91 -0
- package/dist/LevelSelector/index.d.ts +3 -0
- package/dist/LevelSelector/index.js +2 -0
- package/dist/MapControls/MapControls.d.ts +33 -0
- package/dist/MapControls/MapControls.js +38 -0
- package/dist/MapControls/index.d.ts +3 -0
- package/dist/MapControls/index.js +2 -0
- package/dist/MobileToggleButton/MobileToggleButton.d.ts +12 -0
- package/dist/MobileToggleButton/MobileToggleButton.js +8 -0
- package/dist/MobileToggleButton/index.d.ts +3 -0
- package/dist/MobileToggleButton/index.js +1 -0
- package/dist/Modal/Modal.d.ts +34 -0
- package/dist/Modal/Modal.js +98 -0
- package/dist/Modal/index.d.ts +3 -0
- package/dist/Modal/index.js +1 -0
- package/dist/MultiSelectGroups/MultiSelectGroups.d.ts +37 -0
- package/dist/MultiSelectGroups/MultiSelectGroups.js +80 -0
- package/dist/MultiSelectGroups/index.d.ts +3 -0
- package/dist/MultiSelectGroups/index.js +1 -0
- package/dist/OverlayGrip/OverlayGrip.d.ts +11 -0
- package/dist/OverlayGrip/OverlayGrip.js +8 -0
- package/dist/OverlayGrip/index.d.ts +3 -0
- package/dist/OverlayGrip/index.js +2 -0
- package/dist/PermissionNotice/PermissionNotice.d.ts +16 -0
- package/dist/PermissionNotice/PermissionNotice.js +11 -0
- package/dist/PermissionNotice/index.d.ts +3 -0
- package/dist/PermissionNotice/index.js +2 -0
- package/dist/Radio/Radio.d.ts +15 -0
- package/dist/Radio/Radio.js +13 -0
- package/dist/Radio/index.d.ts +3 -0
- package/dist/Radio/index.js +1 -0
- package/dist/RebookingNotes/RebookingNotes.d.ts +11 -0
- package/dist/RebookingNotes/RebookingNotes.js +18 -0
- package/dist/RebookingNotes/index.d.ts +3 -0
- package/dist/RebookingNotes/index.js +1 -0
- package/dist/RebookingRadioGroup/RebookingRadioGroup.d.ts +17 -0
- package/dist/RebookingRadioGroup/RebookingRadioGroup.js +13 -0
- package/dist/RebookingRadioGroup/index.d.ts +3 -0
- package/dist/RebookingRadioGroup/index.js +1 -0
- package/dist/ScrollableRow/ScrollableRow.d.ts +21 -0
- package/dist/ScrollableRow/ScrollableRow.js +155 -0
- package/dist/ScrollableRow/index.d.ts +3 -0
- package/dist/ScrollableRow/index.js +2 -0
- package/dist/Share/Share.d.ts +22 -0
- package/dist/Share/Share.js +24 -0
- package/dist/Share/index.d.ts +3 -0
- package/dist/Share/index.js +1 -0
- package/dist/ShowMoreButton/ShowMoreButton.d.ts +11 -0
- package/dist/ShowMoreButton/ShowMoreButton.js +7 -0
- package/dist/ShowMoreButton/index.d.ts +3 -0
- package/dist/ShowMoreButton/index.js +1 -0
- package/dist/SidebarActions/SidebarActions.d.ts +26 -0
- package/dist/SidebarActions/SidebarActions.js +32 -0
- package/dist/SidebarActions/index.d.ts +3 -0
- package/dist/SidebarActions/index.js +2 -0
- package/dist/SimpleRow/SimpleRow.d.ts +15 -0
- package/dist/SimpleRow/SimpleRow.js +11 -0
- package/dist/SimpleRow/index.d.ts +3 -0
- package/dist/SimpleRow/index.js +2 -0
- package/dist/Spinner/Spinner.d.ts +9 -0
- package/dist/Spinner/Spinner.js +8 -0
- package/dist/Spinner/index.d.ts +3 -0
- package/dist/Spinner/index.js +1 -0
- package/dist/ToggleButton/ToggleButton.d.ts +17 -0
- package/dist/ToggleButton/ToggleButton.js +8 -0
- package/dist/ToggleButton/index.d.ts +3 -0
- package/dist/ToggleButton/index.js +1 -0
- package/dist/ToggleSwitch/ToggleSwitch.d.ts +12 -0
- package/dist/ToggleSwitch/ToggleSwitch.js +10 -0
- package/dist/ToggleSwitch/index.d.ts +3 -0
- package/dist/ToggleSwitch/index.js +1 -0
- package/dist/TouchHand/TouchHand.d.ts +5 -0
- package/dist/TouchHand/TouchHand.js +7 -0
- package/dist/TouchHand/index.d.ts +2 -0
- package/dist/TouchHand/index.js +1 -0
- package/dist/WayfindingFloorSelector/WayfindingFloorSelector.d.ts +24 -0
- package/dist/WayfindingFloorSelector/WayfindingFloorSelector.js +27 -0
- package/dist/WayfindingFloorSelector/index.d.ts +3 -0
- package/dist/WayfindingFloorSelector/index.js +1 -0
- package/dist/components/Alert/Alert.d.ts +20 -0
- package/dist/components/Alert/Alert.js +23 -0
- package/dist/components/Alert/index.d.ts +3 -0
- package/dist/components/Alert/index.js +1 -0
- package/dist/components/Autocomplete/Autocomplete.d.ts +21 -0
- package/dist/components/Autocomplete/Autocomplete.js +183 -0
- package/dist/components/Autocomplete/index.d.ts +3 -0
- package/dist/components/Autocomplete/index.js +1 -0
- package/dist/components/Badge/Badge.d.ts +14 -0
- package/dist/components/Badge/Badge.js +15 -0
- package/dist/components/Badge/index.d.ts +3 -0
- package/dist/components/Badge/index.js +1 -0
- package/dist/components/Button/Button.d.ts +30 -0
- package/dist/components/Button/Button.js +41 -0
- package/dist/components/Button/index.d.ts +3 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/Checkbox/Checkbox.d.ts +19 -0
- package/dist/components/Checkbox/Checkbox.js +19 -0
- package/dist/components/Checkbox/index.d.ts +3 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/CheckboxButton/CheckboxButton.d.ts +12 -0
- package/dist/components/CheckboxButton/CheckboxButton.js +19 -0
- package/dist/components/CheckboxButton/index.d.ts +3 -0
- package/dist/components/CheckboxButton/index.js +1 -0
- package/dist/components/DownloadList/DownloadList.d.ts +15 -0
- package/dist/components/DownloadList/DownloadList.js +9 -0
- package/dist/components/DownloadList/index.d.ts +3 -0
- package/dist/components/DownloadList/index.js +2 -0
- package/dist/components/Draggable/Draggable.d.ts +9 -0
- package/dist/components/Draggable/Draggable.js +92 -0
- package/dist/components/Draggable/index.d.ts +3 -0
- package/dist/components/Draggable/index.js +2 -0
- package/dist/components/EntityItem/EntityItem.d.ts +46 -0
- package/dist/components/EntityItem/EntityItem.js +29 -0
- package/dist/components/EntityItem/index.d.ts +3 -0
- package/dist/components/EntityItem/index.js +1 -0
- package/dist/components/EventBadge/EventBadge.d.ts +13 -0
- package/dist/components/EventBadge/EventBadge.js +10 -0
- package/dist/components/EventBadge/index.d.ts +3 -0
- package/dist/components/EventBadge/index.js +1 -0
- package/dist/components/Gallery/Gallery.d.ts +25 -0
- package/dist/components/Gallery/Gallery.js +25 -0
- package/dist/components/Gallery/GalleryBadges/GalleryBadges.d.ts +8 -0
- package/dist/components/Gallery/GalleryBadges/GalleryBadges.js +5 -0
- package/dist/components/Gallery/GalleryControls/GalleryControls.d.ts +11 -0
- package/dist/components/Gallery/GalleryControls/GalleryControls.js +5 -0
- package/dist/components/Gallery/GalleryImg/GalleryImg.d.ts +13 -0
- package/dist/components/Gallery/GalleryImg/GalleryImg.js +37 -0
- package/dist/components/Gallery/GalleryItem/GalleryItem.d.ts +14 -0
- package/dist/components/Gallery/GalleryItem/GalleryItem.js +6 -0
- package/dist/components/Gallery/GalleryModal/GalleryModal.d.ts +18 -0
- package/dist/components/Gallery/GalleryModal/GalleryModal.js +88 -0
- package/dist/components/Gallery/GalleryPreLoader.d.ts +7 -0
- package/dist/components/Gallery/GalleryPreLoader.js +29 -0
- package/dist/components/Gallery/TransformImg/TransformImg.d.ts +10 -0
- package/dist/components/Gallery/TransformImg/TransformImg.js +15 -0
- package/dist/components/Gallery/index.d.ts +3 -0
- package/dist/components/Gallery/index.js +1 -0
- package/dist/components/HeatmapLegend/HeatmapLegend.d.ts +15 -0
- package/dist/components/HeatmapLegend/HeatmapLegend.js +11 -0
- package/dist/components/HeatmapLegend/index.d.ts +3 -0
- package/dist/components/HeatmapLegend/index.js +2 -0
- package/dist/components/HighlightText/HighlightText.d.ts +7 -0
- package/dist/components/HighlightText/HighlightText.js +14 -0
- package/dist/components/HighlightText/index.d.ts +2 -0
- package/dist/components/HighlightText/index.js +1 -0
- package/dist/components/LevelBadge/LevelBadge.d.ts +9 -0
- package/dist/components/LevelBadge/LevelBadge.js +10 -0
- package/dist/components/LevelBadge/index.d.ts +3 -0
- package/dist/components/LevelBadge/index.js +2 -0
- package/dist/components/LevelSelector/LevelSelector.d.ts +19 -0
- package/dist/components/LevelSelector/LevelSelector.js +91 -0
- package/dist/components/LevelSelector/index.d.ts +3 -0
- package/dist/components/LevelSelector/index.js +2 -0
- package/dist/components/MapControls/MapControls.d.ts +33 -0
- package/dist/components/MapControls/MapControls.js +38 -0
- package/dist/components/MapControls/index.d.ts +3 -0
- package/dist/components/MapControls/index.js +2 -0
- package/dist/components/MobileToggleButton/MobileToggleButton.d.ts +12 -0
- package/dist/components/MobileToggleButton/MobileToggleButton.js +8 -0
- package/dist/components/MobileToggleButton/index.d.ts +3 -0
- package/dist/components/MobileToggleButton/index.js +1 -0
- package/dist/components/Modal/Modal.d.ts +34 -0
- package/dist/components/Modal/Modal.js +98 -0
- package/dist/components/Modal/index.d.ts +3 -0
- package/dist/components/Modal/index.js +1 -0
- package/dist/components/MultiSelectGroups/MultiSelectGroups.d.ts +37 -0
- package/dist/components/MultiSelectGroups/MultiSelectGroups.js +80 -0
- package/dist/components/MultiSelectGroups/index.d.ts +3 -0
- package/dist/components/MultiSelectGroups/index.js +1 -0
- package/dist/components/Overlay/Overlay.d.ts +29 -0
- package/dist/components/Overlay/Overlay.js +251 -0
- package/dist/components/Overlay/OverlayScrollContext.d.ts +7 -0
- package/dist/components/Overlay/OverlayScrollContext.js +7 -0
- package/dist/components/Overlay/index.d.ts +4 -0
- package/dist/components/Overlay/index.js +2 -0
- package/dist/components/OverlayGrip/OverlayGrip.d.ts +11 -0
- package/dist/components/OverlayGrip/OverlayGrip.js +8 -0
- package/dist/components/OverlayGrip/index.d.ts +3 -0
- package/dist/components/OverlayGrip/index.js +2 -0
- package/dist/components/PermissionNotice/PermissionNotice.d.ts +16 -0
- package/dist/components/PermissionNotice/PermissionNotice.js +11 -0
- package/dist/components/PermissionNotice/index.d.ts +3 -0
- package/dist/components/PermissionNotice/index.js +2 -0
- package/dist/components/Radio/Radio.d.ts +15 -0
- package/dist/components/Radio/Radio.js +13 -0
- package/dist/components/Radio/index.d.ts +3 -0
- package/dist/components/Radio/index.js +1 -0
- package/dist/components/RebookingNotes/RebookingNotes.d.ts +11 -0
- package/dist/components/RebookingNotes/RebookingNotes.js +18 -0
- package/dist/components/RebookingNotes/index.d.ts +3 -0
- package/dist/components/RebookingNotes/index.js +1 -0
- package/dist/components/RebookingRadioGroup/RebookingRadioGroup.d.ts +17 -0
- package/dist/components/RebookingRadioGroup/RebookingRadioGroup.js +13 -0
- package/dist/components/RebookingRadioGroup/index.d.ts +3 -0
- package/dist/components/RebookingRadioGroup/index.js +1 -0
- package/dist/components/ScrollableRow/ScrollableRow.d.ts +21 -0
- package/dist/components/ScrollableRow/ScrollableRow.js +155 -0
- package/dist/components/ScrollableRow/index.d.ts +3 -0
- package/dist/components/ScrollableRow/index.js +2 -0
- package/dist/components/Share/Share.d.ts +22 -0
- package/dist/components/Share/Share.js +24 -0
- package/dist/components/Share/index.d.ts +3 -0
- package/dist/components/Share/index.js +1 -0
- package/dist/components/ShowMoreButton/ShowMoreButton.d.ts +11 -0
- package/dist/components/ShowMoreButton/ShowMoreButton.js +7 -0
- package/dist/components/ShowMoreButton/index.d.ts +3 -0
- package/dist/components/ShowMoreButton/index.js +1 -0
- package/dist/components/SidebarActions/SidebarActions.d.ts +26 -0
- package/dist/components/SidebarActions/SidebarActions.js +32 -0
- package/dist/components/SidebarActions/index.d.ts +3 -0
- package/dist/components/SidebarActions/index.js +2 -0
- package/dist/components/SimpleRow/SimpleRow.d.ts +15 -0
- package/dist/components/SimpleRow/SimpleRow.js +11 -0
- package/dist/components/SimpleRow/index.d.ts +3 -0
- package/dist/components/SimpleRow/index.js +2 -0
- package/dist/components/Spinner/Spinner.d.ts +9 -0
- package/dist/components/Spinner/Spinner.js +8 -0
- package/dist/components/Spinner/index.d.ts +3 -0
- package/dist/components/Spinner/index.js +1 -0
- package/dist/components/ToggleButton/ToggleButton.d.ts +17 -0
- package/dist/components/ToggleButton/ToggleButton.js +8 -0
- package/dist/components/ToggleButton/index.d.ts +3 -0
- package/dist/components/ToggleButton/index.js +1 -0
- package/dist/components/ToggleSwitch/ToggleSwitch.d.ts +12 -0
- package/dist/components/ToggleSwitch/ToggleSwitch.js +10 -0
- package/dist/components/ToggleSwitch/index.d.ts +3 -0
- package/dist/components/ToggleSwitch/index.js +1 -0
- package/dist/components/TouchHand/TouchHand.d.ts +5 -0
- package/dist/components/TouchHand/TouchHand.js +7 -0
- package/dist/components/TouchHand/index.d.ts +2 -0
- package/dist/components/TouchHand/index.js +1 -0
- package/dist/components/WayfindingFloorSelector/WayfindingFloorSelector.d.ts +24 -0
- package/dist/components/WayfindingFloorSelector/WayfindingFloorSelector.js +27 -0
- package/dist/components/WayfindingFloorSelector/index.d.ts +3 -0
- package/dist/components/WayfindingFloorSelector/index.js +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +69 -0
- package/dist/shared/debounce.d.ts +2 -0
- package/dist/shared/debounce.js +9 -0
- package/dist/shared/hooks/useDragGesture.d.ts +19 -0
- package/dist/shared/hooks/useDragGesture.js +45 -0
- package/dist/shared/hooks/useOnClickOutside.d.ts +14 -0
- package/dist/shared/hooks/useOnClickOutside.js +43 -0
- package/dist/shared/hooks/useOnEscape.d.ts +14 -0
- package/dist/shared/hooks/useOnEscape.js +31 -0
- package/dist/shared/hooks/useWindowSize.d.ts +5 -0
- package/dist/shared/hooks/useWindowSize.js +40 -0
- package/dist/shared/interactive.d.ts +2 -0
- package/dist/shared/interactive.js +4 -0
- package/package.json +70 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import './Modal.scss';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { useEffect, useId, useRef, useState } from 'react';
|
|
5
|
+
import { createPortal } from 'react-dom';
|
|
6
|
+
import Button from '../Button';
|
|
7
|
+
const MODAL_EXIT_TRANSITION_MS = 200;
|
|
8
|
+
const isElementVisible = (el) => el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden';
|
|
9
|
+
const Modal = ({ open, className, variant = 'default', title, ariaLabel, maxWidth, children, closeLabel, renderTarget, footerLeft = [], footerRight = [], onClose, }) => {
|
|
10
|
+
const modalRef = useRef(null);
|
|
11
|
+
const previousFocusRef = useRef(null);
|
|
12
|
+
const titleId = useId();
|
|
13
|
+
const [isOpen, setIsOpen] = useState(open);
|
|
14
|
+
const [isVisible, setIsVisible] = useState(open);
|
|
15
|
+
// Focus restore + body scroll lock + enter/exit animation. Driven solely by `open`.
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!open) {
|
|
18
|
+
const deactivateFrame = requestAnimationFrame(() => setIsOpen(false));
|
|
19
|
+
const unmountTimer = setTimeout(() => setIsVisible(false), MODAL_EXIT_TRANSITION_MS);
|
|
20
|
+
previousFocusRef.current?.focus();
|
|
21
|
+
previousFocusRef.current = null;
|
|
22
|
+
return () => {
|
|
23
|
+
cancelAnimationFrame(deactivateFrame);
|
|
24
|
+
clearTimeout(unmountTimer);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
previousFocusRef.current ??= document.activeElement;
|
|
28
|
+
const previousBodyOverflow = document.body.style.overflow;
|
|
29
|
+
document.body.style.overflow = 'hidden';
|
|
30
|
+
let activateFrame = 0;
|
|
31
|
+
const mountFrame = requestAnimationFrame(() => {
|
|
32
|
+
setIsVisible(true);
|
|
33
|
+
activateFrame = requestAnimationFrame(() => setIsOpen(true));
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
cancelAnimationFrame(mountFrame);
|
|
37
|
+
cancelAnimationFrame(activateFrame);
|
|
38
|
+
document.body.style.overflow = previousBodyOverflow;
|
|
39
|
+
};
|
|
40
|
+
}, [open]);
|
|
41
|
+
// Keydown handling (Escape + focus trap). Kept separate from the lifecycle
|
|
42
|
+
// effect above so a new `onClose` identity only re-subscribes this listener
|
|
43
|
+
// and never restarts the enter/exit animation or scroll lock.
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!open)
|
|
46
|
+
return;
|
|
47
|
+
const handleKeyDown = (e) => {
|
|
48
|
+
if (e.key === 'Escape') {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
e.stopImmediatePropagation();
|
|
51
|
+
onClose();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (e.key !== 'Tab')
|
|
55
|
+
return;
|
|
56
|
+
const container = modalRef.current;
|
|
57
|
+
if (!container)
|
|
58
|
+
return;
|
|
59
|
+
const focusable = Array.from(container.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')).filter(isElementVisible);
|
|
60
|
+
if (focusable.length === 0) {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const first = focusable[0];
|
|
65
|
+
const last = focusable[focusable.length - 1];
|
|
66
|
+
const active = document.activeElement;
|
|
67
|
+
if (e.shiftKey) {
|
|
68
|
+
if (active === first || active === container) {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
last.focus();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (active === last) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
first.focus();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
79
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
80
|
+
}, [open, onClose]);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!isOpen)
|
|
83
|
+
return;
|
|
84
|
+
let inner = 0;
|
|
85
|
+
const outer = requestAnimationFrame(() => {
|
|
86
|
+
inner = requestAnimationFrame(() => modalRef.current?.focus());
|
|
87
|
+
});
|
|
88
|
+
return () => {
|
|
89
|
+
cancelAnimationFrame(outer);
|
|
90
|
+
cancelAnimationFrame(inner);
|
|
91
|
+
};
|
|
92
|
+
}, [isOpen]);
|
|
93
|
+
if (!isVisible || !renderTarget)
|
|
94
|
+
return null;
|
|
95
|
+
const renderButtons = (buttons) => buttons?.map(({ label, onClick, variant = 'primary', disabled, withBadge }, idx) => (_jsx(Button, { onClick: onClick, variant: variant, size: "md", inline: true, disabled: disabled, withBadge: withBadge, children: label }, idx)));
|
|
96
|
+
return createPortal(_jsx("div", { className: classNames('efp-modal', `efp-modal--${variant}`, { 'efp-modal--open': isOpen }, className), role: "dialog", "aria-modal": "true", "aria-labelledby": title ? titleId : undefined, "aria-label": !title ? ariaLabel : undefined, ref: modalRef, tabIndex: -1, onClick: onClose, children: _jsxs("div", { className: "efp-modal__box", style: maxWidth ? { maxWidth: `${maxWidth}px` } : undefined, onClick: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "efp-modal__header", children: [title && (_jsx("div", { className: "efp-modal__title-container", children: _jsx("h2", { className: "efp-modal__title", id: titleId, children: title }) })), _jsx("button", { type: "button", className: "efp-modal__close", onClick: onClose, "aria-label": closeLabel, title: closeLabel, children: _jsx("i", { className: "icon-close", "aria-hidden": "true" }) })] }), _jsx("div", { className: "efp-modal__body", children: children }), (footerLeft.length > 0 || footerRight.length > 0) && (_jsxs("div", { className: "efp-modal__footer", children: [_jsx("div", { className: "efp-modal__footer-left", children: footerLeft.length > 0 && renderButtons(footerLeft) }), footerRight.length > 0 && (_jsx("div", { className: "efp-modal__footer-right", children: renderButtons(footerRight) }))] }))] }) }), renderTarget);
|
|
97
|
+
};
|
|
98
|
+
export default Modal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Modal';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import './MultiSelectGroups.scss';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface MultiSelectGroupItem {
|
|
4
|
+
id: number | string;
|
|
5
|
+
name: string;
|
|
6
|
+
count?: number;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
countProvider?: () => number;
|
|
9
|
+
}
|
|
10
|
+
export interface MultiSelectGroup {
|
|
11
|
+
groupName: string;
|
|
12
|
+
items: MultiSelectGroupItem[];
|
|
13
|
+
showGroupActions?: boolean;
|
|
14
|
+
customGroupClass?: string;
|
|
15
|
+
fullWidth?: boolean;
|
|
16
|
+
id?: string | number;
|
|
17
|
+
}
|
|
18
|
+
export type MultiSelectVariant = 'default' | 'categories';
|
|
19
|
+
export interface MultiSelectGroupsProps {
|
|
20
|
+
groups: MultiSelectGroup[];
|
|
21
|
+
selectedIds: (number | string)[];
|
|
22
|
+
showItemCounts?: boolean;
|
|
23
|
+
showGroupActions?: boolean;
|
|
24
|
+
variant?: MultiSelectVariant;
|
|
25
|
+
maxItemsVisible?: number;
|
|
26
|
+
selectAllLabel: string;
|
|
27
|
+
clearAllLabel: string;
|
|
28
|
+
selectedLabel: string;
|
|
29
|
+
showMoreLabel: string;
|
|
30
|
+
showLessLabel: string;
|
|
31
|
+
onChange: (selectedIds: (number | string)[]) => void;
|
|
32
|
+
itemCountProvider?: (item: MultiSelectGroupItem) => number;
|
|
33
|
+
customItemRenderer?: (item: MultiSelectGroupItem, isSelected: boolean) => React.ReactNode;
|
|
34
|
+
}
|
|
35
|
+
declare function MultiSelectGroups({ groups, selectedIds, showItemCounts, showGroupActions, variant, maxItemsVisible, selectAllLabel, clearAllLabel, selectedLabel, showMoreLabel, showLessLabel, itemCountProvider, customItemRenderer, onChange, }: MultiSelectGroupsProps): React.JSX.Element | null;
|
|
36
|
+
export default MultiSelectGroups;
|
|
37
|
+
//# sourceMappingURL=MultiSelectGroups.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import './MultiSelectGroups.scss';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import ShowMoreButton from '../ShowMoreButton';
|
|
6
|
+
const GroupItem = React.memo(({ item, isSelected, variant, showCount, count, onClick, customRenderer }) => {
|
|
7
|
+
if (customRenderer) {
|
|
8
|
+
return _jsx(_Fragment, { children: customRenderer(item, isSelected) });
|
|
9
|
+
}
|
|
10
|
+
return (_jsxs("button", { type: "button", className: cn('efp-multi-select-groups__item', {
|
|
11
|
+
'efp-multi-select-groups__item--selected': isSelected,
|
|
12
|
+
'efp-multi-select-groups__item--disabled': item.disabled,
|
|
13
|
+
[`efp-multi-select-groups__item--${variant}`]: variant,
|
|
14
|
+
}), onClick: () => !item.disabled && onClick(item.id), disabled: item.disabled, "aria-pressed": isSelected, children: [_jsx("div", { className: "efp-multi-select-groups__item-name", children: item.name }), showCount && count > 0 && (_jsx("span", { className: "efp-multi-select-groups__item-count", children: count }))] }));
|
|
15
|
+
});
|
|
16
|
+
function MultiSelectGroups({ groups = [], selectedIds = [], showItemCounts = true, showGroupActions = true, variant = 'default', maxItemsVisible = 20, selectAllLabel, clearAllLabel, selectedLabel, showMoreLabel, showLessLabel, itemCountProvider, customItemRenderer, onChange, }) {
|
|
17
|
+
const [expandedGroups, setExpandedGroups] = useState(() => new Set());
|
|
18
|
+
const handleItemToggle = useCallback((id) => {
|
|
19
|
+
const newSelected = selectedIds.includes(id)
|
|
20
|
+
? selectedIds.filter((i) => i !== id)
|
|
21
|
+
: [...selectedIds, id];
|
|
22
|
+
onChange(newSelected);
|
|
23
|
+
}, [selectedIds, onChange]);
|
|
24
|
+
const selectAllInGroup = useCallback((group) => {
|
|
25
|
+
const groupItemIds = group.items
|
|
26
|
+
.filter((item) => item.id && !item.disabled)
|
|
27
|
+
.map((item) => item.id);
|
|
28
|
+
const uniqueNewIds = groupItemIds.filter((id) => !selectedIds.includes(id));
|
|
29
|
+
if (uniqueNewIds.length === 0)
|
|
30
|
+
return;
|
|
31
|
+
onChange([...selectedIds, ...uniqueNewIds]);
|
|
32
|
+
}, [selectedIds, onChange]);
|
|
33
|
+
const clearAllInGroup = useCallback((group) => {
|
|
34
|
+
const groupItemIds = new Set(group.items.map((item) => item.id));
|
|
35
|
+
const newSelected = selectedIds.filter((id) => !groupItemIds.has(id));
|
|
36
|
+
onChange(newSelected);
|
|
37
|
+
}, [selectedIds, onChange]);
|
|
38
|
+
const toggleGroupExpansion = useCallback((groupName) => {
|
|
39
|
+
setExpandedGroups((prev) => {
|
|
40
|
+
const newSet = new Set(prev);
|
|
41
|
+
if (newSet.has(groupName))
|
|
42
|
+
newSet.delete(groupName);
|
|
43
|
+
else
|
|
44
|
+
newSet.add(groupName);
|
|
45
|
+
return newSet;
|
|
46
|
+
});
|
|
47
|
+
}, []);
|
|
48
|
+
const getItemCount = (item) => {
|
|
49
|
+
if (item.count !== undefined)
|
|
50
|
+
return item.count;
|
|
51
|
+
if (item.countProvider)
|
|
52
|
+
return item.countProvider();
|
|
53
|
+
if (itemCountProvider)
|
|
54
|
+
return itemCountProvider(item);
|
|
55
|
+
return 0;
|
|
56
|
+
};
|
|
57
|
+
const selectedSet = useMemo(() => new Set(selectedIds), [selectedIds]);
|
|
58
|
+
if (!Array.isArray(groups) || !groups.length) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return (_jsx("div", { className: "efp-multi-select-groups", children: _jsx("div", { className: "efp-multi-select-groups__list", children: groups.map((group) => {
|
|
62
|
+
if (!group?.groupName || !Array.isArray(group.items))
|
|
63
|
+
return null;
|
|
64
|
+
const validItems = group.items.filter((i) => i.id);
|
|
65
|
+
const selectedItemsInGroup = validItems.filter((item) => selectedSet.has(item.id));
|
|
66
|
+
const isFull = selectedItemsInGroup.length === validItems.length && validItems.length > 0;
|
|
67
|
+
const isPartial = selectedItemsInGroup.length > 0 && !isFull;
|
|
68
|
+
const isExpanded = expandedGroups.has(group.groupName);
|
|
69
|
+
const visibleItems = isExpanded || validItems.length <= maxItemsVisible
|
|
70
|
+
? validItems
|
|
71
|
+
: validItems.slice(0, maxItemsVisible);
|
|
72
|
+
const hiddenCount = validItems.length - visibleItems.length;
|
|
73
|
+
const hiddenSelectedCount = hiddenCount > 0
|
|
74
|
+
? validItems.slice(maxItemsVisible).filter((item) => selectedSet.has(item.id)).length
|
|
75
|
+
: 0;
|
|
76
|
+
return (_jsxs("div", { className: cn('efp-multi-select-groups__group', { 'efp-multi-select-groups__group--full-width': group.fullWidth }, group.customGroupClass), children: [_jsxs("div", { className: "efp-multi-select-groups__group-header", children: [_jsx("div", { className: "efp-multi-select-groups__group-title", children: group.groupName }), showGroupActions && group.showGroupActions !== false && (_jsxs("div", { className: "efp-multi-select-groups__group-actions", children: [!isFull && (_jsx("button", { type: "button", className: "efp-multi-select-groups__action-btn", onClick: () => selectAllInGroup(group), children: selectAllLabel })), (isPartial || isFull) && (_jsx("button", { type: "button", className: "efp-multi-select-groups__action-btn", onClick: () => clearAllInGroup(group), children: clearAllLabel }))] }))] }), _jsx("div", { className: "efp-multi-select-groups__group-items", children: visibleItems.map((item) => (_jsx(GroupItem, { item: item, isSelected: selectedSet.has(item.id), variant: variant, showCount: showItemCounts, count: getItemCount(item), onClick: handleItemToggle, customRenderer: customItemRenderer }, item.id))) }), validItems.length > maxItemsVisible && (_jsx(ShowMoreButton, { className: "efp-multi-select-groups__show-more", expanded: isExpanded, showMoreLabel: showMoreLabel, showLessLabel: showLessLabel, onClick: () => toggleGroupExpansion(group.groupName), suffix: !isExpanded &&
|
|
77
|
+
hiddenSelectedCount > 0 && (_jsxs("span", { className: "efp-multi-select-groups__show-more-badge", children: [hiddenSelectedCount, " ", selectedLabel] })) }))] }, group.groupName));
|
|
78
|
+
}) }) }));
|
|
79
|
+
}
|
|
80
|
+
export default MultiSelectGroups;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './MultiSelectGroups';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './OverlayGrip.scss';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface OverlayGripProps {
|
|
4
|
+
isFull: boolean;
|
|
5
|
+
onToggle: () => void;
|
|
6
|
+
ariaLabel: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const OverlayGrip: ({ isFull, onToggle, ariaLabel, className }: OverlayGripProps) => React.JSX.Element;
|
|
10
|
+
export default OverlayGrip;
|
|
11
|
+
//# sourceMappingURL=OverlayGrip.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import './OverlayGrip.scss';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
const OverlayGrip = ({ isFull, onToggle, ariaLabel, className }) => {
|
|
6
|
+
return (_jsx("button", { type: "button", className: cn('efp-overlay-grip', { 'efp-overlay-grip--full': isFull }, className), onClick: onToggle, "aria-label": ariaLabel, "aria-expanded": isFull, children: _jsxs("svg", { viewBox: "0 0 1200 200", preserveAspectRatio: "xMidYMid meet", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", children: [_jsx("path", { d: "M100,100 l 500 100 L 1100 100" }), _jsx("path", { d: "M100,150 l 500 0 L 1100 150" })] }) }));
|
|
7
|
+
};
|
|
8
|
+
export default OverlayGrip;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import './PermissionNotice.scss';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export type PermissionNoticePlacement = 'bottom-right' | 'bottom-left';
|
|
4
|
+
export interface PermissionNoticeProps {
|
|
5
|
+
title: string;
|
|
6
|
+
acceptText: string;
|
|
7
|
+
rejectText: string;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
placement?: PermissionNoticePlacement;
|
|
10
|
+
onAccept?: () => void;
|
|
11
|
+
onReject?: () => void;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const PermissionNotice: ({ title, acceptText, rejectText, children, placement, onAccept, onReject, className, }: PermissionNoticeProps) => React.JSX.Element;
|
|
15
|
+
export default PermissionNotice;
|
|
16
|
+
//# sourceMappingURL=PermissionNotice.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import './PermissionNotice.scss';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import { useId } from 'react';
|
|
5
|
+
import Button from '../Button';
|
|
6
|
+
const PermissionNotice = ({ title, acceptText, rejectText, children, placement = 'bottom-right', onAccept, onReject, className, }) => {
|
|
7
|
+
const titleId = useId();
|
|
8
|
+
const descId = useId();
|
|
9
|
+
return (_jsxs("div", { className: cn('efp-permission-notice', `efp-permission-notice--${placement}`, className), role: "dialog", "aria-labelledby": titleId, "aria-describedby": descId, children: [_jsx("div", { className: "efp-permission-notice__title", id: titleId, children: title }), _jsx("div", { className: "efp-permission-notice__text", id: descId, children: children }), _jsxs("div", { className: "efp-permission-notice__bottom", children: [_jsx(Button, { size: "md", onClick: onAccept, children: acceptText }), _jsx(Button, { size: "md", variant: "gray", onClick: onReject, children: rejectText })] })] }));
|
|
10
|
+
};
|
|
11
|
+
export default PermissionNotice;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import './Radio.scss';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface RadioProps {
|
|
4
|
+
name: string;
|
|
5
|
+
label: string;
|
|
6
|
+
value: string | number;
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
ariaLabel?: string;
|
|
11
|
+
onChange?: () => void;
|
|
12
|
+
}
|
|
13
|
+
declare const Radio: ({ name, label, value, checked, disabled, className, ariaLabel, onChange, }: RadioProps) => React.JSX.Element;
|
|
14
|
+
export default Radio;
|
|
15
|
+
//# sourceMappingURL=Radio.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import './Radio.scss';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import { useId } from 'react';
|
|
6
|
+
const Radio = ({ name, label, value, checked, disabled, className, ariaLabel, onChange, }) => {
|
|
7
|
+
const id = useId();
|
|
8
|
+
return (_jsxs("label", { htmlFor: id, className: classNames('efp-radio', className, {
|
|
9
|
+
'efp-radio--checked': checked,
|
|
10
|
+
'efp-radio--disabled': disabled,
|
|
11
|
+
}), children: [_jsx("input", { type: "radio", className: "efp-radio__input", id: id, name: name, value: value, checked: checked, disabled: disabled, "aria-label": ariaLabel, onChange: onChange }), _jsx("span", { className: "efp-radio__control", "aria-hidden": "true" }), _jsx("span", { className: "efp-radio__label", children: label })] }));
|
|
12
|
+
};
|
|
13
|
+
export default Radio;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Radio';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './RebookingNotes.scss';
|
|
2
|
+
export interface RebookingNotesProps {
|
|
3
|
+
value?: string;
|
|
4
|
+
noteLabel: string;
|
|
5
|
+
saveButtonLabel: string;
|
|
6
|
+
saveButtonAriaLabel: string;
|
|
7
|
+
onSave: (value: string) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const RebookingNotes: ({ value, noteLabel, saveButtonLabel, saveButtonAriaLabel, onSave, }: RebookingNotesProps) => import("react").JSX.Element;
|
|
10
|
+
export default RebookingNotes;
|
|
11
|
+
//# sourceMappingURL=RebookingNotes.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import './RebookingNotes.scss';
|
|
3
|
+
import { useId, useState } from 'react';
|
|
4
|
+
import Button from '../Button';
|
|
5
|
+
const RebookingNotes = ({ value, noteLabel, saveButtonLabel, saveButtonAriaLabel, onSave, }) => {
|
|
6
|
+
const id = useId();
|
|
7
|
+
const labelId = `${id}-label`;
|
|
8
|
+
const textareaId = `${id}-textarea`;
|
|
9
|
+
// Uncontrolled editing buffer seeded from `value`; consumers reset it by remounting via `key`
|
|
10
|
+
// (see RebookingNotesContainer usage). Committed to the parent only on save.
|
|
11
|
+
const [internalValue, setInternalValue] = useState(value ?? '');
|
|
12
|
+
const handleChange = (event) => setInternalValue(event.target.value);
|
|
13
|
+
const handleSave = () => {
|
|
14
|
+
onSave(internalValue);
|
|
15
|
+
};
|
|
16
|
+
return (_jsxs("div", { className: "rebooking-notes", children: [_jsx("div", { className: "rebooking-notes__view-header", children: _jsx("strong", { id: labelId, children: noteLabel }) }), _jsxs("div", { className: "rebooking-notes__edit", children: [_jsx("div", { className: "rebooking-notes__val", children: _jsx("textarea", { id: textareaId, value: internalValue, onChange: handleChange, "aria-labelledby": labelId }) }), _jsx("div", { className: "rebooking-notes__buttons", children: _jsx(Button, { inline: true, onClick: handleSave, disabled: (value ?? '') === internalValue, "aria-label": saveButtonAriaLabel, children: saveButtonLabel }) })] })] }));
|
|
17
|
+
};
|
|
18
|
+
export default RebookingNotes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './RebookingNotes';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './RebookingRadioGroup.scss';
|
|
2
|
+
export interface RebookingOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
iconName?: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
color: string;
|
|
8
|
+
}
|
|
9
|
+
export interface RebookingRadioGroupProps {
|
|
10
|
+
options: RebookingOption[];
|
|
11
|
+
value: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
onChange: (value: string) => void;
|
|
14
|
+
}
|
|
15
|
+
declare const RebookingRadioGroup: ({ options, value, title, onChange }: RebookingRadioGroupProps) => import("react").JSX.Element;
|
|
16
|
+
export default RebookingRadioGroup;
|
|
17
|
+
//# sourceMappingURL=RebookingRadioGroup.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import './RebookingRadioGroup.scss';
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
const RebookingRadioGroup = ({ options, value, title, onChange }) => {
|
|
5
|
+
const idPrefix = useId();
|
|
6
|
+
return (_jsxs("div", { className: "rebooking-radio-group", children: [title && _jsx("div", { className: "rebooking-radio-group__title", children: title }), _jsx("div", { className: "rebooking-radio-group__options", children: options.map((option) => {
|
|
7
|
+
const optionId = `${idPrefix}-${option.value}`;
|
|
8
|
+
return (_jsxs("div", { className: "rebooking-radio", style: {
|
|
9
|
+
'--rebooking-color-primary': option.color,
|
|
10
|
+
}, children: [_jsx("input", { type: "radio", name: idPrefix, value: option.value, id: optionId, checked: option.value === value, disabled: option.disabled, onChange: () => onChange(option.value) }), _jsxs("label", { htmlFor: optionId, children: [_jsx("div", { className: "rebooking-radio__label", children: option.label }), _jsx("div", { className: "rebooking-radio__icon", children: _jsx("i", { className: option.iconName, "aria-hidden": "true" }) })] })] }, option.value));
|
|
11
|
+
}) })] }));
|
|
12
|
+
};
|
|
13
|
+
export default RebookingRadioGroup;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './RebookingRadioGroup';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import './ScrollableRow.scss';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
export interface ScrollableRowProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
ariaLabel: string;
|
|
6
|
+
leftAriaLabel: string;
|
|
7
|
+
rightAriaLabel: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
scrollAmount?: number;
|
|
10
|
+
mobileBreakpoint?: number;
|
|
11
|
+
showArrowsOnMobile?: boolean;
|
|
12
|
+
arrowPosition?: 'inside' | 'outside';
|
|
13
|
+
scrollBehavior?: 'smooth' | 'auto';
|
|
14
|
+
isRtl?: boolean;
|
|
15
|
+
enableDragScroll?: boolean;
|
|
16
|
+
dragScrollSensitivity?: number;
|
|
17
|
+
onScroll?: (scrollLeft: number) => void;
|
|
18
|
+
}
|
|
19
|
+
declare const ScrollableRow: ({ children, ariaLabel, leftAriaLabel, rightAriaLabel, className, scrollAmount, mobileBreakpoint, showArrowsOnMobile, arrowPosition, scrollBehavior, isRtl, enableDragScroll, dragScrollSensitivity, onScroll, }: ScrollableRowProps) => React.JSX.Element;
|
|
20
|
+
export default ScrollableRow;
|
|
21
|
+
//# sourceMappingURL=ScrollableRow.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable @typescript-eslint/consistent-type-imports, @eslint-react/set-state-in-effect */
|
|
3
|
+
import './ScrollableRow.scss';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { ResizeObserver } from 'resize-observer';
|
|
7
|
+
import { isInteractiveTarget } from '../shared/interactive';
|
|
8
|
+
const SCROLL_THRESHOLD = 5;
|
|
9
|
+
const DEFAULT_MOBILE_BREAKPOINT = 768;
|
|
10
|
+
const ScrollableRow = ({ children, ariaLabel, leftAriaLabel, rightAriaLabel, className, scrollAmount = 150, mobileBreakpoint = DEFAULT_MOBILE_BREAKPOINT, showArrowsOnMobile = false, arrowPosition = 'inside', scrollBehavior = 'smooth', isRtl = false, enableDragScroll = true, dragScrollSensitivity = 1, onScroll, }) => {
|
|
11
|
+
const containerRef = useRef(null);
|
|
12
|
+
const scrollRef = useRef(null);
|
|
13
|
+
const resizeObserverRef = useRef(null);
|
|
14
|
+
const [showLeftArrow, setShowLeftArrow] = useState(false);
|
|
15
|
+
const [showRightArrow, setShowRightArrow] = useState(false);
|
|
16
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
17
|
+
const [startX, setStartX] = useState(0);
|
|
18
|
+
const [dragStartScrollLeft, setDragStartScrollLeft] = useState(0);
|
|
19
|
+
const isDesktop = useCallback(() => {
|
|
20
|
+
return (window.innerWidth > mobileBreakpoint &&
|
|
21
|
+
!('ontouchstart' in window || navigator.maxTouchPoints > 0));
|
|
22
|
+
}, [mobileBreakpoint]);
|
|
23
|
+
const normalizeRTLScroll = useCallback((scrollLeft, scrollWidth, clientWidth) => {
|
|
24
|
+
const maxScroll = scrollWidth - clientWidth;
|
|
25
|
+
if (scrollLeft < 0) {
|
|
26
|
+
return Math.abs(scrollLeft);
|
|
27
|
+
}
|
|
28
|
+
else if (scrollLeft > maxScroll / 2) {
|
|
29
|
+
return maxScroll - scrollLeft;
|
|
30
|
+
}
|
|
31
|
+
return scrollLeft;
|
|
32
|
+
}, []);
|
|
33
|
+
const checkArrows = useCallback(() => {
|
|
34
|
+
const scrollEl = scrollRef.current;
|
|
35
|
+
if (!scrollEl)
|
|
36
|
+
return;
|
|
37
|
+
const isMobile = window.innerWidth <= mobileBreakpoint;
|
|
38
|
+
if (isMobile && !showArrowsOnMobile) {
|
|
39
|
+
setShowLeftArrow(false);
|
|
40
|
+
setShowRightArrow(false);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const { scrollLeft, scrollWidth, clientWidth } = scrollEl;
|
|
44
|
+
const hasOverflow = scrollWidth > clientWidth;
|
|
45
|
+
if (!hasOverflow) {
|
|
46
|
+
setShowLeftArrow(false);
|
|
47
|
+
setShowRightArrow(false);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (isRtl) {
|
|
51
|
+
const maxScroll = scrollWidth - clientWidth;
|
|
52
|
+
const normalizedScroll = normalizeRTLScroll(scrollLeft, scrollWidth, clientWidth);
|
|
53
|
+
setShowLeftArrow(normalizedScroll > SCROLL_THRESHOLD);
|
|
54
|
+
setShowRightArrow(normalizedScroll < maxScroll - SCROLL_THRESHOLD);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
setShowLeftArrow(scrollLeft > SCROLL_THRESHOLD);
|
|
58
|
+
setShowRightArrow(scrollLeft < scrollWidth - clientWidth - SCROLL_THRESHOLD);
|
|
59
|
+
}
|
|
60
|
+
}, [mobileBreakpoint, showArrowsOnMobile, normalizeRTLScroll, isRtl]);
|
|
61
|
+
const handleScroll = useCallback(() => {
|
|
62
|
+
checkArrows();
|
|
63
|
+
if (onScroll && scrollRef.current) {
|
|
64
|
+
onScroll(scrollRef.current.scrollLeft);
|
|
65
|
+
}
|
|
66
|
+
}, [checkArrows, onScroll]);
|
|
67
|
+
const scroll = useCallback((direction) => {
|
|
68
|
+
const scrollEl = scrollRef.current;
|
|
69
|
+
if (!scrollEl)
|
|
70
|
+
return;
|
|
71
|
+
const currentScroll = scrollEl.scrollLeft;
|
|
72
|
+
let newScroll;
|
|
73
|
+
if (isRtl) {
|
|
74
|
+
const maxScrollLeft = -(scrollEl.scrollWidth - scrollEl.clientWidth);
|
|
75
|
+
newScroll =
|
|
76
|
+
direction === 'left'
|
|
77
|
+
? Math.min(0, currentScroll + scrollAmount)
|
|
78
|
+
: Math.max(maxScrollLeft, currentScroll - scrollAmount);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
newScroll =
|
|
82
|
+
direction === 'left'
|
|
83
|
+
? Math.max(0, currentScroll - scrollAmount)
|
|
84
|
+
: currentScroll + scrollAmount;
|
|
85
|
+
}
|
|
86
|
+
scrollEl.scrollTo({
|
|
87
|
+
left: newScroll,
|
|
88
|
+
behavior: scrollBehavior,
|
|
89
|
+
});
|
|
90
|
+
}, [scrollAmount, scrollBehavior, isRtl]);
|
|
91
|
+
const handleMouseDown = useCallback((e) => {
|
|
92
|
+
if (!enableDragScroll || !isDesktop() || !scrollRef.current)
|
|
93
|
+
return;
|
|
94
|
+
if (isInteractiveTarget(e.target))
|
|
95
|
+
return;
|
|
96
|
+
setIsDragging(true);
|
|
97
|
+
setStartX(e.pageX - scrollRef.current.offsetLeft);
|
|
98
|
+
setDragStartScrollLeft(scrollRef.current.scrollLeft);
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
}, [enableDragScroll, isDesktop]);
|
|
101
|
+
const handleMouseMove = useCallback((e) => {
|
|
102
|
+
if (!isDragging || !scrollRef.current)
|
|
103
|
+
return;
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
const x = e.pageX - scrollRef.current.offsetLeft;
|
|
106
|
+
const walk = (x - startX) * dragScrollSensitivity;
|
|
107
|
+
scrollRef.current.scrollLeft = dragStartScrollLeft - walk;
|
|
108
|
+
}, [isDragging, startX, dragStartScrollLeft, dragScrollSensitivity]);
|
|
109
|
+
const endDrag = useCallback(() => {
|
|
110
|
+
setIsDragging(false);
|
|
111
|
+
}, []);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (!isDragging)
|
|
114
|
+
return;
|
|
115
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
116
|
+
document.addEventListener('mouseup', endDrag);
|
|
117
|
+
document.addEventListener('mouseleave', endDrag);
|
|
118
|
+
return () => {
|
|
119
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
120
|
+
document.removeEventListener('mouseup', endDrag);
|
|
121
|
+
document.removeEventListener('mouseleave', endDrag);
|
|
122
|
+
};
|
|
123
|
+
}, [isDragging, handleMouseMove, endDrag]);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
checkArrows();
|
|
126
|
+
const handleResize = () => checkArrows();
|
|
127
|
+
window.addEventListener('resize', handleResize);
|
|
128
|
+
if (containerRef.current && !resizeObserverRef.current) {
|
|
129
|
+
resizeObserverRef.current = new ResizeObserver(checkArrows);
|
|
130
|
+
resizeObserverRef.current.observe(containerRef.current);
|
|
131
|
+
}
|
|
132
|
+
return () => {
|
|
133
|
+
window.removeEventListener('resize', handleResize);
|
|
134
|
+
if (resizeObserverRef.current) {
|
|
135
|
+
resizeObserverRef.current.disconnect();
|
|
136
|
+
resizeObserverRef.current = null;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}, [checkArrows]);
|
|
140
|
+
const showDragCursor = enableDragScroll && isDesktop();
|
|
141
|
+
const cursorStyle = showDragCursor ? (isDragging ? 'grabbing' : 'grab') : undefined;
|
|
142
|
+
return (_jsx("div", { ref: containerRef, className: cn('efp-scrollable-row', className), role: "group", "aria-label": ariaLabel, children: _jsxs("div", { className: cn('efp-scrollable-row__container', {
|
|
143
|
+
[`efp-scrollable-row__container--${arrowPosition}`]: arrowPosition,
|
|
144
|
+
}), children: [showLeftArrow && (_jsx("button", { type: "button", className: cn('efp-scrollable-row__arrow', 'efp-scrollable-row__arrow--left', {
|
|
145
|
+
'efp-scrollable-row__arrow--rtl': isRtl,
|
|
146
|
+
}), onClick: () => scroll('left'), "aria-label": leftAriaLabel, children: _jsx("i", { className: "icon-chevron-left" }) })), _jsx("div", { ref: scrollRef, className: cn('efp-scrollable-row__scroll-wrapper', {
|
|
147
|
+
'efp-scrollable-row__scroll-wrapper--dragging': isDragging,
|
|
148
|
+
}), onScroll: handleScroll, onMouseDown: handleMouseDown, style: {
|
|
149
|
+
cursor: cursorStyle,
|
|
150
|
+
userSelect: isDragging ? 'none' : undefined,
|
|
151
|
+
}, children: _jsx("div", { className: "efp-scrollable-row__content", children: children }) }), showRightArrow && (_jsx("button", { type: "button", className: cn('efp-scrollable-row__arrow', 'efp-scrollable-row__arrow--right', {
|
|
152
|
+
'efp-scrollable-row__arrow--rtl': isRtl,
|
|
153
|
+
}), onClick: () => scroll('right'), "aria-label": rightAriaLabel, children: _jsx("i", { className: "icon-chevron-right" }) }))] }) }));
|
|
154
|
+
};
|
|
155
|
+
export default ScrollableRow;
|