From 424205879f9203e7c582711c0a8d928e63429aaf Mon Sep 17 00:00:00 2001 From: Wayne Carson Date: Thu, 31 Jan 2019 18:56:58 -0800 Subject: [PATCH 1/2] [micromodal] Initial commit. --- types/micromodal/index.d.ts | 63 ++++++++++++++++++++++++++++ types/micromodal/micromodal-tests.ts | 18 ++++++++ types/micromodal/tsconfig.json | 23 ++++++++++ types/micromodal/tslint.json | 1 + 4 files changed, 105 insertions(+) create mode 100644 types/micromodal/index.d.ts create mode 100644 types/micromodal/micromodal-tests.ts create mode 100644 types/micromodal/tsconfig.json create mode 100644 types/micromodal/tslint.json diff --git a/types/micromodal/index.d.ts b/types/micromodal/index.d.ts new file mode 100644 index 0000000000..112d24c33d --- /dev/null +++ b/types/micromodal/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for micromodal 0.3 +// Project: https://github.com/ghosh/micromodal#readme +// Definitions by: Wayne Carson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * MicroModal configuration options + */ +export interface MicroModalConfig { + + /** This is fired when the modal is opening. */ + onShow?: (modal?: HTMLElement) => void; + + /** This is fired when the modal is closing. */ + onClose?: (modal?: HTMLElement) => void; + + /** Custom data attribute to open modal. Default is data-micromodal-trigger. */ + openTrigger?: string; + + /** Custom data attribute to close modal. Default is data-micromodal-close. */ + closeTrigger?: string; + + /** This disables scrolling on the page while the modal is open. The default value is false. */ + disableScroll?: boolean; + + /** Disable auto focus on first focusable element. Default is false */ + disableFocus?: boolean; + + /** + * Set this to true if using css animations to hide the modal. This allows it to wait for the animation to + * finish before removing it from the DOM. Default is false + */ + awaitCloseAnimation?: boolean; + + /** This option suppresses the console warnings if passed as true. The default value is false. */ + debugMode?: boolean; +} + +/** + * MicroModal controller + */ +declare namespace MicroModal { + + /** + * Binds click handlers to all modal triggers + * @param config configuration options + */ + export function init(config?: MicroModalConfig): void; + + /** + * Shows a particular modal + * @param targetModal The id of the modal to display + * @param config configuration options + */ + export function show(targetModal: string, config?: MicroModalConfig): void; + + /** + * Closes the active modal + */ + export function close(): void; +} + +export default MicroModal; diff --git a/types/micromodal/micromodal-tests.ts b/types/micromodal/micromodal-tests.ts new file mode 100644 index 0000000000..4e7c0433ae --- /dev/null +++ b/types/micromodal/micromodal-tests.ts @@ -0,0 +1,18 @@ +import MicroModal, { MicroModalConfig } from 'micromodal'; + +const config: MicroModalConfig = { + onShow: (modal: HTMLElement) => { console.log(modal.id); }, + onClose: (modal: HTMLElement) => { console.log(modal.id); }, + openTrigger: 'data-modal-open', + closeTrigger: 'data-modal-close', + disableScroll: true, + disableFocus: true, + awaitCloseAnimation: true, + debugMode: true +}; + +MicroModal.init(config); + +MicroModal.show('my-modal'); + +MicroModal.close(); diff --git a/types/micromodal/tsconfig.json b/types/micromodal/tsconfig.json new file mode 100644 index 0000000000..64e891d82b --- /dev/null +++ b/types/micromodal/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "micromodal-tests.ts" + ] +} diff --git a/types/micromodal/tslint.json b/types/micromodal/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/micromodal/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From a3f37b9189509b327b89ecfaf7bc840b24b2b527 Mon Sep 17 00:00:00 2001 From: Wayne Carson Date: Thu, 31 Jan 2019 19:17:16 -0800 Subject: [PATCH 2/2] [micromodal] Fixed line ending mismatch --- types/micromodal/index.d.ts | 8 +++----- types/micromodal/micromodal-tests.ts | 4 ++-- types/micromodal/tsconfig.json | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/types/micromodal/index.d.ts b/types/micromodal/index.d.ts index 112d24c33d..3796eba976 100644 --- a/types/micromodal/index.d.ts +++ b/types/micromodal/index.d.ts @@ -7,7 +7,6 @@ * MicroModal configuration options */ export interface MicroModalConfig { - /** This is fired when the modal is opening. */ onShow?: (modal?: HTMLElement) => void; @@ -40,24 +39,23 @@ export interface MicroModalConfig { * MicroModal controller */ declare namespace MicroModal { - /** * Binds click handlers to all modal triggers * @param config configuration options */ - export function init(config?: MicroModalConfig): void; + function init(config?: MicroModalConfig): void; /** * Shows a particular modal * @param targetModal The id of the modal to display * @param config configuration options */ - export function show(targetModal: string, config?: MicroModalConfig): void; + function show(targetModal: string, config?: MicroModalConfig): void; /** * Closes the active modal */ - export function close(): void; + function close(): void; } export default MicroModal; diff --git a/types/micromodal/micromodal-tests.ts b/types/micromodal/micromodal-tests.ts index 4e7c0433ae..e2d2d386bd 100644 --- a/types/micromodal/micromodal-tests.ts +++ b/types/micromodal/micromodal-tests.ts @@ -1,8 +1,8 @@ import MicroModal, { MicroModalConfig } from 'micromodal'; const config: MicroModalConfig = { - onShow: (modal: HTMLElement) => { console.log(modal.id); }, - onClose: (modal: HTMLElement) => { console.log(modal.id); }, + onShow: (modal) => { console.log(modal!.id); }, + onClose: (modal) => { console.log(modal!.id); }, openTrigger: 'data-modal-open', closeTrigger: 'data-modal-close', disableScroll: true, diff --git a/types/micromodal/tsconfig.json b/types/micromodal/tsconfig.json index 64e891d82b..58ce896244 100644 --- a/types/micromodal/tsconfig.json +++ b/types/micromodal/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../"