yet-another-react-lightbox 3.19.0 → 3.20.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/index.d.ts CHANGED
@@ -204,9 +204,10 @@ type ImageSlideProps = Partial<Pick<CarouselSettings, "imageFit" | "imageProps">
204
204
  rect?: ContainerRect;
205
205
  onClick?: () => void;
206
206
  onLoad?: (image: HTMLImageElement) => void;
207
+ onError?: () => void;
207
208
  style?: React.CSSProperties;
208
209
  };
209
- declare function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps, onClick, onLoad, style, }: ImageSlideProps): React.JSX.Element;
210
+ declare function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps, onClick, onLoad, onError, style, }: ImageSlideProps): React.JSX.Element;
210
211
 
211
212
  declare const LightboxRoot: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
212
213
 
package/dist/index.js CHANGED
@@ -623,7 +623,7 @@ function useThrottle(callback, delay) {
623
623
 
624
624
  const slidePrefix = makeComposePrefix("slide");
625
625
  const slideImagePrefix = makeComposePrefix("slide_image");
626
- function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps, onClick, onLoad, style, }) {
626
+ function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps, onClick, onLoad, onError, style, }) {
627
627
  var _a, _b, _c, _d, _e, _f, _g;
628
628
  const [status, setStatus] = React.useState(SLIDE_STATUS_LOADING);
629
629
  const { publish } = useEvents();
@@ -656,9 +656,10 @@ function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps,
656
656
  const handleOnLoad = React.useCallback((event) => {
657
657
  handleLoading(event.currentTarget);
658
658
  }, [handleLoading]);
659
- const onError = React.useCallback(() => {
659
+ const handleOnError = useEventCallback(() => {
660
660
  setStatus(SLIDE_STATUS_ERROR);
661
- }, []);
661
+ onError === null || onError === void 0 ? void 0 : onError();
662
+ });
662
663
  const cover = isImageFitCover(image, imageFit);
663
664
  const nonInfinite = (value, fallback) => (Number.isFinite(value) ? value : fallback);
664
665
  const maxWidth = nonInfinite(Math.max(...((_b = (_a = image.srcSet) === null || _a === void 0 ? void 0 : _a.map((x) => x.width)) !== null && _b !== void 0 ? _b : []).concat(image.width ? [image.width] : []).filter(Boolean)), ((_c = imageRef.current) === null || _c === void 0 ? void 0 : _c.naturalWidth) || 0);
@@ -677,7 +678,7 @@ function ImageSlide({ slide: image, offset, render, rect, imageFit, imageProps,
677
678
  const sizes = srcSet && rect && hasWindow() ? `${Math.round(Math.min(estimateActualWidth(), rect.width))}px` : undefined;
678
679
  const { style: imagePropsStyle, className: imagePropsClassName, ...restImageProps } = imageProps || {};
679
680
  return (React.createElement(React.Fragment, null,
680
- React.createElement("img", { ref: setImageRef, onLoad: handleOnLoad, onError: onError, onClick: onClick, draggable: false, className: clsx(cssClass(slideImagePrefix()), cover && cssClass(slideImagePrefix("cover")), status !== SLIDE_STATUS_COMPLETE && cssClass(slideImagePrefix("loading")), imagePropsClassName), style: { ...defaultStyle, ...style, ...imagePropsStyle }, ...restImageProps, alt: image.alt, sizes: sizes, srcSet: srcSet, src: image.src }),
681
+ React.createElement("img", { ref: setImageRef, onLoad: handleOnLoad, onError: handleOnError, onClick: onClick, draggable: false, className: clsx(cssClass(slideImagePrefix()), cover && cssClass(slideImagePrefix("cover")), status !== SLIDE_STATUS_COMPLETE && cssClass(slideImagePrefix("loading")), imagePropsClassName), style: { ...defaultStyle, ...style, ...imagePropsStyle }, ...restImageProps, alt: image.alt, sizes: sizes, srcSet: srcSet, src: image.src }),
681
682
  status !== SLIDE_STATUS_COMPLETE && (React.createElement("div", { className: cssClass(slidePrefix(SLIDE_STATUS_PLACEHOLDER)) },
682
683
  status === SLIDE_STATUS_LOADING &&
683
684
  ((render === null || render === void 0 ? void 0 : render.iconLoading) ? (render.iconLoading()) : (React.createElement(LoadingIcon, { className: clsx(cssClass(ELEMENT_ICON), cssClass(slidePrefix(SLIDE_STATUS_LOADING))) }))),
@@ -19,6 +19,8 @@ declare module "yet-another-react-lightbox" {
19
19
  captions?: {
20
20
  /** Captions plugin ref */
21
21
  ref?: React.ForwardedRef<CaptionsRef>;
22
+ /** if `true`, captions are hidden when the lightbox opens */
23
+ hidden?: boolean;
22
24
  /** if `true`, show Captions Toggle button in the toolbar */
23
25
  showToggle?: boolean;
24
26
  /** description text alignment */
@@ -1,5 +1,5 @@
1
- import { cssClass, useLightboxProps, makeUseContext, useController, clsx, cssVar, createIcon, createIconDisabled, IconButton, addToolbarButton, createModule } from '../../index.js';
2
1
  import * as React from 'react';
2
+ import { cssClass, useLightboxProps, makeUseContext, useController, clsx, cssVar, createIcon, createIconDisabled, IconButton, addToolbarButton, createModule } from '../../index.js';
3
3
  import { PLUGIN_CAPTIONS } from '../../types.js';
4
4
 
5
5
  const cssPrefix = (className) => cssClass(`slide_${className}`);
@@ -8,6 +8,7 @@ const defaultCaptionsProps = {
8
8
  descriptionTextAlign: "start",
9
9
  descriptionMaxLines: 3,
10
10
  showToggle: false,
11
+ hidden: false,
11
12
  };
12
13
  const resolveCaptionsProps = (captions) => ({
13
14
  ...defaultCaptionsProps,
@@ -21,8 +22,8 @@ function useCaptionsProps() {
21
22
  const CaptionsContext = React.createContext(null);
22
23
  const useCaptions = makeUseContext("useCaptions", "CaptionsContext", CaptionsContext);
23
24
  function CaptionsContextProvider({ captions, children }) {
24
- const { ref } = resolveCaptionsProps(captions);
25
- const [visible, setVisible] = React.useState(true);
25
+ const { ref, hidden } = resolveCaptionsProps(captions);
26
+ const [visible, setVisible] = React.useState(!hidden);
26
27
  const context = React.useMemo(() => ({
27
28
  visible,
28
29
  show: () => setVisible(true),
@@ -1,5 +1,5 @@
1
- import { createIcon, useLightboxProps, useLightboxState, isImageSlide, IconButton, addToolbarButton } from '../../index.js';
2
1
  import * as React from 'react';
2
+ import { createIcon, useLightboxProps, useLightboxState, isImageSlide, IconButton, addToolbarButton } from '../../index.js';
3
3
  import { PLUGIN_DOWNLOAD } from '../../types.js';
4
4
 
5
5
  const defaultDownloadProps = {
@@ -1,5 +1,5 @@
1
- import { makeUseContext, useDocumentContext, useLayoutEffect, cleanup, useEventCallback, clsx, cssClass, createIcon, useLightboxProps, IconButton, addToolbarButton, createModule } from '../../index.js';
2
1
  import * as React from 'react';
2
+ import { makeUseContext, useDocumentContext, useLayoutEffect, cleanup, useEventCallback, clsx, cssClass, createIcon, useLightboxProps, IconButton, addToolbarButton, createModule } from '../../index.js';
3
3
  import { PLUGIN_FULLSCREEN, CLASS_FULLSIZE, PLUGIN_THUMBNAILS, MODULE_CONTROLLER } from '../../types.js';
4
4
 
5
5
  const defaultFullscreenProps = {
@@ -1,5 +1,5 @@
1
- import { createIcon, useLightboxProps, useLightboxState, isImageSlide, IconButton, addToolbarButton } from '../../index.js';
2
1
  import * as React from 'react';
2
+ import { createIcon, useLightboxProps, useLightboxState, isImageSlide, IconButton, addToolbarButton } from '../../index.js';
3
3
 
4
4
  const defaultShareProps = {
5
5
  share: undefined,
@@ -1,5 +1,5 @@
1
- import { makeUseContext, useLightboxState, useTimeouts, useEvents, useController, useEventCallback, cleanup, createIcon, useLightboxProps, useLoseFocus, IconButton, addToolbarButton, createModule } from '../../index.js';
2
1
  import * as React from 'react';
2
+ import { makeUseContext, useLightboxState, useTimeouts, useEvents, useController, useEventCallback, cleanup, createIcon, useLightboxProps, useLoseFocus, IconButton, addToolbarButton, createModule } from '../../index.js';
3
3
  import { SLIDE_STATUS_LOADING, SLIDE_STATUS_PLAYING, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, ACTIVE_SLIDE_ERROR, SLIDE_STATUS_ERROR, ACTIVE_SLIDE_COMPLETE, SLIDE_STATUS_COMPLETE, PLUGIN_SLIDESHOW } from '../../types.js';
4
4
 
5
5
  const defaultSlideshowProps = {
@@ -36,6 +36,8 @@ declare module "yet-another-react-lightbox" {
36
36
  imageFit?: ImageFit;
37
37
  /** if `true`, show the vignette effect on the edges of the thumbnails track */
38
38
  vignette?: boolean;
39
+ /** if `true`, thumbnails are hidden when the lightbox opens */
40
+ hidden?: boolean;
39
41
  /** if `true`, show the Toggle Thumbnails button in the toolbar */
40
42
  showToggle?: boolean;
41
43
  };
@@ -1,5 +1,5 @@
1
- import { useLightboxProps, composePrefix, createIcon, ImageSlide, isImageSlide, cssClass, makeComposePrefix, useDocumentContext, useEventCallback, clsx, cssVar, getSlideKey, useRTL, useEvents, useLightboxState, useSensors, useKeyboardNavigation, useAnimation, cleanup, calculatePreload, hasSlides, getSlide, makeUseContext, LightboxPropsProvider, createIconDisabled, IconButton, addToolbarButton, createModule } from '../../index.js';
2
1
  import * as React from 'react';
2
+ import { useLightboxProps, composePrefix, createIcon, ImageSlide, isImageSlide, cssClass, makeComposePrefix, useDocumentContext, useEventCallback, clsx, cssVar, getSlideKey, useRTL, useEvents, useLightboxState, useSensors, useKeyboardNavigation, useAnimation, cleanup, calculatePreload, hasSlides, getSlide, makeUseContext, LightboxPropsProvider, createIconDisabled, IconButton, addToolbarButton, createModule } from '../../index.js';
3
3
  import { PLUGIN_THUMBNAILS, ELEMENT_ICON, CLASS_FLEX_CENTER, ACTION_SWIPE, ACTION_NEXT, ACTION_PREV, PLUGIN_FULLSCREEN, MODULE_CONTROLLER } from '../../types.js';
4
4
 
5
5
  const defaultThumbnailsProps = {
@@ -13,6 +13,8 @@ const defaultThumbnailsProps = {
13
13
  gap: 16,
14
14
  imageFit: "contain",
15
15
  vignette: true,
16
+ hidden: false,
17
+ showToggle: false,
16
18
  };
17
19
  const resolveThumbnailsProps = (thumbnails) => ({
18
20
  ...defaultThumbnailsProps,
@@ -205,9 +207,9 @@ function ThumbnailsTrack({ visible, containerRef }) {
205
207
  const ThumbnailsContext = React.createContext(null);
206
208
  const useThumbnails = makeUseContext("useThumbnails", "ThumbnailsContext", ThumbnailsContext);
207
209
  function ThumbnailsContextProvider({ children, ...props }) {
208
- const [visible, setVisible] = React.useState(true);
210
+ const { ref, position, hidden } = resolveThumbnailsProps(props.thumbnails);
211
+ const [visible, setVisible] = React.useState(!hidden);
209
212
  const containerRef = React.useRef(null);
210
- const { ref, position } = resolveThumbnailsProps(props.thumbnails);
211
213
  const context = React.useMemo(() => ({
212
214
  visible,
213
215
  show: () => setVisible(true),
@@ -1,5 +1,5 @@
1
- import { useLightboxProps, useMotionPreference, useEventCallback, useLayoutEffect, useLightboxState, isImageSlide, isImageFitCover, round, useDocumentContext, useController, usePointerEvents, cleanup, makeUseContext, createIcon, IconButton, devicePixelRatio, ImageSlide, clsx, cssClass, addToolbarButton, createModule } from '../../index.js';
2
1
  import * as React from 'react';
2
+ import { useLightboxProps, useMotionPreference, useEventCallback, useLayoutEffect, useLightboxState, isImageSlide, isImageFitCover, round, useDocumentContext, useController, usePointerEvents, cleanup, makeUseContext, createIcon, IconButton, devicePixelRatio, ImageSlide, clsx, cssClass, addToolbarButton, createModule } from '../../index.js';
3
3
  import { EVENT_ON_KEY_DOWN, EVENT_ON_WHEEL, UNKNOWN_ACTION_TYPE, CLASS_FULLSIZE, CLASS_FLEX_CENTER, CLASS_SLIDE_WRAPPER, PLUGIN_ZOOM } from '../../types.js';
4
4
 
5
5
  const defaultZoomProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.19.0",
3
+ "version": "3.20.1",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",