From d7c4168ae7f75e7ba75278118e3c2b203c258299 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:23:54 +0800 Subject: [PATCH 1/7] move v0.100 files to v0 --- types/materialize-css/{ => v0}/index.d.ts | 0 types/materialize-css/{ => v0}/materialize-css-tests.ts | 0 types/materialize-css/{ => v0}/tsconfig.json | 6 +++--- types/materialize-css/{ => v0}/tslint.json | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename types/materialize-css/{ => v0}/index.d.ts (100%) rename types/materialize-css/{ => v0}/materialize-css-tests.ts (100%) rename types/materialize-css/{ => v0}/tsconfig.json (90%) rename types/materialize-css/{ => v0}/tslint.json (100%) diff --git a/types/materialize-css/index.d.ts b/types/materialize-css/v0/index.d.ts similarity index 100% rename from types/materialize-css/index.d.ts rename to types/materialize-css/v0/index.d.ts diff --git a/types/materialize-css/materialize-css-tests.ts b/types/materialize-css/v0/materialize-css-tests.ts similarity index 100% rename from types/materialize-css/materialize-css-tests.ts rename to types/materialize-css/v0/materialize-css-tests.ts diff --git a/types/materialize-css/tsconfig.json b/types/materialize-css/v0/tsconfig.json similarity index 90% rename from types/materialize-css/tsconfig.json rename to types/materialize-css/v0/tsconfig.json index cc986baa67..770e3cce3f 100644 --- a/types/materialize-css/tsconfig.json +++ b/types/materialize-css/v0/tsconfig.json @@ -9,9 +9,9 @@ "noImplicitThis": true, "strictNullChecks": false, "strictFunctionTypes": true, - "baseUrl": "../", + "baseUrl": "../../", "typeRoots": [ - "../" + "../../" ], "types": [], "noEmit": true, @@ -21,4 +21,4 @@ "index.d.ts", "materialize-css-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/materialize-css/tslint.json b/types/materialize-css/v0/tslint.json similarity index 100% rename from types/materialize-css/tslint.json rename to types/materialize-css/v0/tslint.json 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 2/7] 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": { + + } + } From c5ad054706234b4b6a98a483a56689f7fa91e019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Wed, 29 Nov 2017 00:52:43 +0800 Subject: [PATCH 3/7] add jQuery support add Tabs --- types/materialize-css/index.d.ts | 110 ++++++++++++++---- .../test/materialize-css-global.test.ts | 5 +- .../test/materialize-css-jquery.test.ts | 9 ++ .../test/materialize-css-module.test.ts | 33 +++++- types/materialize-css/tsconfig.json | 3 +- 5 files changed, 130 insertions(+), 30 deletions(-) create mode 100644 types/materialize-css/test/materialize-css-jquery.test.ts diff --git a/types/materialize-css/index.d.ts b/types/materialize-css/index.d.ts index 076dc309dc..8c7914f2fd 100644 --- a/types/materialize-css/index.d.ts +++ b/types/materialize-css/index.d.ts @@ -4,16 +4,13 @@ // 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); - + class Sidenav extends Component { /** * Get Instance */ @@ -29,21 +26,6 @@ declare global { */ 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 */ @@ -91,22 +73,100 @@ declare global { /** * Function called when sidenav starts entering */ - onOpenStart: (instance: Sidenav, elem: Element) => void; + onOpenStart: (this: Sidenav, elem: Element) => void; /** * Function called when sidenav finishes entering */ - onOpenEnd: (instance: Sidenav, elem: Element) => void; + onOpenEnd: (this: Sidenav, elem: Element) => void; /** * Function called when sidenav starts exiting */ - onCloseStart: (instance: Sidenav, elem: Element) => void; + onCloseStart: (this: Sidenav, elem: Element) => void; /** * Function called when sidenav finishes exiting */ - onCloseEnd: (instance: Sidenav, elem: Element) => void; + onCloseEnd: (this: Sidenav, elem: Element) => void; + } + + class Tabs extends Component { + /** + * Get Instance + */ + static getInstance(elem: Element): Tabs; + + /** + * Show tab content that corresponds to the tab with the id + * @param tabId The id of the tab that you want to switch to + */ + select(tabId: string): void; + + /** + * The index of tab that is currently shown + */ + index: number; + } + + /** + * Options for the Tabs + */ + interface TabsOptions { + /** + * Transition duration in milliseconds. + * @default 300 + */ + duration: number; + + /** + * Callback for when a new tab content is shown + */ + onShow: (this: Tabs, newContent: Element) => void; + + /** + * Set to true to enable swipeable tabs. This also uses the responsiveThreshold option + * @default false + */ + swipeable: boolean; + + /** + * The maximum width of the screen, in pixels, where the swipeable functionality initializes. + * @default infinity + */ + responsiveThreshold: number; + } + + abstract class Component { + /** + * Construct component instance and set everything up + */ + constructor(elem: Element, options?: Partial); + + /** + * 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: TOptions; } } + + interface JQuery { + // Pick to check methods exist. + sidenav(method: keyof Pick): JQuery; + sidenav(options?: Partial): JQuery; + + tabs(method: keyof Pick): JQuery; + tabs(method: keyof Pick, tabId: string): JQuery; + tabs(options?: Partial): JQuery; + } } diff --git a/types/materialize-css/test/materialize-css-global.test.ts b/types/materialize-css/test/materialize-css-global.test.ts index 5c3d4213c6..90ca3de1c5 100644 --- a/types/materialize-css/test/materialize-css-global.test.ts +++ b/types/materialize-css/test/materialize-css-global.test.ts @@ -1,3 +1,6 @@ -const elem = document.querySelector('.sidenav')!; +const elem = document.querySelector('.whatever')!; // $ExpectType Sidenav const sidenav = new M.Sidenav(elem); + +// $ExpectType Tabs +const tabs = new M.Tabs(elem); diff --git a/types/materialize-css/test/materialize-css-jquery.test.ts b/types/materialize-css/test/materialize-css-jquery.test.ts new file mode 100644 index 0000000000..543bab8cc2 --- /dev/null +++ b/types/materialize-css/test/materialize-css-jquery.test.ts @@ -0,0 +1,9 @@ +$(".whatever").sidenav(); +$(".whatever").sidenav({inDuration: 200}); +$(".whatever").sidenav("open"); +$(".whatever").sidenav("destroy"); + +$(".whatever").tabs(); +$(".whatever").tabs({ duration: 200 }); +$(".whatever").tabs("destroy"); +$(".whatever").tabs("select", "id"); diff --git a/types/materialize-css/test/materialize-css-module.test.ts b/types/materialize-css/test/materialize-css-module.test.ts index 76ce89595e..14221464c9 100644 --- a/types/materialize-css/test/materialize-css-module.test.ts +++ b/types/materialize-css/test/materialize-css-module.test.ts @@ -1,21 +1,48 @@ import * as materialize from "materialize-css"; +const elem = document.querySelector('.whatever')!; + // Sidenav -const elem = document.querySelector('.sidenav')!; +// $ExpectType Sidenav +new materialize.Sidenav(elem); // $ExpectType Sidenav const sidenav = new materialize.Sidenav(elem, { edge: "left", inDuration: 300, - onCloseStart: () => console.log("closing") + onCloseStart(el) { + // $ExpectType Sidenav + this; + // $ExpectType Element + el; + } }); // $ExpectType void sidenav.open(); // $ExpectType void sidenav.destroy(); - // $ExpectType SidenavOptions sidenav.options; // $ExpectType Element sidenav.el; // $ExpectType boolean sidenav.isOpen; + +// Tabs +// $ExpectType Tabs +const tabs = new materialize.Tabs(elem, { + duration: 200, + onShow(content) { + // $ExpectType Tabs + this; + // $ExpectType Element + content; + } +}); +// $ExpectType void +tabs.destroy(); +// $ExpectType void +tabs.select("id"); +// $ExpectType TabsOptions +tabs.options; +// $ExpectType number +tabs.index; diff --git a/types/materialize-css/tsconfig.json b/types/materialize-css/tsconfig.json index 25a5435fd4..316e2f8361 100644 --- a/types/materialize-css/tsconfig.json +++ b/types/materialize-css/tsconfig.json @@ -20,6 +20,7 @@ "files": [ "index.d.ts", "test/materialize-css-global.test.ts", - "test/materialize-css-module.test.ts" + "test/materialize-css-module.test.ts", + "test/materialize-css-jquery.test.ts" ] } From a26611b24c7a365d5b8697a52f3c893ea19d7499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Wed, 29 Nov 2017 18:18:54 +0800 Subject: [PATCH 4/7] add modal --- types/materialize-css/index.d.ts | 81 +++++++++++++++++++ .../test/materialize-css-global.test.ts | 3 + .../test/materialize-css-jquery.test.ts | 5 ++ .../test/materialize-css-module.test.ts | 26 ++++++ 4 files changed, 115 insertions(+) diff --git a/types/materialize-css/index.d.ts b/types/materialize-css/index.d.ts index 8c7914f2fd..ebbe4923c4 100644 --- a/types/materialize-css/index.d.ts +++ b/types/materialize-css/index.d.ts @@ -137,6 +137,84 @@ declare global { responsiveThreshold: number; } + class Modal extends Component { + /** + * Get Instance + */ + static getInstance(elem: Element): Modal; + + /** + * Open modal + */ + open(): void; + + /** + * Close modal + */ + close(): void; + + /** + * If the modal is open. + */ + isOpen: boolean; + + /** + * ID of the modal element + */ + id: string; + } + + /** + * Options for the Modal + */ + interface ModalOptions { + /** + * Opacity of the modal overlay. + * @default 0.5 + */ + opacity: number; + + /** + * Transition in duration in milliseconds. + * @default 250 + */ + inDuration: number; + + /** + * Transition out duration in milliseconds. + * @default 250 + */ + outDuration: number; + + /** + * Callback function called when modal is finished entering. + */ + ready: (this: Modal, elem: Element, openingTrigger: Element) => void; + + /** + * Callback function called when modal is finished exiting. + */ + complete: (this: Modal, elem: Element) => void; + + /** + * Allow modal to be dismissed by keyboard or overlay click. + * @default true + */ + dismissible: boolean; + + /** + * Starting top offset + * @default '4%' + */ + startingTop: string; + + /** + * Ending top offset + * @default '10%' + */ + endingTop: string; + } + abstract class Component { /** * Construct component instance and set everything up @@ -168,5 +246,8 @@ declare global { tabs(method: keyof Pick): JQuery; tabs(method: keyof Pick, tabId: string): JQuery; tabs(options?: Partial): JQuery; + + modal(method: keyof Pick): JQuery; + modal(options?: Partial): JQuery; } } diff --git a/types/materialize-css/test/materialize-css-global.test.ts b/types/materialize-css/test/materialize-css-global.test.ts index 90ca3de1c5..d123c21651 100644 --- a/types/materialize-css/test/materialize-css-global.test.ts +++ b/types/materialize-css/test/materialize-css-global.test.ts @@ -4,3 +4,6 @@ const sidenav = new M.Sidenav(elem); // $ExpectType Tabs const tabs = new M.Tabs(elem); + +// $ExpectType Modal +const modal = new M.Modal(elem); diff --git a/types/materialize-css/test/materialize-css-jquery.test.ts b/types/materialize-css/test/materialize-css-jquery.test.ts index 543bab8cc2..6fd40b5aa7 100644 --- a/types/materialize-css/test/materialize-css-jquery.test.ts +++ b/types/materialize-css/test/materialize-css-jquery.test.ts @@ -7,3 +7,8 @@ $(".whatever").tabs(); $(".whatever").tabs({ duration: 200 }); $(".whatever").tabs("destroy"); $(".whatever").tabs("select", "id"); + +$(".whatever").modal(); +$(".whatever").modal({ inDuration: 200 }); +$(".whatever").modal("open"); +$(".whatever").modal("destroy"); diff --git a/types/materialize-css/test/materialize-css-module.test.ts b/types/materialize-css/test/materialize-css-module.test.ts index 14221464c9..edf2ee36ef 100644 --- a/types/materialize-css/test/materialize-css-module.test.ts +++ b/types/materialize-css/test/materialize-css-module.test.ts @@ -46,3 +46,29 @@ tabs.select("id"); tabs.options; // $ExpectType number tabs.index; + +// Modal +// $ExpectType Modal +new materialize.Modal(elem); +// $ExpectType Modal +const modal = new materialize.Modal(elem, { + inDuration: 300, + ready(el, trigger) { + // $ExpectType Modal + this; + // $ExpectType Element + el; + // $ExpectType Element + trigger; + } +}); +// $ExpectType void +modal.open(); +// $ExpectType void +modal.destroy(); +// $ExpectType ModalOptions +modal.options; +// $ExpectType Element +modal.el; +// $ExpectType boolean +modal.isOpen; From 07010408fb2e0fae883974568c94947fda526dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Thu, 30 Nov 2017 00:24:08 +0800 Subject: [PATCH 5/7] add autocomplete and characterCounter --- types/materialize-css/index.d.ts | 85 ++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/types/materialize-css/index.d.ts b/types/materialize-css/index.d.ts index ebbe4923c4..4ff883aea8 100644 --- a/types/materialize-css/index.d.ts +++ b/types/materialize-css/index.d.ts @@ -10,6 +10,73 @@ export = M; declare global { namespace M { + class Autocomplete extends Component{ + /** + * Get Instance + */ + static getInstance(elem: Element): Autocomplete; + + /** + * Select a specific autocomplete options. + * @param el Element of the autocomplete option. + */ + selectOption(el: Element): void; + + /** + * Update autocomplete options data. + * @param data Autocomplete options data object. + */ + updateData(data: AutocompleteOptions): void; + + /** + * If the autocomplete is open. + */ + isOpen: boolean; + + /** + * Number of matching autocomplete options. + */ + count: number; + + /** + * Index of the current selected option. + */ + activeIndex: number; + } + + interface AutocompleteData { + [key: string]: string | null + } + + interface AutocompleteOptions { + /** + * Data object defining autocomplete options with optional icon strings. + */ + data: AutocompleteData; + + /** + * Limit of results the autocomplete shows. + * @default infinity + */ + limit: number; + + /** + * Callback for when autocompleted. + */ + onAutocomplete: (this: Autocomplete, text: string) => void; + + /** + * Minimum number of characters before autocomplete starts. + * @default 1 + */ + minLength: number; + + /** + * Sort function that defines the order of the list of autocomplete options. + */ + sortFunction: (a: string, b: string, inputText: string) => number; + } + class Sidenav extends Component { /** * Get Instance @@ -215,6 +282,17 @@ declare global { endingTop: string; } + function updateTextFields(): void; + + class CharacterCounter extends Component{ + /** + * Get Instance + */ + static getInstance(elem: Element): CharacterCounter + } + + interface CharacterCounterOptions { } + abstract class Component { /** * Construct component instance and set everything up @@ -240,6 +318,11 @@ declare global { interface JQuery { // Pick to check methods exist. + autocomplete(method: keyof Pick): JQuery; + autocomplete(method: keyof Pick, el: Element): JQuery; + autocomplete(method: keyof Pick, data: M.AutocompleteData): JQuery; + autocomplete(options?: Partial): JQuery; + sidenav(method: keyof Pick): JQuery; sidenav(options?: Partial): JQuery; @@ -249,5 +332,7 @@ declare global { modal(method: keyof Pick): JQuery; modal(options?: Partial): JQuery; + + characterCounter(options?: Partial): JQuery } } From 68baa16088ceec61be481c04b602e1eefa9c51fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Thu, 30 Nov 2017 01:25:52 +0800 Subject: [PATCH 6/7] add Autocomplete --- types/materialize-css/index.d.ts | 98 +++++++++++++++++-- .../test/materialize-css-global.test.ts | 9 ++ .../test/materialize-css-jquery.test.ts | 18 +++- .../test/materialize-css-module.test.ts | 68 +++++++++++++ 4 files changed, 183 insertions(+), 10 deletions(-) diff --git a/types/materialize-css/index.d.ts b/types/materialize-css/index.d.ts index 4ff883aea8..ebc997c51f 100644 --- a/types/materialize-css/index.d.ts +++ b/types/materialize-css/index.d.ts @@ -10,7 +10,7 @@ export = M; declare global { namespace M { - class Autocomplete extends Component{ + class Autocomplete extends Component { /** * Get Instance */ @@ -26,7 +26,7 @@ declare global { * Update autocomplete options data. * @param data Autocomplete options data object. */ - updateData(data: AutocompleteOptions): void; + updateData(data: AutocompleteData): void; /** * If the autocomplete is open. @@ -45,7 +45,7 @@ declare global { } interface AutocompleteData { - [key: string]: string | null + [key: string]: string | null; } interface AutocompleteOptions { @@ -282,16 +282,91 @@ declare global { endingTop: string; } - function updateTextFields(): void; - - class CharacterCounter extends Component{ + class Tooltip extends Component { /** * Get Instance */ - static getInstance(elem: Element): CharacterCounter + static getInstance(elem: Element): Tooltip; + + /** + * Show tooltip. + */ + open(): void; + + /** + * Hide tooltip. + */ + close(): void; + + /** + * If tooltip is open. + */ + isOpen: boolean; + + /** + * If tooltip is hovered. + */ + isHovered: boolean; } - interface CharacterCounterOptions { } + interface TooltipOptions { + /** + * Delay time before tooltip disappears. + * @default 0 + */ + exitDelay: number; + + /** + * Delay time before tooltip appears. + * @default 200 + */ + enterDelay: number; + + /** + * Can take regular text or HTML strings. + * @default null + */ + html: string | null; + + /** + * Set distance tooltip appears away from its activator excluding transitionMovement. + * @default 5 + */ + margin: number; + + /** + * Enter transition duration. + * @default 300 + */ + inDuration: number; + + /** + * Exit transition duration. + * @default 250 + */ + outDuration: number; + + /** + * Set the direction of the tooltip. + * @default 'bottom' + */ + position: 'top' | 'right' | 'bottom' | 'left'; + + /** + * Amount in px that the tooltip moves during its transition. + * @default 10 + */ + transitionMovement: number; + } + + function updateTextFields(): void; + + class CharacterCounter extends Component { + /** + * Get Instance + */ + static getInstance(elem: Element): CharacterCounter; + } abstract class Component { /** @@ -330,9 +405,14 @@ declare global { tabs(method: keyof Pick, tabId: string): JQuery; tabs(options?: Partial): JQuery; + tooltip(method: keyof Pick): JQuery; + tooltip(options?: Partial): JQuery; + modal(method: keyof Pick): JQuery; modal(options?: Partial): JQuery; - characterCounter(options?: Partial): JQuery + // tslint:disable-next-line unified-signatures + characterCounter(method: keyof Pick): JQuery; + characterCounter(): JQuery; } } diff --git a/types/materialize-css/test/materialize-css-global.test.ts b/types/materialize-css/test/materialize-css-global.test.ts index d123c21651..fa228b444f 100644 --- a/types/materialize-css/test/materialize-css-global.test.ts +++ b/types/materialize-css/test/materialize-css-global.test.ts @@ -7,3 +7,12 @@ const tabs = new M.Tabs(elem); // $ExpectType Modal const modal = new M.Modal(elem); + +// $ExpectType Autocomplete +const autocomplete = new M.Autocomplete(elem); + +// $ExpectType CharacterCounter +const characterCounter = new M.CharacterCounter(elem); + +// $ExpectType Tooltip +const tooltips = new M.Tooltip(elem); diff --git a/types/materialize-css/test/materialize-css-jquery.test.ts b/types/materialize-css/test/materialize-css-jquery.test.ts index 6fd40b5aa7..42af7fcefd 100644 --- a/types/materialize-css/test/materialize-css-jquery.test.ts +++ b/types/materialize-css/test/materialize-css-jquery.test.ts @@ -1,5 +1,5 @@ $(".whatever").sidenav(); -$(".whatever").sidenav({inDuration: 200}); +$(".whatever").sidenav({ inDuration: 200 }); $(".whatever").sidenav("open"); $(".whatever").sidenav("destroy"); @@ -12,3 +12,19 @@ $(".whatever").modal(); $(".whatever").modal({ inDuration: 200 }); $(".whatever").modal("open"); $(".whatever").modal("destroy"); + +$(".whatever").characterCounter(); +$(".whatever").characterCounter("destroy"); + +$(".whatever").autocomplete({ + data: { + Apple: null, + Google: "https://placehold.it/250x250" + } +}); +$(".whatever").autocomplete("updateData", { Microsoft: null }); + +$(".whatever").tooltip(); +$(".whatever").tooltip({ html: "" }); +$(".whatever").tooltip("open"); +$(".whatever").tooltip("destroy"); diff --git a/types/materialize-css/test/materialize-css-module.test.ts b/types/materialize-css/test/materialize-css-module.test.ts index edf2ee36ef..2665586b5d 100644 --- a/types/materialize-css/test/materialize-css-module.test.ts +++ b/types/materialize-css/test/materialize-css-module.test.ts @@ -29,6 +29,8 @@ sidenav.isOpen; // Tabs // $ExpectType Tabs +new materialize.Tabs(elem); +// $ExpectType Tabs const tabs = new materialize.Tabs(elem, { duration: 200, onShow(content) { @@ -44,6 +46,8 @@ tabs.destroy(); tabs.select("id"); // $ExpectType TabsOptions tabs.options; +// $ExpectType Element +tabs.el; // $ExpectType number tabs.index; @@ -72,3 +76,67 @@ modal.options; modal.el; // $ExpectType boolean modal.isOpen; + +// CharacterCounter +// $ExpectType CharacterCounter +const characterCounter = new materialize.CharacterCounter(elem); +// $ExpectType void +characterCounter.destroy(); +// $ExpectType Element +characterCounter.el; + +// Autocomplete +// $ExpectType Autocomplete +new materialize.Autocomplete(elem); +// $ExpectType Autocomplete +const autocomplete = new materialize.Autocomplete(elem, { + data: { + Apple: null, + Google: "https://placehold.it/250x250" + }, + minLength: 3, + onAutocomplete(text) { + // $ExpectType Autocomplete + this; + // $ExpectType string + text; + }, + sortFunction(a, b, input) { + // $ExpectType string + a; + // $ExpectType string + b; + // $ExpectType string + input; + return 0; + } +}); +// $ExpectType void +autocomplete.updateData({ Microsoft: null }); +// $ExpectType void +autocomplete.destroy(); +// $ExpectType AutocompleteOptions +autocomplete.options; +// $ExpectType Element +autocomplete.el; +// $ExpectType boolean +autocomplete.isOpen; + +// Tooltip +// $ExpectType Tooltip +new materialize.Tooltip(elem); +// $ExpectType Tooltip +const tooltip = new materialize.Tooltip(elem, { + inDuration: 300, + position: "right" +}); +// $ExpectType void +tooltip.open(); +// $ExpectType void +tooltip.destroy(); +// $ExpectType TooltipOptions +tooltip.options; +// $ExpectType Element +tooltip.el; +// $ExpectType boolean +tooltip.isOpen; From 6a4d20e5d3dd51b24b8ff362244b2dc2f27864aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Thu, 30 Nov 2017 01:58:38 +0800 Subject: [PATCH 7/7] fix travis-ci build error --- types/materialize-css/v0/tsconfig.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/materialize-css/v0/tsconfig.json b/types/materialize-css/v0/tsconfig.json index 770e3cce3f..4f000774ea 100644 --- a/types/materialize-css/v0/tsconfig.json +++ b/types/materialize-css/v0/tsconfig.json @@ -13,6 +13,11 @@ "typeRoots": [ "../../" ], + "paths": { + "materialize-css": [ + "materialize-css/v0" + ] + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true