@yamada-ui/radio
Version:
Yamada UI radio component
124 lines (122 loc) • 3.98 kB
JavaScript
"use client"
import {
RadioCardAddon
} from "./chunk-YRIADAI7.mjs";
import {
RadioCardDescription
} from "./chunk-27VC2SJI.mjs";
import {
RadioCardLabel
} from "./chunk-Q5GTUIUF.mjs";
import {
useRadio
} from "./chunk-QJKELJFS.mjs";
import {
RadioCardProvider,
useRadioCardGroupContext
} from "./chunk-ZLJHOIFP.mjs";
// src/radio-card.tsx
import { omitThemeProps, ui, useComponentMultiStyle } from "@yamada-ui/core";
import { useFormControl } from "@yamada-ui/form-control";
import {
cx,
findChild,
funcAll,
getValidChildren,
isEmpty,
omitChildren
} from "@yamada-ui/utils";
import { forwardRef } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var RadioCard = forwardRef(
(props, ref) => {
var _a, _b, _c, _d, _e;
const group = useRadioCardGroupContext();
const { value: groupValue, ...groupProps } = { ...group };
const control = useFormControl(props);
const [styles, mergedProps] = useComponentMultiStyle("RadioCard", {
...groupProps,
...props
});
const {
className,
addon,
children,
description,
disabled = (_a = groupProps.disabled) != null ? _a : control.disabled,
invalid = (_b = groupProps.invalid) != null ? _b : control.invalid,
label,
readOnly = (_c = groupProps.readOnly) != null ? _c : control.readOnly,
required = (_d = groupProps.required) != null ? _d : control.required,
withIcon = true,
addonProps,
descriptionProps,
iconProps,
inputProps,
labelProps,
...computedProps
} = omitThemeProps(mergedProps);
(_e = computedProps.checked) != null ? _e : computedProps.checked = computedProps.isChecked;
const checkedProp = groupValue && computedProps.value ? groupValue === computedProps.value : computedProps.checked;
const onChange = groupProps.onChange && computedProps.value ? funcAll(groupProps.onChange, computedProps.onChange) : computedProps.onChange;
const {
checked,
props: rest,
getContainerProps,
getIconProps,
getInputProps
} = useRadio({
...computedProps,
checked: checkedProp,
disabled,
invalid,
readOnly,
required,
onChange
});
const tabIndex = !groupValue ? 0 : checked ? 0 : -1;
const validChildren = getValidChildren(children);
const customLabel = findChild(validChildren, RadioCardLabel);
const customDescription = findChild(validChildren, RadioCardDescription);
const customAddon = findChild(validChildren, RadioCardAddon);
const computedChildren = !isEmpty(validChildren) ? omitChildren(
validChildren,
RadioCardLabel,
RadioCardDescription,
RadioCardAddon
) : children;
return /* @__PURE__ */ jsx(RadioCardProvider, { value: { styles, withIcon, getIconProps, iconProps }, children: /* @__PURE__ */ jsxs(
ui.label,
{
className: cx("ui-radio-card", className),
...getContainerProps(rest),
__css: { ...styles.container },
children: [
/* @__PURE__ */ jsx(
ui.input,
{
className: "ui-radio-card__input",
...getInputProps(
{
...inputProps,
tabIndex
},
ref
)
}
),
customLabel != null ? customLabel : label ? /* @__PURE__ */ jsx(RadioCardLabel, { ...labelProps, children: label }) : null,
customDescription != null ? customDescription : description ? /* @__PURE__ */ jsx(RadioCardDescription, { ...descriptionProps, children: description }) : null,
customAddon != null ? customAddon : addon ? /* @__PURE__ */ jsx(RadioCardAddon, { ...addonProps, children: addon }) : null,
computedChildren
]
}
) });
}
);
RadioCard.displayName = "RadioCard";
RadioCard.__ui__ = "RadioCard";
export {
RadioCard
};
//# sourceMappingURL=chunk-R7JQ4H4D.mjs.map