{"version":3,"sources":["slide-down/slide-down.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAa,KAAK,EAAE,MAAM,OAAO,CAAC;AAEzC,oBAAY,cAAc,GAAG;IAEzB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE3B;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAE5B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CAE3B,CAAC;AAEF,aAAK,cAAc,GAAG;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,qBAAa,SAAU,SAAQ,KAAK,CAAC,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC;IAC9E,SAAS,CAAC,EAAE;;;;;;iBAA0B;IAEtC,KAAK;;;MAGH;IAEF,OAAO,CAAC,SAAS,CAA+B;IAEhD,OAAO,CAAC,gBAAgB,CAA8B;IAEtD,kBAAkB,CAAC,SAAS,EAAE,cAAc;IAgB5C,MAAM;IAsBN,OAAO,CAAC,mBAAmB,CAOzB;IAEF,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,wBAAwB;IAShC,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,aAAa;CAKxB;;AAED,wBAA+D","file":"slide-down.d.ts","sourcesContent":["/* This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n\nimport React, { createRef } from 'react';\nimport { createCn } from 'bem-react-classname';\nimport { withTheme, Theme } from '../cn';\n\nexport type SlideDownProps = {\n\n    /**\n     * Управление состоянием expand/collapse компонента\n     */\n    isExpanded?: boolean;\n\n    /**\n     * Контент компонента\n     */\n    children?: React.ReactNode;\n\n    /**\n     * Тема компонента\n     */\n    theme?: Theme;\n\n    /**\n     * Дополнительный класс\n     */\n    className?: string;\n\n    /**\n     * Идентификатор компонента в DOM\n     */\n    id?: string;\n\n    /**\n     * Обработчик события начала анимации\n     */\n    onAnimationStart?: () => void;\n\n    /**\n     * Обработчик события окончания анимации\n     */\n    onAnimationEnd?: () => void;\n\n    /**\n     * Идентификатор для систем автоматизированного тестирования\n     */\n    'data-test-id'?: string;\n\n};\n\ntype SlideDownState = {\n    height: number | string;\n    isHeightAuto: boolean;\n};\n\n/**\n * Компонент \"расхлопа\".\n * Позволяет скрывать и отображать контент.\n */\nexport class SlideDown extends React.PureComponent<SlideDownProps, SlideDownState> {\n    protected cn = createCn('slide-down');\n\n    state = {\n        height: this.props.isExpanded ? 'auto' : 0,\n        isHeightAuto: this.props.isExpanded,\n    };\n\n    private slideDown = createRef<HTMLDivElement>();\n\n    private slideDownContent = createRef<HTMLDivElement>()\n\n    componentDidUpdate(prevProps: SlideDownProps) {\n        const { isExpanded, onAnimationStart } = this.props;\n\n        if (prevProps.isExpanded !== isExpanded) {\n            if (isExpanded) {\n                this.setHeightToContentHeight();\n            } else {\n                this.setHeightToNull();\n            }\n\n            if (onAnimationStart) {\n                onAnimationStart();\n            }\n        }\n    }\n\n    render() {\n        return (\n            <div\n                className={ this.cn() }\n                id={ this.props.id }\n                style={\n                    { height: this.getHeight() }\n                }\n                onTransitionEnd={ this.handleTransitionEnd }\n                ref={ this.slideDown }\n                data-test-id={ this.props['data-test-id'] }\n            >\n                <div\n                    className={ this.cn('content', { expanded: this.state.isHeightAuto }) }\n                    ref={ this.slideDownContent }\n                >\n                    { this.props.children }\n                </div>\n            </div>\n        );\n    }\n\n    private handleTransitionEnd = (event: React.TransitionEvent<HTMLDivElement>) => {\n        if (event.propertyName === 'height' && this.props.isExpanded) {\n            this.setAutoHeight();\n        }\n        if (this.props.onAnimationEnd) {\n            this.props.onAnimationEnd();\n        }\n    };\n\n    private getHeight() {\n        return this.state.isHeightAuto\n            ? 'auto'\n            : this.state.height;\n    }\n\n    private setHeightToContentHeight() {\n        if (this.slideDownContent.current) {\n            this.setState({\n                isHeightAuto: false,\n                height: this.slideDownContent.current.offsetHeight,\n            });\n        }\n    }\n\n    private setHeightToNull() {\n        this.setHeightToContentHeight();\n\n        // Заставляем React перерисовать элемент\n        this.forceUpdate(() => {\n            // Заставляем браузер сделать reflow\n            if (this.slideDown.current) {\n                this.slideDown.current.getBoundingClientRect();\n            }\n\n            this.setState({ height: 0 });\n        });\n    }\n\n    private setAutoHeight() {\n        this.setState({\n            isHeightAuto: true,\n        });\n    }\n}\n\nexport default withTheme<SlideDownProps, SlideDown>(SlideDown);\n"]}