From dd2f9f7d095c8092ce237cff686e11625c2decc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Tue, 28 Nov 2017 21:25:08 +0800 Subject: [PATCH] begin work at v1.0.0-alpha.1 add Sidenav --- types/materialize-css/index.d.ts | 112 ++++++++++++++++++ .../test/materialize-css-global.test.ts | 3 + .../test/materialize-css-module.test.ts | 21 ++++ types/materialize-css/tsconfig.json | 25 ++++ types/materialize-css/tslint.json | 6 + 5 files changed, 167 insertions(+) create mode 100644 types/materialize-css/index.d.ts create mode 100644 types/materialize-css/test/materialize-css-global.test.ts create mode 100644 types/materialize-css/test/materialize-css-module.test.ts create mode 100644 types/materialize-css/tsconfig.json create mode 100644 types/materialize-css/tslint.json diff --git a/types/materialize-css/index.d.ts b/types/materialize-css/index.d.ts new file mode 100644 index 0000000000..076dc309dc --- /dev/null +++ b/types/materialize-css/index.d.ts @@ -0,0 +1,112 @@ +// Type definitions for materialize-css 1.0 +// Project: http://materializecss.com/ +// Definitions by: 胡玮文 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +export = M; + +declare global { + namespace M { + class Sidenav { + /** + * Construct Sidenav instance and set up overlay + */ + constructor(elem: Element, options?: Partial); + + /** + * Get Instance + */ + static getInstance(elem: Element): Sidenav; + + /** + * Opens Sidenav + */ + open(): void; + + /** + * Closes Sidenav + */ + close(): void; + + /** + * Destroy plugin instance and teardown + */ + destroy(): void; + + /** + * The DOM element the plugin was initialized with + */ + el: Element; + + /** + * The options the instance was initialized with + */ + options: SidenavOptions; + + /** + * Describes open/close state of Sidenav + */ + isOpen: boolean; + + /** + * Describes if sidenav is fixed + */ + isFixed: boolean; + + /** + * Describes if Sidenav is being dragged + */ + isDragged: boolean; + } + + /** + * Options for the Sidenav + */ + interface SidenavOptions { + /** + * Side of screen on which Sidenav appears + * @default 'left' + */ + edge: 'left' | 'right'; + + /** + * Allow swipe gestures to open/close Sidenav + * @default true + */ + draggable: boolean; + + /** + * Length in ms of enter transition + * @default 250 + */ + inDuration: number; + + /** + * Length in ms of exit transition + * @default 200 + */ + outDuration: number; + + /** + * Function called when sidenav starts entering + */ + onOpenStart: (instance: Sidenav, elem: Element) => void; + + /** + * Function called when sidenav finishes entering + */ + onOpenEnd: (instance: Sidenav, elem: Element) => void; + + /** + * Function called when sidenav starts exiting + */ + onCloseStart: (instance: Sidenav, elem: Element) => void; + + /** + * Function called when sidenav finishes exiting + */ + onCloseEnd: (instance: Sidenav, elem: Element) => void; + } + } +} diff --git a/types/materialize-css/test/materialize-css-global.test.ts b/types/materialize-css/test/materialize-css-global.test.ts new file mode 100644 index 0000000000..5c3d4213c6 --- /dev/null +++ b/types/materialize-css/test/materialize-css-global.test.ts @@ -0,0 +1,3 @@ +const elem = document.querySelector('.sidenav')!; +// $ExpectType Sidenav +const sidenav = new M.Sidenav(elem); diff --git a/types/materialize-css/test/materialize-css-module.test.ts b/types/materialize-css/test/materialize-css-module.test.ts new file mode 100644 index 0000000000..76ce89595e --- /dev/null +++ b/types/materialize-css/test/materialize-css-module.test.ts @@ -0,0 +1,21 @@ +import * as materialize from "materialize-css"; + +// Sidenav +const elem = document.querySelector('.sidenav')!; +// $ExpectType Sidenav +const sidenav = new materialize.Sidenav(elem, { + edge: "left", + inDuration: 300, + onCloseStart: () => console.log("closing") +}); +// $ExpectType void +sidenav.open(); +// $ExpectType void +sidenav.destroy(); + +// $ExpectType SidenavOptions +sidenav.options; +// $ExpectType Element +sidenav.el; +// $ExpectType boolean +sidenav.isOpen; diff --git a/types/materialize-css/tsconfig.json b/types/materialize-css/tsconfig.json new file mode 100644 index 0000000000..25a5435fd4 --- /dev/null +++ b/types/materialize-css/tsconfig.json @@ -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 + }, + "files": [ + "index.d.ts", + "test/materialize-css-global.test.ts", + "test/materialize-css-module.test.ts" + ] +} diff --git a/types/materialize-css/tslint.json b/types/materialize-css/tslint.json new file mode 100644 index 0000000000..5f6e69415a --- /dev/null +++ b/types/materialize-css/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + + } + }