@yandex/ui
Version:
Yandex UI components
38 lines (37 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Radiobox = exports.cnRadiobox = void 0;
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importStar(require("react"));
var di_1 = require("@bem-react/di");
var classname_1 = require("@bem-react/classname");
var Radiobox_context_1 = require("./Radiobox.context");
require("./Radiobox.css");
exports.cnRadiobox = classname_1.cn('Radiobox');
/**
* Компонент для создания радиопереключателя.
* @param {RadioboxProps} props Свойства компонента.
*/
var Radiobox = function (_a) {
var children = _a.children, className = _a.className, disabled = _a.disabled, innerRef = _a.innerRef, name = _a.name, onChange = _a.onChange, _b = _a.options, options = _b === void 0 ? [] : _b, value = _a.value,
// Извлекаем свойства, т.к. они не нужны на DOM узле
// FIXME: https://github.com/bem/bem-react/issues/381
// @ts-ignore
_view = _a.view,
// @ts-ignore
_size = _a.size,
// @ts-ignore
_theme = _a.theme;
var Radio = di_1.useComponentRegistry(exports.cnRadiobox()).Radio;
var _c = tslib_1.__read(react_1.useState({ onChange: onChange, value: value, disabled: disabled, name: name }), 2), context = _c[0], setContext = _c[1];
react_1.useEffect(function () {
setContext({ onChange: onChange, value: value, disabled: disabled, name: name });
}, [onChange, value, disabled, name]);
return (react_1.default.createElement("span", { className: exports.cnRadiobox(null, [className]), ref: innerRef, role: "radiogroup" },
react_1.default.createElement(Radiobox_context_1.RadioGroupProvider, { value: context }, children || options.map(function (_a) {
var label = _a.label, option = tslib_1.__rest(_a, ["label"]);
return (react_1.default.createElement(Radio, tslib_1.__assign({ key: option.value }, option), label));
}))));
};
exports.Radiobox = Radiobox;
exports.Radiobox.displayName = exports.cnRadiobox();