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I,IAAI;IAMX;;OAEG;IACI,QAAQ;CAQlB;;IA1UG;;OAEG;;IAEH;;OAEG;;;IAaH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;;IA7FH;;OAEG;;IAEH;;OAEG;;;IAIH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;;AAsOP,wBAAmD","file":"radio.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 TagButton from '../tag-button/tag-button';\nimport scrollTo from '../lib/scroll-to';\nimport { SCROLL_TO_CORRECTION } from '../vars';\n\nexport type RadioProps = ({\n    /**\n     * Тип\n     */\n    type?: 'normal';\n    /**\n     * Размер компонента\n     */\n    size?: 'm' | 'l';\n} | {\n    /**\n     * Тип\n     */\n    type?: 'button';\n    /**\n     * Размер компонента\n     */\n    size?: 's'| 'm' | 'l' | 'xl';\n}) & {\n\n    /**\n     * Управление состоянием вкл/выкл компонента\n     */\n    checked?: boolean;\n\n    /**\n     * Управление возможностью изменения состояние 'checked' компонента\n     */\n    disabled?: boolean;\n\n    /**\n     * Уникальный идентификатор блока\n     */\n    id?: string;\n\n    /**\n     * Уникальное имя блока\n     */\n    name?: string;\n\n    /**\n     * Значение радио-кнопки, которое будет отправлено на сервер, если она выбрана\n     */\n    value?: string;\n\n    /**\n     * Текст подписи к радио-кнопке\n     */\n    text?: React.ReactNode;\n\n    /**\n     * Управление шириной кнопки для типа 'button'. При значении 'available'\n     * растягивает кнопку на ширину родителя\n     */\n    width?: 'default' | 'available';\n\n    /**\n     * Отображение в состоянии ошибки\n     */\n    error?: boolean;\n\n    /**\n     * Последовательность перехода между контролами при нажатии на Tab\n     */\n    tabIndex?: number;\n\n    /**\n     * Тема компонента\n     */\n    theme?: 'alfa-on-color' | 'alfa-on-white';\n\n    /**\n     * Дополнительный класс\n     */\n    className?: string;\n\n    /**\n     * Обработчик изменения значения 'checked' компонента, принимает на вход isChecked и value компонента\n     */\n    onChange?: (value?: string, isChecked?: boolean, event?: React.ChangeEvent<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\ntype RadioState = {\n    focused: boolean;\n    hovered: boolean;\n    checked: boolean;\n    pressed?: boolean;\n}\n\n/**\n * Компонент радио-кнопки.\n */\nexport class Radio extends React.PureComponent<RadioProps, RadioState> {\n    protected cn = createCn('radio');\n\n    static defaultProps: Partial<RadioProps> = {\n        size: 'm',\n        tabIndex: 0,\n    };\n\n    state: RadioState = {\n        focused: false,\n        hovered: false,\n        checked: false,\n    };\n\n    private label;\n\n    private control;\n\n    render() {\n        const checked = this.props.checked === undefined ? this.state.checked : this.props.checked;\n\n        return (\n            // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n            <label\n                className={ this.cn({\n                    size: this.props.size,\n                    disabled: this.props.disabled,\n                    checked,\n                    focused: this.state.focused,\n                    hovered: this.state.hovered,\n                    pressed: this.state.pressed,\n                    invalid: !!this.props.error,\n                    width: this.props.type === 'button' ? this.props.width : null,\n                }) }\n                htmlFor={ this.props.id }\n                tabIndex={ this.props.tabIndex }\n                onFocus={ this.handleFocus }\n                onBlur={ this.handleBlur }\n                onMouseEnter={ this.handleMouseEnter }\n                onMouseLeave={ this.handleMouseLeave }\n                onMouseDown={ this.handleUnfocus }\n                onMouseUp={ this.handleUnfocus }\n                ref={ (label) => {\n                    this.label = label;\n                } }\n                data-test-id={ this.props['data-test-id'] }\n            >\n                { this.props.type === 'button'\n                    ? this.renderButtonRadio(checked, TagButton)\n                    : this.renderNormalRadio(checked) }\n            </label>\n        );\n    }\n\n    renderNormalRadio(checked) {\n        return [\n            <span className={ this.cn('box') } key={ 0 }>\n                <input\n                    checked={ checked }\n                    disabled={ this.props.disabled }\n                    name={ this.props.name }\n                    id={ this.props.id }\n                    value={ this.props.value }\n                    autoComplete=\"off\"\n                    tabIndex={ -1 }\n                    type=\"radio\"\n                    className={ this.cn('control') }\n                    ref={ (control) => {\n                        this.control = control;\n                    } }\n                    onClick={ this.handleInputControlClick }\n                    onChange={ this.handleChange }\n                />\n            </span>,\n            this.props.text && (\n                <span className={ this.cn('text') } role=\"presentation\" key={ 1 }>\n                    { this.props.text }\n                </span>\n            ),\n        ];\n    }\n\n    renderButtonRadio(checked, TagButton) {\n        return (\n            <div>\n                <TagButton\n                    togglable=\"check\"\n                    checked={ checked }\n                    disabled={ this.props.disabled }\n                    size={ this.props.size }\n                    width={ this.props.width }\n                    focused={ this.state.focused }\n                    hovered={ this.state.hovered }\n                    tabIndex={ -1 }\n                    onClick={ this.handleChange }\n                >\n                    { this.props.text ? this.props.text : '' }\n                </TagButton>\n                <input\n                    checked={ checked }\n                    disabled={ this.props.disabled }\n                    name={ this.props.name }\n                    id={ this.props.id }\n                    value={ this.props.value }\n                    autoComplete=\"off\"\n                    tabIndex={ -1 }\n                    type=\"radio\"\n                    className={ this.cn('control') }\n                    onChange={ this.handleChange }\n                    ref={ (control) => {\n                        this.control = control;\n                    } }\n                />\n            </div>\n        );\n    }\n\n    private handleInputControlClick = (event) => {\n        event.stopPropagation();\n    };\n\n    private handleChange = (event) => {\n        if (!this.props.disabled) {\n            // eslint-disable-next-line react/no-access-state-in-setstate\n            const nextCheckedValue = !(this.props.checked === undefined ? this.state.checked : this.props.checked);\n\n            this.setState({ checked: nextCheckedValue });\n\n            if (this.props.onChange) {\n                this.props.onChange(this.props.value, nextCheckedValue, event);\n            }\n        }\n    };\n\n    private handleFocus = (event) => {\n        if (!this.props.disabled) {\n            this.setState({ focused: true });\n        }\n\n        if (this.props.type !== 'button') {\n            // eslint-disable-next-line no-param-reassign\n            event.target.value = this.props.value;\n        }\n\n        if (this.props.onFocus) {\n            this.props.onFocus(event);\n        }\n    };\n\n    private handleUnfocus = () => setImmediate(() => this.setState({ focused: false }));\n\n    private handleBlur = (event) => {\n        if (!this.props.disabled) {\n            this.setState({ focused: false });\n        }\n\n        if (this.props.type !== 'button') {\n            // eslint-disable-next-line no-param-reassign\n            event.target.value = this.props.value;\n        }\n\n        if (this.props.onBlur) {\n            this.props.onBlur(event);\n        }\n    };\n\n    private handleMouseEnter = (event) => {\n        if (!this.props.disabled) {\n            this.setState({ hovered: true });\n        }\n\n        if (this.props.onMouseEnter) {\n            this.props.onMouseEnter(event);\n        }\n    };\n\n    private handleMouseLeave = (event) => {\n        if (!this.props.disabled) {\n            this.setState({ hovered: false });\n        }\n\n        if (this.props.onMouseLeave) {\n            this.props.onMouseLeave(event);\n        }\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    /**\n     * Скроллит страницу до радио-кнопки.\n     */\n    public scrollTo() {\n        const elementRect = this.label.getBoundingClientRect();\n\n        scrollTo({\n            // eslint-disable-next-line no-mixed-operators\n            targetY: elementRect.top + window.pageYOffset - SCROLL_TO_CORRECTION,\n        });\n    }\n}\n\nexport default withTheme<RadioProps, Radio>(Radio);\n"]}