@lumx/react 3.9.4-alpha.3 → 3.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +18 -12
- package/index.js +5831 -5798
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/badge/BadgeWrapper.stories.tsx +76 -0
- package/src/components/badge/BadgeWrapper.test.tsx +49 -0
- package/src/components/badge/BadgeWrapper.tsx +36 -0
- package/src/components/badge/index.ts +1 -0
- package/src/components/expansion-panel/ExpansionPanel.test.tsx +5 -2
- package/src/components/expansion-panel/ExpansionPanel.tsx +32 -3
- package/src/components/image-lightbox/internal/ImageSlideshow.tsx +0 -2
- package/src/components/image-lightbox/internal/usePointerZoom.ts +1 -1
- package/src/components/slideshow/Slides.tsx +7 -15
- package/src/components/slideshow/Slideshow.stories.tsx +1 -12
- package/src/components/slideshow/Slideshow.tsx +16 -2
- package/src/components/slideshow/SlideshowControls.stories.tsx +3 -2
- package/src/components/slideshow/SlideshowControls.tsx +73 -63
- package/src/components/slideshow/SlideshowItem.tsx +10 -1
- package/src/components/slideshow/SlideshowItemGroup.tsx +33 -16
- package/src/components/slideshow/constants.ts +0 -4
- package/src/components/slideshow/useSlideFocusManagement.tsx +62 -74
- package/src/{components/slideshow → hooks}/useSlideshowControls.ts +60 -69
- package/src/stories/generated/Mosaic/Demos.stories.tsx +1 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
3
|
import { useInterval } from '@lumx/react/hooks/useInterval';
|
|
4
|
+
import { AUTOPLAY_DEFAULT_INTERVAL } from '@lumx/react/components/slideshow/constants';
|
|
4
5
|
import { useId } from '@lumx/react/hooks/useId';
|
|
5
6
|
|
|
6
|
-
import { AUTOPLAY_DEFAULT_INTERVAL, NEXT_SLIDE_EVENT, PREV_SLIDE_EVENT } from './constants';
|
|
7
|
-
|
|
8
7
|
export interface UseSlideshowControlsOptions {
|
|
9
8
|
/** default active index to be displayed */
|
|
10
9
|
defaultActiveIndex?: number;
|
|
@@ -44,9 +43,9 @@ export interface UseSlideshowControls {
|
|
|
44
43
|
/** id to be used for the wrapper that contains the slides */
|
|
45
44
|
slideshowSlidesId: string;
|
|
46
45
|
/** callback that triggers the previous slide while using the slideshow controls */
|
|
47
|
-
onPreviousClick: (
|
|
46
|
+
onPreviousClick: (loopback: boolean) => void;
|
|
48
47
|
/** callback that triggers the next slide while using the slideshow controls */
|
|
49
|
-
onNextClick: (
|
|
48
|
+
onNextClick: (loopback: boolean) => void;
|
|
50
49
|
/** callback that triggers a specific page while using the slideshow controls */
|
|
51
50
|
onPaginationClick: (index: number) => void;
|
|
52
51
|
/** whether the slideshow is autoplaying or not */
|
|
@@ -55,18 +54,16 @@ export interface UseSlideshowControls {
|
|
|
55
54
|
isForcePaused: boolean;
|
|
56
55
|
/** callback to change whether the slideshow is autoplaying or not */
|
|
57
56
|
toggleAutoPlay: () => void;
|
|
58
|
-
/**
|
|
57
|
+
/** calback to change whether the slideshow should be force paused or not */
|
|
59
58
|
toggleForcePause: () => void;
|
|
60
59
|
/** current active slide index */
|
|
61
60
|
activeIndex: number;
|
|
62
61
|
/** set the current index as the active one */
|
|
63
62
|
setActiveIndex: (index: number) => void;
|
|
64
|
-
/** callback that stops the
|
|
63
|
+
/** callback that stops the auto play */
|
|
65
64
|
stopAutoPlay: () => void;
|
|
66
|
-
/** callback that starts the
|
|
65
|
+
/** callback that starts the auto play */
|
|
67
66
|
startAutoPlay: () => void;
|
|
68
|
-
/** True if the last slide change is user activated */
|
|
69
|
-
isUserActivated?: boolean;
|
|
70
67
|
}
|
|
71
68
|
|
|
72
69
|
export const DEFAULT_OPTIONS: Partial<UseSlideshowControlsOptions> = {
|
|
@@ -93,34 +90,40 @@ export const useSlideshowControls = ({
|
|
|
93
90
|
// Number of slides when using groupBy prop.
|
|
94
91
|
const slidesCount = Math.ceil(itemsCount / Math.min(groupBy as number, itemsCount));
|
|
95
92
|
|
|
96
|
-
//
|
|
97
|
-
const
|
|
98
|
-
(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
93
|
+
// Change current index to display next slide.
|
|
94
|
+
const goToNextSlide = useCallback(
|
|
95
|
+
(loopback = true) => {
|
|
96
|
+
setCurrentIndex((index) => {
|
|
97
|
+
if (loopback && index === slidesCount - 1) {
|
|
98
|
+
// Loopback to the start.
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
if (index < slidesCount - 1) {
|
|
102
|
+
// Next slide.
|
|
103
|
+
return index + 1;
|
|
104
|
+
}
|
|
105
|
+
return index;
|
|
106
|
+
});
|
|
107
107
|
},
|
|
108
|
-
[
|
|
108
|
+
[slidesCount, setCurrentIndex],
|
|
109
109
|
);
|
|
110
110
|
|
|
111
|
-
// Change
|
|
112
|
-
const
|
|
113
|
-
(
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
// Change current index to display previous slide.
|
|
112
|
+
const goToPreviousSlide = useCallback(
|
|
113
|
+
(loopback = true) => {
|
|
114
|
+
setCurrentIndex((index) => {
|
|
115
|
+
if (loopback && index === 0) {
|
|
116
|
+
// Loopback to the end.
|
|
117
|
+
return slidesCount - 1;
|
|
118
|
+
}
|
|
119
|
+
if (index > 0) {
|
|
120
|
+
// Previous slide.
|
|
121
|
+
return index - 1;
|
|
119
122
|
}
|
|
120
|
-
return
|
|
121
|
-
}
|
|
123
|
+
return index;
|
|
124
|
+
});
|
|
122
125
|
},
|
|
123
|
-
[slidesCount,
|
|
126
|
+
[slidesCount, setCurrentIndex],
|
|
124
127
|
);
|
|
125
128
|
|
|
126
129
|
// Auto play
|
|
@@ -129,22 +132,22 @@ export const useSlideshowControls = ({
|
|
|
129
132
|
|
|
130
133
|
const isSlideshowAutoPlaying = isForcePaused ? false : isAutoPlaying;
|
|
131
134
|
// Start
|
|
132
|
-
useInterval(
|
|
135
|
+
useInterval(goToNextSlide, isSlideshowAutoPlaying && slidesCount > 1 ? (interval as number) : null);
|
|
133
136
|
|
|
134
|
-
// Reset current index if it
|
|
137
|
+
// Reset current index if it become invalid.
|
|
135
138
|
useEffect(() => {
|
|
136
139
|
if (currentIndex > slidesCount - 1) {
|
|
137
|
-
|
|
140
|
+
setCurrentIndex(defaultActiveIndex as number);
|
|
138
141
|
}
|
|
139
|
-
}, [currentIndex, slidesCount, defaultActiveIndex
|
|
142
|
+
}, [currentIndex, slidesCount, defaultActiveIndex]);
|
|
140
143
|
|
|
141
|
-
const startAutoPlay =
|
|
144
|
+
const startAutoPlay = () => {
|
|
142
145
|
setIsAutoPlaying(Boolean(autoPlay));
|
|
143
|
-
}
|
|
146
|
+
};
|
|
144
147
|
|
|
145
|
-
const stopAutoPlay =
|
|
148
|
+
const stopAutoPlay = () => {
|
|
146
149
|
setIsAutoPlaying(false);
|
|
147
|
-
}
|
|
150
|
+
};
|
|
148
151
|
|
|
149
152
|
// Handle click on a bullet to go to a specific slide.
|
|
150
153
|
const onPaginationClick = useCallback(
|
|
@@ -153,48 +156,36 @@ export const useSlideshowControls = ({
|
|
|
153
156
|
setIsForcePaused(true);
|
|
154
157
|
|
|
155
158
|
if (index >= 0 && index < slidesCount) {
|
|
156
|
-
|
|
159
|
+
setCurrentIndex(index);
|
|
157
160
|
}
|
|
158
161
|
},
|
|
159
|
-
[
|
|
162
|
+
[slidesCount, setCurrentIndex],
|
|
160
163
|
);
|
|
161
164
|
|
|
162
165
|
// Handle click or keyboard event to go to next slide.
|
|
163
166
|
const onNextClick = useCallback(
|
|
164
|
-
(
|
|
167
|
+
(loopback = true) => {
|
|
165
168
|
stopAutoPlay();
|
|
166
169
|
setIsForcePaused(true);
|
|
167
|
-
|
|
170
|
+
goToNextSlide(loopback);
|
|
168
171
|
},
|
|
169
|
-
[
|
|
172
|
+
[goToNextSlide],
|
|
170
173
|
);
|
|
171
174
|
|
|
172
175
|
// Handle click or keyboard event to go to previous slide.
|
|
173
176
|
const onPreviousClick = useCallback(
|
|
174
|
-
(
|
|
177
|
+
(loopback = true) => {
|
|
175
178
|
stopAutoPlay();
|
|
176
179
|
setIsForcePaused(true);
|
|
177
|
-
|
|
180
|
+
goToPreviousSlide(loopback);
|
|
178
181
|
},
|
|
179
|
-
[
|
|
182
|
+
[goToPreviousSlide],
|
|
180
183
|
);
|
|
181
184
|
|
|
182
|
-
// Listen to custom next/prev slide events
|
|
183
|
-
useEffect(() => {
|
|
184
|
-
if (!element) return undefined;
|
|
185
|
-
|
|
186
|
-
element.addEventListener(NEXT_SLIDE_EVENT, onNextClick);
|
|
187
|
-
element.addEventListener(PREV_SLIDE_EVENT, onPreviousClick);
|
|
188
|
-
return () => {
|
|
189
|
-
element.removeEventListener(NEXT_SLIDE_EVENT, onNextClick);
|
|
190
|
-
element.removeEventListener(PREV_SLIDE_EVENT, onPreviousClick);
|
|
191
|
-
};
|
|
192
|
-
}, [element, onNextClick, onPreviousClick]);
|
|
193
|
-
|
|
194
185
|
// If the activeIndex props changes, update the current slide
|
|
195
186
|
useEffect(() => {
|
|
196
|
-
|
|
197
|
-
}, [activeIndex
|
|
187
|
+
setCurrentIndex(activeIndex as number);
|
|
188
|
+
}, [activeIndex]);
|
|
198
189
|
|
|
199
190
|
// If the slide changes, with autoplay for example, trigger "onChange"
|
|
200
191
|
useEffect(() => {
|
|
@@ -208,15 +199,15 @@ export const useSlideshowControls = ({
|
|
|
208
199
|
const generatedSlidesId = useId();
|
|
209
200
|
const slideshowSlidesId = slidesId || generatedSlidesId;
|
|
210
201
|
|
|
211
|
-
const toggleAutoPlay =
|
|
202
|
+
const toggleAutoPlay = () => {
|
|
212
203
|
if (isSlideshowAutoPlaying) {
|
|
213
204
|
stopAutoPlay();
|
|
214
205
|
} else {
|
|
215
206
|
startAutoPlay();
|
|
216
207
|
}
|
|
217
|
-
}
|
|
208
|
+
};
|
|
218
209
|
|
|
219
|
-
const toggleForcePause =
|
|
210
|
+
const toggleForcePause = () => {
|
|
220
211
|
const shouldBePaused = !isForcePaused;
|
|
221
212
|
|
|
222
213
|
setIsForcePaused(shouldBePaused);
|
|
@@ -226,7 +217,7 @@ export const useSlideshowControls = ({
|
|
|
226
217
|
} else {
|
|
227
218
|
stopAutoPlay();
|
|
228
219
|
}
|
|
229
|
-
}
|
|
220
|
+
};
|
|
230
221
|
|
|
231
222
|
// Start index and end index of visible slides.
|
|
232
223
|
const startIndexVisible = currentIndex * (groupBy as number);
|
|
@@ -246,7 +237,7 @@ export const useSlideshowControls = ({
|
|
|
246
237
|
toggleAutoPlay,
|
|
247
238
|
activeIndex: currentIndex,
|
|
248
239
|
slidesCount,
|
|
249
|
-
setActiveIndex,
|
|
240
|
+
setActiveIndex: setCurrentIndex,
|
|
250
241
|
startAutoPlay,
|
|
251
242
|
stopAutoPlay,
|
|
252
243
|
isForcePaused,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export default { title: 'LumX components/mosaic/Mosaic Demos' };
|
|
5
5
|
|
|
6
|
+
export { App as Clickable } from './clickable';
|
|
6
7
|
export { App as FourImages } from './four-images';
|
|
7
8
|
export { App as MoreImages } from './more-images';
|
|
8
9
|
export { App as ThreeImages } from './three-images';
|