import { createElement } from "react"; /** * External dependencies */ import classnames from 'classnames'; /** * WordPress dependencies */ import { useInstanceId } from '@wordpress/compose'; /** * Internal dependencies */ import BaseControl from '../base-control'; import { VStack } from '../v-stack'; /** * Render a user interface to select the user type using radio inputs. * * ```jsx * import { RadioControl } from '@wordpress/components'; * import { useState } from '@wordpress/element'; * * const MyRadioControl = () => { * const [ option, setOption ] = useState( 'a' ); * * return ( * setOption( value ) } * /> * ); * }; * ``` */ export function RadioControl(props) { const { label, className, selected, help, onChange, hideLabelFromVision, options = [], ...additionalProps } = props; const instanceId = useInstanceId(RadioControl); const id = `inspector-radio-control-${instanceId}`; const onChangeValue = event => onChange(event.target.value); if (!options?.length) { return null; } return createElement(BaseControl, { __nextHasNoMarginBottom: true, label: label, id: id, hideLabelFromVision: hideLabelFromVision, help: help, className: classnames(className, 'components-radio-control') }, createElement(VStack, { spacing: 1 }, options.map((option, index) => createElement("div", { key: `${id}-${index}`, className: "components-radio-control__option" }, createElement("input", { id: `${id}-${index}`, className: "components-radio-control__input", type: "radio", name: id, value: option.value, onChange: onChangeValue, checked: option.value === selected, "aria-describedby": !!help ? `${id}__help` : undefined, ...additionalProps }), createElement("label", { className: "components-radio-control__label", htmlFor: `${id}-${index}` }, option.label))))); } export default RadioControl; //# sourceMappingURL=index.js.map