UNPKG

3.67 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent } from "../../common";
3import { Props } from "../../common/props";
4export interface CollapseProps extends Props {
5 /** Contents to collapse. */
6 children?: React.ReactNode;
7 /**
8 * Component to render as the root element.
9 * Useful when rendering a `Collapse` inside a `<table>`, for instance.
10 *
11 * @default "div"
12 */
13 component?: React.ElementType;
14 /**
15 * Whether the component is open or closed.
16 *
17 * @default false
18 */
19 isOpen?: boolean;
20 /**
21 * Whether the child components will remain mounted when the `Collapse` is closed.
22 * Setting to true may improve performance by avoiding re-mounting children.
23 *
24 * @default false
25 */
26 keepChildrenMounted?: boolean;
27 /**
28 * The length of time the transition takes, in milliseconds. This must match
29 * the duration of the animation in CSS. Only set this prop if you override
30 * Blueprint's default transitions with new transitions of a different
31 * length.
32 *
33 * @default 200
34 */
35 transitionDuration?: number;
36}
37export interface CollapseState {
38 /** The state the element is currently in. */
39 animationState: AnimationStates;
40 /** The height that should be used for the content animations. This is a CSS value, not just a number. */
41 height: string | undefined;
42 /**
43 * The most recent non-zero height (once a height has been measured upon first open; it is undefined until then)
44 */
45 heightWhenOpen: number | undefined;
46}
47/**
48 * `Collapse` can be in one of six states, enumerated here.
49 * When changing the `isOpen` prop, the following happens to the states:
50 * isOpen={true} : CLOSED -> OPEN_START -> OPENING -> OPEN
51 * isOpen={false} : OPEN -> CLOSING_START -> CLOSING -> CLOSED
52 */
53export declare enum AnimationStates {
54 /**
55 * The body is re-rendered, height is set to the measured body height and
56 * the body Y is set to 0.
57 */
58 OPEN_START = 0,
59 /**
60 * Animation begins, height is set to auto. This is all animated, and on
61 * complete, the state changes to OPEN.
62 */
63 OPENING = 1,
64 /**
65 * The collapse height is set to auto, and the body Y is set to 0 (so the
66 * element can be seen as normal).
67 */
68 OPEN = 2,
69 /**
70 * Height has been changed from auto to the measured height of the body to
71 * prepare for the closing animation in CLOSING.
72 */
73 CLOSING_START = 3,
74 /**
75 * Height is set to 0 and the body Y is at -height. Both of these properties
76 * are transformed, and then after the animation is complete, the state
77 * changes to CLOSED.
78 */
79 CLOSING = 4,
80 /**
81 * The contents of the collapse is not rendered, the collapse height is 0,
82 * and the body Y is at -height (so that the bottom of the body is at Y=0).
83 */
84 CLOSED = 5
85}
86/**
87 * Collapse component.
88 *
89 * @see https://blueprintjs.com/docs/#core/components/collapse
90 */
91export declare class Collapse extends AbstractPureComponent<CollapseProps, CollapseState> {
92 static displayName: string;
93 static defaultProps: Partial<CollapseProps>;
94 static getDerivedStateFromProps(props: CollapseProps, state: CollapseState): {
95 animationState: AnimationStates;
96 height?: undefined;
97 } | {
98 animationState: AnimationStates;
99 height: string;
100 } | null;
101 state: CollapseState;
102 private contents;
103 render(): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
104 componentDidMount(): void;
105 componentDidUpdate(): void;
106 private contentsRefHandler;
107 private onDelayedStateChange;
108}