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D;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAEjD;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAEvD;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAEvD;;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;;;;;;iBAAyB;IAErC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,CAGzC;IAEF,KAAK;;;MAGH;IAEF,OAAO,CAAC,IAAI,CAAC;IAEb,OAAO,CAAC,OAAO,CAAC;IAEhB,MAAM;IA6FN,OAAO,CAAC,WAAW,CAUjB;IAEF,OAAO,CAAC,WAAW,CAMjB;IAEF,OAAO,CAAC,UAAU,CAMhB;IAEF,OAAO,CAAC,gBAAgB,CAMtB;IAEF,OAAO,CAAC,gBAAgB,CAMtB;IAEF;;OAEG;IACI,OAAO;IAId;;OAEG;IACI,KAAK;IAIZ;;OAEG;IAEI,IAAI;CAKd;;AAED,wBAA4D","file":"menu-item.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 Dropdown from '../dropdown/dropdown';\nimport Link from '../link/link';\n\nexport type MenuItemProps = {\n\n    /**\n     * Тип элемента меню\n     */\n    type?: 'link' | 'dropdown' | 'block';\n\n    /**\n     * Тип ссылки, для компонента с type='link'\n     */\n    view?: 'plain' | 'underlined' | 'pseudo';\n\n    /**\n     * href ссылки, для компонента с type='link'\n     */\n    url?: string;\n\n    /**\n     * target для ссылки\n     */\n    target?: '_self' | '_blank' | '_parent' | '_top';\n\n    /**\n     * Уникальное значение элемента. Для использования в Menu\n     */\n    value?: string | number;\n\n    /**\n     * Попап для компонента с type='dropdown'\n     */\n    popup?: React.ReactNode;\n\n    /**\n     * Управление возможностью выбирать данный компонент\n     */\n    disabled?: boolean;\n\n    /**\n     * Управление состоянием выбран/не выбран компонента\n     */\n    checked?: boolean;\n\n    /**\n     * Управление видимостью компонента\n     */\n    hidden?: boolean;\n\n    /**\n     * Управление визуальным выделением компонента\n     */\n    hovered?: boolean;\n\n    /**\n     * Размер компонента\n     */\n    size?: 's' | 'm' | 'l' | 'xl';\n\n    /**\n     * Дочерние элементы `MenuItem`\n     */\n    children?: React.ReactNode;\n\n    /**\n     * Тема компонента\n     */\n    theme?: Theme;\n\n    /**\n     * Дополнительный класс\n     */\n    className?: string;\n\n    /**\n     * Только для type='link', обработчик клика по компоненту\n     */\n    onClick?: (event?: React.MouseEvent<any>) => void;\n\n    /**\n     * Обработчик фокуса компонента\n     */\n    onFocus?: (event?: React.FocusEvent<any>) => void;\n\n    /**\n     * Обработчик снятия фокуса компонента\n     */\n    onBlur?: (event?: React.FocusEvent<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    'data-test-id'?: string;\n};\n\n/**\n * Компонент элемента меню. Как правило, используется совместно с `Menu`.\n */\nexport class MenuItem extends React.PureComponent<MenuItemProps> {\n    protected cn = createCn('menu-item');\n\n    static defaultProps: Partial<MenuItemProps> = {\n        type: 'link',\n        view: 'plain',\n    };\n\n    state = {\n        hovered: false,\n        focused: false,\n    };\n\n    private root;\n\n    private control;\n\n    render() {\n        const content: any = this.props.children || this.props.value;\n        let itemElement;\n        let menuItemProps: any = {\n            ref: (root) => {\n                this.root = root;\n            },\n            'data-test-id': this.props['data-test-id'],\n        };\n\n        switch (this.props.type) {\n        case 'dropdown':\n            itemElement = (\n                <Dropdown\n                    ref={ (control) => {\n                        this.control = control;\n                    } }\n                    className={ `${this.cn('control')} ${this.cn('dropdown')}` }\n                    size={ this.props.size }\n                    theme={ this.props.theme }\n                    opened={ this.state.hovered }\n                    switcherType=\"link\"\n                    switcherText={ content }\n                    popupContent={ this.props.popup }\n                    popupProps={ {\n                        directions: ['bottom-left'],\n                        target: 'anchor',\n                    } }\n                    mode=\"hover\"\n                    onSwitcherClick={ this.handleClick }\n                    onSwitcherMouseEnter={ this.handleMouseEnter }\n                    onSwitcherMouseLeave={ this.handleMouseLeave }\n                />\n            );\n            break;\n        case 'block':\n            menuItemProps = {\n                ref: (control) => {\n                    this.root = control;\n                    this.control = control;\n                },\n                onClick: this.handleClick,\n                onMouseEnter: this.handleMouseEnter,\n                onMouseLeave: this.handleMouseLeave,\n            };\n            itemElement = <span className={ this.cn('control') }>{ content }</span>;\n\n            break;\n        case 'link':\n        default:\n            itemElement = (\n                <Link\n                    ref={ (control) => {\n                        this.control = control;\n                    } }\n                    className={ `${this.cn('control')} ${this.cn('link')}` }\n                    size={ this.props.size }\n                    theme={ this.props.theme }\n                    pseudo={ this.props.view === 'pseudo' }\n                    disabled={ this.props.disabled }\n                    checked={ this.props.checked }\n                    text={ this.props.view !== 'plain' && content }\n                    url={ this.props.url }\n                    target={ this.props.target }\n                    onClick={ this.handleClick }\n                    onFocus={ this.handleFocus }\n                    onBlur={ this.handleBlur }\n                    onMouseEnter={ this.handleMouseEnter }\n                    onMouseLeave={ this.handleMouseLeave }\n                >\n                    { this.props.view === 'plain' && content }\n                </Link>\n            );\n            break;\n        }\n\n        return (\n            <div\n                className={ this.cn({\n                    disabled: this.props.disabled,\n                    checked: this.props.checked,\n                    hidden: this.props.hidden,\n                    type: this.props.type,\n                    hovered: this.props.hovered === undefined ? this.state.hovered : this.props.hovered,\n                    focused: this.state.focused,\n                }) }\n                { ...menuItemProps }\n            >\n                { itemElement }\n            </div>\n        );\n    }\n\n    private handleClick = (event) => {\n        if (this.props.disabled) {\n            event.preventDefault();\n\n            return;\n        }\n\n        if (this.props.onClick) {\n            this.props.onClick(event);\n        }\n    };\n\n    private handleFocus = (event) => {\n        this.setState({ focused: true });\n\n        if (this.props.onFocus) {\n            this.props.onFocus(event);\n        }\n    };\n\n    private handleBlur = (event) => {\n        this.setState({ focused: false });\n\n        if (this.props.onBlur) {\n            this.props.onBlur(event);\n        }\n    };\n\n    private handleMouseEnter = (event) => {\n        this.setState({ hovered: true });\n\n        if (this.props.onMouseEnter) {\n            this.props.onMouseEnter(event);\n        }\n    };\n\n    private handleMouseLeave = (event) => {\n        this.setState({ hovered: false });\n\n        if (this.props.onMouseLeave) {\n            this.props.onMouseLeave(event);\n        }\n    };\n\n    /**\n     * Возвращает корневой `HTMLElement` компонента.\n     */\n    public getNode() {\n        return this.root;\n    }\n\n    /**\n     * Устанавливает фокус на элементе меню.\n     */\n    public focus() {\n        this.control.focus();\n    }\n\n    /**\n     * Убирает фокус с элемента меню.\n     */\n    // eslint-disable-next-line class-methods-use-this\n    public blur() {\n        if (document.activeElement) {\n            (document.activeElement as HTMLElement).blur();\n        }\n    }\n}\n\nexport default withTheme<MenuItemProps, MenuItem>(MenuItem);\n"]}