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,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAE/D;;OAEG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,mBAAmB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAE9D;;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,CAQzC;IAEF,KAAK;;;;MAIH;IAEF,OAAO,CAAC,KAAK,CAAC;IAEd,OAAO,CAAC,QAAQ,CAAC;IAEjB,iBAAiB;IAIjB,MAAM;IAaN,cAAc;IASd,oBAAoB,CAAC,OAAO,KAAA,EAAE,MAAM,KAAA;IAoBpC,kBAAkB,CAAC,OAAO,KAAA;IAkB1B,WAAW;IAwCX,OAAO,CAAC,mBAAmB,CAWzB;IAEF,OAAO,CAAC,wBAAwB,CAM9B;IAEF,OAAO,CAAC,wBAAwB,CAM9B;IAEF,OAAO,CAAC,qBAAqB,CAM3B;IAEF,OAAO,CAAC,qBAAqB,CAM3B;IAEF,OAAO,CAAC,uBAAuB,CAM9B;CACJ;;AAED,wBAA4D","file":"dropdown.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, Theme } from '../cn';\n\nimport Button from '../button/button';\nimport Link from '../link/link';\nimport Popup, { PopupProps } from '../popup/popup';\n\nimport { POPUP_MAIN_OFFSET } from '../vars';\n\nexport type DropdownProps = {\n\n    /**\n     * Тип компонента\n     */\n    switcherType?: 'link' | 'button';\n\n    /**\n     * Текст кнопки компонента\n     */\n    switcherText?: React.ReactNode;\n\n    /**\n     * Компонент [Popup](#!/Popup)\n     */\n    popupContent?: React.ReactNode;\n\n    /**\n     * Свойства для компонента [Popup](#!/Popup)\n     */\n    popupProps?: PopupProps;\n\n    /**\n     * Управление возможностью отображать попап при наведении курсора\n     */\n    mode?: 'hover' | 'normal';\n\n    /**\n     * Управление возможностью открытия попапа\n     */\n    disabled?: boolean;\n\n    /**\n     * Управление состоянием открыт/закрыт попапа\n     */\n    opened?: boolean;\n\n    /**\n     * Только для switcherType='button'. Тип переключателя для кнопки, 'check'\n     */\n    togglable?: 'button' | 'check';\n\n    /**\n     * Размер компонента\n     */\n    size?: 's' | 'm' | 'l' | 'xl';\n\n    /**\n     * Дочерние элементы `Dropdown`\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    onSwitcherClick?: (isOpened?: boolean) => void;\n\n    /**\n     * Обработчик события наведения курсора на кнопку компонента\n     */\n    onSwitcherMouseEnter?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик события снятия курсора с кнопки компонента\n     */\n    onSwitcherMouseLeave?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик события наведения курсора на попап\n     */\n    onPopupMouseEnter?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик события снятия курсора с попапа\n     */\n    onPopupMouseLeave?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик события клика попапа за пределами попапа\n     */\n    onPopupClickOutside?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Идентификатор для систем автоматизированного тестирования\n     */\n    'data-test-id'?: string;\n};\n\n/**\n * Компонент «выпадашка»: ссылка или кнопка. По клику показывается Popup.\n */\nexport class Dropdown extends React.PureComponent<DropdownProps> {\n    protected cn = createCn('dropdown');\n\n    static defaultProps: Partial<DropdownProps> = {\n        switcherType: 'link',\n        switcherText: 'Switcher',\n        disabled: false,\n        popupProps: {\n            target: 'anchor',\n        },\n        size: 'm',\n    };\n\n    state = {\n        opened: false,\n        switcherHovered: false,\n        popupHovered: false,\n    };\n\n    private popup;\n\n    private switcher;\n\n    componentDidMount() {\n        this.popup.setTarget(this.switcher.getNode());\n    }\n\n    render() {\n        return (\n            <div\n                className={ this.cn() }\n                id={ this.props.id }\n                data-test-id={ this.props['data-test-id'] }\n            >\n                { this.renderSwitcher() }\n                { this.renderPopup() }\n            </div>\n        );\n    }\n\n    renderSwitcher() {\n        const content = this.props.children || this.props.switcherText;\n        const opened = this.props.opened === undefined ? this.state.opened : this.props.opened;\n\n        return this.props.switcherType === 'button'\n            ? this.renderSwitcherButton(content, opened)\n            : this.renderSwitcherLink(content);\n    }\n\n    renderSwitcherButton(content, opened) {\n        return (\n            <Button\n                className={ this.cn('switcher') }\n                size={ this.props.size }\n                ref={ (switcher) => {\n                    this.switcher = switcher;\n                } }\n                disabled={ this.props.disabled }\n                togglable={ this.props.togglable as any /** TODO: разобраться детально */ }\n                checked={ this.props.togglable === 'check' && opened }\n                onClick={ this.props.disabled ? undefined : this.handleSwitcherClick }\n                onMouseEnter={ this.handleSwitcherMouseEnter }\n                onMouseLeave={ this.handleSwitcherMouseLeave }\n            >\n                { content }\n            </Button>\n        );\n    }\n\n    renderSwitcherLink(content) {\n        return (\n            <Link\n                className={ this.cn('switcher') }\n                size={ this.props.size }\n                ref={ (switcher) => {\n                    this.switcher = switcher;\n                } }\n                disabled={ this.props.disabled }\n                pseudo={ true }\n                text={ content }\n                onClick={ this.props.disabled ? undefined : this.handleSwitcherClick }\n                onMouseEnter={ this.handleSwitcherMouseEnter }\n                onMouseLeave={ this.handleSwitcherMouseLeave }\n            />\n        );\n    }\n\n    renderPopup() {\n        let mainOffset;\n        const opened = this.props.opened === undefined ? this.state.opened : this.props.opened;\n\n        if (this.props.popupProps === undefined || (\n            this.props.popupProps && this.props.popupProps.type !== 'tooltip')) {\n            switch (this.props.size) {\n            case 's':\n            case 'm': mainOffset = POPUP_MAIN_OFFSET / 2; break;\n            case 'l':\n            case 'xl': mainOffset = POPUP_MAIN_OFFSET; break;\n            }\n        }\n\n        const popupProps = {\n            className: this.cn('popup'),\n            size: this.props.size,\n            mainOffset,\n            ...this.props.popupProps,\n        };\n\n        return (\n            <Popup\n                { ...popupProps }\n                ref={ (popup) => {\n                    this.popup = popup;\n                } }\n                visible={\n                    (!this.props.disabled && opened)\n                    || (this.props.mode === 'hover' && (this.state.switcherHovered || this.state.popupHovered))\n                }\n                onMouseEnter={ this.handlePopupMouseEnter }\n                onMouseLeave={ this.handlePopupMouseLeave }\n                onClickOutside={ this.handlePopupClickOutside }\n            >\n                { this.props.popupContent }\n            </Popup>\n        );\n    }\n\n    private handleSwitcherClick = () => {\n        // eslint-disable-next-line react/no-access-state-in-setstate\n        const newOpenedStatusValue = this.props.opened === undefined ? !this.state.opened : !this.props.opened;\n\n        this.setState({\n            opened: newOpenedStatusValue,\n        });\n\n        if (this.props.onSwitcherClick) {\n            this.props.onSwitcherClick(newOpenedStatusValue);\n        }\n    };\n\n    private handleSwitcherMouseEnter = (event) => {\n        this.setState({ switcherHovered: true });\n\n        if (this.props.onSwitcherMouseEnter) {\n            this.props.onSwitcherMouseEnter(event);\n        }\n    };\n\n    private handleSwitcherMouseLeave = (event) => {\n        this.setState({ switcherHovered: false });\n\n        if (this.props.onSwitcherMouseLeave) {\n            this.props.onSwitcherMouseLeave(event);\n        }\n    };\n\n    private handlePopupMouseEnter = (event) => {\n        this.setState({ popupHovered: true });\n\n        if (this.props.onPopupMouseEnter) {\n            this.props.onPopupMouseEnter(event);\n        }\n    };\n\n    private handlePopupMouseLeave = (event) => {\n        this.setState({ popupHovered: false });\n\n        if (this.props.onPopupMouseLeave) {\n            this.props.onPopupMouseLeave(event);\n        }\n    };\n\n    private handlePopupClickOutside = (event) => {\n        this.setState({ opened: false });\n\n        if (this.props.onPopupClickOutside) {\n            this.props.onPopupClickOutside(event);\n        }\n    }\n}\n\nexport default withTheme<DropdownProps, Dropdown>(Dropdown);\n"]}