diff --git a/types/basiclightbox/basiclightbox-tests.ts b/types/basiclightbox/basiclightbox-tests.ts new file mode 100644 index 0000000000..9d63bccb26 --- /dev/null +++ b/types/basiclightbox/basiclightbox-tests.ts @@ -0,0 +1,27 @@ +import * as basicLightbox from 'basiclightbox'; + +const instance = basicLightbox.create(` +

Dynamic Content

+

You can set the content of the lightbox with JS.

+`); + +const instance2 = basicLightbox.create(` +

Not closable

+

It's not possible to close this lightbox with a click.

+`, { + closable: false +}); + +const instance3 = basicLightbox.create( + document.querySelector('#template')! +); + +const visible = basicLightbox.visible(); + +instance.show(() => console.log('lightbox now visible')); + +instance.close(() => console.log('lightbox not visible anymore')); + +const visible2 = instance.visible(); + +const elem = instance.element(); diff --git a/types/basiclightbox/index.d.ts b/types/basiclightbox/index.d.ts new file mode 100644 index 0000000000..4986419cd6 --- /dev/null +++ b/types/basiclightbox/index.d.ts @@ -0,0 +1,64 @@ +// Type definitions for basiclightbox 5.0 +// Project: https://basiclightbox.electerious.com +// Definitions by: Adrian Hope-Bailie +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface BasicLightBox { + /** + * Shows a lightbox instance. + * + * @param cb A function that gets executed as soon as the lightbox starts to fade in. + */ + show: (cb?: () => void) => void; + + /** + * Closes a lightbox instance. + * + * @param cb A function that gets executed as soon as the lightbox has been faded out. + */ + close: (cb?: () => void) => void; + + /** + * Returns true when the lightbox instance is visible. Also returns true when the lightbox is currently in the process of showing/hiding and not fully visible/hidden, yet. + */ + visible: () => boolean; + + /** + * Returns the DOM element/node associated with the instance. + */ + element: () => Element; + } + + export interface BasicLightBoxOptions { + /* + * Prevents the lightbox from closing when clicking its background. + */ + closable?: boolean; + /* + * One or more space separated classes to be added to the basicLightbox element. + */ + className?: string; + /* + * Function that gets executed before the lightbox will be shown. + * Returning false will prevent the lightbox from showing. + */ + onShow?: (instance: BasicLightBox) => boolean; + /* + * Function that gets executed before the lightbox closes. + * Returning false will prevent the lightbox from closing. + */ + onClose?: (instance: BasicLightBox) => boolean; + } + + /** + * Creates a new BasicLightbox instance. + * + * @param content Content of the lightbox. + * @param options An object of options. + */ + export function create(content: string | Element, options?: BasicLightBoxOptions): BasicLightBox; + + /** + * Returns `true` when a lightbox is visible. Also returns true when a lightbox is currently in the process of showing/hiding and not fully visible/hidden, yet. + */ + export function visible(): boolean; diff --git a/types/basiclightbox/tsconfig.json b/types/basiclightbox/tsconfig.json new file mode 100644 index 0000000000..2884b1f0df --- /dev/null +++ b/types/basiclightbox/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "dom", + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "basiclightbox-tests.ts" + ] +} diff --git a/types/basiclightbox/tslint.json b/types/basiclightbox/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/basiclightbox/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }