@mabi-ui/radio
Version:
Radio group and radio button components for Mabi-UI
69 lines (67 loc) • 2.1 kB
JavaScript
"use client";import {
radioGroup
} from "./chunk-VZETEH6S.mjs";
// src/RadioGroup.tsx
import { PreflightWrapper } from "@mabi-ui/preflight";
import { Typography } from "@mabi-ui/typography";
import { cn } from "@mabi-ui/utils";
import React, {
createContext,
forwardRef
} from "react";
import { useRadioGroup } from "react-aria";
import { useRadioGroupState } from "react-stately";
var RadioContext = createContext(null);
var RadioGroup = forwardRef(
({ color, className, ...props }, ref) => {
const {
children,
label,
description,
errorMessage,
orientation = "vertical"
} = props;
const state = useRadioGroupState(props);
const { radioGroupProps, labelProps, descriptionProps, errorMessageProps } = useRadioGroup(props, state);
return /* @__PURE__ */ React.createElement(PreflightWrapper, null, /* @__PURE__ */ React.createElement("div", { ...radioGroupProps, className }, Boolean(label) && (typeof label === "string" ? /* @__PURE__ */ React.createElement(
Typography,
{
children: label,
variant: "subtitle2",
className: "dark:text-white",
...labelProps
}
) : label), Boolean(description) && (typeof description === "string" ? /* @__PURE__ */ React.createElement(
Typography,
{
children: description,
variant: "caption",
...descriptionProps,
className: "mt-1 text-black/70 dark:text-white/70"
}
) : description), /* @__PURE__ */ React.createElement(RadioContext.Provider, { value: { state, color } }, /* @__PURE__ */ React.createElement(
"div",
{
ref,
className: cn(
radioGroup({ orientation }),
"RadioGroup-container"
)
},
children
)), Boolean(errorMessage) && /* @__PURE__ */ React.createElement(
Typography,
{
children: errorMessage,
variant: "caption",
...errorMessageProps,
className: "text-error"
}
)));
}
);
export {
RadioContext,
RadioGroup
};
//# sourceMappingURL=chunk-5YH4EE2M.mjs.map