diff --git a/types/smooth-scroll/index.d.ts b/types/smooth-scroll/index.d.ts new file mode 100644 index 0000000000..87f90cc298 --- /dev/null +++ b/types/smooth-scroll/index.d.ts @@ -0,0 +1,68 @@ +// Type definitions for smooth-scroll 14.2 +// Project: https://github.com/cferdinandi/smooth-scroll +// Definitions by: Andrei Horodinca +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export as namespace SmoothScroll; + +export = SmoothScroll; + +declare namespace SmoothScroll { + type Easing = + | "Linear" + | "easeInQuad" + | "easeInCubic" + | "easeInQuart" + | "easeInQuint" + | "easeInOutQuad" + | "easeInOutCubic" + | "easeInOutQuart" + | "easeInOutQuint" + | "easeOutQuad" + | "easeOutCubic" + | "easeOutQuart" + | "easeOutQuint"; + + interface Options { + // Selectors + ignore?: string; + header?: string; + topOnEmptyHash?: boolean; + + // Speed & Easing + speed?: number; + clip?: boolean; + offset?: + | number + | (( + anchor?: Element | number | null, + toggle?: Element | null + ) => number); + easing?: Easing; + customEasing?: (time: number) => number; + + // History + updateURL?: boolean; + popstate?: boolean; + + // Custom Events + emitEvents?: boolean; + } +} + +declare class SmoothScroll { + constructor(selector?: string, options?: SmoothScroll.Options); + + init(options?: SmoothScroll.Options): void; + + destroy(): void; + + animateScroll( + anchor: Element | number | null, + toggle?: Element | null, + options?: SmoothScroll.Options + ): void; + + cancelScroll(noEvent?: boolean): void; +} diff --git a/types/smooth-scroll/test/smooth-scroll-global.test.ts b/types/smooth-scroll/test/smooth-scroll-global.test.ts new file mode 100644 index 0000000000..e230635f9e --- /dev/null +++ b/types/smooth-scroll/test/smooth-scroll-global.test.ts @@ -0,0 +1,34 @@ +// Initialize and destroy SmoothScroll +const example1 = new SmoothScroll('a[href*="#"]', { + ignore: ".ignore", + header: '[data-scroll="header"]', + topOnEmptyHash: false, + speed: 1000, + clip: true, + offset: () => 10, + easing: "easeInCubic", + customEasing: () => 50, + updateURL: false, + popstate: false, + emitEvents: false +}); +example1.destroy(); + +// Scrolling to an anchor +const example2 = () => { + const scroll = new SmoothScroll(); + const anchor = document.querySelector("#bazinga"); + scroll.animateScroll(anchor, null, { speed: 1000 }); +}; + +// Scrolling to a specific Y-position +const example3 = () => { + const scroll = new SmoothScroll('a[href*="#"]'); + scroll.animateScroll(750); +}; + +// Cancel scroll +const example4 = () => { + const scroll = new SmoothScroll(); + scroll.cancelScroll(); +}; diff --git a/types/smooth-scroll/test/smooth-scroll.test.ts b/types/smooth-scroll/test/smooth-scroll.test.ts new file mode 100644 index 0000000000..a64b8bd2d0 --- /dev/null +++ b/types/smooth-scroll/test/smooth-scroll.test.ts @@ -0,0 +1,36 @@ +import SmoothScroll = require("smooth-scroll"); + +// Initialize and destroy SmoothScroll +const example1 = new SmoothScroll('a[href*="#"]', { + ignore: ".ignore", + header: '[data-scroll="header"]', + topOnEmptyHash: false, + speed: 1000, + clip: true, + offset: () => 10, + easing: "easeInCubic", + customEasing: () => 50, + updateURL: false, + popstate: false, + emitEvents: false +}); +example1.destroy(); + +// Scrolling to an anchor +const example2 = () => { + const scroll = new SmoothScroll(); + const anchor = document.querySelector("#bazinga"); + scroll.animateScroll(anchor, null, { speed: 1000 }); +}; + +// Scrolling to a specific Y-position +const example3 = () => { + const scroll = new SmoothScroll('a[href*="#"]'); + scroll.animateScroll(750); +}; + +// Cancel scroll +const example4 = () => { + const scroll = new SmoothScroll(); + scroll.cancelScroll(); +}; diff --git a/types/smooth-scroll/tsconfig.json b/types/smooth-scroll/tsconfig.json new file mode 100644 index 0000000000..8d1fa8372b --- /dev/null +++ b/types/smooth-scroll/tsconfig.json @@ -0,0 +1,20 @@ +{ + "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/smooth-scroll-global.test.ts", + "test/smooth-scroll.test.ts" + ] +} diff --git a/types/smooth-scroll/tslint.json b/types/smooth-scroll/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/smooth-scroll/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }