UNPKG

@ozen-ui/kit

Version:

React component library

50 lines (49 loc) 2.87 kB
import { __assign, __rest } from "tslib"; import './Radio.css'; import React, { useContext, forwardRef } from 'react'; import { useDeprecatedComponent } from '../../hooks/useDeprecated'; import { useThemeProps } from '../../hooks/useThemeProps'; import { cn } from '../../utils/classname'; import { FormControlLabel } from '../FormControlLabel'; import { RadioGroupContext } from '../RadioGroup/RadioGroupContext'; import { RADIO_DEFAULT_ALIGN, RADIO_DEFAULT_LABEL_PLACEMENT, RADIO_DEFAULT_SIZE, } from './constants'; export var cnRadio = cn('Radio'); /** * @deprecated Компонент устарел. Для замены используйте компонент RadioNext */ export var Radio = forwardRef(function (inProps, ref) { useDeprecatedComponent('Radio'); var props = useThemeProps({ props: inProps, name: 'Radio', }); var _a = props.align, align = _a === void 0 ? RADIO_DEFAULT_ALIGN : _a, _b = props.labelPlacement, labelPlacement = _b === void 0 ? RADIO_DEFAULT_LABEL_PLACEMENT : _b, _c = props.size, sizeProp = _c === void 0 ? RADIO_DEFAULT_SIZE : _c, onChangeProp = props.onChange, checkedProp = props.checked, nameProp = props.name, className = props.className, label = props.label, labelProps = props.labelProps, disabled = props.disabled, inputRef = props.inputRef, other = __rest(props, ["align", "labelPlacement", "size", "onChange", "checked", "name", "className", "label", "labelProps", "disabled", "inputRef"]); var radioGroup = useContext(RadioGroupContext); var checked = checkedProp; var name = nameProp; var size = sizeProp; if (radioGroup) { if (checked === undefined && radioGroup.value) { checked = radioGroup.value === other.value; } if (name === undefined && radioGroup.name) { name = radioGroup.name; } if (inProps.size === undefined && radioGroup.size) { size = radioGroup.size; } } var onChange = function (event) { onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(event); radioGroup === null || radioGroup === void 0 ? void 0 : radioGroup.onChange(event); }; return (React.createElement(FormControlLabel, __assign({ label: label, size: size, labelPlacement: labelPlacement, disabled: disabled, align: align, className: className, ref: ref }, labelProps), React.createElement("span", { className: cnRadio({ size: size, disabled: disabled, checked: checked, }) }, React.createElement("input", __assign({ className: cnRadio('Input'), disabled: disabled, checked: checked, onChange: onChange, name: name }, other, { type: "radio", ref: inputRef })), React.createElement("span", { className: cnRadio('Box') })))); }); Radio.displayName = 'Radio';