@yamada-ui/radio
Version:
Yamada UI radio component
107 lines (105 loc) • 2.41 kB
JavaScript
"use client"
import {
RadioCard
} from "./chunk-R7JQ4H4D.mjs";
import {
useRadioGroup
} from "./chunk-RSGQTWJA.mjs";
import {
RadioCardGroupProvider
} from "./chunk-ZLJHOIFP.mjs";
// src/radio-card-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 RadioCardGroup = forwardRef(
({
id: idProp,
className,
colorScheme,
size,
variant,
children,
direction = "row",
gap = "0.5rem",
items = [],
withIcon = true,
addonProps,
descriptionProps,
labelProps,
...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, i) => /* @__PURE__ */ jsx(RadioCard, { ...props2 }, i));
return /* @__PURE__ */ jsx(
RadioCardGroupProvider,
{
value: {
name,
colorScheme,
size,
variant,
disabled,
invalid,
readOnly,
required,
value,
withIcon,
addonProps,
descriptionProps,
labelProps,
onChange
},
children: /* @__PURE__ */ jsx(
Flex,
{
ref,
className: cx("ui-radio-card-group", className),
gap,
w: "100%",
...getContainerProps({
id,
"aria-labelledby": labelId,
...rest
}),
direction,
children: children != null ? children : computedChildren
}
)
}
);
}
);
RadioCardGroup.displayName = "RadioCardGroup";
RadioCardGroup.__ui__ = "RadioCardGroup";
export {
RadioCardGroup
};
//# sourceMappingURL=chunk-MMHQMCQ2.mjs.map