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H,YAAY,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAEvD;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAEzD;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAElD;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC;IACpE,SAAS,CAAC,EAAE;;;;;;iBAA4B;IAExC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAK7C;IAEF,KAAK;;MAEH;IAEF,OAAO,CAAC,IAAI,CAAiB;IAE7B,OAAO,CAAC,YAAY,CAAQ;IAE5B,OAAO,CAAC,qBAAqB,CAAQ;IAErC,OAAO,CAAC,mBAAmB,CAAS;IAEpC,iBAAiB;IAQjB,kBAAkB,CAAC,SAAS,KAAA;IAQ5B,oBAAoB;IAQpB,MAAM;IAqEN,OAAO,CAAC,WAAW,CAIjB;IAEF,OAAO,CAAC,iBAAiB,CAIvB;IAEF,OAAO,CAAC,aAAa,CAInB;IAEF,OAAO,CAAC,gBAAgB,CAOtB;IAEF,OAAO,CAAC,gBAAgB,CAQtB;IAEF,OAAO,CAAC,WAAW,CAIjB;IAEF,OAAO,CAAC,iBAAiB,CAMvB;IAEF,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,gBAAgB;CAsB3B;;AAED,wBAAwE","file":"notification.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\n/* eslint jsx-a11y/no-static-element-interactions: 0 */\n\nimport React from 'react';\nimport { createCn } from 'bem-react-classname';\nimport {\n    CloseSIcon,\n} from '@alfalab/icons-classic/CloseSIcon';\nimport {\n    ErrorMColorIcon,\n} from '@alfalab/icons-classic/ErrorMColorIcon';\nimport {\n    FailMIcon,\n} from '@alfalab/icons-classic/FailMIcon';\nimport {\n    OkMColorIcon,\n} from '@alfalab/icons-classic/OkMColorIcon';\nimport { withTheme, Theme } from '../cn';\n\nimport IconButton from '../icon-button/icon-button';\nimport Swipeable from '../swipeable';\n\nimport { isNodeOutsideElement } from '../lib/window';\n\nexport type NotificationProps = {\n    /**\n     * Тип компонента\n     */\n    status?: 'error' | 'fail' | 'ok';\n\n    /**\n     * Управление видимостью компонента\n     */\n    visible?: boolean;\n\n    /**\n     * Отступ от верхнего края\n     */\n    offset?: number;\n\n    /**\n     * К какому краю прижат попап\n     */\n    stickTo?: 'left' | 'right';\n\n    /**\n     * Управляет отображением кнопки закрытия уведомления\n     */\n    hasCloser?: boolean;\n\n    /**\n     * Дочерние элементы `Notification`\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    title?: React.ReactNode;\n\n    /**\n     * Замена стандартной иконки\n     */\n    icon?: React.ReactNode;\n\n    /**\n     * Время до закрытия компонента\n     */\n    autoCloseDelay?: number;\n\n    /**\n     * Обработчик события истечения времени до закрытия компонента\n     */\n    onCloseTimeout?: () => void;\n\n    /**\n     * Обработчик клика по крестику компонента\n     */\n    onCloserClick?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик события нажатия на клавишу клавиатуры в момент, когда фокус находится на компоненте\n     */\n    onKeyDown?: (event?: React.KeyboardEvent<any>) => void;\n\n    /**\n     * Обработчик события наведения курсора на попап\n     */\n    onMouseEnter?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик события снятия курсора с попапа\n     */\n    onMouseLeave?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик клика вне компонента\n     */\n    onClickOutside?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик клика по компоненту\n     */\n    onClick?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Идентификатор для систем автоматизированного тестирования\n     */\n    'data-test-id'?: string;\n};\n\n/**\n * Компонент всплывающего окна.\n */\nexport class Notification extends React.PureComponent<NotificationProps> {\n    protected cn = createCn('notification');\n\n    static defaultProps: Partial<NotificationProps> = {\n        autoCloseDelay: 5000,\n        stickTo: 'right',\n        offset: 12,\n        hasCloser: true,\n    };\n\n    state = {\n        hovered: false,\n    };\n\n    private root: HTMLDivElement;\n\n    private closeTimeout = null;\n\n    private clickEventBindTimeout = null;\n\n    private isWindowClickBinded = false;\n\n    componentDidMount() {\n        this.startCloseTimer();\n\n        if (this.props.onClickOutside) {\n            this.ensureClickEvent();\n        }\n    }\n\n    componentDidUpdate(prevProps) {\n        if (prevProps.onClickOutside !== this.props.onClickOutside) {\n            this.ensureClickEvent();\n        } else if (prevProps.visible !== this.props.visible) {\n            this.ensureClickEvent(!this.props.visible);\n        }\n    }\n\n    componentWillUnmount() {\n        this.stopCloseTimer();\n\n        if (this.props.onClickOutside) {\n            this.ensureClickEvent(true);\n        }\n    }\n\n    render() {\n        const { theme, status } = this.props;\n        let ToggledIcon;\n\n        switch (status) {\n        case 'error': ToggledIcon = ErrorMColorIcon; break;\n        case 'fail': ToggledIcon = FailMIcon; break;\n        case 'ok': ToggledIcon = OkMColorIcon; break;\n        default: ToggledIcon = OkMColorIcon; break;\n        }\n\n        return (\n            <Swipeable onSwipe={ this.handleSwipe }>\n                <div\n                    ref={ (root) => {\n                        this.root = root;\n                    } }\n                    className={ this.cn({\n                        visible: this.props.visible,\n                        status,\n                        hovered: this.state.hovered,\n                        'has-closer': this.props.hasCloser,\n                        'stick-to': this.props.stickTo,\n                    }) }\n                    id={ this.props.id }\n                    style={ this.getPosition() }\n                    onMouseEnter={ this.handleMouseEnter }\n                    onMouseLeave={ this.handleMouseLeave }\n                    onClick={ this.handleClick }\n                    onKeyDown={ this.handleKeyDown }\n                    data-test-id={ this.props['data-test-id'] }\n                >\n                    <div className={ this.cn('icon', { theme }) }>\n                        {\n                            this.props.icon\n                            || (\n                                <ToggledIcon />\n                            )\n                        }\n                    </div>\n                    { this.props.title\n                        && (\n                            <div className={ this.cn('title') }>\n                                { this.props.title }\n                            </div>\n                        ) }\n                    { this.props.children\n                        && (\n                            <div className={ this.cn('content') }>\n                                { this.props.children }\n                            </div>\n                        ) }\n                    {\n                        this.props.hasCloser\n                        && (\n                            <IconButton\n                                className={ this.cn('closer', { theme }) }\n                                size=\"m\"\n                                onClick={ this.handleCloserClick }\n                            >\n                                <CloseSIcon />\n                            </IconButton>\n                        )\n                    }\n                </div>\n            </Swipeable>\n        );\n    }\n\n    private handleSwipe = (direction) => {\n        if (direction === 'left' || direction === 'right' || direction === 'top') {\n            this.handleCloserClick();\n        }\n    };\n\n    private handleCloserClick = (event?) => {\n        if (this.props.onCloserClick) {\n            this.props.onCloserClick(event);\n        }\n    };\n\n    private handleKeyDown = (event) => {\n        if (this.props.onKeyDown) {\n            this.props.onKeyDown(event);\n        }\n    };\n\n    private handleMouseEnter = (event) => {\n        this.setState({ hovered: true });\n        this.stopCloseTimer();\n\n        if (this.props.onMouseEnter) {\n            this.props.onMouseEnter(event);\n        }\n    };\n\n    private handleMouseLeave = (event) => {\n        this.setState({ hovered: false });\n        this.stopCloseTimer();\n        this.startCloseTimer();\n\n        if (this.props.onMouseLeave) {\n            this.props.onMouseLeave(event);\n        }\n    };\n\n    private handleClick = (event) => {\n        if (this.props.onClick) {\n            this.props.onClick(event);\n        }\n    };\n\n    private handleWindowClick = (event) => {\n        if (this.props.onClickOutside && this.root\n            && isNodeOutsideElement(event.target, this.root)\n        ) {\n            this.props.onClickOutside(event);\n        }\n    };\n\n    private getPosition() {\n        return { top: this.props.offset };\n    }\n\n    private startCloseTimer() {\n        this.closeTimeout = setTimeout(() => {\n            if (this.props.onCloseTimeout) {\n                this.props.onCloseTimeout();\n            }\n        }, this.props.autoCloseDelay);\n    }\n\n    private stopCloseTimer() {\n        clearTimeout(this.closeTimeout);\n        this.closeTimeout = null;\n    }\n\n    private ensureClickEvent(isDestroy?) {\n        const isNeedBindEvent = isDestroy === undefined ? this.props.visible : !isDestroy;\n\n        // We need timeouts to not to catch the event that causes\n        // popup opening (because it propagates to the `window`).\n        if (this.clickEventBindTimeout) {\n            clearTimeout(this.clickEventBindTimeout);\n            this.clickEventBindTimeout = null;\n        }\n\n        this.clickEventBindTimeout = setTimeout(() => {\n            if (!this.isWindowClickBinded && isNeedBindEvent) {\n                window.addEventListener('click', this.handleWindowClick);\n                window.addEventListener('touchend', this.handleWindowClick);\n                this.isWindowClickBinded = true;\n            } else if (this.isWindowClickBinded && !isNeedBindEvent) {\n                window.removeEventListener('click', this.handleWindowClick);\n                window.removeEventListener('touchend', this.handleWindowClick);\n                this.isWindowClickBinded = false;\n            }\n        }, 0);\n    }\n}\n\nexport default withTheme<NotificationProps, Notification>(Notification);\n"]}