UNPKG

@ray-js/components

Version:

Ray basic components

54 lines 1.75 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; import "core-js/modules/esnext.iterator.constructor.js"; import "core-js/modules/esnext.iterator.map.js"; import * as React from 'react'; import { useEventListener } from 'ahooks'; import handleProps from '../utils/handleProps'; const RadioGroup = props => { const { options, disabled, children } = props; const currentNode = React.useRef(null); useEventListener('change', e => { var _props$onChange; !disabled && ((_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, _objectSpread(_objectSpread({}, e), {}, { type: 'change', value: e.detail.value }))); }, { target: currentNode }); return ( /*#__PURE__*/ // @ts-ignore React.createElement("v-radio-group", _extends({}, handleProps(props), { ref: currentNode }), children || (() => { return options.map((item, index) => { var _item$checked; const radioProps = { value: item.value, color: item.color }; if ((_item$checked = item.checked) !== null && _item$checked !== void 0 ? _item$checked : false) { radioProps.checked = true; } if (disabled || item.disabled || false) { radioProps.disabled = true; } return ( /*#__PURE__*/ // @ts-ignore React.createElement("label", { key: index + '_' + item.value }, /*#__PURE__*/React.createElement("v-radio", radioProps), item.label) ); }); })()) ); }; RadioGroup.displayName = 'RadioGroup'; export default RadioGroup;