UNPKG

acud

Version:

acg react 组件库

65 lines • 2.85 kB
import _extends from "@babel/runtime/helpers/esm/extends"; var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; // @ts-nocheck rc have bug import * as React from 'react'; import { ConfigContext } from '../config-provider'; import ButtonCheckbox from './ButtonCheckbox'; import { GroupContext } from './Group'; var GroupButtonCheckbox = function GroupButtonCheckbox(_a) { var customizePrefixCls = _a.prefixCls, className = _a.className, children = _a.children, style = _a.style, restProps = __rest(_a, ["prefixCls", "className", "children", "style"]); var _React$useContext = React.useContext(ConfigContext), getPrefixCls = _React$useContext.getPrefixCls; var checkboxGroup = React.useContext(GroupContext); var prevValue = React.useRef(restProps.value); React.useEffect(function () { checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.registerValue(restProps.value); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); React.useEffect(function () { if (restProps.value !== prevValue.current) { checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.cancelValue(prevValue.current); checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.registerValue(restProps.value); } return function () { return checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.cancelValue(restProps.value); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [restProps.value]); var prefixCls = getPrefixCls('checkbox', customizePrefixCls); var checkboxProps = _extends({}, restProps); if (checkboxGroup) { checkboxProps.onChange = function () { if (restProps.onChange) { restProps.onChange.apply(restProps, arguments); } if (checkboxGroup.toggleOption) { checkboxGroup.toggleOption({ label: children, value: restProps.value }); } }; checkboxProps.name = checkboxGroup.name; checkboxProps.checked = checkboxGroup.value.indexOf(restProps.value) !== -1; checkboxProps.disabled = restProps.disabled || checkboxGroup.disabled; } return /*#__PURE__*/React.createElement(ButtonCheckbox, _extends({}, checkboxProps, { prefixCls: prefixCls, children: children, style: style, className: className })); }; GroupButtonCheckbox.displayName = 'GroupButtonCheckbox'; export default GroupButtonCheckbox;