UNPKG

@visactor/react-vtable

Version:

The react version of VTable

48 lines (41 loc) 1.95 kB
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 { Checkbox as VCheckbox } from "../vrender-components/checkbox"; import { merge } from "@visactor/vutils"; import React, { useCallback, useEffect } from "react"; const defaultProps = {}; function CheckboxComponent(baseProps, ref) { const props = merge({}, defaultProps, baseProps), {textStyle: textStyle, boxStyle: boxStyle, iconStyle: iconStyle, children: children} = props, rest = __rest(props, [ "textStyle", "boxStyle", "iconStyle", "children" ]); let checkboxRef = React.useRef(null); checkboxRef = ref || checkboxRef; const handleChange = useCallback((event => { props.onChange && props.onChange(event.target.attribute.checked); }), []); return useEffect((() => { var _a; return null === (_a = checkboxRef.current) || void 0 === _a || _a.addEventListener("checkbox_state_change", handleChange), () => { var _a; null === (_a = checkboxRef.current) || void 0 === _a || _a.removeEventListener("checkbox_state_change", handleChange); }; }), []), React.createElement(VCheckbox, Object.assign({ ref: checkboxRef, attribute: Object.assign({ text: Object.assign(Object.assign({}, textStyle), { text: children }), box: boxStyle, icon: iconStyle }, rest) }, rest)); } export const Checkbox = React.forwardRef(CheckboxComponent); Checkbox.displayName = "Checkbox"; //# sourceMappingURL=checkbox.js.map