[a11y-dialog] Create new definitions (#29509)

* Create d.ts file for a11y-dialog.

* Finish up implementation for a11y-dialog.

* Construct unit tests for a11y-dialog.

* added missing create functions.

* tslint successfully passes for a11y-dialog

* Split out constructor for best practices

* none of the duplicates were getters / setters
This commit is contained in:
Yuto Otaguro
2018-10-08 11:20:05 -05:00
committed by Andy
parent 973ba79f9b
commit 8bb6ac0a18
4 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import A11yDialog = require('a11y-dialog');
const dialogEl = new A11yDialog(document.getElementById("test"));
const dialogElTwo = new A11yDialog(document.getElementById("test"), document.getElementById("testContainer"));
const dialogElThree = new A11yDialog(document.getElementById("test"), "dummy-element");
dialogEl.show();
dialogEl.hide();
dialogElTwo.destroy();
dialogElThree.create();
// Test out interfaces that extends Element.
dialogEl.on("show", (el: HTMLElement) => {
el.textContent;
});
// Test out element and event.
dialogEl.on("create", (el: HTMLElement, evt) => {
el.textContent;
evt.target;
});
dialogEl.on('hide', () => {
const t = 5;
});
dialogEl.off("show", (el: HTMLElement) => {
el.textContent;
});

31
types/a11y-dialog/index.d.ts vendored Normal file
View File

@@ -0,0 +1,31 @@
// Type definitions for a11y-dialog 5.2
// Project: https://github.com/edenspiekermann/a11y-dialog
// Definitions by: Yuto <https://github.com/Goyatuzo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
type DialogEvents = "show" | "hide" | "destroy" | "create";
declare class A11yDialog {
constructor(el: Element | null, containers?: NodeList | Element | string | null);
/**
* Shows the dialog.
*/
show(): void;
/**
* Hides the dialog.
*/
hide(): void;
/**
* Unbind click listeners from dialog openers and closers and remove all bound custom event listeners registered with `.on()`
*/
destroy(): void;
/**
* Bind click listeners to dialog openers and closers.
*/
create(el?: Element | null, containers?: NodeList | Element | string | null): void;
on(evt: DialogEvents, callback: (dialogElement: any, event: Event) => void): void;
off(evt: DialogEvents, callback: (dialogElement: any, event: Event) => void): void;
}
export = A11yDialog;

View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"a11y-dialog-tests.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}