mh-rn-component
Version:
54 lines (49 loc) • 2.27 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { useState } from 'react';
import { View } from 'react-native';
import Radio from '../Checkbox';
const RadioGroup = _ref => {
let {
checked,
onChange,
options,
children,
...rest
} = _ref;
const [_value, set_value] = useState(checked);
const checkRadio = value => {
// if (_value === value) {
// set_value('')
// onChange('')
// return
// }
set_value(value);
onChange(value);
};
return /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
style: rest.style
}, options && options.map((item, index) => {
return /*#__PURE__*/React.createElement(Radio, _extends({
onPress: checkRadio,
checked: item.value === _value,
key: index
}, item, rest));
})), /*#__PURE__*/React.createElement(View, {
style: rest.style
}, children && React.Children.toArray(children).map(child => {
return /*#__PURE__*/React.cloneElement(child, {
onPress: checkRadio,
checked: (child === null || child === void 0 ? void 0 : child.props.value) === _value,
name: rest.name,
disabled: (child === null || child === void 0 ? void 0 : child.props.disabled) || rest.disabled,
activeIcon: (child === null || child === void 0 ? void 0 : child.props.activeIcon) || rest.activeIcon,
inactiveIcon: (child === null || child === void 0 ? void 0 : child.props.inactiveIcon) || rest.inactiveIcon,
rightIcon: (child === null || child === void 0 ? void 0 : child.props.rightIcon) || rest.rightIcon,
checkedColor: (child === null || child === void 0 ? void 0 : child.props.checkedColor) || rest.checkedColor,
children: child === null || child === void 0 ? void 0 : child.props.children,
iconSize: (child === null || child === void 0 ? void 0 : child.props.iconSize) || rest.iconSize
});
})));
};
export default RadioGroup;
//# sourceMappingURL=index.js.map