From 8f3259b1037788f7de1ce200b89ee2b68d238a41 Mon Sep 17 00:00:00 2001 From: Kristofer Selbekk Date: Fri, 15 Nov 2019 20:09:29 +0100 Subject: [PATCH] Update types for react-collapse@5 (#40362) --- types/react-collapse/index.d.ts | 57 ++++++++++++------ types/react-collapse/react-collapse-tests.tsx | 59 +++++-------------- 2 files changed, 53 insertions(+), 63 deletions(-) diff --git a/types/react-collapse/index.d.ts b/types/react-collapse/index.d.ts index c960fcd825..c22c7e9793 100644 --- a/types/react-collapse/index.d.ts +++ b/types/react-collapse/index.d.ts @@ -1,28 +1,47 @@ -// Type definitions for react-collapse 4.0 +// Type definitions for react-collapse 5.0 // Project: https://github.com/nkbt/react-collapse -// Definitions by: Adam Binford +// Definitions by: Adam Binford +// Kristofer Giltvedt Selbekk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import * as React from 'react'; -export interface CollapseProps extends React.HTMLProps { +export interface CollapseCallbackArgs { + /** `true` only when Collapse reached final height */ + isFullyOpened: boolean; + /** `true` only when Collapse is fully closed and height is zero */ + isFullyClosed: boolean; + /** `true` if Collapse has any non-zero height */ 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; + /** current pixel height of Collapse container (changes until reaches `contentHeight`) */ + containerHeight: number; + /** determined height of supplied Content */ + contentHeight: number; } -export class Collapse extends React.PureComponent { } +export interface CollapseProps extends React.HTMLProps { + /** Expands or collapses content. */ + isOpened: boolean; + /** One or multiple children with static, variable or dynamic height. */ + children: React.ReactNode; + /** It is possible to set className for extra div elements that ReactCollapse creates. */ + theme?: { + collapse?: string; + content?: string; + }; + /** Callback function triggered when animation has completed */ + onRest?: (args: CollapseCallbackArgs) => void; + /** Callback function triggered when animation begins */ + onWork?: (args: CollapseCallbackArgs) => void; + /** A way to control the initial element style. Will not be valid after the initial render */ + initialStyle?: { + height?: string | number; + overflow?: string; + }; + /** How often (in ms) the height of the content is checked. */ + checkTimeout?: number; +} -export class UnmountClosed extends React.PureComponent { } +export class Collapse extends React.PureComponent {} + +export class UnmountClosed extends React.PureComponent {} diff --git a/types/react-collapse/react-collapse-tests.tsx b/types/react-collapse/react-collapse-tests.tsx index cb4177c18a..a304ebebd9 100644 --- a/types/react-collapse/react-collapse-tests.tsx +++ b/types/react-collapse/react-collapse-tests.tsx @@ -5,13 +5,11 @@ class TestRequired extends React.Component { render() { return (
- -
+ +
- -
+ +
); @@ -20,53 +18,26 @@ class TestRequired extends React.Component { class TestAll extends React.Component { render() { - const springConfig = { - stiffness: 1, - damping: 1, - precision: 1, - }; - const theme = { collapse: 'collapse-class', - content: 'content-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 }) => {}; + const onWork = () => {}; + + const initialStyle = { + height: 200, + overflow: 'auto', + }; return (
- -
+ +
- -
+ +
);