@yamada-ui/radio
Version:
Yamada UI radio component
98 lines (96 loc) • 2.23 kB
JavaScript
"use client"
import {
Radio
} from "./chunk-RA4K44ZS.mjs";
import {
useRadioGroup
} from "./chunk-RSGQTWJA.mjs";
import {
RadioGroupProvider
} from "./chunk-ZLJHOIFP.mjs";
// src/radio-group.tsx
import { useFormControl } from "@yamada-ui/form-control";
import { Flex } from "@yamada-ui/layouts";
import { cx, getValidChildren } from "@yamada-ui/utils";
import { forwardRef } from "react";
import { jsx } from "react/jsx-runtime";
var RadioGroup = forwardRef(
({
id: idProp,
className,
colorScheme,
size,
variant,
children,
direction = "column",
gap,
items = [],
...props
}, ref) => {
const {
disabled,
invalid,
isDisabled: _isDisabled,
isInvalid: _isInvalid,
isReadOnly: _isReadOnly,
isRequired: _isRequired,
labelId,
readOnly,
required,
...computedProps
} = useFormControl({
id: idProp,
...props
});
const {
id,
name,
props: rest,
value,
getContainerProps,
onChange
} = useRadioGroup(computedProps);
const validChildren = getValidChildren(children);
let computedChildren = [];
if (!validChildren.length && items.length)
computedChildren = items.map((props2, index) => /* @__PURE__ */ jsx(Radio, { ...props2 }, index));
return /* @__PURE__ */ jsx(
RadioGroupProvider,
{
value: {
name,
colorScheme,
size,
variant,
disabled,
invalid,
readOnly,
required,
value,
onChange
},
children: /* @__PURE__ */ jsx(
Flex,
{
ref,
className: cx("ui-radio-group", className),
gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
...getContainerProps({
id,
"aria-labelledby": labelId,
...rest
}),
direction,
children: children != null ? children : computedChildren
}
)
}
);
}
);
RadioGroup.displayName = "RadioGroup";
RadioGroup.__ui__ = "RadioGroup";
export {
RadioGroup
};
//# sourceMappingURL=chunk-3BH4NFIL.mjs.map