@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
47 lines (46 loc) • 1.64 kB
JavaScript
"use client";
import { useProps } from "../../../core/MantineProvider/use-props/use-props.mjs";
import { genericFactory } from "../../../core/factory/factory.mjs";
import { Input } from "../../Input/Input.mjs";
import { InputsGroupFieldset } from "../../../utils/InputsGroupFieldset/InputsGroupFieldset.mjs";
import { createContext } from "react";
import { useId as useId$1, useUncontrolled } from "@mantine/hooks";
import { jsx } from "react/jsx-runtime";
//#region packages/@mantine/core/src/components/Radio/RadioGroup/RadioGroup.tsx
const RadioGroupContext = createContext(null);
const RadioGroup = genericFactory(((props) => {
const { value, defaultValue, onChange, size, wrapperProps, children, name, readOnly, disabled, ...others } = useProps("RadioGroup", null, props);
const _name = useId$1(name);
const [_value, setValue] = useUncontrolled({
value,
defaultValue,
finalValue: "",
onChange
});
const handleChange = (event) => !readOnly && setValue(typeof event === "string" ? event : event.currentTarget.value);
return /* @__PURE__ */ jsx(RadioGroupContext, {
value: {
value: _value,
onChange: handleChange,
size,
name: _name,
disabled
},
children: /* @__PURE__ */ jsx(Input.Wrapper, {
size,
...wrapperProps,
...others,
labelElement: "div",
__staticSelector: "RadioGroup",
children: /* @__PURE__ */ jsx(InputsGroupFieldset, {
role: "radiogroup",
children
})
})
});
}));
RadioGroup.classes = Input.Wrapper.classes;
RadioGroup.displayName = "@mantine/core/RadioGroup";
//#endregion
export { RadioGroup, RadioGroupContext };
//# sourceMappingURL=RadioGroup.mjs.map