@wordpress/components
Version:
UI components for WordPress.
64 lines (61 loc) • 1.64 kB
JavaScript
/**
* External dependencies
*/
import * as Ariakit from '@ariakit/react';
/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
import { useMemo, forwardRef } from '@wordpress/element';
import { isRTL } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import ButtonGroup from '../button-group';
import { RadioGroupContext } from './context';
import { jsx as _jsx } from "react/jsx-runtime";
function UnforwardedRadioGroup({
label,
checked,
defaultChecked,
disabled,
onChange,
children,
...props
}, ref) {
const radioStore = Ariakit.useRadioStore({
value: checked,
defaultValue: defaultChecked,
setValue: newValue => {
onChange?.(newValue !== null && newValue !== void 0 ? newValue : undefined);
},
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: children
}),
"aria-label": label,
ref: ref,
...props
})
});
}
/**
* @deprecated Use `RadioControl` or `ToggleGroupControl` instead.
*/
export const RadioGroup = forwardRef(UnforwardedRadioGroup);
export default RadioGroup;
//# sourceMappingURL=index.js.map