@wordpress/components
Version:
UI components for WordPress.
54 lines (49 loc) • 1.41 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { createElement } from "@wordpress/element";
/**
* External dependencies
*/
import { isEmpty } from 'lodash';
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
/**
* Internal dependencies
*/
import BaseControl from '../base-control';
export default function RadioControl({
label,
className,
selected,
help,
onChange,
options = [],
...props
}) {
const instanceId = useInstanceId(RadioControl);
const id = `inspector-radio-control-${instanceId}`;
const onChangeValue = event => onChange(event.target.value);
return !isEmpty(options) && createElement(BaseControl, {
label: label,
id: id,
help: help,
className: classnames(className, 'components-radio-control')
}, options.map((option, index) => createElement("div", {
key: `${id}-${index}`,
className: "components-radio-control__option"
}, createElement("input", _extends({
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
}, props)), createElement("label", {
htmlFor: `${id}-${index}`
}, option.label))));
}
//# sourceMappingURL=index.js.map