UNPKG

@gechiui/components

Version:
57 lines (52 loc) 1.51 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@gechiui/element"; /** * External dependencies */ import { isEmpty } from 'lodash'; import classnames from 'classnames'; /** * GeChiUI dependencies */ import { useInstanceId } from '@gechiui/compose'; /** * Internal dependencies */ import BaseControl from '../base-control'; export default function RadioControl(_ref) { let { label, className, selected, help, onChange, hideLabelFromVision, options = [], ...props } = _ref; 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, hideLabelFromVision: hideLabelFromVision, 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