[react-scroll-into-view-if-needed] add types

This commit is contained in:
Jonathan Ly
2019-02-25 09:27:02 +11:00
parent b1285dace3
commit c77d6dad5e
4 changed files with 91 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
// Type definitions for react-scroll-into-view-if-needed 2.1
// Project: https://github.com/icd2k3/react-scroll-into-view-if-needed#readme
// Definitions by: Angus Fretwell <https://github.com/angusfretwell>
// Allan Pope <https://github.com/allanpope>
// Jonathan Ly <https://github.com/jonathanly>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
import * as React from 'react';
import * as ScrollIntoViewIfNeeded from 'scroll-into-view-if-needed';
export interface ReactScrollIntoViewIfNeededProps
extends React.HTMLProps<HTMLElement> {
options?: ScrollIntoViewIfNeeded.Options;
active?: boolean;
elementType?: keyof JSX.IntrinsicElements;
}
export default class ReactScrollIntoViewIfNeeded extends React.Component<
ReactScrollIntoViewIfNeededProps
> {}
@@ -0,0 +1,52 @@
import * as React from 'react';
import ReactScrollIntoViewIfNeeded from 'react-scroll-into-view-if-needed';
const validOptions = {
block: 'start',
scrollMode: 'if-needed',
skipOverflowHiddenElements: true
};
const invalidOptions = {
invalidOption: 'foobar'
};
() => (
<ReactScrollIntoViewIfNeeded
active={true}
options={validOptions}
elementType="h1"
>
Children
</ReactScrollIntoViewIfNeeded>
);
() => (
<ReactScrollIntoViewIfNeeded
active={true}
options={invalidOptions}
elementType="h1"
>
Children
</ReactScrollIntoViewIfNeeded>
);
() => (
<ReactScrollIntoViewIfNeeded
active={5} // $ExpectError
options={validOptions}
elementType="h1"
>
Children
</ReactScrollIntoViewIfNeeded>
);
() => (
<ReactScrollIntoViewIfNeeded
active={true}
options={validOptions}
elementType="h8" // $ExpectError
>
Children
</ReactScrollIntoViewIfNeeded>
);
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6", "dom"],
"jsx": "react",
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "react-scroll-into-view-if-needed-tests.tsx"]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }