yet-another-react-lightbox-lite 1.3.1 → 1.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 +26 -2
- package/dist/index.d.ts +18 -7
- package/dist/index.js +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,9 +26,12 @@ size.
|
|
|
26
26
|
|
|
27
27
|
[https://github.com/igordanchenko/yet-another-react-lightbox-lite](https://github.com/igordanchenko/yet-another-react-lightbox-lite)
|
|
28
28
|
|
|
29
|
-
##
|
|
29
|
+
## Examples
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
- Live demo -
|
|
32
|
+
[https://stackblitz.com/edit/yet-another-react-lightbox-lite](https://stackblitz.com/edit/yet-another-react-lightbox-lite?file=src%2FApp.tsx)
|
|
33
|
+
- Examples -
|
|
34
|
+
[https://stackblitz.com/edit/yet-another-react-lightbox-lite-examples](https://stackblitz.com/edit/yet-another-react-lightbox-lite-examples?file=src%2FApp.tsx)
|
|
32
35
|
|
|
33
36
|
## Changelog
|
|
34
37
|
|
|
@@ -235,6 +238,27 @@ Usage example:
|
|
|
235
238
|
/>
|
|
236
239
|
```
|
|
237
240
|
|
|
241
|
+
### carousel
|
|
242
|
+
|
|
243
|
+
Type: `object`
|
|
244
|
+
|
|
245
|
+
Carousel settings.
|
|
246
|
+
|
|
247
|
+
- `preload` - the lightbox preloads `(2 * preload + 1)` slides (default: `2`)
|
|
248
|
+
- `imageProps` - custom image slide attributes
|
|
249
|
+
|
|
250
|
+
Usage example:
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
<Lightbox
|
|
254
|
+
carousel={{
|
|
255
|
+
preload: 5,
|
|
256
|
+
imageProps: { crossOrigin: "anonymous" },
|
|
257
|
+
}}
|
|
258
|
+
// ...
|
|
259
|
+
/>
|
|
260
|
+
```
|
|
261
|
+
|
|
238
262
|
### controller
|
|
239
263
|
|
|
240
264
|
Type: `object`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Dispatch, SetStateAction, Key, ReactNode, ComponentProps, CSSProperties, MouseEvent } from 'react';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
/** Lightbox props */
|
|
@@ -8,13 +8,15 @@ interface LightboxProps {
|
|
|
8
8
|
/** slide index */
|
|
9
9
|
index: number | undefined;
|
|
10
10
|
/** slide index change callback */
|
|
11
|
-
setIndex:
|
|
11
|
+
setIndex: Dispatch<SetStateAction<number | undefined>>;
|
|
12
12
|
/** custom UI labels / translations */
|
|
13
13
|
labels?: Labels;
|
|
14
14
|
/** custom render functions */
|
|
15
15
|
render?: Render;
|
|
16
16
|
/** toolbar settings */
|
|
17
17
|
toolbar?: ToolbarSettings;
|
|
18
|
+
/** carousel settings */
|
|
19
|
+
carousel?: CarouselSettings;
|
|
18
20
|
/** controller settings */
|
|
19
21
|
controller?: ControllerSettings;
|
|
20
22
|
/** zoom settings */
|
|
@@ -36,7 +38,7 @@ type SlideTypeKey = keyof SlideTypes;
|
|
|
36
38
|
/** Generic slide */
|
|
37
39
|
interface GenericSlide {
|
|
38
40
|
/** slide key */
|
|
39
|
-
key?:
|
|
41
|
+
key?: Key;
|
|
40
42
|
/** slide type */
|
|
41
43
|
type?: SlideTypeKey;
|
|
42
44
|
}
|
|
@@ -103,10 +105,17 @@ interface RenderSlideProps {
|
|
|
103
105
|
/** Toolbar settings */
|
|
104
106
|
interface ToolbarSettings {
|
|
105
107
|
/** custom toolbar buttons */
|
|
106
|
-
buttons?:
|
|
108
|
+
buttons?: ReactNode[];
|
|
107
109
|
/** if `true`, the toolbar is positioned statically above the carousel */
|
|
108
110
|
fixed?: boolean;
|
|
109
111
|
}
|
|
112
|
+
/** Carousel settings */
|
|
113
|
+
interface CarouselSettings {
|
|
114
|
+
/** the lightbox preloads (2 * preload + 1) slides */
|
|
115
|
+
preload?: number;
|
|
116
|
+
/** custom image slide attributes */
|
|
117
|
+
imageProps?: ComponentProps<"img">;
|
|
118
|
+
}
|
|
110
119
|
/** Controller settings */
|
|
111
120
|
interface ControllerSettings {
|
|
112
121
|
/** if `true`, close the lightbox on pull-up gesture (default: `true`) */
|
|
@@ -141,7 +150,7 @@ interface SlotType {
|
|
|
141
150
|
/** Customization slots */
|
|
142
151
|
type Slot = SlotType[keyof SlotType];
|
|
143
152
|
/** Customization slot CSS properties */
|
|
144
|
-
interface SlotCSSProperties extends
|
|
153
|
+
interface SlotCSSProperties extends CSSProperties {
|
|
145
154
|
[key: `--yarll__${string}`]: string | number;
|
|
146
155
|
}
|
|
147
156
|
/** Customization slots styles */
|
|
@@ -150,13 +159,15 @@ type SlotStyles = {
|
|
|
150
159
|
};
|
|
151
160
|
/** Rect */
|
|
152
161
|
type Rect = {
|
|
162
|
+
/** rect width */
|
|
153
163
|
width: number;
|
|
164
|
+
/** rect height */
|
|
154
165
|
height: number;
|
|
155
166
|
};
|
|
156
167
|
/** Generic callback function */
|
|
157
168
|
type Callback<T = void> = () => T;
|
|
158
169
|
/** Render function */
|
|
159
|
-
type RenderFunction<T = void> = [T] extends [void] ? () =>
|
|
170
|
+
type RenderFunction<T = void> = [T] extends [void] ? () => ReactNode : (props: T) => ReactNode;
|
|
160
171
|
|
|
161
172
|
/** Lightbox component */
|
|
162
173
|
declare function Lightbox({ slides, index, setIndex, ...rest }: LightboxProps): react_jsx_runtime.JSX.Element | null;
|
|
@@ -185,4 +196,4 @@ type ZoomContextType = {
|
|
|
185
196
|
/** `useZoom` hook */
|
|
186
197
|
declare const useZoom: () => ZoomContextType;
|
|
187
198
|
|
|
188
|
-
export { type Callback, type ControllerSettings, type GenericSlide, type ImageSource, type Label, type Labels, type LightboxProps, type Rect, type Render, type RenderFunction, type RenderSlideProps, type Slide, type SlideImage, type SlideTypeKey, type SlideTypes, type Slot, type SlotStyles, type SlotType, type ToolbarSettings, type ZoomSettings, Lightbox as default, useZoom as unstable_useZoom };
|
|
199
|
+
export { type Callback, type CarouselSettings, type ControllerSettings, type GenericSlide, type ImageSource, type Label, type Labels, type LightboxProps, type Rect, type Render, type RenderFunction, type RenderSlideProps, type Slide, type SlideImage, type SlideTypeKey, type SlideTypes, type Slot, type SlotStyles, type SlotType, type ToolbarSettings, type ZoomSettings, Lightbox as default, useZoom as unstable_useZoom };
|
package/dist/index.js
CHANGED
|
@@ -135,7 +135,7 @@ function getImageDimensions(slide, rect) {
|
|
|
135
135
|
function ImageSlide({ slide, rect, zoom }) {
|
|
136
136
|
const [scale, setScale] = useState(1);
|
|
137
137
|
const persistScaleTimeout = useRef();
|
|
138
|
-
const { styles } = useLightboxContext();
|
|
138
|
+
const { carousel: { imageProps } = {}, styles } = useLightboxContext();
|
|
139
139
|
if (zoom > scale) {
|
|
140
140
|
clearTimeout(persistScaleTimeout.current);
|
|
141
141
|
persistScaleTimeout.current = setTimeout(() => {
|
|
@@ -149,16 +149,16 @@ function ImageSlide({ slide, rect, zoom }) {
|
|
|
149
149
|
.join(", ");
|
|
150
150
|
const [width, height] = getImageDimensions(slide, rect);
|
|
151
151
|
const sizes = width ? `${round(width * scale, 2)}px` : undefined;
|
|
152
|
-
return (jsx("img", { draggable: false, style: styles?.image, className: cssClass("slide_image"), srcSet: srcSet, sizes: sizes, width: width, height: height, src: slide.src, alt: slide.alt }));
|
|
152
|
+
return (jsx("img", { draggable: false, style: styles?.image, className: cssClass("slide_image"), srcSet: srcSet, sizes: sizes, width: width, height: height, src: slide.src, alt: slide.alt, ...imageProps }));
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
function Carousel() {
|
|
156
|
-
const { slides, index, styles, render: { slide: renderSlide, slideHeader, slideFooter } = {} } = useLightboxContext();
|
|
156
|
+
const { slides, index, styles, carousel: { preload = 2 } = {}, render: { slide: renderSlide, slideHeader, slideFooter } = {}, } = useLightboxContext();
|
|
157
157
|
const { rect, zoom, offsetX, offsetY } = useZoom();
|
|
158
158
|
const { setCarouselRef } = useZoomInternal();
|
|
159
159
|
return (jsx("div", { ref: setCarouselRef, style: styles?.carousel, className: cssClass("carousel"), children: rect &&
|
|
160
|
-
Array.from({ length:
|
|
161
|
-
const slideIndex = index -
|
|
160
|
+
Array.from({ length: 2 * preload + 1 }).map((_, i) => {
|
|
161
|
+
const slideIndex = index - preload + i;
|
|
162
162
|
if (slideIndex < 0 || slideIndex >= slides.length)
|
|
163
163
|
return null;
|
|
164
164
|
const slide = slides[slideIndex];
|