UNPKG

@yandex/ui

Version:

Yandex UI components

22 lines (21 loc) 1.88 kB
import React from 'react'; import { withControl } from '../../withControl/withControl'; import { useUniqId } from '../../useUniqId'; import { IS_TESTING } from '../../lib/env'; import { RadioboxBox as Box } from '../Box/Radiobox-Box'; import { RadioboxControl as Control } from '../Control/Radiobox-Control'; import { cnRadiobox as cn } from '../Radiobox'; import { useRadioGroup } from '../Radiobox.context'; import './Radiobox-Radio.css'; export var RadioboxRadio = 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 = useRadioGroup(); var checked = radioGroup.value ? radioGroup.value === value : htmlChecked; var disabled = radioGroup.disabled || htmlDisabled; var radioId = IS_TESTING ? '0' : useUniqId('radio'); var labelledById = "label-" + radioId; return (React.createElement("label", { className: cn('Radio', { checked: checked, disabled: disabled, focused: focused, pressed: pressed }, [className]), onBlur: onBlur, onClick: onClick, onFocus: onFocus, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, ref: innerRef }, React.createElement(Box, null, React.createElement(Control, { autoFocus: autoFocus, checked: checked, controlRef: controlRef, disabled: disabled, labelledBy: labelledById, name: radioGroup.name || name, onChange: radioGroup.onChange || onChange, value: value })), React.createElement("span", { "aria-hidden": "true", className: cn('Text'), id: labelledById }, children))); });