@ozen-ui/kit
Version:
React component library
59 lines (58 loc) • 3.62 kB
JavaScript
import { __assign, __rest } from "tslib";
import './Radio.css';
import React, { forwardRef } from 'react';
import { useThemeProps } from '../../hooks/useThemeProps';
import { cn } from '../../utils/classname';
import { FormControlCarcass } from '../FormControlCarcass';
import { useRadioGroupContext } from '../RadioGroupNext';
import { RADIO_DEFAULT_DISABLED, RADIO_DEFAULT_MIRRORED, RADIO_DEFAULT_VARIANT, RADIO_DEFAULT_ALIGN, RADIO_DEFAULT_SIZE, } from './constants';
export var cnRadio = cn('RadioNext');
export var Radio = forwardRef(function (inProps, ref) {
var props = useThemeProps({
props: inProps,
name: 'RadioNext',
});
var _a = props.align, alignProp = _a === void 0 ? RADIO_DEFAULT_ALIGN : _a, _b = props.mirrored, mirroredProp = _b === void 0 ? RADIO_DEFAULT_MIRRORED : _b, hint = props.hint, hintProps = props.hintProps, renderAfter = props.renderAfter, renderAfterProps = props.renderAfterProps, dataTestid = props.dataTestid, _c = props.variant, variantProp = _c === void 0 ? RADIO_DEFAULT_VARIANT : _c, _d = props.size, sizeProp = _d === void 0 ? RADIO_DEFAULT_SIZE : _d, onChangeProp = props.onChange, checkedProp = props.checked, nameProp = props.name, className = props.className, label = props.label, carcassProps = props.carcassProps, _e = props.disabled, disabled = _e === void 0 ? RADIO_DEFAULT_DISABLED : _e, inputRef = props.inputRef, other = __rest(props, ["align", "mirrored", "hint", "hintProps", "renderAfter", "renderAfterProps", "dataTestid", "variant", "size", "onChange", "checked", "name", "className", "label", "carcassProps", "disabled", "inputRef"]);
var radioGroup = useRadioGroupContext();
var checked = checkedProp;
var name = nameProp;
var size = sizeProp;
var variant = variantProp;
var align = alignProp;
var mirrored = mirroredProp;
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;
}
if (inProps.variant === undefined && radioGroup.variant) {
variant = radioGroup.variant;
}
if (inProps.align === undefined && radioGroup.align) {
align = radioGroup.align;
}
if (inProps.mirrored === undefined && radioGroup.mirrored) {
mirrored = radioGroup.mirrored;
}
}
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(FormControlCarcass, __assign({}, carcassProps, { ref: ref, size: size, variant: variant, align: align, mirrored: mirrored, hint: hint, label: label, hintProps: hintProps, disabled: disabled, className: cnRadio({
disabled: disabled,
variant: variant,
mirrored: mirrored,
size: size,
}, [className]), controlProps: {
className: cnRadio('Box'),
}, renderAfter: renderAfter, renderAfterProps: renderAfterProps, "data-testid": dataTestid }),
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('BoxRadio') })));
});
Radio.displayName = 'Radio';