{"version":3,"sources":["collapse/collapse.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,oBAAY,aAAa,GAAG;IACxB;;SAEK;IACL,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;SAEK;IACL,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;SAEK;IACL,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE3B;;OAEG;IACH,KAAK,CAAC,EAAE,eAAe,GAAG,eAAe,CAAC;IAE1C;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAElD;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC;IAC5D,SAAS,CAAC,EAAE;;;;;;iBAAwB;IAEpC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,CAGzC;IAEF,KAAK;;MAEH;IAEF,OAAO,CAAC,OAAO,CAAiB;IAEhC,OAAO,CAAC,WAAW,CAAiB;IAEpC,iBAAiB;IAIjB,kBAAkB;IAIlB,MAAM;IAiDN,OAAO,CAAC,oBAAoB,CAW1B;IAEF,OAAO,CAAC,mBAAmB,CAc1B;CACJ;;AAED,wBAA4D","file":"collapse.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 from 'react';\nimport { createCn } from 'bem-react-classname';\nimport { withTheme } from '../cn';\n\nimport IconArrowDown from '../icon/ui/arrow-down';\nimport IconArrowUp from '../icon/ui/arrow-up';\nimport Link from '../link/link';\nimport { ResizeSensor } from '../resize-sensor/resize-sensor';\n\nexport type CollapseProps = {\n    /**\n     * Управление `expanded` состоянием компонента\n     * */\n    isExpanded?: boolean;\n\n    /**\n     * Текст ссылки в `expanded` состоянии\n     * */\n    collapsedLabel?: string;\n\n    /**\n     * Текст ссылки в `collapsed` состоянии\n     * */\n    expandedLabel?: string;\n\n    /**\n     * Дочерние элементы `Collapse`\n     */\n    children?: React.ReactNode;\n\n    /**\n     * Тема компонента\n     */\n    theme?: 'alfa-on-color' | 'alfa-on-white';\n\n    /**\n     * Дополнительный класс\n     */\n    className?: string;\n\n    /**\n     * Идентификатор компонента в DOM\n     */\n    id?: string;\n\n    /**\n     * Обработчик смены состояний `expanded/collapsed`\n     */\n    onExpandedChange?: (isExpanded?: boolean) => void;\n\n    /**\n     * Идентификатор для систем автоматизированного тестирования\n     */\n    'data-test-id'?: string;\n};\n\n/**\n * Компонент «подката» позволяет спрятать кусок текста за ссылку «Еще...».\n */\nexport class Collapse extends React.PureComponent<CollapseProps> {\n    protected cn = createCn('collapse');\n\n    static defaultProps: Partial<CollapseProps> = {\n        expandedLabel: 'Collapse',\n        collapsedLabel: 'Expand',\n    };\n\n    state = {\n        isExpanded: false,\n    };\n\n    private content: HTMLDivElement;\n\n    private contentCase: HTMLDivElement;\n\n    componentDidMount() {\n        this.updateContentHeight();\n    }\n\n    componentDidUpdate() {\n        this.updateContentHeight();\n    }\n\n    render() {\n        let ToggledIcon;\n        const expanded = this.props.isExpanded === undefined ? this.state.isExpanded : this.props.isExpanded;\n\n        switch (expanded) {\n        case true: ToggledIcon = IconArrowUp; break;\n        case false: ToggledIcon = IconArrowDown; break;\n        }\n\n        return (\n            <div\n                className={ this.cn({\n                    expanded,\n                }) }\n                id={ this.props.id }\n                data-test-id={ this.props['data-test-id'] }\n            >\n                <div\n                    ref={ (content) => {\n                        this.content = content;\n                    } }\n                    className={ this.cn('content') }\n                >\n                    <div ref={ (contentCase) => {\n                        this.contentCase = contentCase;\n                    } }\n                    >\n                        { this.props.children }\n                    </div>\n                    <ResizeSensor onResize={ this.updateContentHeight } />\n                </div>\n                <Link\n                    className={ this.cn('link') }\n                    pseudo={ true }\n                    icon={\n                        <ToggledIcon size=\"s\" />\n                    }\n                    iconPosition=\"right\"\n                    onClick={ this.handleExpandedChange }\n                    text={\n                        expanded\n                            ? this.props.expandedLabel\n                            : this.props.collapsedLabel\n                    }\n                />\n            </div>\n        );\n    }\n\n    private handleExpandedChange = () => {\n        // eslint-disable-next-line react/no-access-state-in-setstate\n        const newExpandedValue = this.props.isExpanded === undefined ? !this.state.isExpanded : !this.props.isExpanded;\n\n        this.setState({\n            isExpanded: newExpandedValue,\n        });\n\n        if (this.props.onExpandedChange) {\n            this.props.onExpandedChange(newExpandedValue);\n        }\n    };\n\n    private updateContentHeight = () => {\n        const expanded = this.props.isExpanded === undefined ? this.state.isExpanded : this.props.isExpanded;\n\n        let contentHeight;\n\n        if (expanded) {\n            contentHeight = this.contentCase.offsetHeight;\n        } else {\n            contentHeight = 0;\n        }\n\n        if (this.content) {\n            this.content.style.height = `${contentHeight}px`;\n        }\n    }\n}\n\nexport default withTheme<CollapseProps, Collapse>(Collapse);\n"]}