@gravity-ui/uikit
Version:
Gravity UI base styling and components
28 lines (27 loc) • 1.45 kB
JavaScript
'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { createElement as _createElement } from "react";
import * as React from 'react';
import { useRadioGroup } from "../../hooks/private/index.js";
import { Radio } from "../Radio/index.js";
import { useDefaultProps } from "../theme/useDefaultProps.js";
import { block } from "../utils/cn.js";
import "./RadioGroup.css";
const b = block('radio-group');
export const RadioGroup = React.forwardRef(function RadioGroup(rawProps, ref) {
const props = useDefaultProps('RadioGroup', rawProps);
const { size = 'm', direction = 'horizontal', style, className, optionClassName, qa, children, } = props;
let options = props.options;
if (!options) {
options = React.Children.toArray(children).map(({ props: radioProps }) => ({
value: radioProps.value,
content: radioProps.content || radioProps.children,
disabled: radioProps.disabled,
qa: radioProps.qa,
}));
}
const { containerProps, optionsProps } = useRadioGroup({ ...props, options });
return (_jsx("div", { ...containerProps, ref: ref, style: style, className: b({ size, direction }, className), "data-qa": qa, children: optionsProps.map((optionProps) => (_createElement(Radio, { ...optionProps, key: optionProps.value, className: b('option', optionClassName), size: size }))) }));
});
RadioGroup.Option = Radio;
//# sourceMappingURL=RadioGroup.js.map