yet-another-react-lightbox 3.2.0 → 3.3.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.
@@ -1,9 +1,8 @@
1
1
  import * as React from "react";
2
- import { clsx, cssClass } from "../utils.js";
2
+ import { clsx, cssClass, label as translateLabel } from "../utils.js";
3
3
  import { useLightboxProps } from "../contexts/index.js";
4
4
  import { ELEMENT_BUTTON, ELEMENT_ICON } from "../consts.js";
5
- export const IconButton = React.forwardRef(({ label, className, icon: Icon, renderIcon, onClick, style, ...rest }, ref) => {
6
- const { styles } = useLightboxProps();
7
- return (React.createElement("button", { ref: ref, type: "button", "aria-label": label, className: clsx(cssClass(ELEMENT_BUTTON), className), onClick: onClick, style: { ...style, ...styles.button }, ...rest }, renderIcon ? renderIcon() : React.createElement(Icon, { className: cssClass(ELEMENT_ICON), style: styles.icon })));
5
+ export const IconButton = React.forwardRef(function IconButton({ label, className, icon: Icon, renderIcon, onClick, style, ...rest }, ref) {
6
+ const { styles, labels } = useLightboxProps();
7
+ return (React.createElement("button", { ref: ref, type: "button", "aria-label": translateLabel(labels, label), className: clsx(cssClass(ELEMENT_BUTTON), className), onClick: onClick, style: { ...style, ...styles.button }, ...rest }, renderIcon ? renderIcon() : React.createElement(Icon, { className: cssClass(ELEMENT_ICON), style: styles.icon })));
8
8
  });
9
- IconButton.displayName = "IconButton";
@@ -1,14 +1,13 @@
1
1
  import * as React from "react";
2
2
  import { createModule } from "../config.js";
3
3
  import { useEventCallback, useLoseFocus, useRTL, useThrottle } from "../hooks/index.js";
4
- import { cssClass, label as translateLabel } from "../utils.js";
4
+ import { cssClass } from "../utils.js";
5
5
  import { IconButton, NextIcon, PreviousIcon } from "../components/index.js";
6
- import { useLightboxProps, useLightboxState } from "../contexts/index.js";
6
+ import { 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
9
  export function NavigationButton({ label, icon, renderIcon, action, onClick, disabled }) {
10
- const { labels } = useLightboxProps();
11
- return (React.createElement(IconButton, { label: translateLabel(labels, label), icon: icon, renderIcon: renderIcon, className: cssClass(`navigation_${action}`), disabled: disabled, onClick: onClick, ...useLoseFocus(disabled) }));
10
+ return (React.createElement(IconButton, { label: label, icon: icon, renderIcon: renderIcon, className: cssClass(`navigation_${action}`), disabled: disabled, onClick: onClick, ...useLoseFocus(disabled) }));
12
11
  }
13
12
  export function Navigation({ carousel: { finite }, animation, render: { buttonPrev, buttonNext, iconPrev, iconNext }, }) {
14
13
  var _a;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { ComponentProps } from "../../types.js";
3
- export declare function Toolbar({ toolbar: { buttons }, labels, render: { buttonClose, iconClose } }: ComponentProps): JSX.Element;
3
+ export declare function Toolbar({ toolbar: { buttons }, render: { buttonClose, iconClose } }: ComponentProps): JSX.Element;
4
4
  export declare const ToolbarModule: import("../../types.js").Module;
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { createModule } from "../config.js";
3
- import { composePrefix, cssClass, label } from "../utils.js";
3
+ import { useLayoutEffect } from "../hooks/index.js";
4
+ import { composePrefix, cssClass } from "../utils.js";
4
5
  import { CloseIcon, IconButton } from "../components/index.js";
5
6
  import { useContainerRect } from "../hooks/useContainerRect.js";
6
7
  import { useController } from "./Controller.js";
@@ -8,13 +9,17 @@ import { ACTION_CLOSE, MODULE_TOOLBAR } from "../consts.js";
8
9
  function cssPrefix(value) {
9
10
  return composePrefix(MODULE_TOOLBAR, value);
10
11
  }
11
- export function Toolbar({ toolbar: { buttons }, labels, render: { buttonClose, iconClose } }) {
12
+ export function Toolbar({ toolbar: { buttons }, render: { buttonClose, iconClose } }) {
12
13
  const { close, setToolbarWidth } = useController();
13
14
  const { setContainerRef, containerRect } = useContainerRect();
14
- React.useEffect(() => {
15
+ useLayoutEffect(() => {
15
16
  setToolbarWidth(containerRect === null || containerRect === void 0 ? void 0 : containerRect.width);
16
17
  }, [setToolbarWidth, containerRect === null || containerRect === void 0 ? void 0 : containerRect.width]);
17
- const renderCloseButton = () => buttonClose ? (buttonClose()) : (React.createElement(IconButton, { key: ACTION_CLOSE, label: label(labels, "Close"), icon: CloseIcon, renderIcon: iconClose, onClick: () => close() }));
18
+ const renderCloseButton = () => {
19
+ if (buttonClose)
20
+ return buttonClose();
21
+ return React.createElement(IconButton, { key: ACTION_CLOSE, label: "Close", icon: CloseIcon, renderIcon: iconClose, onClick: close });
22
+ };
18
23
  return (React.createElement("div", { ref: setContainerRef, className: cssClass(cssPrefix()) }, buttons === null || buttons === void 0 ? void 0 : buttons.map((button) => (button === ACTION_CLOSE ? renderCloseButton() : button))));
19
24
  }
20
25
  export const ToolbarModule = createModule(MODULE_TOOLBAR, Toolbar);
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { ContainerRect, Labels, LengthOrPercentage, LightboxProps, Slide, SlideImage } from "../types.js";
2
+ import { ContainerRect, Labels, LengthOrPercentage, LightboxProps, Slide, SlideImage, ToolbarSettings } from "../types.js";
3
3
  export declare const clsx: (...classes: (string | boolean | undefined)[]) => string;
4
4
  export declare const cssClass: (name: string) => string;
5
5
  export declare const cssVar: (name: string) => string;
@@ -26,3 +26,4 @@ export declare function computeSlideRect(containerRect: ContainerRect, padding:
26
26
  export declare const devicePixelRatio: () => number;
27
27
  export declare const getSlideIndex: (index: number, slidesCount: number) => number;
28
28
  export declare const getSlide: (slides: Slide[], index: number) => Slide;
29
+ export declare function addToolbarButton(toolbar: ToolbarSettings, key: string, button: React.ReactNode): ToolbarSettings;
@@ -47,3 +47,16 @@ export function computeSlideRect(containerRect, padding) {
47
47
  export const devicePixelRatio = () => (hasWindow() ? window === null || window === void 0 ? void 0 : window.devicePixelRatio : undefined) || 1;
48
48
  export const getSlideIndex = (index, slidesCount) => ((index % slidesCount) + slidesCount) % slidesCount;
49
49
  export const getSlide = (slides, index) => slides[getSlideIndex(index, slides.length)];
50
+ export function addToolbarButton(toolbar, key, button) {
51
+ if (!button)
52
+ return toolbar;
53
+ const { buttons, ...restToolbar } = toolbar;
54
+ const index = buttons.findIndex((item) => item === key);
55
+ const buttonWithKey = React.isValidElement(button) ? React.cloneElement(button, { key }, null) : button;
56
+ if (index >= 0) {
57
+ const result = [...buttons];
58
+ result.splice(index, 1, buttonWithKey);
59
+ return { buttons: result, ...restToolbar };
60
+ }
61
+ return { buttons: [buttonWithKey, ...buttons], ...restToolbar };
62
+ }
@@ -1,12 +1,12 @@
1
1
  import * as React from "react";
2
- import { createModule, PLUGIN_CAPTIONS } from "../../core/index.js";
2
+ import { addToolbarButton, createModule, PLUGIN_CAPTIONS } from "../../core/index.js";
3
3
  import { Title } from "./Title.js";
4
4
  import { Description } from "./Description.js";
5
5
  import { CaptionsButton } from "./CaptionsButton.js";
6
6
  import { CaptionsContextProvider } from "./CaptionsContext.js";
7
7
  import { resolveCaptionsProps } from "./props.js";
8
8
  export function Captions({ augment, addModule }) {
9
- augment(({ render: { slideFooter: renderFooter, ...restRender }, toolbar: { buttons, ...restToolbar }, captions: captionsProps, ...restProps }) => {
9
+ augment(({ captions: captionsProps, render: { slideFooter: renderFooter, ...restRender }, toolbar, ...restProps }) => {
10
10
  const captions = resolveCaptionsProps(captionsProps);
11
11
  return {
12
12
  render: {
@@ -16,10 +16,7 @@ export function Captions({ augment, addModule }) {
16
16
  slide.description && React.createElement(Description, { description: slide.description }))),
17
17
  ...restRender,
18
18
  },
19
- toolbar: {
20
- buttons: [...(captions.showToggle ? [React.createElement(CaptionsButton, { key: PLUGIN_CAPTIONS })] : []), ...buttons],
21
- ...restToolbar,
22
- },
19
+ toolbar: addToolbarButton(toolbar, PLUGIN_CAPTIONS, captions.showToggle ? React.createElement(CaptionsButton, null) : null),
23
20
  captions,
24
21
  ...restProps,
25
22
  };
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { createIcon, createIconDisabled, IconButton, label, useLightboxProps } from "../../core/index.js";
2
+ import { createIcon, createIconDisabled, IconButton, useLightboxProps } from "../../core/index.js";
3
3
  import { useCaptions } from "./CaptionsContext.js";
4
4
  const captionsIcon = () => (React.createElement(React.Fragment, null,
5
5
  React.createElement("path", { strokeWidth: 2, stroke: "currentColor", strokeLinejoin: "round", fill: "none", d: "M3 5l18 0l0 14l-18 0l0-14z" }),
@@ -8,9 +8,9 @@ const CaptionsVisible = createIcon("CaptionsVisible", captionsIcon());
8
8
  const CaptionsHidden = createIconDisabled("CaptionsVisible", captionsIcon());
9
9
  export function CaptionsButton() {
10
10
  const { visible, show, hide } = useCaptions();
11
- const { render, labels } = useLightboxProps();
11
+ const { render } = useLightboxProps();
12
12
  if (render.buttonCaptions) {
13
13
  return React.createElement(React.Fragment, null, render.buttonCaptions({ visible, show, hide }));
14
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 }));
15
+ return (React.createElement(IconButton, { label: visible ? "Hide captions" : "Show captions", icon: visible ? CaptionsVisible : CaptionsHidden, renderIcon: visible ? render.iconCaptionsVisible : render.iconCaptionsHidden, onClick: visible ? hide : show }));
16
16
  }
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { PLUGIN_CAPTIONS } from "../../core/index.js";
2
3
  import { Captions } from "./Captions.js";
3
4
  declare module "../../types.js" {
4
5
  type TextAlignment = "start" | "end" | "center";
@@ -8,6 +9,9 @@ declare module "../../types.js" {
8
9
  /** slide description */
9
10
  description?: React.ReactNode;
10
11
  }
12
+ interface ToolbarButtonKeys {
13
+ [PLUGIN_CAPTIONS]: null;
14
+ }
11
15
  interface LightboxProps {
12
16
  /** Captions plugin settings */
13
17
  captions?: {
@@ -1,2 +1,3 @@
1
+ import { PLUGIN_CAPTIONS } from "../../core/index.js";
1
2
  import { Captions } from "./Captions.js";
2
3
  export default Captions;
@@ -1,11 +1,11 @@
1
1
  import * as React from "react";
2
- import { createModule, MODULE_CONTROLLER, PLUGIN_FULLSCREEN, PLUGIN_THUMBNAILS } from "../../core/index.js";
2
+ import { addToolbarButton, createModule, MODULE_CONTROLLER, PLUGIN_FULLSCREEN, PLUGIN_THUMBNAILS, } from "../../core/index.js";
3
3
  import { resolveFullscreenProps } from "./props.js";
4
4
  import { FullscreenButton } from "./FullscreenButton.js";
5
5
  import { FullscreenContextProvider } from "./FullscreenContext.js";
6
6
  export function Fullscreen({ augment, contains, addParent }) {
7
- augment(({ fullscreen, toolbar: { buttons, ...restToolbar }, ...restProps }) => ({
8
- toolbar: { buttons: [React.createElement(FullscreenButton, { key: PLUGIN_FULLSCREEN }), ...buttons], ...restToolbar },
7
+ augment(({ fullscreen, toolbar, ...restProps }) => ({
8
+ toolbar: addToolbarButton(toolbar, PLUGIN_FULLSCREEN, React.createElement(FullscreenButton, null)),
9
9
  fullscreen: resolveFullscreenProps(fullscreen),
10
10
  ...restProps,
11
11
  }));
@@ -1,16 +1,16 @@
1
1
  import * as React from "react";
2
- import { createIcon, IconButton, label, useLightboxProps } from "../../core/index.js";
2
+ import { createIcon, IconButton, useLightboxProps } from "../../core/index.js";
3
3
  import { useFullscreen } from "./FullscreenContext.js";
4
4
  const EnterFullscreenIcon = createIcon("EnterFullscreen", React.createElement("path", { d: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" }));
5
5
  const ExitFullscreenIcon = createIcon("ExitFullscreen", React.createElement("path", { d: "M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z" }));
6
6
  export function FullscreenButton() {
7
7
  var _a;
8
8
  const { fullscreen, disabled, enter, exit } = useFullscreen();
9
- const { labels, render } = useLightboxProps();
9
+ const { render } = useLightboxProps();
10
10
  if (disabled)
11
11
  return null;
12
12
  if (render.buttonFullscreen) {
13
13
  return React.createElement(React.Fragment, null, (_a = render.buttonFullscreen) === null || _a === void 0 ? void 0 : _a.call(render, { fullscreen, disabled, enter, exit }));
14
14
  }
15
- return (React.createElement(IconButton, { disabled: disabled, label: label(labels, fullscreen ? "Exit Fullscreen" : "Enter Fullscreen"), icon: fullscreen ? ExitFullscreenIcon : EnterFullscreenIcon, renderIcon: fullscreen ? render.iconExitFullscreen : render.iconEnterFullscreen, onClick: fullscreen ? exit : enter }));
15
+ return (React.createElement(IconButton, { disabled: disabled, label: fullscreen ? "Exit Fullscreen" : "Enter Fullscreen", icon: fullscreen ? ExitFullscreenIcon : EnterFullscreenIcon, renderIcon: fullscreen ? render.iconExitFullscreen : render.iconEnterFullscreen, onClick: fullscreen ? exit : enter }));
16
16
  }
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { PLUGIN_FULLSCREEN } from "../../core/index.js";
2
3
  import { Fullscreen } from "./Fullscreen.js";
3
4
  declare module "../../types.js" {
4
5
  interface LightboxProps {
@@ -18,6 +19,9 @@ declare module "../../types.js" {
18
19
  /** render custom Exit Fullscreen icon */
19
20
  iconExitFullscreen?: RenderFunction;
20
21
  }
22
+ interface ToolbarButtonKeys {
23
+ [PLUGIN_FULLSCREEN]: null;
24
+ }
21
25
  /** Fullscreen plugin ref */
22
26
  interface FullscreenRef {
23
27
  /** current fullscreen status */
@@ -1,2 +1,3 @@
1
+ import { PLUGIN_FULLSCREEN } from "../../core/index.js";
1
2
  import { Fullscreen } from "./Fullscreen.js";
2
3
  export default Fullscreen;
@@ -1,11 +1,11 @@
1
1
  import * as React from "react";
2
- import { createModule, PLUGIN_SLIDESHOW } from "../../core/index.js";
2
+ import { addToolbarButton, createModule, PLUGIN_SLIDESHOW } from "../../core/index.js";
3
3
  import { resolveSlideshowProps } from "./props.js";
4
4
  import { SlideshowContextProvider } from "./SlideshowContext.js";
5
5
  import { SlideshowButton } from "./SlideshowButton.js";
6
6
  export function Slideshow({ augment, addModule }) {
7
- augment(({ slideshow, toolbar: { buttons, ...restToolbar }, ...restProps }) => ({
8
- toolbar: { buttons: [React.createElement(SlideshowButton, { key: PLUGIN_SLIDESHOW }), ...buttons], ...restToolbar },
7
+ augment(({ slideshow, toolbar, ...restProps }) => ({
8
+ toolbar: addToolbarButton(toolbar, PLUGIN_SLIDESHOW, React.createElement(SlideshowButton, null)),
9
9
  slideshow: resolveSlideshowProps(slideshow),
10
10
  ...restProps,
11
11
  }));
@@ -1,14 +1,14 @@
1
1
  import * as React from "react";
2
- import { createIcon, IconButton, label, useLightboxProps, useLoseFocus } from "../../core/index.js";
2
+ import { createIcon, IconButton, useLightboxProps, useLoseFocus } from "../../core/index.js";
3
3
  import { useSlideshow } from "./SlideshowContext.js";
4
4
  const PlayIcon = createIcon("Play", React.createElement("path", { d: "M8 5v14l11-7z" }));
5
5
  const PauseIcon = createIcon("Pause", React.createElement("path", { d: "M6 19h4V5H6v14zm8-14v14h4V5h-4z" }));
6
6
  export function SlideshowButton() {
7
7
  const { playing, disabled, play, pause } = useSlideshow();
8
- const { render, labels } = useLightboxProps();
8
+ const { render } = useLightboxProps();
9
9
  const focusListeners = useLoseFocus(disabled);
10
10
  if (render.buttonSlideshow) {
11
11
  return React.createElement(React.Fragment, null, render.buttonSlideshow({ playing, disabled, play, pause }));
12
12
  }
13
- return (React.createElement(IconButton, { label: label(labels, playing ? "Pause" : "Play"), icon: playing ? PauseIcon : PlayIcon, renderIcon: playing ? render.iconSlideshowPause : render.iconSlideshowPlay, onClick: playing ? pause : play, disabled: disabled, ...focusListeners }));
13
+ return (React.createElement(IconButton, { label: playing ? "Pause" : "Play", icon: playing ? PauseIcon : PlayIcon, renderIcon: playing ? render.iconSlideshowPause : render.iconSlideshowPlay, onClick: playing ? pause : play, disabled: disabled, ...focusListeners }));
14
14
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { PLUGIN_SLIDESHOW } from "../../core/index.js";
2
3
  import { Slideshow } from "./Slideshow.js";
3
4
  declare module "../../types.js" {
4
5
  interface LightboxProps {
@@ -20,6 +21,9 @@ declare module "../../types.js" {
20
21
  /** render custom Slideshow button */
21
22
  buttonSlideshow?: RenderFunction<SlideshowRef>;
22
23
  }
24
+ interface ToolbarButtonKeys {
25
+ [PLUGIN_SLIDESHOW]: null;
26
+ }
23
27
  /** Slideshow plugin ref */
24
28
  interface SlideshowRef {
25
29
  /** current slideshow playback status */
@@ -1,2 +1,3 @@
1
+ import { PLUGIN_SLIDESHOW } from "../../core/index.js";
1
2
  import { Slideshow } from "./Slideshow.js";
2
3
  export default Slideshow;
@@ -1,16 +1,13 @@
1
1
  import * as React from "react";
2
- import { createModule, MODULE_CONTROLLER, PLUGIN_FULLSCREEN, PLUGIN_THUMBNAILS } from "../../core/index.js";
2
+ import { addToolbarButton, createModule, MODULE_CONTROLLER, PLUGIN_FULLSCREEN, PLUGIN_THUMBNAILS, } from "../../core/index.js";
3
3
  import { resolveThumbnailsProps } from "./props.js";
4
4
  import { ThumbnailsContextProvider } from "./ThumbnailsContext.js";
5
5
  import { ThumbnailsButton } from "./ThumbnailsButton.js";
6
6
  export function Thumbnails({ augment, contains, append, addParent }) {
7
- augment(({ thumbnails: thumbnailsProps, toolbar: { buttons, ...restToolbar }, ...restProps }) => {
7
+ augment(({ thumbnails: thumbnailsProps, toolbar, ...restProps }) => {
8
8
  const thumbnails = resolveThumbnailsProps(thumbnailsProps);
9
9
  return {
10
- toolbar: {
11
- buttons: [...(thumbnails.showToggle ? [React.createElement(ThumbnailsButton, { key: PLUGIN_THUMBNAILS })] : []), ...buttons],
12
- ...restToolbar,
13
- },
10
+ toolbar: addToolbarButton(toolbar, PLUGIN_THUMBNAILS, thumbnails.showToggle ? React.createElement(ThumbnailsButton, null) : null),
14
11
  thumbnails,
15
12
  ...restProps,
16
13
  };
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { createIcon, createIconDisabled, IconButton, label, useLightboxProps } from "../../core/index.js";
2
+ import { createIcon, createIconDisabled, IconButton, useLightboxProps } from "../../core/index.js";
3
3
  import { useThumbnails } from "./ThumbnailsContext.js";
4
4
  const thumbnailsIcon = () => (React.createElement(React.Fragment, null,
5
5
  React.createElement("path", { strokeWidth: 2, stroke: "currentColor", strokeLinejoin: "round", fill: "none", d: "M3 5l18 0l0 14l-18 0l0-14z" }),
@@ -8,9 +8,9 @@ const ThumbnailsVisible = createIcon("ThumbnailsVisible", thumbnailsIcon());
8
8
  const ThumbnailsHidden = createIconDisabled("ThumbnailsHidden", thumbnailsIcon());
9
9
  export function ThumbnailsButton() {
10
10
  const { visible, show, hide } = useThumbnails();
11
- const { render, labels } = useLightboxProps();
11
+ const { render } = useLightboxProps();
12
12
  if (render.buttonThumbnails) {
13
13
  return React.createElement(React.Fragment, null, render.buttonThumbnails({ visible, show, hide }));
14
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 }));
15
+ return (React.createElement(IconButton, { label: visible ? "Hide thumbnails" : "Show thumbnails", icon: visible ? ThumbnailsVisible : ThumbnailsHidden, renderIcon: visible ? render.iconThumbnailsVisible : render.iconThumbnailsHidden, onClick: visible ? hide : show }));
16
16
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { PLUGIN_THUMBNAILS } from "../../core/index.js";
2
3
  import { Thumbnails } from "./Thumbnails.js";
3
4
  type Position = "top" | "bottom" | "start" | "end";
4
5
  declare module "../../types.js" {
@@ -54,6 +55,9 @@ declare module "../../types.js" {
54
55
  /** thumbnails container customization slot */
55
56
  thumbnailsContainer: "thumbnailsContainer";
56
57
  }
58
+ interface ToolbarButtonKeys {
59
+ [PLUGIN_THUMBNAILS]: null;
60
+ }
57
61
  /** Thumbnails plugin ref */
58
62
  interface ThumbnailsRef {
59
63
  /** if `true`, thumbnails are visible */
@@ -1,2 +1,3 @@
1
+ import { PLUGIN_THUMBNAILS } from "../../core/index.js";
1
2
  import { Thumbnails } from "./Thumbnails.js";
2
3
  export default Thumbnails;
@@ -1,13 +1,13 @@
1
1
  import * as React from "react";
2
- import { createModule, isImageSlide, PLUGIN_ZOOM } from "../../core/index.js";
2
+ import { addToolbarButton, createModule, isImageSlide, PLUGIN_ZOOM } from "../../core/index.js";
3
3
  import { resolveZoomProps } from "./props.js";
4
4
  import { ZoomContextProvider } from "./ZoomController.js";
5
5
  import { ZoomToolbarControl } from "./ZoomToolbarControl.js";
6
6
  import { ZoomWrapper } from "./ZoomWrapper.js";
7
7
  export const Zoom = ({ augment, addModule }) => {
8
- augment(({ toolbar: { buttons, ...restToolbar }, render, zoom, ...restProps }) => ({
8
+ augment(({ toolbar, render, zoom, ...restProps }) => ({
9
9
  zoom: resolveZoomProps(zoom),
10
- toolbar: { buttons: [React.createElement(ZoomToolbarControl, { key: PLUGIN_ZOOM }), ...buttons], ...restToolbar },
10
+ toolbar: addToolbarButton(toolbar, PLUGIN_ZOOM, React.createElement(ZoomToolbarControl, null)),
11
11
  render: {
12
12
  ...render,
13
13
  slide: (props) => { var _a; return isImageSlide(props.slide) ? React.createElement(ZoomWrapper, { render: render, ...props }) : (_a = render.slide) === null || _a === void 0 ? void 0 : _a.call(render, props); },
@@ -1,15 +1,15 @@
1
1
  import * as React from "react";
2
- import { createIcon, IconButton, label, useLightboxProps } from "../../core/index.js";
2
+ import { createIcon, IconButton, useLightboxProps } from "../../core/index.js";
3
3
  import { useZoom } from "./ZoomController.js";
4
4
  const ZoomInIcon = createIcon("ZoomIn", React.createElement(React.Fragment, null,
5
5
  React.createElement("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" }),
6
6
  React.createElement("path", { d: "M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z" })));
7
7
  const ZoomOutIcon = createIcon("ZoomOut", React.createElement("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7z" }));
8
- export const ZoomButton = React.forwardRef(({ zoomIn, onLoseFocus }, ref) => {
8
+ export const ZoomButton = React.forwardRef(function ZoomButton({ zoomIn, onLoseFocus }, ref) {
9
9
  const wasEnabled = React.useRef(false);
10
10
  const wasFocused = React.useRef(false);
11
11
  const { zoom, maxZoom, zoomIn: zoomInCallback, zoomOut: zoomOutCallback, disabled: zoomDisabled } = useZoom();
12
- const { render, labels } = useLightboxProps();
12
+ const { render } = useLightboxProps();
13
13
  const disabled = zoomDisabled || (zoomIn ? zoom >= maxZoom : zoom <= 1);
14
14
  React.useEffect(() => {
15
15
  if (disabled && wasEnabled.current && wasFocused.current) {
@@ -19,10 +19,9 @@ export const ZoomButton = React.forwardRef(({ zoomIn, onLoseFocus }, ref) => {
19
19
  wasEnabled.current = true;
20
20
  }
21
21
  }, [disabled, onLoseFocus]);
22
- return (React.createElement(IconButton, { ref: ref, disabled: disabled, label: label(labels, zoomIn ? "Zoom in" : "Zoom out"), icon: zoomIn ? ZoomInIcon : ZoomOutIcon, renderIcon: zoomIn ? render.iconZoomIn : render.iconZoomOut, onClick: zoomIn ? zoomInCallback : zoomOutCallback, onFocus: () => {
22
+ return (React.createElement(IconButton, { ref: ref, disabled: disabled, label: zoomIn ? "Zoom in" : "Zoom out", icon: zoomIn ? ZoomInIcon : ZoomOutIcon, renderIcon: zoomIn ? render.iconZoomIn : render.iconZoomOut, onClick: zoomIn ? zoomInCallback : zoomOutCallback, onFocus: () => {
23
23
  wasFocused.current = true;
24
24
  }, onBlur: () => {
25
25
  wasFocused.current = false;
26
26
  } }));
27
27
  });
28
- ZoomButton.displayName = "ZoomButton";
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { PLUGIN_ZOOM } from "../../core/index.js";
2
3
  import { Zoom } from "./Zoom.js";
3
4
  declare module "../../types.js" {
4
5
  interface LightboxProps {
@@ -53,6 +54,9 @@ declare module "../../types.js" {
53
54
  /** current zoom level */
54
55
  zoom: number;
55
56
  }
57
+ interface ToolbarButtonKeys {
58
+ [PLUGIN_ZOOM]: null;
59
+ }
56
60
  /** Zoom plugin ref */
57
61
  interface ZoomRef {
58
62
  /** current zoom level */
@@ -1,2 +1,3 @@
1
+ import { PLUGIN_ZOOM } from "../../core/index.js";
1
2
  import { Zoom } from "./Zoom.js";
2
3
  export default Zoom;
package/dist/types.d.ts CHANGED
@@ -278,7 +278,11 @@ export type Labels = {
278
278
  /** Toolbar settings */
279
279
  export interface ToolbarSettings {
280
280
  /** buttons to render in the toolbar */
281
- buttons: ("close" | React.ReactNode)[];
281
+ buttons: (ToolbarButtonKey | React.ReactNode)[];
282
+ }
283
+ export type ToolbarButtonKey = keyof ToolbarButtonKeys;
284
+ export interface ToolbarButtonKeys {
285
+ close: null;
282
286
  }
283
287
  /** Plugin methods */
284
288
  export interface PluginProps {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",