Add definitions for react-virtualized-auto-sizer (#34187)

This commit is contained in:
otofu-square
2019-03-29 19:49:00 -07:00
committed by Ron Buckton
parent f04b80f2b5
commit 98906728d1
4 changed files with 125 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
// Type definitions for react-virtualized-auto-sizer 1.0
// Project: https://github.com/bvaughn/react-virtualized-auto-sizer/
// Definitions by: Hidemi Yukita <https://github.com/otofu-square>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from "react";
export interface Size {
height: number;
width: number;
}
export interface AutoSizerProps {
/** Function responsible for rendering children. */
children: (size: Size) => React.ReactNode;
/** Optional custom CSS class name to attach to root AutoSizer element. */
className?: string;
/** Default height to use for initial render; useful for SSR */
defaultHeight?: number;
/** Default width to use for initial render; useful for SSR */
defaultWidth?: number;
/** Disable dynamic :height property */
disableHeight?: boolean;
/** Disable dynamic :width property */
disableWidth?: boolean;
/** Nonce of the inlined stylesheet for Content Security Policy */
nonce?: string;
/** Callback to be invoked on-resize */
onResize?: (size: Size) => void;
/** Optional inline style */
style?: React.CSSProperties;
}
export default class extends React.Component<AutoSizerProps> {}
@@ -0,0 +1,51 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import AutoSizer, { Size } from 'react-virtualized-auto-sizer';
class TestAutoSizer extends AutoSizer {}
class TestApp extends React.Component {
onResize = (size: Size) => {
console.log(`width: ${size.width}`);
console.log(`height: ${size.height}`);
}
render() {
return (
<>
<TestAutoSizer>
{({ width, height }) => {
const _width: number = width;
const _height: number = height;
console.log(`width: ${_width}`);
console.log(`height: ${_height}`);
return null;
}}
</TestAutoSizer>
<TestAutoSizer
className="className"
defaultHeight={0}
defaultWidth={0}
disableHeight={false}
disableWidth={false}
nonce="nonce"
style={{ display: "none" }}
onResize={this.onResize}
>
{({ width, height }) => {
const _width: number = width;
const _height: number = height;
console.log(`width: ${_width}`);
console.log(`height: ${_height}`);
return null;
}}
</TestAutoSizer>
</>
);
}
}
ReactDOM.render(
<TestApp/>,
document.getElementById("test-app"),
);
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"jsx": "react",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"react-virtualized-auto-sizer-tests.tsx"
]
}
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-empty-interface": false
}
}