diff --git a/package.json b/package.json index ec4c7d9..ad7cfd2 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "url": "https://github.com/Nycto/PicoModal.git" }, "main": "src/picoModal.js", + "types": "typings/picoModal.d.ts", "devDependencies": { "chai": "^3.4.1", "express": "^4.13.4", diff --git a/typings/picoModal.d.ts b/typings/picoModal.d.ts new file mode 100644 index 0000000..a67b474 --- /dev/null +++ b/typings/picoModal.d.ts @@ -0,0 +1,103 @@ +// Type definitions for PicoModal 3.0.0 +// Project: https://github.com/Nycto/PicoModal +// Definitions by: Aluísio Augusto Silva Gonçalves + +export as namespace picoModal; +export = picoModal; + +declare function picoModal(content: string | Node): picoModal.Modal; +declare function picoModal(options: picoModal.Options): picoModal.Modal; + +declare namespace picoModal { + type Option = T | ((defaultValue: T | undefined) => T); + type Html = string | Node; + type CssProps = {[key: string]: any}; + type Callback = (context: T, event: {detail: any, preventDefault(): void}) => void; + + export interface Options { + content?: Option; + width?: Option; + closeButton?: Option; + closeHtml?: Option; + closeStyles?: Option; + closeClass?: Option; + overlayClose?: Option; + overlayStyles?: Option; + overlayClass?: Option; + modalStyles?: Option; + modalClass?: Option; + modalId?: Option; + parent?: Option; + escCloses?: Option; + focus?: Option; + ariaDescribedBy?: Option; + ariaLabelledBy?: Option; + bodyOverflow?: Option; + } + + export interface Modal { + /** + * Returns the wrapping modal element. + */ + modalElem(): HTMLElement; + /** + * Returns the close button element. + */ + closeElem(): HTMLElement; + /** + * Returns the overlay element. + */ + overlayElem(): HTMLElement; + /** + * Shows this modal. + */ + show(detail?: any): this; + /** + * Builds the DOM without showing the modal. + */ + buildDom(detail?: any): this; + /** + * Hides this modal. + */ + close(detail?: any): this; + /** + * Force closes this modal. This will not call beforeClose events and will + * just immediately hide the modal + */ + forceClose(detail?: any): this; + /** + * Destroys this modal. + */ + destroy(): void; + /** + * Returns whether this modal is currently being shown. + */ + isVisible(): boolean; + /** + * Updates the options for this modal. This will only let you change + * options that are re-evaluted regularly, such as `overlayClose`. + */ + options(options: Options): void; + + /** + * Registers a callback to invoke when the modal is created. + */ + afterCreate(callback: Callback): this; + /** + * Registers a callback to invoke before the modal is shown. + */ + beforeShow(callback: Callback): this; + /** + * Registers a callback to invoke when the modal is shown. + */ + afterShow(callback: Callback): this; + /** + * Registers a callback to invoke before the modal is closed. + */ + beforeClose(callback: Callback): this; + /** + * Registers a callback to invoke when the modal is closed. + */ + afterClose(callback: Callback): this; + } +}