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AC;IAEpC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK,CAAC,aAAa,CAAC,eAAe,CAAC;IAChE,SAAS,CAAC,EAAE;;;;;;iBAA2B;IAEvC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,eAAe,CAAC,CAG3C;IAEF,KAAK;;MAEH;IAGF,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,MAAM;IA4EN,OAAO,CAAC,iBAAiB,CAQvB;IAEF,OAAO,CAAC,WAAW,CAIjB;IAEF,OAAO,CAAC,UAAU,CAIhB;IAEF;;OAEG;IACI,KAAK;IAMZ;;OAEG;IAEI,IAAI;CAKd;;AAED,wBAAkE","file":"radio-group.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 createFragment from 'react-addons-create-fragment';\nimport React from 'react';\nimport { createCn } from 'bem-react-classname';\nimport { withTheme, Theme } from '../cn';\nimport { Radio } from '../radio/radio';\n\nexport type RadioGroupProps = {\n\n    /**\n     * Тип группы кнопок\n     */\n    type?: 'normal' | 'button' | 'line';\n\n    /**\n     * Значение выбранной радио-кнопки\n     */\n    value?: string;\n\n    /**\n     * Отображение попапа с ошибкой в момент когда фокус находится на компоненте\n     */\n    error?: React.ReactNode;\n\n    /**\n     * Размеры pub и sub\n     */\n    size?: 's' | 'm' | 'l' | 'xl';\n\n    /**\n     * Управление шириной группы кнопок для типа 'button'. При значении\n'available' растягивает группу на ширину родителя\n     */\n    width?: 'default' | 'available';\n\n    /**\n     * Уникальное имя блока\n     */\n    name?: string;\n\n    /**\n     * Управление возможностью изменения состояния 'checked' дочерних компонентов `Radio`\n     */\n    disabled?: boolean;\n\n    /**\n     * Дочерние элементы `RadioGroup`, как правило, компоненты `Radio`\n     */\n    children?: React.ReactNode;\n\n    /**\n     * Тема компонента\n     */\n    theme?: Theme;\n\n    /**\n     * Дополнительный класс\n     */\n    className?: string;\n\n    /**\n     * Лейбл для группы\n     */\n    label?: React.ReactNode;\n\n    /**\n     * Подсказка под полем\n     */\n    hint?: React.ReactNode;\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     * Обработчик изменения значения 'checked' одного из дочерних радио-кнопок\n     */\n    onChange?: (value?: string) => void;\n\n    /**\n     * Идентификатор для систем автоматизированного тестирования\n     */\n    'data-test-id'?: string;\n};\n\n/**\n * Компонент группы радио-кнопок.\n */\nexport class RadioGroup extends React.PureComponent<RadioGroupProps> {\n    protected cn = createCn('radio-group');\n\n    static defaultProps: Partial<RadioGroupProps> = {\n        type: 'normal',\n        size: 'm',\n    };\n\n    state = {\n        value: '',\n    };\n\n    // TODO [issues/1018] переписать тесты нужно, что бы private был\n    radios: Radio[];\n\n    render() {\n        let children: React.ReactNode = null;\n        const { size, name } = this.props;\n        let props: { name: string; disabled?: boolean; width?: 'default' | 'available' } = { name };\n        const radioGroupParts = {};\n\n        if (this.props.disabled !== undefined) {\n            props.disabled = this.props.disabled;\n        }\n\n        if (this.props.children) {\n            const { children: propsChildren } = this.props;\n\n            children = React.Children.toArray(propsChildren);\n        }\n\n        if (this.props.type === 'button') {\n            props = { ...props, width: this.props.width };\n        }\n\n        if (children) {\n            this.radios = [];\n            const value = this.props.value === undefined ? this.state.value : this.props.value;\n\n            React.Children.forEach(children, (radio, index) => {\n                if (React.isValidElement(radio)) {\n                    radioGroupParts[`radio-${index}`] = React.cloneElement(radio, {\n                        ref: (radio) => this.radios.push(radio),\n                        error: radio.props.error === undefined ? Boolean(this.props.error) : radio.props.error,\n                        checked: (\n                            radio.props.checked === undefined ? (value === radio.props.value) : radio.props.checked\n                        ),\n                        onChange: radio.props.onChange === undefined ? this.handleRadioChange : radio.props.onChange,\n                        ...props,\n                    });\n                }\n            });\n        }\n\n        return (\n            <div\n                className={\n                    `${this.cn({\n                        type: this.props.type,\n                        invalid: !!this.props.error,\n                        size,\n                        ...props,\n                    })} control-group${this.props.error ? ' control-group_invalid' : ''}`\n                }\n                role=\"group\"\n                tabIndex={ -1 }\n                onFocus={ this.handleFocus }\n                onBlur={ this.handleBlur }\n                data-test-id={ this.props['data-test-id'] }\n            >\n                <div className={ this.cn('inner') }>\n                    {\n                        !!this.props.label\n                        && <div className={ this.cn('top') }>{ this.props.label }</div>\n                    }\n                    <div className={ this.cn('box') }>\n                        { createFragment(radioGroupParts) }\n                    </div>\n                    {\n                        (this.props.error || this.props.hint)\n                        && (\n                            <span className={ this.cn('sub') }>\n                                { this.props.error || this.props.hint }\n                            </span>\n                        )\n                    }\n                </div>\n            </div>\n        );\n    }\n\n    private handleRadioChange = (value) => {\n        if (this.state.value !== value) {\n            this.setState({ value });\n        }\n\n        if (this.props.value !== value && this.props.onChange) {\n            this.props.onChange(value);\n        }\n    };\n\n    private handleFocus = (event) => {\n        if (this.props.onFocus) {\n            this.props.onFocus(event);\n        }\n    };\n\n    private handleBlur = (event) => {\n        if (this.props.onBlur) {\n            this.props.onBlur(event);\n        }\n    };\n\n    /**\n     * Устанавливает фокус на первую радиокнопку в группе.\n     */\n    public focus() {\n        if (this.radios && this.radios[0]) {\n            this.radios[0].focus();\n        }\n    }\n\n    /**\n     * Убирает фокус с группы радио-кнопок.\n     */\n    // eslint-disable-next-line class-methods-use-this\n    public blur() {\n        if (document.activeElement instanceof HTMLElement) {\n            document.activeElement.blur();\n        }\n    }\n}\n\nexport default withTheme<RadioGroupProps, RadioGroup>(RadioGroup);\n"]}