UNPKG

@wordpress/components

Version:
48 lines (43 loc) 1.17 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@wordpress/element"; /** * External dependencies */ import { useRadioState, RadioGroup as ReakitRadioGroup } from 'reakit/Radio'; /** * WordPress dependencies */ import { forwardRef } from '@wordpress/element'; /** * Internal dependencies */ import ButtonGroup from '../button-group'; import RadioContext from '../radio-context'; function RadioGroup({ label, checked, defaultChecked, disabled, onChange, ...props }, ref) { const radioState = useRadioState({ state: defaultChecked, baseId: props.id }); const radioContext = { ...radioState, disabled, // controlled or uncontrolled state: checked !== null && checked !== void 0 ? checked : radioState.state, setState: onChange !== null && onChange !== void 0 ? onChange : radioState.setState }; return createElement(RadioContext.Provider, { value: radioContext }, createElement(ReakitRadioGroup, _extends({ ref: ref, as: ButtonGroup, "aria-label": label }, radioState, props))); } export default forwardRef(RadioGroup); //# sourceMappingURL=index.js.map