Added type definitions for react-collapse (#22704)

This commit is contained in:
Adam Binford
2018-01-05 14:07:11 -05:00
committed by Mohamed Hegazy
parent 538bee5326
commit 23ab5e0c1a
4 changed files with 127 additions and 0 deletions

28
types/react-collapse/index.d.ts vendored Normal file
View File

@@ -0,0 +1,28 @@
// Type definitions for react-collapse 4.0
// Project: https://github.com/nkbt/react-collapse
// Definitions by: Adam Binford <https://github.com/Kimahriman>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as React from 'react';
export interface CollapseProps extends React.HTMLProps<Collapse> {
isOpened: boolean;
children: React.ReactNode;
springConfig?: { [key: string]: number }; // react-motion doesn't export the config interface
forceInitialAnimation?: boolean;
hasNestedCollapse?: boolean;
fixedHeight?: number;
theme?: {
collapse: string
content: string
};
style?: React.CSSProperties;
onRender?: ({ current, from, to }: { current: number; from: number; to: number; }) => void;
onRest?: () => void;
onMeasure?: ({ width, height }: { width: number; height: number; }) => void;
}
export class Collapse extends React.PureComponent<CollapseProps> { }
export class UnmountClosed extends React.PureComponent<CollapseProps> { }

View File

@@ -0,0 +1,74 @@
import * as React from 'react';
import { Collapse, UnmountClosed } from 'react-collapse';
class TestRequired extends React.Component {
render() {
return (
<div>
<Collapse
isOpened>
<div/>
</Collapse>
<UnmountClosed
isOpened>
<div/>
</UnmountClosed>
</div>
);
}
}
class TestAll extends React.Component {
render() {
const springConfig = {
stiffness: 1,
damping: 1,
precision: 1,
};
const theme = {
collapse: 'collapse-class',
content: 'content-class'
};
const style: React.CSSProperties = {
fontWeight: 'bold',
fontSize: 16
};
const onRender = (object: { current: number; from: number; to: number; }) => {};
const onRest = () => {};
const onMeasure = (object: { width: number; height: number }) => {};
return (
<div>
<Collapse
isOpened
springConfig={ springConfig }
forceInitialAnimation
hasNestedCollapse
fixedHeight={ 0 }
theme={ theme }
style={ style }
onRender={ onRender }
onRest={ onRest }
onMeasure={ onMeasure}>
<div/>
</Collapse>
<UnmountClosed
isOpened
springConfig={ springConfig }
forceInitialAnimation
hasNestedCollapse
fixedHeight={ 0 }
theme={ theme }
style={ style }
onRender={ onRender }
onRest={ onRest }
onMeasure={ onMeasure}>
<div/>
</UnmountClosed>
</div>
);
}
}

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"jsx": "react",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"react-collapse-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }