Skip to content

Commit

Permalink
fix: add on.download callback
Browse files Browse the repository at this point in the history
  • Loading branch information
igordanchenko committed Apr 24, 2023
1 parent 265b3d2 commit 5e43170
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/plugins/download/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const DownloadIcon = createIcon(
);

export function DownloadButton() {
const { render } = useLightboxProps();
const { currentSlide } = useLightboxState();
const { render, on } = useLightboxProps();
const { currentSlide, currentIndex } = useLightboxState();

if (render.buttonDownload) {
return <>{render.buttonDownload()}</>;
Expand All @@ -28,6 +28,8 @@ export function DownloadButton() {
onClick={() => {
if (downloadUrl) {
saveAs(downloadUrl, currentSlide?.downloadFilename);

on.download?.({ index: currentIndex });
}
}}
/>
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/download/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RenderFunction } from "../../types.js";
import { Callback, RenderFunction } from "../../types.js";
import { PLUGIN_DOWNLOAD } from "../../core/index.js";
import { Download } from "./Download.js";

Expand All @@ -17,6 +17,14 @@ declare module "../../types.js" {
iconDownload?: RenderFunction;
}

interface Callbacks {
download?: Callback<DownloadCallbackProps>;
}

export interface DownloadCallbackProps {
index: number;
}

// noinspection JSUnusedGlobalSymbols
interface ToolbarButtonKeys {
[PLUGIN_DOWNLOAD]: null;
Expand Down

0 comments on commit 5e43170

Please sign in to comment.