Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions types/moxy__next-router-scroll/RouterScrollProvider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { NextScrollBehaviorContext } from './scroll-behavior';
import { ShouldUpdateScroll } from 'scroll-behavior';
import { ReactChildren } from 'react';
export default ScrollBehaviorProvider;
declare function ScrollBehaviorProvider({
disableNextLinkScroll,
shouldUpdateScroll,
children,
}: {
disableNextLinkScroll?: boolean;
shouldUpdateScroll?: ShouldUpdateScroll<NextScrollBehaviorContext>;
children?: React.ReactNode;
}): JSX.Element;

declare namespace ScrollBehaviorProvider {
namespace defaultProps {
function shouldUpdateScroll(): boolean;
const disableNextLinkScroll: boolean;
}
namespace propTypes {
const disableNextLinkScroll: boolean;
const shouldUpdateScroll: any;
const children: ReactChildren;
}
}
18 changes: 18 additions & 0 deletions types/moxy__next-router-scroll/context.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Context } from 'react';
import { ShouldUpdateScroll } from 'scroll-behavior';
import { NextScrollBehaviorContext } from './scroll-behavior';

export default RouterScrollProvider;

declare const RouterScrollProvider: Context<RouterScrollContext>;

export interface RouterScrollContext {
updateScroll: (prevContext?: NextScrollBehaviorContext | null, context?: NextScrollBehaviorContext | null) => void;
registerElement: (
key: string,
element: HTMLElement,
shouldUpdateScroll?: ShouldUpdateScroll<NextScrollBehaviorContext> | null,
context?: NextScrollBehaviorContext,
) => void;
unregisterElement: (key: string) => void;
}
7 changes: 7 additions & 0 deletions types/moxy__next-router-scroll/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Type definitions for @moxy/next-router-scroll 2.2
// Project: https://github.com/moxystudio/next-router-scroll#readme
// Definitions by: Lee seung chan <https://github.com/me>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export { default as RouterScrollProvider } from './RouterScrollProvider';
export { default as useRouterScroll } from './use-router-scroll';
export { default as withRouterScroll } from './with-router-scroll';
64 changes: 64 additions & 0 deletions types/moxy__next-router-scroll/moxy__next-router-scroll-tests.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useRouterScroll, RouterScrollProvider, withRouterScroll } from 'moxy__next-router-scroll';
import * as React from 'react';
import { render } from 'react-dom';

declare function beforeAll(f: () => void): void;
declare function describe(desc: string, f: () => void): void;
declare function it(desc: string, f: () => void): void;
declare const expect: any;

declare let reactRoot: any;

beforeAll(() => {
reactRoot = document.createElement('div');
});

describe('useRouterScroll', () => {
it('should return three funcitons', () => {
class Component extends React.PureComponent {
render() {
const MyComponent = () => {
const routerScroll = useRouterScroll();

expect(routerScroll).toEqual({
updateScroll: expect.any(Function),
registerElement: expect.any(Function),
unregisterElement: expect.any(Function),
});

return null;
};

return (
<RouterScrollProvider>
<MyComponent />
</RouterScrollProvider>
);
}
}
render(<Component />, reactRoot);
});
});

describe('withRouterScroll', () => {
it('should return component with scroll context', () => {
class Component extends React.PureComponent {
render() {
const MyComponent = withRouterScroll(({ routerScroll }: any) => {
const providerValue = useRouterScroll();

expect(routerScroll).toBe(providerValue);

return null;
});
return (
<RouterScrollProvider>
<MyComponent />
</RouterScrollProvider>
);
}
}

render(<Component />, reactRoot);
});
});
6 changes: 6 additions & 0 deletions types/moxy__next-router-scroll/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"scroll-behavior": "^0.11.0"
}
}
27 changes: 27 additions & 0 deletions types/moxy__next-router-scroll/scroll-behavior/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference types="node" />
/// <reference lib="dom" />

export default class NextScrollBehavior extends ScrollBehavior<Location & LocationBase, NextScrollBehaviorContext> {
constructor(shouldUpdateScroll: ShouldUpdateScroll<NextScrollBehaviorContext>);
_context: NextScrollBehaviorContext;
_prevContext: NextScrollBehaviorContext;
_debounceSavePositionMap: Map<string, ScrollPosition>;
_setScrollRestoration: () => void;
_createContext(): NextScrollBehaviorContext;
_setScrollRestorationWithoutUserAgentSniffing(): void;
_oldScrollRestoration: ScrollRestoration;
_savePosition(key: string, element: HTMLElement): void;
_cleanupDebouncedSavePosition(): void;
}
import { ParsedUrlQuery } from 'querystring';
import ScrollBehavior, { LocationBase, ScrollPosition, ShouldUpdateScroll } from 'scroll-behavior';
import { Location } from 'history';

export interface NextScrollBehaviorContext {
location: Location & LocationBase;
router: {
pathname: string;
asPath: string;
query: ParsedUrlQuery;
};
}
17 changes: 17 additions & 0 deletions types/moxy__next-router-scroll/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6", "dom"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": ["index.d.ts", "moxy__next-router-scroll-tests.tsx"]
}
1 change: 1 addition & 0 deletions types/moxy__next-router-scroll/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
4 changes: 4 additions & 0 deletions types/moxy__next-router-scroll/use-router-scroll.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { RouterScrollContext } from './context';

export default useRouterScroll;
declare function useRouterScroll(): RouterScrollContext;
4 changes: 4 additions & 0 deletions types/moxy__next-router-scroll/with-router-scroll.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ForwardRefExoticComponent, ReactNode } from 'react';

export default withRouterScroll;
declare function withRouterScroll(WrappedComponent: ReactNode): ForwardRefExoticComponent<any>;