mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Add types for basicLightbox (#35935)
* Add types for basicLightbox * Fix header * Add strictFunctionTypes * Fix linting errors * Fix return type of instance.visible()
This commit is contained in:
committed by
Andrew Casey
parent
9286ec2fcd
commit
b334bed556
27
types/basiclightbox/basiclightbox-tests.ts
Normal file
27
types/basiclightbox/basiclightbox-tests.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as basicLightbox from 'basiclightbox';
|
||||
|
||||
const instance = basicLightbox.create(`
|
||||
<h1>Dynamic Content</h1>
|
||||
<p>You can set the content of the lightbox with JS.</p>
|
||||
`);
|
||||
|
||||
const instance2 = basicLightbox.create(`
|
||||
<h1>Not closable</h1>
|
||||
<p>It's not possible to close this lightbox with a click.</p>
|
||||
`, {
|
||||
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();
|
||||
64
types/basiclightbox/index.d.ts
vendored
Normal file
64
types/basiclightbox/index.d.ts
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// Type definitions for basiclightbox 5.0
|
||||
// Project: https://basiclightbox.electerious.com
|
||||
// Definitions by: Adrian Hope-Bailie <https://github.com/adrianhopebailie>
|
||||
// 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;
|
||||
24
types/basiclightbox/tsconfig.json
Normal file
24
types/basiclightbox/tsconfig.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
1
types/basiclightbox/tslint.json
Normal file
1
types/basiclightbox/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user