Skip to content

Commit

Permalink
Merge pull request #173 from itoldya/ts-declaration
Browse files Browse the repository at this point in the history
Add TypeScript declaration file
  • Loading branch information
benhowell authored Aug 14, 2022
2 parents c9a7c72 + a55a323 commit 12708e1
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 7 deletions.
101 changes: 101 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import * as React from "react";

declare module "react-grid-gallery" {
export interface ReactGridGalleryImageComponentProps {
item: ReactGridGalleryImage;
index: number;
margin: number;
height: number;
isSelectable: boolean;
onClick: (index: number, event: React.MouseEvent<HTMLElement>) => void;
onSelectImage: (
index: number,
event: React.MouseEvent<HTMLElement>
) => void;
tileViewportStyle: () => React.CSSProperties;
thumbnailStyle: () => React.CSSProperties;
tagStyle: React.CSSProperties;
customOverlay: React.ReactNode;
thumbnailImageComponent: React.ComponentType<ReactGridGalleryThumbnailImageComponentProps>;
}

export interface ReactGridGalleryThumbnailImageComponentImageProps {
key: string;
src: string;
alt: string;
title: string | null;
style: React.CSSProperties;
}

export type ReactGridGalleryThumbnailImageComponentProps =
ReactGridGalleryImageComponentProps & {
imageProps: ReactGridGalleryThumbnailImageComponentImageProps;
};

export interface ReactGridGalleryImageTag {
value: React.ReactNode;
title: string;
key?: string;
}

export interface ReactGridGalleryImage {
src: string;
thumbnail: string;
thumbnailWidth: number;
thumbnailHeight: number;
nano?: string;
alt?: string;
tags?: ReactGridGalleryImageTag[];
isSelected?: boolean;
caption?: React.ReactNode;
srcSet?: string[];
customOverlay?: React.ReactNode;
thumbnailCaption?: React.ReactNode;
orientation?: number;
}

export interface ReactGridGalleryProps {
images: ReactGridGalleryImage[];
id?: string;
enableImageSelection?: boolean;
onSelectImage?: (index: number, image: ReactGridGalleryImage) => void;
rowHeight?: number;
maxRows?: number;
margin?: number;
enableLightbox?: boolean;
onClickThumbnail?: (
index: number,
event: React.MouseEvent<HTMLElement>
) => void;
lightboxWillOpen?: (index: number) => void;
lightboxWillClose?: () => void;
tagStyle?: React.CSSProperties;
tileViewportStyle?: () => React.CSSProperties;
thumbnailStyle?: () => React.CSSProperties;
thumbnailImageComponent?: React.ComponentType<ReactGridGalleryThumbnailImageComponentProps>;

backdropClosesModal?: boolean;
currentImage?: number;
preloadNextImage?: boolean;
customControls?: React.ReactNode[];
enableKeyboardInput?: boolean;
imageCountSeparator?: string;
isOpen?: boolean;
showCloseButton?: boolean;
showImageCount?: boolean;
onClickImage?: (event: React.MouseEvent<HTMLElement>) => void;
onClickPrev?: () => void;
onClickNext?: () => void;

currentImageWillChange?: (index: number) => void;
showLightboxThumbnails?: boolean;

onClickLightboxThumbnail?: (index: number) => void;
lightboxWidth?: number;
lightBoxProps?: any;
}

class ReactGridGallery extends React.Component<ReactGridGalleryProps> {}

export default ReactGridGallery;
}
37 changes: 31 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.5",
"@types/jest": "^28.1.6",
"@types/react": "^16.14.30",
"gh-pages": "^4.0.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
Expand Down
19 changes: 18 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import serve from "rollup-plugin-serve";
import livereload from "rollup-plugin-livereload";
import copy from "rollup-plugin-copy";
import pkg from "./package.json";

const isWatchMode = process.env.ROLLUP_WATCH;
Expand Down Expand Up @@ -53,6 +54,22 @@ export default [
{ file: pkg.main, format: "cjs", exports: "default" },
{ file: pkg.module, format: "es", exports: "default" },
],
plugins: [babel({ babelHelpers: "bundled" })],
plugins: [
babel({ babelHelpers: "bundled" }),
copy({
targets: [
{
src: "./index.d.ts",
dest: "./dist",
rename: `${pkg.name}.cjs.d.ts`,
},
{
src: "./index.d.ts",
dest: "./dist",
rename: `${pkg.name}.esm.d.ts`,
},
],
}),
],
},
];

0 comments on commit 12708e1

Please sign in to comment.