@visactor/react-vtable
Version:
The react version of VTable
47 lines (40 loc) • 1.84 kB
JavaScript
var __rest = this && this.__rest || function(s, e) {
var t = {};
for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
var i = 0;
for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
}
return t;
};
import { Radio as VRadio } from "../vrender-components/radio";
import { merge } from "@visactor/vutils";
import React, { useCallback, useEffect } from "react";
const defaultProps = {};
function RadioComponent(baseProps, ref) {
const props = merge({}, defaultProps, baseProps), {textStyle: textStyle, circleStyle: circleStyle, children: children} = props, rest = __rest(props, [ "textStyle", "circleStyle", "children" ]);
let radioRef = React.useRef(null);
radioRef = ref || radioRef;
const handleChange = useCallback((event => {
props.onChange && props.onChange(event.target.attribute.checked);
}), []);
return useEffect((() => {
var _a;
return null === (_a = radioRef.current) || void 0 === _a || _a.addEventListener("radio_checked", handleChange),
() => {
var _a;
null === (_a = radioRef.current) || void 0 === _a || _a.removeEventListener("radio_checked", handleChange);
};
}), []), React.createElement(VRadio, Object.assign({
ref: radioRef,
attribute: Object.assign({
text: Object.assign(Object.assign({}, textStyle), {
text: children
}),
circle: circleStyle
}, rest)
}, rest));
}
export const Radio = React.forwardRef(RadioComponent);
Radio.displayName = "Radio";
//# sourceMappingURL=radio.js.map