@wordpress/components
Version:
UI components for WordPress.
47 lines (46 loc) • 1.51 kB
JavaScript
import * as Ariakit from "@ariakit/react";
import deprecated from "@wordpress/deprecated";
import { forwardRef, useMemo } from "@wordpress/element";
import { isRTL } from "@wordpress/i18n";
import ButtonGroup from "../button-group/index.mjs";
import { RadioGroupContext } from "./context.mjs";
import { jsx } from "react/jsx-runtime";
// packages/components/src/radio-group/index.tsx
function UnforwardedRadioGroup({ label, checked, defaultChecked, disabled, onChange, children, ...props }, ref) {
const radioStore = Ariakit.useRadioStore({
value: checked,
defaultValue: defaultChecked,
setValue: (newValue) => {
onChange?.(newValue ?? void 0);
},
rtl: isRTL()
});
const contextValue = useMemo(() => ({
store: radioStore,
disabled
}), [radioStore, disabled]);
deprecated("wp.components.__experimentalRadioGroup", {
alternative: "wp.components.RadioControl or wp.components.__experimentalToggleGroupControl",
since: "6.8"
});
return /* @__PURE__ */ jsx(RadioGroupContext.Provider, {
value: contextValue,
children: /* @__PURE__ */ jsx(Ariakit.RadioGroup, {
store: radioStore,
render: /* @__PURE__ */ jsx(ButtonGroup, {
__shouldNotWarnDeprecated: true,
children
}),
"aria-label": label,
ref,
...props
})
});
}
/**
* @deprecated Use `RadioControl` or `ToggleGroupControl` instead.
*/
const RadioGroup = forwardRef(UnforwardedRadioGroup);
RadioGroup.displayName = "RadioGroup";
export { RadioGroup, RadioGroup as default };
//# sourceMappingURL=index.mjs.map