UNPKG

@yandex/ui

Version:

Yandex UI components

26 lines (25 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RadioboxRadio = void 0; var tslib_1 = require("tslib"); var react_1 = tslib_1.__importDefault(require("react")); var withControl_1 = require("../../withControl/withControl"); var useUniqId_1 = require("../../useUniqId"); var env_1 = require("../../lib/env"); var Radiobox_Box_1 = require("../Box/Radiobox-Box"); var Radiobox_Control_1 = require("../Control/Radiobox-Control"); var Radiobox_1 = require("../Radiobox"); var Radiobox_context_1 = require("../Radiobox.context"); require("./Radiobox-Radio.css"); exports.RadioboxRadio = withControl_1.withControl(function (_a) { var autoFocus = _a.autoFocus, htmlChecked = _a.checked, children = _a.children, className = _a.className, controlRef = _a.controlRef, htmlDisabled = _a.disabled, focused = _a.focused, innerRef = _a.innerRef, name = _a.name, onBlur = _a.onBlur, onChange = _a.onChange, onClick = _a.onClick, onFocus = _a.onFocus, onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave, pressed = _a.pressed, value = _a.value; var radioGroup = Radiobox_context_1.useRadioGroup(); var checked = radioGroup.value ? radioGroup.value === value : htmlChecked; var disabled = radioGroup.disabled || htmlDisabled; var radioId = env_1.IS_TESTING ? '0' : useUniqId_1.useUniqId('radio'); var labelledById = "label-" + radioId; return (react_1.default.createElement("label", { className: Radiobox_1.cnRadiobox('Radio', { checked: checked, disabled: disabled, focused: focused, pressed: pressed }, [className]), onBlur: onBlur, onClick: onClick, onFocus: onFocus, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, ref: innerRef }, react_1.default.createElement(Radiobox_Box_1.RadioboxBox, null, react_1.default.createElement(Radiobox_Control_1.RadioboxControl, { autoFocus: autoFocus, checked: checked, controlRef: controlRef, disabled: disabled, labelledBy: labelledById, name: radioGroup.name || name, onChange: radioGroup.onChange || onChange, value: value })), react_1.default.createElement("span", { "aria-hidden": "true", className: Radiobox_1.cnRadiobox('Text'), id: labelledById }, children))); });