begin work at v1.0.0-alpha.1

add Sidenav
This commit is contained in:
胡玮文
2017-11-28 21:25:08 +08:00
parent d7c4168ae7
commit dd2f9f7d09
5 changed files with 167 additions and 0 deletions

112
types/materialize-css/index.d.ts vendored Normal file
View File

@@ -0,0 +1,112 @@
// Type definitions for materialize-css 1.0
// Project: http://materializecss.com/
// Definitions by: 胡玮文 <https://github.com/huww98>
// 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<SidenavOptions>);
/**
* 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;
}
}
}

View File

@@ -0,0 +1,3 @@
const elem = document.querySelector('.sidenav')!;
// $ExpectType Sidenav
const sidenav = new M.Sidenav(elem);

View File

@@ -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;

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
},
"files": [
"index.d.ts",
"test/materialize-css-global.test.ts",
"test/materialize-css-module.test.ts"
]
}

View File

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