@trail-ui/react
Version:
81 lines (79 loc) • 3.95 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/radio/radio-group.tsx
var radio_group_exports = {};
__export(radio_group_exports, {
RadioGroup: () => _RadioGroup,
RadioGroupThemeContext: () => RadioGroupThemeContext
});
module.exports = __toCommonJS(radio_group_exports);
var import_shared_utils = require("@trail-ui/shared-utils");
var import_theme = require("@trail-ui/theme");
var import_react = require("react");
var import_react_aria_components = require("react-aria-components");
var import_icons = require("@trail-ui/icons");
var import_jsx_runtime = require("react/jsx-runtime");
var RadioGroupThemeContext = (0, import_react.createContext)({});
function RadioGroup(props, ref) {
const { label, className, classNames, color, size, children, ...otherProps } = props;
const slots = (0, import_react.useMemo)(() => (0, import_theme.radioGroup)(), []);
const baseStyles = (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.base, className);
(0, import_react.useEffect)(() => {
const radioGroup2 = document.querySelector('[role="radiogroup"]');
if (radioGroup2) {
radioGroup2 == null ? void 0 : radioGroup2.removeAttribute("aria-orientation");
}
}, []);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.RadioGroup, { ref, className: slots.base({ class: baseStyles }), ...otherProps, children: (renderProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.Label, { className: slots.label({ class: classNames == null ? void 0 : classNames.label }), children: label }),
children && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadioGroupThemeContext.Provider, { value: { color, size }, children: typeof children === "function" ? children(renderProps) : children }) }),
props.errorMessage ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
import_react_aria_components.Text,
{
slot: "errorMessage",
className: `${slots.errorMessage({ class: classNames == null ? void 0 : classNames.errorMessage })} flex flex-row items-center gap-0.5`,
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_icons.ErrorIcon,
{
role: "img",
"aria-label": "Error",
"aria-hidden": "false",
className: "h-4 w-4 text-red-600"
}
),
props.errorMessage
]
}
) : props.description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_aria_components.Text,
{
slot: "description",
className: slots.description({ class: classNames == null ? void 0 : classNames.description }),
children: props.description
}
) : null
] }) });
}
var _RadioGroup = (0, import_react.forwardRef)(RadioGroup);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
RadioGroup,
RadioGroupThemeContext
});