diff --git a/types/react-scroll/index.d.ts b/types/react-scroll/index.d.ts index 1f31f5f4c3..f4e6aa45d7 100644 --- a/types/react-scroll/index.d.ts +++ b/types/react-scroll/index.d.ts @@ -1,67 +1,9 @@ -// Type definitions for react-scroll +// Type definitions for react-scroll 1.5 // Project: https://github.com/fisshy/react-scroll -// Definitions by: Ioannis Kokkinidis +// Definitions by: Ioannis Kokkinidis +// Giedrius Grabauskas // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.2 -import * as React from 'react'; - -interface Link extends React.ClassicComponentClass { } -interface Element extends React.ClassicComponentClass { } -interface Button extends React.ClassicComponentClass {} -interface DirectLink extends React.ClassicComponentClass {} - -interface scrollEvnt { - register(evtName: string, callback: Function): void, - remove(evtName: string): void -} - -interface Events { - scrollEvent: scrollEvnt -} - -interface scroller { - scrollTo(to: any, animate?: any, duration?: any, offset?: any): void -} - -interface scrollSpy { - update() : void -} - -interface animateScroll { - scrollToTop(options?: any) : void, - scrollToBottom(options?: any) : void, - scrollTo(toY: number, options?: any) : void, - scrollMore(toY: number, options?: any) : void, -} - -interface directScroller { - get() : any -} - -interface Helpers { -} - -declare const Link: Link; -declare const Element: Element; -declare const Events: Events; -declare const scroller: scroller; -declare const DirectLink: DirectLink; -declare const Button: Button; -declare const scrollSpy: scrollSpy; -declare const directScroller: directScroller; -declare const Helpers: Helpers; -declare const animateScroll: animateScroll; - -export { - Link, - Element, - Events, - scroller, - scrollSpy, - directScroller, - DirectLink, - Button, - Helpers, - animateScroll -} +import * as ReactScroll from "./modules/index"; +export = ReactScroll; diff --git a/types/react-scroll/modules/components/Button.d.ts b/types/react-scroll/modules/components/Button.d.ts new file mode 100644 index 0000000000..831ccfb49a --- /dev/null +++ b/types/react-scroll/modules/components/Button.d.ts @@ -0,0 +1,6 @@ +import * as React from "react"; +import { ReactScrollLinkProps } from "./Link"; + +export type ButtonProps = ReactScrollLinkProps & React.HTMLProps; + +export default class Button extends React.Component { } diff --git a/types/react-scroll/modules/components/Element.d.ts b/types/react-scroll/modules/components/Element.d.ts new file mode 100644 index 0000000000..53dae7ef66 --- /dev/null +++ b/types/react-scroll/modules/components/Element.d.ts @@ -0,0 +1,8 @@ +import * as React from "react"; + +export interface ElementProps extends React.HTMLProps { + name: string; + id?: string; +} + +export default class Element extends React.Component { } diff --git a/types/react-scroll/modules/components/Link.d.ts b/types/react-scroll/modules/components/Link.d.ts new file mode 100644 index 0000000000..a1333c35ca --- /dev/null +++ b/types/react-scroll/modules/components/Link.d.ts @@ -0,0 +1,22 @@ +import * as React from "react"; + +export interface ReactScrollLinkProps { + to: string; + containerId?: string; + activeClass?: string; + spy?: boolean; + smooth?: boolean | string; + offset?: number; + delay?: number; + isDynamic?: boolean; + onClick?(): void; + duration?: number | string; + absolute?: boolean; + onSetActive?(to: string): void; + onSetInactive?(): void; + ignoreCancelEvents?: boolean; +} + +export type LinkProps = ReactScrollLinkProps & React.HTMLProps; + +export default class Link extends React.Component { } diff --git a/types/react-scroll/modules/index.d.ts b/types/react-scroll/modules/index.d.ts new file mode 100644 index 0000000000..cf8aa4f454 --- /dev/null +++ b/types/react-scroll/modules/index.d.ts @@ -0,0 +1,14 @@ +export { default as Button } from "./components/Button"; +export { default as Element } from "./components/Element"; +export { default as Link } from "./components/Link"; +export { Helpers } from "./mixins/Helpers"; +export { default as Events } from "./mixins/scroll-events"; +export { default as scrollSpy } from "./mixins/scroll-spy"; + +import * as scroller from "./mixins/scroller"; +import * as animateScroll from "./mixins/animate-scroll"; + +export { + animateScroll, + scroller +}; diff --git a/types/react-scroll/modules/mixins/Helpers.d.ts b/types/react-scroll/modules/mixins/Helpers.d.ts new file mode 100644 index 0000000000..a32adf2954 --- /dev/null +++ b/types/react-scroll/modules/mixins/Helpers.d.ts @@ -0,0 +1,4 @@ +export namespace Helpers { + function Scroll(component: any, customScroller?: any): any; + function Element(component: any): any; +} diff --git a/types/react-scroll/modules/mixins/animate-scroll.d.ts b/types/react-scroll/modules/mixins/animate-scroll.d.ts new file mode 100644 index 0000000000..049e961e96 --- /dev/null +++ b/types/react-scroll/modules/mixins/animate-scroll.d.ts @@ -0,0 +1,6 @@ +export function animateTopScroll(y: number, options: any, to: string, target: any): void; +export function getAnimationType(options: { smooth: boolean | string }): (x: number) => number; +export function scrollToTop(options?: any): void; +export function scrollToBottom(options?: any): void; +export function scrollTo(toY: number, options?: any): void; +export function scrollMore(toY: number, options?: any): void; diff --git a/types/react-scroll/modules/mixins/scroll-events.d.ts b/types/react-scroll/modules/mixins/scroll-events.d.ts new file mode 100644 index 0000000000..e52a22ae1a --- /dev/null +++ b/types/react-scroll/modules/mixins/scroll-events.d.ts @@ -0,0 +1,11 @@ +declare namespace Events { + interface ScrollEvent { + register(eventName: string, callback: (to: string, element: any) => void): void; + remove(eventName: string): void; + } + + const registered: {}; + const scrollEvent: ScrollEvent; +} + +export default Events; diff --git a/types/react-scroll/modules/mixins/scroll-spy.d.ts b/types/react-scroll/modules/mixins/scroll-spy.d.ts new file mode 100644 index 0000000000..2e738744f2 --- /dev/null +++ b/types/react-scroll/modules/mixins/scroll-spy.d.ts @@ -0,0 +1,17 @@ +interface ScrollSpy { + update(): void; + unmount(stateHandler: any, spyHandler: any): void; + updateStates(): void; + addSpyHandler(handler: any, scrollSpyContainer: any): void; + addStateHandler(handler: any): void; + scrollHandler(scrollSpyContainer: any): void; + currentPositionY(scrollSpyContainer: any): number; + isMounted(scrollSpyContainer: any): boolean; + mount(scrollSpyContainer: any): void; + spyCallbacks: any[]; + spySetState: any[]; + scrollSpyContainers: any[]; +} + +declare const scrollSpy: ScrollSpy; +export default scrollSpy; diff --git a/types/react-scroll/modules/mixins/scroller.d.ts b/types/react-scroll/modules/mixins/scroller.d.ts new file mode 100644 index 0000000000..a729070a96 --- /dev/null +++ b/types/react-scroll/modules/mixins/scroller.d.ts @@ -0,0 +1,7 @@ +export function unmount(): void; +export function register(name: string, element: any): void; +export function unregister(name: string): void; +export function get(name: string): any; +export function setActiveLink(link: string): void; +export function getActiveLink(): string; +export function scrollTo(to: string, props: any): void; diff --git a/types/react-scroll/react-scroll-tests.tsx b/types/react-scroll/react-scroll-tests.tsx deleted file mode 100644 index 63db573722..0000000000 --- a/types/react-scroll/react-scroll-tests.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import * as React from 'react'; -import { Link, Element, scroller } from 'react-scroll'; - -let link = ; -let element = ; - -scroller.scrollTo("test"); \ No newline at end of file diff --git a/types/react-scroll/test/react-scroll-tests.tsx b/types/react-scroll/test/react-scroll-tests.tsx new file mode 100644 index 0000000000..f341b4d241 --- /dev/null +++ b/types/react-scroll/test/react-scroll-tests.tsx @@ -0,0 +1,138 @@ +import * as React from "react"; +import { Link, Button, animateScroll, Helpers, Events, Element, scrollSpy, scroller } from "react-scroll"; + +Events.scrollEvent.register('begin', (to, element) => { + console.log("begin"); +}); + +Events.scrollEvent.register('end', (to, element) => { + console.log("end"); +}); + +scrollSpy.update(); + +Events.scrollEvent.remove('begin'); +Events.scrollEvent.remove('end'); + +const smothOptions = { + a: "", + smooth: false +}; +animateScroll.getAnimationType(smothOptions); +animateScroll.scrollToTop(); +animateScroll.scrollTo(100); +animateScroll.scrollMore(100); + +const linkTest1 = { console.log(to); }} +> + Test 1 +; + +const LinkTest2 = + Test 2 (delay) +; + +const linkTest3 = + Test 6 (anchor) +; + +const buttonTest = ; + +const elementTest = + test 1 +; + +const linkTest4 = + Go to first element inside container +; + +const linkTest5 = { console.log(to); }} + onSetInactive={() => { }} + ignoreCancelEvents={false} +> + Your name +; + +const options = {} as any; +animateScroll.scrollToTop(options); +animateScroll.scrollToBottom(options); +animateScroll.scrollTo(100, options); + +scroller.scrollTo('myScrollToElement', { + duration: 1500, + delay: 100, + smooth: true, + containerId: 'ContainerElementID' +}); + +animateScroll.scrollMore(10, options); + +Events.scrollEvent.register('begin', (to, element) => { + console.log("begin", to, element); +}); + +Events.scrollEvent.register('end', (to, element) => { + console.log("end", to, element); +}); + +Events.scrollEvent.remove('begin'); +Events.scrollEvent.remove('end'); + +class CustomComponent extends React.Component<{}, {}> { + render() { + return
+ {this.props.children} +
; + } +} + +const CustomElement = Helpers.Element(CustomComponent); +const CustomLink = Helpers.Scroll(CustomComponent); + +scroller.scrollTo('myScrollToElement', { + duration: 1500, + delay: 100, + smooth: "easeInOutQuint", + containerId: 'ContainerElementID' +}); diff --git a/types/react-scroll/tsconfig.json b/types/react-scroll/tsconfig.json index 82e3ee3f92..a4f8e54e6c 100644 --- a/types/react-scroll/tsconfig.json +++ b/types/react-scroll/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "jsx": "react", "typeRoots": [ @@ -19,6 +19,15 @@ }, "files": [ "index.d.ts", - "react-scroll-tests.tsx" + "modules/index.d.ts", + "modules/components/Button.d.ts", + "modules/components/Element.d.ts", + "modules/components/Link.d.ts", + "modules/mixins/animate-scroll.d.ts", + "modules/mixins/Helpers.d.ts", + "modules/mixins/scroll-events.d.ts", + "modules/mixins/scroll-spy.d.ts", + "modules/mixins/scroller.d.ts", + "test/react-scroll-tests.tsx" ] -} \ No newline at end of file +} diff --git a/types/react-scroll/tslint.json b/types/react-scroll/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-scroll/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }