From 862dc5c3e56cf155c9397dc24ecf2a8a49b848eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alu=C3=ADsio=20Augusto=20Silva=20Gon=C3=A7alves?= Date: Wed, 25 Jan 2017 09:46:30 -0200 Subject: [PATCH 1/2] Add TypeScript definitions --- package.json | 1 + typings/picoModal.d.ts | 104 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 typings/picoModal.d.ts 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..44bc28f --- /dev/null +++ b/typings/picoModal.d.ts @@ -0,0 +1,104 @@ +// 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 + } +} From 3fd261f204c6011388e70356886664c1cdaeb576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alu=C3=ADsio=20Augusto=20Silva=20Gon=C3=A7alves?= Date: Wed, 25 Jan 2017 09:56:19 -0200 Subject: [PATCH 2/2] Reformat TSD --- typings/picoModal.d.ts | 83 +++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/typings/picoModal.d.ts b/typings/picoModal.d.ts index 44bc28f..a67b474 100644 --- a/typings/picoModal.d.ts +++ b/typings/picoModal.d.ts @@ -2,103 +2,102 @@ // 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 +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 + 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 + 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 + modalElem(): HTMLElement; /** * Returns the close button element. */ - closeElem: () => HTMLElement + closeElem(): HTMLElement; /** * Returns the overlay element. */ - overlayElem: () => HTMLElement + overlayElem(): HTMLElement; /** * Shows this modal. */ - show: (detail?: any) => this + show(detail?: any): this; /** * Builds the DOM without showing the modal. */ - buildDom: (detail?: any) => this + buildDom(detail?: any): this; /** * Hides this modal. */ - close: (detail?: any) => this + 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 + forceClose(detail?: any): this; /** * Destroys this modal. */ - destroy: () => void + destroy(): void; /** * Returns whether this modal is currently being shown. */ - isVisible: () => boolean + 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 + options(options: Options): void; /** * Registers a callback to invoke when the modal is created. */ - afterCreate: (callback: Callback) => this + afterCreate(callback: Callback): this; /** * Registers a callback to invoke before the modal is shown. */ - beforeShow: (callback: Callback) => this + beforeShow(callback: Callback): this; /** * Registers a callback to invoke when the modal is shown. */ - afterShow: (callback: Callback) => this + afterShow(callback: Callback): this; /** * Registers a callback to invoke before the modal is closed. */ - beforeClose: (callback: Callback) => this + beforeClose(callback: Callback): this; /** * Registers a callback to invoke when the modal is closed. */ - afterClose: (callback: Callback) => this + afterClose(callback: Callback): this; } }