yet-another-react-lightbox 3.1.0 → 3.2.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.
Files changed (30) hide show
  1. package/dist/core/components/Icons.d.ts +4 -0
  2. package/dist/core/components/Icons.js +17 -4
  3. package/dist/core/consts.d.ts +1 -0
  4. package/dist/core/consts.js +1 -0
  5. package/dist/plugins/captions/Captions.d.ts +1 -1
  6. package/dist/plugins/captions/Captions.js +16 -8
  7. package/dist/plugins/captions/CaptionsButton.d.ts +2 -0
  8. package/dist/plugins/captions/CaptionsButton.js +16 -0
  9. package/dist/plugins/captions/CaptionsContext.d.ts +5 -0
  10. package/dist/plugins/captions/CaptionsContext.js +16 -0
  11. package/dist/plugins/captions/Description.d.ts +3 -3
  12. package/dist/plugins/captions/Description.js +8 -4
  13. package/dist/plugins/captions/Title.d.ts +3 -3
  14. package/dist/plugins/captions/Title.js +11 -3
  15. package/dist/plugins/captions/index.d.ts +21 -0
  16. package/dist/plugins/captions/props.d.ts +10 -0
  17. package/dist/plugins/captions/props.js +6 -0
  18. package/dist/plugins/thumbnails/Thumbnails.js +15 -6
  19. package/dist/plugins/thumbnails/ThumbnailsButton.d.ts +2 -0
  20. package/dist/plugins/thumbnails/ThumbnailsButton.js +16 -0
  21. package/dist/plugins/thumbnails/ThumbnailsContext.d.ts +6 -0
  22. package/dist/plugins/thumbnails/ThumbnailsContext.js +24 -0
  23. package/dist/plugins/thumbnails/ThumbnailsTrack.d.ts +0 -2
  24. package/dist/plugins/thumbnails/ThumbnailsTrack.js +3 -0
  25. package/dist/plugins/thumbnails/index.d.ts +21 -1
  26. package/dist/plugins/thumbnails/props.d.ts +6 -0
  27. package/dist/plugins/thumbnails/props.js +1 -0
  28. package/package.json +1 -1
  29. package/dist/plugins/thumbnails/ThumbnailsContainer.d.ts +0 -4
  30. package/dist/plugins/thumbnails/ThumbnailsContainer.js +0 -14
@@ -3,6 +3,10 @@ export declare function createIcon(name: string, glyph: React.ReactNode): {
3
3
  (props: React.SVGProps<SVGSVGElement>): JSX.Element;
4
4
  displayName: string;
5
5
  };
6
+ export declare function createIconDisabled(name: string, glyph: React.ReactNode): {
7
+ (props: React.SVGProps<SVGSVGElement>): JSX.Element;
8
+ displayName: string;
9
+ };
6
10
  export declare const CloseIcon: {
7
11
  (props: React.SVGProps<SVGSVGElement>): JSX.Element;
8
12
  displayName: string;
@@ -1,11 +1,24 @@
1
1
  import * as React from "react";
2
+ function svgIcon(name, children) {
3
+ const icon = (props) => (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24", "aria-hidden": "true", focusable: "false", ...props }, children));
4
+ icon.displayName = name;
5
+ return icon;
6
+ }
2
7
  export function createIcon(name, glyph) {
3
- const icon = (props) => (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "24", height: "24", "aria-hidden": "true", focusable: "false", ...props },
4
- React.createElement("g", { fill: "currentColor" },
8
+ return svgIcon(name, React.createElement("g", { fill: "currentColor" },
9
+ React.createElement("path", { d: "M0 0h24v24H0z", fill: "none" }),
10
+ glyph));
11
+ }
12
+ export function createIconDisabled(name, glyph) {
13
+ return svgIcon(name, React.createElement(React.Fragment, null,
14
+ React.createElement("defs", null,
15
+ React.createElement("mask", { id: "strike" },
16
+ React.createElement("path", { d: "M0 0h24v24H0z", fill: "white" }),
17
+ React.createElement("path", { d: "M0 0L24 24", stroke: "black", strokeWidth: 4 }))),
18
+ React.createElement("path", { d: "M0.70707 2.121320L21.878680 23.292883", stroke: "currentColor", strokeWidth: 2 }),
19
+ React.createElement("g", { fill: "currentColor", mask: "url(#strike)" },
5
20
  React.createElement("path", { d: "M0 0h24v24H0z", fill: "none" }),
6
21
  glyph)));
7
- icon.displayName = name;
8
- return icon;
9
22
  }
10
23
  export const CloseIcon = createIcon("Close", React.createElement("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }));
11
24
  export const PreviousIcon = createIcon("Previous", React.createElement("path", { d: "M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" }));
@@ -5,6 +5,7 @@ export declare const MODULE_NO_SCROLL = "no-scroll";
5
5
  export declare const MODULE_PORTAL = "portal";
6
6
  export declare const MODULE_ROOT = "root";
7
7
  export declare const MODULE_TOOLBAR = "toolbar";
8
+ export declare const PLUGIN_CAPTIONS = "captions";
8
9
  export declare const PLUGIN_COUNTER = "counter";
9
10
  export declare const PLUGIN_FULLSCREEN = "fullscreen";
10
11
  export declare const PLUGIN_INLINE = "inline";
@@ -5,6 +5,7 @@ export const MODULE_NO_SCROLL = "no-scroll";
5
5
  export const MODULE_PORTAL = "portal";
6
6
  export const MODULE_ROOT = "root";
7
7
  export const MODULE_TOOLBAR = "toolbar";
8
+ export const PLUGIN_CAPTIONS = "captions";
8
9
  export const PLUGIN_COUNTER = "counter";
9
10
  export const PLUGIN_FULLSCREEN = "fullscreen";
10
11
  export const PLUGIN_INLINE = "inline";
@@ -1,3 +1,3 @@
1
1
  import { PluginProps } from "../../types.js";
2
2
  /** Captions plugin */
3
- export declare function Captions({ augment }: PluginProps): void;
3
+ export declare function Captions({ augment, addModule }: PluginProps): void;
@@ -1,20 +1,28 @@
1
1
  import * as React from "react";
2
- import { resolveCaptionsProps } from "./props.js";
3
- import { Description } from "./Description.js";
2
+ import { createModule, PLUGIN_CAPTIONS } from "../../core/index.js";
4
3
  import { Title } from "./Title.js";
5
- export function Captions({ augment }) {
6
- augment(({ render: { slideFooter: renderFooter, ...restRender }, captions, styles, ...restProps }) => {
4
+ import { Description } from "./Description.js";
5
+ import { CaptionsButton } from "./CaptionsButton.js";
6
+ import { CaptionsContextProvider } from "./CaptionsContext.js";
7
+ import { resolveCaptionsProps } from "./props.js";
8
+ export function Captions({ augment, addModule }) {
9
+ augment(({ render: { slideFooter: renderFooter, ...restRender }, toolbar: { buttons, ...restToolbar }, captions: captionsProps, ...restProps }) => {
10
+ const captions = resolveCaptionsProps(captionsProps);
7
11
  return {
8
12
  render: {
9
13
  slideFooter: ({ slide }) => (React.createElement(React.Fragment, null, renderFooter === null || renderFooter === void 0 ? void 0 :
10
14
  renderFooter({ slide }),
11
- slide.title && React.createElement(Title, { styles: styles, title: slide.title }),
12
- slide.description && React.createElement(Description, { styles: styles, description: slide.description }))),
15
+ slide.title && React.createElement(Title, { title: slide.title }),
16
+ slide.description && React.createElement(Description, { description: slide.description }))),
13
17
  ...restRender,
14
18
  },
15
- captions: resolveCaptionsProps(captions),
16
- styles,
19
+ toolbar: {
20
+ buttons: [...(captions.showToggle ? [React.createElement(CaptionsButton, { key: PLUGIN_CAPTIONS })] : []), ...buttons],
21
+ ...restToolbar,
22
+ },
23
+ captions,
17
24
  ...restProps,
18
25
  };
19
26
  });
27
+ addModule(createModule(PLUGIN_CAPTIONS, CaptionsContextProvider));
20
28
  }
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function CaptionsButton(): JSX.Element;
@@ -0,0 +1,16 @@
1
+ import * as React from "react";
2
+ import { createIcon, createIconDisabled, IconButton, label, useLightboxProps } from "../../core/index.js";
3
+ import { useCaptions } from "./CaptionsContext.js";
4
+ const captionsIcon = () => (React.createElement(React.Fragment, null,
5
+ React.createElement("path", { strokeWidth: 2, stroke: "currentColor", strokeLinejoin: "round", fill: "none", d: "M3 5l18 0l0 14l-18 0l0-14z" }),
6
+ React.createElement("path", { d: "M7 15h3c.55 0 1-.45 1-1v-1H9.5v.5h-2v-3h2v.5H11v-1c0-.55-.45-1-1-1H7c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1zm7 0h3c.55 0 1-.45 1-1v-1h-1.5v.5h-2v-3h2v.5H18v-1c0-.55-.45-1-1-1h-3c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1z" })));
7
+ const CaptionsVisible = createIcon("CaptionsVisible", captionsIcon());
8
+ const CaptionsHidden = createIconDisabled("CaptionsVisible", captionsIcon());
9
+ export function CaptionsButton() {
10
+ const { visible, show, hide } = useCaptions();
11
+ const { render, labels } = useLightboxProps();
12
+ if (render.buttonCaptions) {
13
+ return React.createElement(React.Fragment, null, render.buttonCaptions({ visible, show, hide }));
14
+ }
15
+ return (React.createElement(IconButton, { label: label(labels, visible ? "Hide captions" : "Show captions"), icon: visible ? CaptionsVisible : CaptionsHidden, renderIcon: visible ? render.iconCaptionsVisible : render.iconCaptionsHidden, onClick: visible ? hide : show }));
16
+ }
@@ -0,0 +1,5 @@
1
+ import * as React from "react";
2
+ import { CaptionsRef, ComponentProps } from "../../types.js";
3
+ export declare const CaptionsContext: React.Context<CaptionsRef | null>;
4
+ export declare const useCaptions: () => CaptionsRef;
5
+ export declare function CaptionsContextProvider({ captions, children }: ComponentProps): JSX.Element;
@@ -0,0 +1,16 @@
1
+ import * as React from "react";
2
+ import { makeUseContext } from "../../core/index.js";
3
+ import { resolveCaptionsProps } from "./props.js";
4
+ export const CaptionsContext = React.createContext(null);
5
+ export const useCaptions = makeUseContext("useCaptions", "CaptionsContext", CaptionsContext);
6
+ export function CaptionsContextProvider({ captions, children }) {
7
+ const { ref } = resolveCaptionsProps(captions);
8
+ const [visible, setVisible] = React.useState(true);
9
+ const context = React.useMemo(() => ({
10
+ visible,
11
+ show: () => setVisible(true),
12
+ hide: () => setVisible(false),
13
+ }), [visible]);
14
+ React.useImperativeHandle(ref, () => context, [context]);
15
+ return React.createElement(CaptionsContext.Provider, { value: context }, children);
16
+ }
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { LightboxProps, Slide } from "../../types.js";
3
- export type DescriptionProps = Required<Pick<Slide, "description">> & Pick<LightboxProps, "styles">;
4
- export declare function Description({ description, styles }: DescriptionProps): JSX.Element;
2
+ import { Slide } from "../../types.js";
3
+ export type DescriptionProps = Pick<Slide, "description">;
4
+ export declare function Description({ description }: DescriptionProps): JSX.Element | null;
@@ -1,10 +1,14 @@
1
1
  import * as React from "react";
2
2
  import { clsx, cssVar, useLightboxProps } from "../../core/index.js";
3
- import { defaultCaptionsProps, resolveCaptionsProps } from "./props.js";
4
3
  import { cssPrefix } from "./utils.js";
5
- export function Description({ description, styles }) {
6
- const { captions } = useLightboxProps();
7
- const { descriptionTextAlign, descriptionMaxLines } = resolveCaptionsProps(captions);
4
+ import { defaultCaptionsProps, useCaptionsProps } from "./props.js";
5
+ import { useCaptions } from "./CaptionsContext.js";
6
+ export function Description({ description }) {
7
+ const { descriptionTextAlign, descriptionMaxLines } = useCaptionsProps();
8
+ const { styles } = useLightboxProps();
9
+ const { visible } = useCaptions();
10
+ if (!visible)
11
+ return null;
8
12
  return (React.createElement("div", { style: styles.captionsDescriptionContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("description_container")) },
9
13
  React.createElement("div", { className: cssPrefix("description"), style: {
10
14
  ...(descriptionTextAlign !== defaultCaptionsProps.descriptionTextAlign ||
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { LightboxProps, Slide } from "../../types.js";
3
- export type TitleProps = Pick<LightboxProps, "styles"> & Pick<Slide, "title">;
4
- export declare function Title({ title, styles }: TitleProps): JSX.Element;
2
+ import { Slide } from "../../types.js";
3
+ export type TitleProps = Pick<Slide, "title">;
4
+ export declare function Title({ title }: TitleProps): JSX.Element | null;
@@ -1,8 +1,16 @@
1
1
  import * as React from "react";
2
- import { clsx, cssVar, useController } from "../../core/index.js";
2
+ import { clsx, cssVar, useController, useLightboxProps } from "../../core/index.js";
3
3
  import { cssPrefix } from "./utils.js";
4
- export function Title({ title, styles }) {
4
+ import { useCaptions } from "./CaptionsContext.js";
5
+ export function Title({ title }) {
5
6
  const { toolbarWidth } = useController();
7
+ const { styles } = useLightboxProps();
8
+ const { visible } = useCaptions();
9
+ if (!visible)
10
+ return null;
6
11
  return (React.createElement("div", { style: styles.captionsTitleContainer, className: clsx(cssPrefix("captions_container"), cssPrefix("title_container")) },
7
- React.createElement("div", { style: styles.captionsTitle, className: cssPrefix("title"), ...(toolbarWidth ? { style: { [cssVar("toolbar_width")]: `${toolbarWidth}px` } } : null) }, title)));
12
+ React.createElement("div", { className: cssPrefix("title"), style: {
13
+ ...(toolbarWidth ? { [cssVar("toolbar_width")]: `${toolbarWidth}px` } : null),
14
+ ...styles.captionsTitle,
15
+ } }, title)));
8
16
  }
@@ -11,6 +11,10 @@ declare module "../../types.js" {
11
11
  interface LightboxProps {
12
12
  /** Captions plugin settings */
13
13
  captions?: {
14
+ /** Captions plugin ref */
15
+ ref?: React.ForwardedRef<CaptionsRef>;
16
+ /** if `true`, show Captions Toggle button in the toolbar */
17
+ showToggle?: boolean;
14
18
  /** description text alignment */
15
19
  descriptionTextAlign?: TextAlignment;
16
20
  /** maximum number of lines to display in the description section */
@@ -27,5 +31,22 @@ declare module "../../types.js" {
27
31
  /** captions description container customization slot */
28
32
  captionsDescriptionContainer: "captionsDescriptionContainer";
29
33
  }
34
+ interface Render {
35
+ /** render custom Captions Visible icon */
36
+ iconCaptionsVisible?: RenderFunction;
37
+ /** render custom Captions Hidden icon */
38
+ iconCaptionsHidden?: RenderFunction;
39
+ /** render custom Captions button */
40
+ buttonCaptions?: RenderFunction<CaptionsRef>;
41
+ }
42
+ /** Captions plugin ref */
43
+ interface CaptionsRef {
44
+ /** if `true`, captions are visible */
45
+ visible: boolean;
46
+ /** show captions */
47
+ show: Callback;
48
+ /** hide captions */
49
+ hide: Callback;
50
+ }
30
51
  }
31
52
  export default Captions;
@@ -1,9 +1,19 @@
1
+ /// <reference types="react" />
1
2
  import { LightboxProps } from "../../types.js";
2
3
  export declare const defaultCaptionsProps: {
3
4
  descriptionTextAlign: "start";
4
5
  descriptionMaxLines: number;
6
+ showToggle: boolean;
5
7
  };
6
8
  export declare const resolveCaptionsProps: (captions: LightboxProps["captions"]) => {
9
+ ref?: import("react").ForwardedRef<import("../../types.js").CaptionsRef> | undefined;
10
+ showToggle: boolean;
11
+ descriptionTextAlign: import("../../types.js").TextAlignment;
12
+ descriptionMaxLines: number;
13
+ };
14
+ export declare function useCaptionsProps(): {
15
+ ref?: import("react").ForwardedRef<import("../../types.js").CaptionsRef> | undefined;
16
+ showToggle: boolean;
7
17
  descriptionTextAlign: import("../../types.js").TextAlignment;
8
18
  descriptionMaxLines: number;
9
19
  };
@@ -1,8 +1,14 @@
1
+ import { useLightboxProps } from "../../core/index.js";
1
2
  export const defaultCaptionsProps = {
2
3
  descriptionTextAlign: "start",
3
4
  descriptionMaxLines: 3,
5
+ showToggle: false,
4
6
  };
5
7
  export const resolveCaptionsProps = (captions) => ({
6
8
  ...defaultCaptionsProps,
7
9
  ...captions,
8
10
  });
11
+ export function useCaptionsProps() {
12
+ const { captions } = useLightboxProps();
13
+ return resolveCaptionsProps(captions);
14
+ }
@@ -1,12 +1,21 @@
1
+ import * as React from "react";
1
2
  import { createModule, MODULE_CONTROLLER, PLUGIN_FULLSCREEN, PLUGIN_THUMBNAILS } from "../../core/index.js";
2
3
  import { resolveThumbnailsProps } from "./props.js";
3
- import { ThumbnailsContainer } from "./ThumbnailsContainer.js";
4
+ import { ThumbnailsContextProvider } from "./ThumbnailsContext.js";
5
+ import { ThumbnailsButton } from "./ThumbnailsButton.js";
4
6
  export function Thumbnails({ augment, contains, append, addParent }) {
5
- augment(({ thumbnails, ...restProps }) => ({
6
- thumbnails: resolveThumbnailsProps(thumbnails),
7
- ...restProps,
8
- }));
9
- const module = createModule(PLUGIN_THUMBNAILS, ThumbnailsContainer);
7
+ augment(({ thumbnails: thumbnailsProps, toolbar: { buttons, ...restToolbar }, ...restProps }) => {
8
+ const thumbnails = resolveThumbnailsProps(thumbnailsProps);
9
+ return {
10
+ toolbar: {
11
+ buttons: [...(thumbnails.showToggle ? [React.createElement(ThumbnailsButton, { key: PLUGIN_THUMBNAILS })] : []), ...buttons],
12
+ ...restToolbar,
13
+ },
14
+ thumbnails,
15
+ ...restProps,
16
+ };
17
+ });
18
+ const module = createModule(PLUGIN_THUMBNAILS, ThumbnailsContextProvider);
10
19
  if (contains(PLUGIN_FULLSCREEN)) {
11
20
  append(PLUGIN_FULLSCREEN, module);
12
21
  }
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function ThumbnailsButton(): JSX.Element;
@@ -0,0 +1,16 @@
1
+ import * as React from "react";
2
+ import { createIcon, createIconDisabled, IconButton, label, useLightboxProps } from "../../core/index.js";
3
+ import { useThumbnails } from "./ThumbnailsContext.js";
4
+ const thumbnailsIcon = () => (React.createElement(React.Fragment, null,
5
+ React.createElement("path", { strokeWidth: 2, stroke: "currentColor", strokeLinejoin: "round", fill: "none", d: "M3 5l18 0l0 14l-18 0l0-14z" }),
6
+ React.createElement("path", { d: "M5 14h4v3h-4zM10 14h4v3h-4zM15 14h4v3h-4z" })));
7
+ const ThumbnailsVisible = createIcon("ThumbnailsVisible", thumbnailsIcon());
8
+ const ThumbnailsHidden = createIconDisabled("ThumbnailsHidden", thumbnailsIcon());
9
+ export function ThumbnailsButton() {
10
+ const { visible, show, hide } = useThumbnails();
11
+ const { render, labels } = useLightboxProps();
12
+ if (render.buttonThumbnails) {
13
+ return React.createElement(React.Fragment, null, render.buttonThumbnails({ visible, show, hide }));
14
+ }
15
+ return (React.createElement(IconButton, { label: label(labels, visible ? "Hide thumbnails" : "Show thumbnails"), icon: visible ? ThumbnailsVisible : ThumbnailsHidden, renderIcon: visible ? render.iconThumbnailsVisible : render.iconThumbnailsHidden, onClick: visible ? hide : show }));
16
+ }
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ import { ComponentProps, ThumbnailsRef } from "../../types.js";
3
+ export declare const ThumbnailsContext: React.Context<ThumbnailsRef | null>;
4
+ export declare const useThumbnails: () => ThumbnailsRef;
5
+ /** Thumbnails plugin component */
6
+ export declare function ThumbnailsContextProvider({ children, ...props }: ComponentProps): JSX.Element;
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ import { clsx, cssClass, LightboxPropsProvider, makeUseContext } from "../../core/index.js";
3
+ import { cssPrefix } from "./utils.js";
4
+ import { ThumbnailsTrack } from "./ThumbnailsTrack.js";
5
+ import { resolveThumbnailsProps } from "./props.js";
6
+ export const ThumbnailsContext = React.createContext(null);
7
+ export const useThumbnails = makeUseContext("useThumbnails", "ThumbnailsContext", ThumbnailsContext);
8
+ export function ThumbnailsContextProvider({ children, ...props }) {
9
+ const [visible, setVisible] = React.useState(true);
10
+ const containerRef = React.useRef(null);
11
+ const { ref, position } = resolveThumbnailsProps(props.thumbnails);
12
+ const context = React.useMemo(() => ({
13
+ visible,
14
+ show: () => setVisible(true),
15
+ hide: () => setVisible(false),
16
+ }), [visible]);
17
+ React.useImperativeHandle(ref, () => context, [context]);
18
+ return (React.createElement(LightboxPropsProvider, { ...props },
19
+ React.createElement(ThumbnailsContext.Provider, { value: context },
20
+ React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssPrefix()), cssClass(cssPrefix(`${position}`))) },
21
+ ["start", "top"].includes(position) && React.createElement(ThumbnailsTrack, { containerRef: containerRef }),
22
+ React.createElement("div", { className: cssClass(cssPrefix("wrapper")) }, children),
23
+ ["end", "bottom"].includes(position) && React.createElement(ThumbnailsTrack, { containerRef: containerRef })))));
24
+ }
@@ -1,6 +1,4 @@
1
1
  import * as React from "react";
2
- import { DeepNonNullable, LightboxProps } from "../../types.js";
3
- export type ThumbnailsInternal = DeepNonNullable<LightboxProps["thumbnails"]>;
4
2
  export type ThumbnailsTrackProps = {
5
3
  containerRef: React.RefObject<HTMLDivElement>;
6
4
  };
@@ -3,6 +3,7 @@ import { ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, CLASS_FLEX_CENTER, cleanup, cls
3
3
  import { cssPrefix, cssThumbnailPrefix } from "./utils.js";
4
4
  import { Thumbnail } from "./Thumbnail.js";
5
5
  import { defaultThumbnailsProps, useThumbnailsProps } from "./props.js";
6
+ import { useThumbnails } from "./ThumbnailsContext.js";
6
7
  function isHorizontal(position) {
7
8
  return ["top", "bottom"].includes(position);
8
9
  }
@@ -11,6 +12,7 @@ function boxSize(thumbnails, dimension, includeGap) {
11
12
  }
12
13
  export function ThumbnailsTrack({ containerRef }) {
13
14
  const track = React.useRef(null);
15
+ const { visible } = useThumbnails();
14
16
  const { carousel, styles } = useLightboxProps();
15
17
  const { slides, globalIndex, animation } = useLightboxState().state;
16
18
  const { publish, subscribe } = useEvents();
@@ -93,6 +95,7 @@ export function ThumbnailsTrack({ containerRef }) {
93
95
  }
94
96
  };
95
97
  return (React.createElement("div", { className: clsx(cssClass(cssPrefix("container")), cssClass(CLASS_FLEX_CENTER)), style: {
98
+ ...(!visible ? { display: "none" } : null),
96
99
  ...(width !== defaultThumbnailsProps.width
97
100
  ? { [cssVar(cssThumbnailPrefix("width"))]: `${boxSize(thumbnails, width)}px` }
98
101
  : null),
@@ -1,9 +1,12 @@
1
+ /// <reference types="react" />
1
2
  import { Thumbnails } from "./Thumbnails.js";
2
3
  type Position = "top" | "bottom" | "start" | "end";
3
4
  declare module "../../types.js" {
4
5
  interface LightboxProps {
5
6
  /** Thumbnails plugin settings */
6
7
  thumbnails?: {
8
+ /** Thumbnails plugin ref */
9
+ ref?: React.ForwardedRef<ThumbnailsRef>;
7
10
  /** thumbnails position */
8
11
  position?: Position;
9
12
  /** thumbnail width */
@@ -20,13 +23,21 @@ declare module "../../types.js" {
20
23
  gap?: number;
21
24
  /** `object-fit` setting */
22
25
  imageFit?: ImageFit;
23
- /** vignette effect on the edges of the thumbnails track */
26
+ /** if `true`, show the vignette effect on the edges of the thumbnails track */
24
27
  vignette?: boolean;
28
+ /** if `true`, show the Toggle Thumbnails button in the toolbar */
29
+ showToggle?: boolean;
25
30
  };
26
31
  }
27
32
  interface Render {
28
33
  /** render custom thumbnail */
29
34
  thumbnail?: RenderFunction<RenderThumbnailProps>;
35
+ /** render custom Thumbnails Visible icon */
36
+ iconThumbnailsVisible?: RenderFunction;
37
+ /** render custom Thumbnails Hidden icon */
38
+ iconThumbnailsHidden?: RenderFunction;
39
+ /** render custom Thumbnails button */
40
+ buttonThumbnails?: RenderFunction<ThumbnailsRef>;
30
41
  }
31
42
  /** `render.thumbnail` render function props */
32
43
  type RenderThumbnailProps = {
@@ -43,5 +54,14 @@ declare module "../../types.js" {
43
54
  /** thumbnails container customization slot */
44
55
  thumbnailsContainer: "thumbnailsContainer";
45
56
  }
57
+ /** Thumbnails plugin ref */
58
+ interface ThumbnailsRef {
59
+ /** if `true`, thumbnails are visible */
60
+ visible: boolean;
61
+ /** show thumbnails */
62
+ show: Callback;
63
+ /** hide thuumbnails */
64
+ hide: Callback;
65
+ }
46
66
  }
47
67
  export default Thumbnails;
@@ -1,5 +1,7 @@
1
+ /// <reference types="react" />
1
2
  import { LightboxProps } from "../../types.js";
2
3
  export declare const defaultThumbnailsProps: {
4
+ ref: null;
3
5
  position: "bottom";
4
6
  width: number;
5
7
  height: number;
@@ -11,6 +13,7 @@ export declare const defaultThumbnailsProps: {
11
13
  vignette: boolean;
12
14
  };
13
15
  export declare const resolveThumbnailsProps: (thumbnails: LightboxProps["thumbnails"]) => {
16
+ ref: import("react").ForwardedRef<import("../../types.js").ThumbnailsRef>;
14
17
  position: "end" | "start" | "bottom" | "top";
15
18
  width: number;
16
19
  height: number;
@@ -20,8 +23,10 @@ export declare const resolveThumbnailsProps: (thumbnails: LightboxProps["thumbna
20
23
  gap: number;
21
24
  imageFit: import("../../types.js").ImageFit;
22
25
  vignette: boolean;
26
+ showToggle?: boolean | undefined;
23
27
  };
24
28
  export declare function useThumbnailsProps(): {
29
+ ref: import("react").ForwardedRef<import("../../types.js").ThumbnailsRef>;
25
30
  position: "end" | "start" | "bottom" | "top";
26
31
  width: number;
27
32
  height: number;
@@ -31,4 +36,5 @@ export declare function useThumbnailsProps(): {
31
36
  gap: number;
32
37
  imageFit: import("../../types.js").ImageFit;
33
38
  vignette: boolean;
39
+ showToggle?: boolean | undefined;
34
40
  };
@@ -1,5 +1,6 @@
1
1
  import { useLightboxProps } from "../../core/index.js";
2
2
  export const defaultThumbnailsProps = {
3
+ ref: null,
3
4
  position: "bottom",
4
5
  width: 120,
5
6
  height: 80,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- import { ComponentProps } from "../../types.js";
3
- /** Thumbnails plugin component */
4
- export declare function ThumbnailsContainer({ children, ...props }: ComponentProps): JSX.Element;
@@ -1,14 +0,0 @@
1
- import * as React from "react";
2
- import { clsx, cssClass, LightboxPropsProvider } from "../../core/index.js";
3
- import { cssPrefix } from "./utils.js";
4
- import { ThumbnailsTrack } from "./ThumbnailsTrack.js";
5
- import { resolveThumbnailsProps } from "./props.js";
6
- export function ThumbnailsContainer({ children, ...props }) {
7
- const containerRef = React.useRef(null);
8
- const { position } = resolveThumbnailsProps(props.thumbnails);
9
- return (React.createElement(LightboxPropsProvider, { ...props },
10
- React.createElement("div", { ref: containerRef, className: clsx(cssClass(cssPrefix()), cssClass(cssPrefix(`${position}`))) },
11
- ["start", "top"].includes(position) && React.createElement(ThumbnailsTrack, { containerRef: containerRef }),
12
- React.createElement("div", { className: cssClass(cssPrefix("wrapper")) }, children),
13
- ["end", "bottom"].includes(position) && React.createElement(ThumbnailsTrack, { containerRef: containerRef }))));
14
- }