yet-another-react-lightbox 2.4.3 → 2.5.1
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/dist/core/hooks/useDelay.d.ts +1 -1
- package/dist/core/modules/Controller.d.ts +5 -2
- package/dist/core/modules/Controller.js +4 -4
- package/dist/core/modules/Navigation.d.ts +2 -3
- package/dist/core/modules/Navigation.js +5 -5
- package/dist/plugins/captions/Description.js +2 -4
- package/dist/plugins/thumbnails/ThumbnailsTrack.js +3 -3
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useDelay: () => (callback: (
|
|
1
|
+
export declare const useDelay: () => (callback: () => void, delay: number) => void;
|
|
@@ -3,10 +3,13 @@ import { Component, ComponentProps, ContainerRect } from "../../types.js";
|
|
|
3
3
|
import { SubscribeSensors } from "../hooks/index.js";
|
|
4
4
|
import { LightboxStateAction } from "../contexts/index.js";
|
|
5
5
|
import { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, YARL_EVENT_BACKDROP_CLICK } from "../consts.js";
|
|
6
|
+
export type NavigationAction = {
|
|
7
|
+
count?: number;
|
|
8
|
+
};
|
|
6
9
|
declare module "../" {
|
|
7
10
|
interface EventTypes {
|
|
8
|
-
[ACTION_PREV]:
|
|
9
|
-
[ACTION_NEXT]:
|
|
11
|
+
[ACTION_PREV]: NavigationAction;
|
|
12
|
+
[ACTION_NEXT]: NavigationAction;
|
|
10
13
|
[ACTION_SWIPE]: LightboxStateAction;
|
|
11
14
|
[ACTION_CLOSE]: void;
|
|
12
15
|
[YARL_EVENT_BACKDROP_CLICK]: void;
|
|
@@ -53,11 +53,11 @@ export const Controller = ({ children, ...props }) => {
|
|
|
53
53
|
return undefined;
|
|
54
54
|
});
|
|
55
55
|
const swipe = useEventCallback((action) => {
|
|
56
|
-
var _a;
|
|
57
|
-
const swipeDuration = animation.swipe;
|
|
56
|
+
var _a, _b;
|
|
58
57
|
const currentSwipeOffset = action.offset || 0;
|
|
58
|
+
const swipeDuration = (_a = (!currentSwipeOffset ? animation.navigation : undefined)) !== null && _a !== void 0 ? _a : animation.swipe;
|
|
59
59
|
let { direction } = action;
|
|
60
|
-
const count = (
|
|
60
|
+
const count = (_b = action.count) !== null && _b !== void 0 ? _b : 1;
|
|
61
61
|
let newSwipeState = SwipeState.ANIMATION;
|
|
62
62
|
let newSwipeAnimationDuration = swipeDuration * count;
|
|
63
63
|
if (!direction) {
|
|
@@ -146,7 +146,7 @@ export const Controller = ({ children, ...props }) => {
|
|
|
146
146
|
(_a = on.view) === null || _a === void 0 ? void 0 : _a.call(on, state.currentIndex);
|
|
147
147
|
});
|
|
148
148
|
React.useEffect(handleIndexChange, [state.currentIndex, handleIndexChange]);
|
|
149
|
-
React.useEffect(() => cleanup(subscribe(ACTION_PREV, (
|
|
149
|
+
React.useEffect(() => cleanup(subscribe(ACTION_PREV, (action) => swipe({ direction: ACTION_PREV, ...action })), subscribe(ACTION_NEXT, (action) => swipe({ direction: ACTION_NEXT, ...action })), subscribe(ACTION_SWIPE, (action) => dispatch(action))), [subscribe, swipe, dispatch]);
|
|
150
150
|
React.useEffect(() => subscribeSensors(EVENT_ON_KEY_UP, (event) => {
|
|
151
151
|
if (event.code === VK_ESCAPE) {
|
|
152
152
|
publish(ACTION_CLOSE);
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Component, Labels } from "../../types.js";
|
|
3
|
-
import { Publish } from "../contexts/index.js";
|
|
4
3
|
export type NavigationButtonProps = {
|
|
5
|
-
publish: Publish;
|
|
6
4
|
labels?: Labels;
|
|
7
5
|
label: string;
|
|
8
6
|
icon: React.ElementType;
|
|
9
7
|
renderIcon?: () => React.ReactNode;
|
|
10
8
|
action: "prev" | "next";
|
|
9
|
+
onClick: () => void;
|
|
11
10
|
disabled?: boolean;
|
|
12
11
|
};
|
|
13
|
-
export declare const NavigationButton: ({
|
|
12
|
+
export declare const NavigationButton: ({ labels, label, icon, renderIcon, action, onClick, disabled, }: NavigationButtonProps) => JSX.Element;
|
|
14
13
|
export declare const Navigation: Component;
|
|
15
14
|
export declare const NavigationModule: import("../../types.js").Module;
|
|
@@ -6,15 +6,15 @@ import { IconButton, NextIcon, PreviousIcon } from "../components/index.js";
|
|
|
6
6
|
import { useEvents, useLightboxState } from "../contexts/index.js";
|
|
7
7
|
import { useController } from "./Controller.js";
|
|
8
8
|
import { ACTION_NEXT, ACTION_PREV, EVENT_ON_KEY_DOWN, MODULE_NAVIGATION, VK_ARROW_LEFT, VK_ARROW_RIGHT, } from "../consts.js";
|
|
9
|
-
export const NavigationButton = ({
|
|
10
|
-
export const Navigation = ({ slides, carousel: { finite }, animation: { swipe }, labels, render: { buttonPrev, buttonNext, iconPrev, iconNext }, }) => {
|
|
9
|
+
export const NavigationButton = ({ labels, label, icon, renderIcon, action, onClick, disabled, }) => (React.createElement(IconButton, { label: translateLabel(labels, label), icon: icon, renderIcon: renderIcon, className: cssClass(`navigation_${action}`), disabled: disabled, onClick: onClick, ...useLoseFocus(disabled) }));
|
|
10
|
+
export const Navigation = ({ slides, carousel: { finite }, animation: { swipe, navigation }, labels, render: { buttonPrev, buttonNext, iconPrev, iconNext }, }) => {
|
|
11
11
|
const { currentIndex } = useLightboxState().state;
|
|
12
12
|
const { subscribeSensors } = useController();
|
|
13
13
|
const { publish } = useEvents();
|
|
14
14
|
const isRTL = useRTL();
|
|
15
15
|
const prevDisabled = slides.length === 0 || (finite && currentIndex === 0);
|
|
16
16
|
const nextDisabled = slides.length === 0 || (finite && currentIndex === slides.length - 1);
|
|
17
|
-
const publishThrottled = useThrottle((action) => publish(action), swipe / 2);
|
|
17
|
+
const publishThrottled = useThrottle((action) => publish(action), (navigation !== null && navigation !== void 0 ? navigation : swipe) / 2);
|
|
18
18
|
const handleKeyDown = useEventCallback((event) => {
|
|
19
19
|
if (event.key === VK_ARROW_LEFT && !(isRTL ? nextDisabled : prevDisabled)) {
|
|
20
20
|
publishThrottled(isRTL ? ACTION_NEXT : ACTION_PREV);
|
|
@@ -25,7 +25,7 @@ export const Navigation = ({ slides, carousel: { finite }, animation: { swipe },
|
|
|
25
25
|
});
|
|
26
26
|
React.useEffect(() => subscribeSensors(EVENT_ON_KEY_DOWN, handleKeyDown), [subscribeSensors, handleKeyDown]);
|
|
27
27
|
return (React.createElement(React.Fragment, null,
|
|
28
|
-
buttonPrev ? (buttonPrev()) : (React.createElement(NavigationButton, { label: "Previous", action: ACTION_PREV, icon: PreviousIcon, renderIcon: iconPrev, disabled: prevDisabled, labels: labels,
|
|
29
|
-
buttonNext ? (buttonNext()) : (React.createElement(NavigationButton, { label: "Next", action: ACTION_NEXT, icon: NextIcon, renderIcon: iconNext, disabled: nextDisabled, labels: labels,
|
|
28
|
+
buttonPrev ? (buttonPrev()) : (React.createElement(NavigationButton, { label: "Previous", action: ACTION_PREV, icon: PreviousIcon, renderIcon: iconPrev, disabled: prevDisabled, labels: labels, onClick: () => publish(ACTION_PREV) })),
|
|
29
|
+
buttonNext ? (buttonNext()) : (React.createElement(NavigationButton, { label: "Next", action: ACTION_NEXT, icon: NextIcon, renderIcon: iconNext, disabled: nextDisabled, labels: labels, onClick: () => publish(ACTION_NEXT) }))));
|
|
30
30
|
};
|
|
31
31
|
export const NavigationModule = createModule(MODULE_NAVIGATION, Navigation);
|
|
@@ -7,10 +7,8 @@ export const Description = ({ description, descriptionTextAlign, descriptionMaxL
|
|
|
7
7
|
...(descriptionTextAlign !== defaultCaptionsProps.descriptionTextAlign ||
|
|
8
8
|
descriptionMaxLines !== defaultCaptionsProps.descriptionMaxLines
|
|
9
9
|
? {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
[cssVar("slide_description_max_lines")]: descriptionMaxLines,
|
|
13
|
-
},
|
|
10
|
+
[cssVar("slide_description_text_align")]: descriptionTextAlign,
|
|
11
|
+
[cssVar("slide_description_max_lines")]: descriptionMaxLines,
|
|
14
12
|
}
|
|
15
13
|
: null),
|
|
16
14
|
...styles.captionsDescription,
|
|
@@ -11,8 +11,8 @@ export const ThumbnailsTrack = ({ container, slides, carousel, render, thumbnail
|
|
|
11
11
|
const { publish, subscribe } = useEvents();
|
|
12
12
|
const isRTL = useRTL();
|
|
13
13
|
const index = globalIndex;
|
|
14
|
-
const offset = (animation === null || animation === void 0 ? void 0 : animation.increment) || 0;
|
|
15
14
|
const animationDuration = (animation === null || animation === void 0 ? void 0 : animation.duration) || 0;
|
|
15
|
+
const offset = (animationDuration > 0 && (animation === null || animation === void 0 ? void 0 : animation.increment)) || 0;
|
|
16
16
|
const animate = useAnimation(track, (snapshot) => ({
|
|
17
17
|
keyframes: isHorizontal(thumbnails.position)
|
|
18
18
|
? [
|
|
@@ -78,10 +78,10 @@ export const ThumbnailsTrack = ({ container, slides, carousel, render, thumbnail
|
|
|
78
78
|
}
|
|
79
79
|
const handleClick = (slideIndex) => () => {
|
|
80
80
|
if (slideIndex > index) {
|
|
81
|
-
publish(ACTION_NEXT, slideIndex - index);
|
|
81
|
+
publish(ACTION_NEXT, { count: slideIndex - index });
|
|
82
82
|
}
|
|
83
83
|
else if (slideIndex < index) {
|
|
84
|
-
publish(ACTION_PREV, index - slideIndex);
|
|
84
|
+
publish(ACTION_PREV, { count: index - slideIndex });
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
const { width, height, border, borderRadius, padding, gap, imageFit, vignette } = thumbnails;
|
package/dist/types.d.ts
CHANGED
|
@@ -82,6 +82,8 @@ export interface AnimationSettings {
|
|
|
82
82
|
fade: number;
|
|
83
83
|
/** swipe animation duration */
|
|
84
84
|
swipe: number;
|
|
85
|
+
/** override for `swipe` animation duration when using keyboard navigation or navigation buttons */
|
|
86
|
+
navigation?: number;
|
|
85
87
|
}
|
|
86
88
|
/** Controller settings */
|
|
87
89
|
export interface ControllerSettings {
|